From 050e18ef86f2cb16f2ae981be8b4123ad8e08697 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Sat, 23 Aug 2014 20:00:59 -0400 Subject: [PATCH] 3171: Add administrator UI for toggling user<->role permissions. --- .../assets/javascripts/permission_toggle.js | 55 +++++++++ .../app/views/projects/_show_sharing.html.erb | 2 +- .../app/views/users/_show_admin.html.erb | 115 +++++++++++++++--- 3 files changed, 157 insertions(+), 15 deletions(-) create mode 100644 apps/workbench/app/assets/javascripts/permission_toggle.js diff --git a/apps/workbench/app/assets/javascripts/permission_toggle.js b/apps/workbench/app/assets/javascripts/permission_toggle.js new file mode 100644 index 0000000000..00c1718bd8 --- /dev/null +++ b/apps/workbench/app/assets/javascripts/permission_toggle.js @@ -0,0 +1,55 @@ +$(document). + on('click', '[data-toggle-permission] input[type=checkbox]', function() { + var data = {}; + var keys = ['data-permission-uuid', + 'data-permission-name', + 'data-permission-head', + 'data-permission-tail']; + var attr; + for(var i in keys) { + attr = keys[i]; + data[attr] = $(this).closest('[' + attr + ']').attr(attr); + if (data[attr] === undefined) { + console.log(["Error: no " + attr + " established here.", this]); + return; + } + } + var is_checked = $(this).prop('checked'); + + if (is_checked) { + $.ajax('/links', + {dataType: 'json', + type: 'POST', + data: {'link[tail_uuid]': data['data-permission-tail'], + 'link[head_uuid]': data['data-permission-head'], + 'link[link_class]': 'permission', + 'link[name]': data['data-permission-name']}, + context: this}). + fail(function(jqxhr, status, error) { + $(this).prop('checked', false); + }). + done(function(data, status, jqxhr) { + $(this).attr('data-permission-uuid', data['uuid']); + }). + always(function() { + $(this).prop('disabled', false); + }); + } + else { + $.ajax('/links/' + data['data-permission-uuid'], + {dataType: 'json', + type: 'POST', + data: {'_method': 'DELETE'}, + context: this}). + fail(function(jqxhr, status, error) { + $(this).prop('checked', true); + }). + done(function(data, status, jqxhr) { + $(this).attr('data-permission-uuid', 'x'); + }). + always(function() { + $(this).prop('disabled', false); + }); + } + $(this).prop('disabled', true); + }); diff --git a/apps/workbench/app/views/projects/_show_sharing.html.erb b/apps/workbench/app/views/projects/_show_sharing.html.erb index ff0062c24b..cafaf6dae7 100644 --- a/apps/workbench/app/views/projects/_show_sharing.html.erb +++ b/apps/workbench/app/views/projects/_show_sharing.html.erb @@ -20,7 +20,7 @@ end perms_json = perms_json.to_json choose_filters = { - "groups" => [["group_class", "=", nil]], + "groups" => [["group_class", "=", "role"]], } choose_filters.default = [] owner_icon = fa_icon_class_for_uuid(@object.owner_uuid) diff --git a/apps/workbench/app/views/users/_show_admin.html.erb b/apps/workbench/app/views/users/_show_admin.html.erb index 19c7cb90d6..8d5495093b 100644 --- a/apps/workbench/app/views/users/_show_admin.html.erb +++ b/apps/workbench/app/views/users/_show_admin.html.erb @@ -1,21 +1,108 @@ -

As an admin, you can log in as this user. When you’ve -finished, you will need to log out and log in again with your own -account.

+
+
+

+ As an admin, you can log in as this user. When you’ve + finished, you will need to log out and log in again with your + own account. +

-
-<%= button_to "Log in as #{@object.full_name}", sudo_user_url(id: @object.uuid), class: 'btn btn-primary' %> -
+
+ <%= button_to "Log in as #{@object.full_name}", sudo_user_url(id: @object.uuid), class: 'btn btn-primary' %> +
-

As an admin, you can setup this user. Please input a VM and repository for the user. If you had previously provided any of these items, they are pre-filled for you and you can leave them as is if you would like to reuse them.

+

+ As an admin, you can setup this user. Please input a VM and + repository for the user. If you had previously provided any of + these items, they are pre-filled for you and you can leave them + as is if you would like to reuse them. +

-
-<%= link_to "Setup #{@object.full_name}", setup_popup_user_url(id: @object.uuid), {class: 'btn btn-primary', :remote => true, 'data-toggle' => "modal", 'data-target' => '#user-setup-modal-window'} %> -
+
+ <%= link_to "Setup #{@object.full_name}", setup_popup_user_url(id: @object.uuid), {class: 'btn btn-primary', :remote => true, 'data-toggle' => "modal", 'data-target' => '#user-setup-modal-window'} %> +
-

As an admin, you can deactivate and reset this user. This will remove all repository/VM permissions for the user. If you "setup" the user again, the user will have to sign the user agreement again.

+

+ As an admin, you can deactivate and reset this user. This will + remove all repository/VM permissions for the user. If you + "setup" the user again, the user will have to sign the user + agreement again. +

-
-<%= button_to "Deactivate #{@object.full_name}", unsetup_user_url(id: @object.uuid), class: 'btn btn-primary', data: {confirm: "Are you sure you want to deactivate #{@object.full_name}?"} %> -
+
+ <%= button_to "Deactivate #{@object.full_name}", unsetup_user_url(id: @object.uuid), class: 'btn btn-primary', data: {confirm: "Are you sure you want to deactivate #{@object.full_name}?"} %> +
+
+
+
+
+ Groups +
+
+
+ A permitted user has all permissions available to the group. +
+ A member user is visible to everyone else who can see the group. +
+ (Tip: in most cases, you don't want one without the other.) +
+
+ <% permitted_group_perms = {} + Link.limit(10000).filter([ + ['tail_uuid', '=', @object.uuid], + ['head_uuid', 'is_a', 'arvados#group'], + ['link_class', '=', 'permission'], + ]).each do |perm| + permitted_group_perms[perm.head_uuid] = perm.uuid + end %> + <% member_group_perms = {} + Link.permissions_for(@object).each do |perm| + member_group_perms[perm.tail_uuid] = perm.uuid + end %> + <% Group.order(['name']).where(group_class: 'role').each do |group| %> +
+ + + +
+ <% end.empty? and begin %> +
+ (No groups defined.) +
+ <% end %> +
+
+ +
+
+
-- 2.39.5