allow users to edit groups but only show there groups, disable other groups to not allow removing them

This commit is contained in:
j 2014-10-15 09:34:27 +00:00
parent 4dc89c9456
commit ef0aca6acb
3 changed files with 16 additions and 5 deletions

View file

@ -863,7 +863,7 @@ def group_json(g):
} }
@capability_required_json('canManageUsers') @login_required_json
def getGroups(request, data): def getGroups(request, data):
''' '''
takes {} takes {}
@ -882,7 +882,7 @@ def getGroups(request, data):
actions.register(getGroups) actions.register(getGroups)
@capability_required_json('canManageUsers') @login_required_json
def getGroup(request, data): def getGroup(request, data):
''' '''
takes { takes {

View file

@ -21,6 +21,7 @@ pandora.ui.groupsDialog = function(options) {
width: 584 + Ox.UI.SCROLLBAR_SIZE width: 584 + Ox.UI.SCROLLBAR_SIZE
}), }),
canManageGroups = pandora.site.capabilities.canManageUsers[pandora.user.level],
isItem = options.type == 'item', isItem = options.type == 'item',
$content, $content,
@ -124,6 +125,7 @@ pandora.ui.groupsDialog = function(options) {
var $group = $groups[index] = Ox.$('<div>') var $group = $groups[index] = Ox.$('<div>')
.appendTo($content); .appendTo($content);
$checkboxes[index] = Ox.Checkbox({ $checkboxes[index] = Ox.Checkbox({
disabled: !canManageGroups && !Ox.contains(pandora.user.groups, group.name),
value: Ox.contains(selectedGroups, group.name) value: Ox.contains(selectedGroups, group.name)
}) })
.css({ .css({
@ -137,6 +139,7 @@ pandora.ui.groupsDialog = function(options) {
}) })
.appendTo($group); .appendTo($group);
$inputs[index] = Ox.Input({ $inputs[index] = Ox.Input({
disabled: !canManageGroups,
value: group.name, value: group.name,
width: 192 width: 192
}) })
@ -158,8 +161,9 @@ pandora.ui.groupsDialog = function(options) {
float: 'left', float: 'left',
margin: '4px' margin: '4px'
}) })
.appendTo($group), .appendTo($group);
$removeButtons[index] = Ox.Button({ $removeButtons[index] = Ox.Button({
disabled: !canManageGroups,
title: Ox._('Remove Group'), title: Ox._('Remove Group'),
width: 128 width: 128
}) })
@ -178,6 +182,12 @@ pandora.ui.groupsDialog = function(options) {
function renderGroups(focusInput) { function renderGroups(focusInput) {
Ox.Request.clearCache('getGroups'); Ox.Request.clearCache('getGroups');
pandora.api.getGroups(function(result) { 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'); groups = Ox.sortBy(result.data.groups, 'name');
$content = Ox.Element().css({margin: '12px'}); $content = Ox.Element().css({margin: '12px'});
$label = Ox.Label({ $label = Ox.Label({
@ -193,6 +203,7 @@ pandora.ui.groupsDialog = function(options) {
.appendTo($content); .appendTo($content);
groups.forEach(renderGroup); groups.forEach(renderGroup);
$addButton = Ox.Button({ $addButton = Ox.Button({
disabled: !canManageGroups,
title: Ox._('Add Group'), title: Ox._('Add Group'),
width: 128 width: 128
}) })

View file

@ -430,7 +430,7 @@ pandora.ui.infoView = function(data) {
editMetadata(key, event.value); editMetadata(key, event.value);
} }
}, key == 'groups' ? { }, key == 'groups' ? {
doubleclick: function() { doubleclick: canEdit ? function() {
setTimeout(function() { setTimeout(function() {
if (window.getSelection) { if (window.getSelection) {
window.getSelection().removeAllRanges(); window.getSelection().removeAllRanges();
@ -451,7 +451,7 @@ pandora.ui.infoView = function(data) {
} }
}) })
.open(); .open();
} } : function() {}
} : {})) } : {}))
) )
) )