Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / app / views / application / _show_sharing.html.erb
1 <%# Copyright (C) The Arvados Authors. All rights reserved.
2
3 SPDX-License-Identifier: AGPL-3.0 %>
4
5 <%
6    uuid_map = {}
7    if @share_links
8      [User, Group].each do |type|
9        type
10          .filter([['uuid','in',@share_links.collect(&:tail_uuid)]])
11          .with_count("none")
12          .fetch_multiple_pages(false)
13          .each do |o|
14          uuid_map[o.uuid] = o
15        end
16      end
17    end
18    perm_name_desc_map = {}
19    perm_desc_name_map = {}
20    perms_json = []
21    ['Read', 'Write', 'Manage'].each do |link_desc|
22      link_name = "can_#{link_desc.downcase}"
23      perm_name_desc_map[link_name] = link_desc
24      perm_desc_name_map[link_desc] = link_name
25      perms_json << {value: link_name, text: link_desc}
26    end
27    perms_json = perms_json.to_json
28    choose_filters = {
29      "groups" => [["group_class", "=", "role"]],
30    }
31    if Rails.configuration.Users.AnonymousUserToken.empty?
32      # It would be ideal to filter out the anonymous group by UUID,
33      # but that's not readily doable.  Workbench can't generate the
34      # UUID for a != filter, because it can't introspect the API
35      # server's UUID prefix.  And we can't say "uuid not like
36      # %-anonymouspublic", because the API server doesn't support a
37      # "not like" filter.
38      choose_filters["groups"] << ["name", "!=", "Anonymous users"]
39    end
40    choose_filters.default = []
41    owner_icon = fa_icon_class_for_uuid(@object.owner_uuid)
42    if owner_icon == "fa-users"
43      owner_icon = "fa-folder"
44      owner_type = "parent project"
45    else
46      owner_type = "owning user"
47    end
48
49    sharing_path = url_for(:controller => params['controller'], :action => 'share_with')
50 %>
51
52 <div class="pull-right">
53   <% ["users", "groups"].each do |share_class| %>
54
55   <%= link_to(send("choose_#{share_class}_path",
56       title: "Share with #{share_class}",
57       message: "Only #{share_class} you are allowed to access are shown. Please contact your administrator if you need to be added to a specific group.",
58       by_project: false,
59       preview_pane: false,
60       multiple: true,
61       filters: choose_filters[share_class].to_json,
62       action_method: 'post',
63       action_href: sharing_path,
64       action_name: 'Add',
65       action_data: {selection_param: 'uuids[]', success: 'tab-refresh'}.to_json),
66       class: "btn btn-primary btn-sm", remote: true) do %>
67   <i class="fa fa-fw fa-plus"></i> Share with <%= share_class %>&hellip;
68   <% end %>
69
70   <% end %>
71 </div>
72
73 <p>Permissions for this <%=@object.class_for_display.downcase%> are inherited from the <%= owner_type %>
74   <i class="fa fa-fw <%= owner_icon %>"></i>
75   <%= link_to_if_arvados_object @object.owner_uuid, friendly_name: true %>.
76 </p>
77
78 <% if @object.is_a? Repository %>
79 <p>
80   Please note that changes to git repository sharing may take up to two minutes to take effect.
81 </p>
82 <% end %>
83
84 <table id="object_sharing" class="topalign table" style="clear: both; margin-top: 1em;">
85   <tr>
86     <th>User/Group Name</th>
87     <th>Email Address</th>
88     <th colspan="2"><%=@object.class_for_display%> Access</th>
89   </tr>
90
91   <% @share_links.andand.each do |link|
92        shared_with = uuid_map[link.tail_uuid]
93        if shared_with.nil?
94          link_name = link.tail_uuid
95        elsif shared_with.respond_to?(:full_name)
96          link_name = shared_with.full_name
97        else
98          link_name = shared_with.name
99        end
100        if shared_with && shared_with.respond_to?(:email)
101          email = shared_with.email
102        end
103   %>
104   <tr data-object-uuid="<%= link.uuid %>">
105     <td>
106       <i class="fa fa-fw <%= fa_icon_class_for_uuid(link.tail_uuid) %>"></i>
107       <%= link_to_if_arvados_object(link.tail_uuid, link_text: link_name) %>
108     </td>
109     <td>
110       <%= email %>
111     </td>
112     <td><%= link_to perm_name_desc_map[link.name], '#', {
113       "data-emptytext" => "Read",
114       "data-placement" => "bottom",
115       "data-type" => "select",
116       "data-url" => url_for(action: "update", id: link.uuid, controller: "links", merge: true),
117       "data-title" => "Set #{link_name}'s access level",
118       "data-name" => "[name]",
119       "data-pk" => {id: link.tail_uuid, key: "link"}.to_json,
120       "data-value" => link.name,
121       "data-clear" => false,
122       "data-source" => perms_json,
123       "data-tpl" => "<select id=\"share_change_level\"></select>",
124       "class" => "editable form-control",
125       } %>
126     </td>
127     <td>
128       <%= link_to(
129           {action: 'destroy', id: link.uuid, controller: "links"},
130           {title: 'Revoke', class: 'btn btn-default btn-nodecorate', method: :delete,
131            data: {confirm: "Revoke #{link_name}'s access to this #{@object.class_for_display.downcase}?",
132                   remote: true}}) do %>
133       <i class="fa fa-fw fa-trash-o"></i>
134       <% end %>
135     </td>
136   </tr>
137   <% end %>
138 </table>