editGroup

This commit is contained in:
j 2014-09-30 15:12:21 +02:00
parent 80fdfb5e38
commit c5fcb813e9

View file

@ -822,7 +822,7 @@ def getGroups(request):
takes {} takes {}
returns { returns {
groups: [ groups: [
{name:, users...} {id:, name:, users:...}
] ]
} }
@ -832,6 +832,7 @@ def getGroups(request):
response['data']['groups'] = [] response['data']['groups'] = []
for g in Group.objects.all().order_by('name'): for g in Group.objects.all().order_by('name'):
response['data']['groups'].append({ response['data']['groups'].append({
'id': ox.toAZ(g.id),
'name': g.name, 'name': g.name,
'users': g.user_set.count() 'users': g.user_set.count()
}) })
@ -845,6 +846,7 @@ def addGroup(request):
name: string name: string
} }
returns { returns {
id: string,
name: string name: string
users: int users: int
} }
@ -854,17 +856,45 @@ def addGroup(request):
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
g, created = Group.objects.get_or_create(name=data['name']) g, created = Group.objects.get_or_create(name=data['name'])
response['data'] = { response['data'] = {
'id': ox.toAZ(g.id),
'name': g.name, 'name': g.name,
'users': g.user_set.count() 'users': g.user_set.count()
} }
return render_to_json_response(response) return render_to_json_response(response)
actions.register(addGroup) 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') @capability_required_json('canManageUsers')
def removeGroup(request): def removeGroup(request):
''' '''
takes { takes {
name: string id: string
} }
returns { returns {
} }
@ -872,7 +902,7 @@ def removeGroup(request):
''' '''
response = json_response(status=200, text='ok') response = json_response(status=200, text='ok')
data = json.loads(request.POST['data']) 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(): for i in g.items.all():
i.groups.remove(g) i.groups.remove(g)
for u in g.user_set.all(): for u in g.user_set.all():