From ef0aca6acb36b6e13fee7280fa862a90f85afb01 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 15 Oct 2014 09:34:27 +0000 Subject: [PATCH] allow users to edit groups but only show there groups, disable other groups to not allow removing them --- pandora/user/views.py | 4 ++-- static/js/groupsDialog.js | 13 ++++++++++++- static/js/infoView.padma.js | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pandora/user/views.py b/pandora/user/views.py index 8a39b863..801eb1b4 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -863,7 +863,7 @@ def group_json(g): } -@capability_required_json('canManageUsers') +@login_required_json def getGroups(request, data): ''' takes {} @@ -882,7 +882,7 @@ def getGroups(request, data): actions.register(getGroups) -@capability_required_json('canManageUsers') +@login_required_json def getGroup(request, data): ''' takes { diff --git a/static/js/groupsDialog.js b/static/js/groupsDialog.js index a6ea2091..ec916bda 100644 --- a/static/js/groupsDialog.js +++ b/static/js/groupsDialog.js @@ -21,6 +21,7 @@ pandora.ui.groupsDialog = function(options) { width: 584 + Ox.UI.SCROLLBAR_SIZE }), + canManageGroups = pandora.site.capabilities.canManageUsers[pandora.user.level], isItem = options.type == 'item', $content, @@ -124,6 +125,7 @@ pandora.ui.groupsDialog = function(options) { var $group = $groups[index] = Ox.$('
') .appendTo($content); $checkboxes[index] = Ox.Checkbox({ + disabled: !canManageGroups && !Ox.contains(pandora.user.groups, group.name), value: Ox.contains(selectedGroups, group.name) }) .css({ @@ -137,6 +139,7 @@ pandora.ui.groupsDialog = function(options) { }) .appendTo($group); $inputs[index] = Ox.Input({ + disabled: !canManageGroups, value: group.name, width: 192 }) @@ -158,8 +161,9 @@ pandora.ui.groupsDialog = function(options) { float: 'left', margin: '4px' }) - .appendTo($group), + .appendTo($group); $removeButtons[index] = Ox.Button({ + disabled: !canManageGroups, title: Ox._('Remove Group'), width: 128 }) @@ -178,6 +182,12 @@ pandora.ui.groupsDialog = function(options) { function renderGroups(focusInput) { Ox.Request.clearCache('getGroups'); pandora.api.getGroups(function(result) { + if (!canManageGroups) { + result.data.groups = result.data.groups.filter(function(group) { + return Ox.contains(pandora.user.groups, group.name) || + Ox.contains(selectedGroups, group.name); + }); + } groups = Ox.sortBy(result.data.groups, 'name'); $content = Ox.Element().css({margin: '12px'}); $label = Ox.Label({ @@ -193,6 +203,7 @@ pandora.ui.groupsDialog = function(options) { .appendTo($content); groups.forEach(renderGroup); $addButton = Ox.Button({ + disabled: !canManageGroups, title: Ox._('Add Group'), width: 128 }) diff --git a/static/js/infoView.padma.js b/static/js/infoView.padma.js index a7ba0c8d..f5bb03f8 100644 --- a/static/js/infoView.padma.js +++ b/static/js/infoView.padma.js @@ -430,7 +430,7 @@ pandora.ui.infoView = function(data) { editMetadata(key, event.value); } }, key == 'groups' ? { - doubleclick: function() { + doubleclick: canEdit ? function() { setTimeout(function() { if (window.getSelection) { window.getSelection().removeAllRanges(); @@ -451,7 +451,7 @@ pandora.ui.infoView = function(data) { } }) .open(); - } + } : function() {} } : {})) ) )