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