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