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