4232: remove "dependencies" entries from examples in the tutorials if the API is...
[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    choose_filters.default = []
26    owner_icon = fa_icon_class_for_uuid(@object.owner_uuid)
27    if owner_icon == "fa-users"
28      owner_icon = "fa-folder"
29      owner_type = "parent project"
30    else
31      owner_type = "owning user"
32    end
33
34    sharing_path = url_for(:controller => params['controller'], :action => 'share_with')
35 %>
36
37 <div class="pull-right">
38   <% ["users", "groups"].each do |share_class| %>
39
40   <%= link_to(send("choose_#{share_class}_path",
41       title: "Share with #{share_class}",
42       by_project: false,
43       preview_pane: false,
44       multiple: true,
45       filters: choose_filters[share_class].to_json,
46       action_method: 'post',
47       action_href: sharing_path,
48       action_name: 'Add',
49       action_data: {selection_param: 'uuids[]', success: 'tab-refresh'}.to_json),
50       class: "btn btn-primary btn-sm", remote: true) do %>
51   <i class="fa fa-fw fa-plus"></i> Share with <%= share_class %>&hellip;
52   <% end %>
53
54   <% end %>
55 </div>
56
57 <p>Permissions for this <%=@object.class_for_display.downcase%> are inherited from the <%= owner_type %>
58   <i class="fa fa-fw <%= owner_icon %>"></i>
59   <%= link_to_if_arvados_object @object.owner_uuid, friendly_name: true %>.
60 </p>
61
62 <table id="object_sharing" class="topalign table" style="clear: both; margin-top: 1em;">
63   <tr>
64     <th>User/Group Name</th>
65     <th>Email Address</th>
66     <th colspan="2"><%=@object.class_for_display%> Access</th>
67   </tr>
68
69   <% @share_links.andand.each do |link|
70        shared_with = uuid_map[link.tail_uuid]
71        if shared_with.nil?
72          link_name = link.tail_uuid
73        elsif shared_with.respond_to?(:full_name)
74          link_name = shared_with.full_name
75        else
76          link_name = shared_with.name
77        end
78        if shared_with && shared_with.respond_to?(:email)
79          email = shared_with.email
80        end
81   %>
82   <tr data-object-uuid="<%= link.uuid %>">
83     <td>
84       <i class="fa fa-fw <%= fa_icon_class_for_uuid(link.tail_uuid) %>"></i>
85       <%= link_to_if_arvados_object(link.tail_uuid, link_text: link_name) %>
86     </td>
87     <td>
88       <%= email %>
89     </td>
90     <td><%= link_to perm_name_desc_map[link.name], '#', {
91       "data-emptytext" => "Read",
92       "data-placement" => "bottom",
93       "data-type" => "select",
94       "data-url" => url_for(action: "update", id: link.uuid, controller: "links", merge: true),
95       "data-title" => "Set #{link_name}'s access level",
96       "data-name" => "[name]",
97       "data-pk" => {id: link.tail_uuid, key: "link"}.to_json,
98       "data-value" => link.name,
99       "data-clear" => false,
100       "data-source" => perms_json,
101       "data-tpl" => "<select id=\"share_change_level\"></select>",
102       "class" => "editable form-control",
103       } %>
104     </td>
105     <td>
106       <%= link_to(
107           {action: 'destroy', id: link.uuid, controller: "links"},
108           {title: 'Revoke', class: 'btn btn-default btn-nodecorate', method: :delete,
109            data: {confirm: "Revoke #{link_name}'s access to this #{@object.class_for_display.downcase}?",
110                   remote: true}}) do %>
111       <i class="fa fa-fw fa-trash-o"></i>
112       <% end %>
113     </td>
114   </tr>
115   <% end %>
116 </table>