3531: Look up relevant portion of uuid->{user,group} map when loading projects tab.
[arvados.git] / apps / workbench / app / views / projects / _show_sharing.html.erb
1 <%
2    uuid_map = {}
3    if @share_links
4      [User, Group].each do |type|
5        type.filter([['uuid','in',@share_links.collect(&:tail_uuid)]]).each do |o|
6          uuid_map[o.uuid] = o
7        end
8      end
9    end
10    perm_name_desc_map = {}
11    perm_desc_name_map = {}
12    perms_json = []
13    ['Read', 'Write', 'Manage'].each do |link_desc|
14      link_name = "can_#{link_desc.downcase}"
15      perm_name_desc_map[link_name] = link_desc
16      perm_desc_name_map[link_desc] = link_name
17      perms_json << {value: link_name, text: link_desc}
18    end
19    perms_json = perms_json.to_json
20    choose_filters = {
21      "groups" => [["group_class", "=", nil]],
22    }
23    choose_filters.default = []
24    owner_icon = fa_icon_class_for_uuid(@object.owner_uuid)
25    if owner_icon == "fa-users"
26      owner_icon = "fa-folder"
27      owner_type = "parent project"
28    else
29      owner_type = "owning user"
30    end
31 %>
32
33 <div class="pull-right">
34   <% ["users", "groups"].each do |share_class| %>
35
36   <%= link_to(send("choose_#{share_class}_path",
37       title: "Share with #{share_class}",
38       by_project: false,
39       preview_pane: false,
40       multiple: true,
41       limit: 10000,
42       filters: choose_filters[share_class].to_json,
43       action_method: 'post',
44       action_href: share_with_project_path,
45       action_name: 'Add',
46       action_data: {selection_param: 'uuids[]', success: 'tab-refresh'}.to_json),
47       class: "btn btn-primary btn-sm", remote: true, method: 'get') do %>
48   <i class="fa fa-fw fa-plus"></i> Share with <%= share_class %>&hellip;
49   <% end %>
50
51   <% end %>
52 </div>
53
54 <p>Permissions for this project are inherited from the <%= owner_type %>
55   <i class="fa fa-fw <%= owner_icon %>"></i>
56   <%= link_to_if_arvados_object @object.owner_uuid, friendly_name: true %>.
57 </p>
58
59 <table id="project_sharing" class="topalign table" style="clear: both; margin-top: 1em;">
60   <tr>
61     <th>User/Group Name</th>
62     <th colspan="2">Project Access</th>
63   </tr>
64
65   <% @share_links.andand.each do |link|
66        shared_with = uuid_map[link.tail_uuid]
67        if shared_with.nil?
68          link_name = link.tail_uuid
69        elsif shared_with.respond_to?(:full_name)
70          link_name = shared_with.full_name
71        else
72          link_name = shared_with.name
73        end %>
74   <tr data-object-uuid="<%= link.uuid %>">
75     <td>
76       <i class="fa fa-fw <%= fa_icon_class_for_uuid(link.tail_uuid) %>"></i>
77       <%= link_to_if_arvados_object(link.tail_uuid, link_text: link_name) %>
78     </td>
79     <td><%= link_to perm_name_desc_map[link.name], '#', {
80       "data-emptytext" => "Read",
81       "data-placement" => "bottom",
82       "data-type" => "select",
83       "data-url" => url_for(action: "update", id: link.uuid, controller: "links", merge: true),
84       "data-title" => "Set #{link_name}'s access level",
85       "data-name" => "[name]",
86       "data-pk" => {id: link.tail_uuid, key: "link"}.to_json,
87       "data-value" => link.name,
88       "data-clear" => false,
89       "data-source" => perms_json,
90       "data-tpl" => "<select id=\"share_change_level\"></select>",
91       "class" => "editable form-control",
92       } %>
93     </td>
94     <td>
95       <%= link_to(
96           {action: 'destroy', id: link.uuid, controller: "links"},
97           {title: 'Revoke', class: 'btn btn-default btn-nodecorate', method: :delete,
98            data: {confirm: "Revoke #{link_name}'s access to this project?",
99                   remote: true}}) do %>
100       <i class="fa fa-fw fa-trash-o"></i>
101       <% end %>
102     </td>
103   </tr>
104   <% end %>
105 </table>