From c5fcb813e97f5c86a4aa5e0b870bf5ce0534a4a9 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 30 Sep 2014 15:12:21 +0200 Subject: [PATCH] editGroup --- pandora/user/views.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/pandora/user/views.py b/pandora/user/views.py index 1286c6b3..2772a79c 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -822,7 +822,7 @@ def getGroups(request): takes {} returns { groups: [ - {name:, users...} + {id:, name:, users:...} ] } @@ -832,6 +832,7 @@ def getGroups(request): response['data']['groups'] = [] for g in Group.objects.all().order_by('name'): response['data']['groups'].append({ + 'id': ox.toAZ(g.id), 'name': g.name, 'users': g.user_set.count() }) @@ -845,6 +846,7 @@ def addGroup(request): name: string } returns { + id: string, name: string users: int } @@ -854,17 +856,45 @@ def addGroup(request): data = json.loads(request.POST['data']) g, created = Group.objects.get_or_create(name=data['name']) response['data'] = { + 'id': ox.toAZ(g.id), 'name': g.name, 'users': g.user_set.count() } return render_to_json_response(response) actions.register(addGroup) +@capability_required_json('canManageUsers') +def editGroup(request): + ''' + takes { + id: string, + name: string + + } + returns { + name: string + users: int + } + + ''' + response = json_response(status=200, text='ok') + data = json.loads(request.POST['data']) + g = Group.objects.get(id=ox.fromAZ(data['id'])) + g.name = data['name'] + g.save() + response['data'] = { + 'id': ox.toAZ(g.id), + 'name': g.name, + 'users': g.user_set.count() + } + return render_to_json_response(response) +actions.register(editGroup) + @capability_required_json('canManageUsers') def removeGroup(request): ''' takes { - name: string + id: string } returns { } @@ -872,7 +902,7 @@ def removeGroup(request): ''' response = json_response(status=200, text='ok') data = json.loads(request.POST['data']) - g = Group.objects.get(name=data['name']) + g = Group.objects.get(id=ox.fromAZ(data['id'])) for i in g.items.all(): i.groups.remove(g) for u in g.user_set.all():