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