Commit 2ca3fcdc by Őry Máté

acl: refactor AclUpdateView.post

parent 59534d71
...@@ -88,6 +88,11 @@ class AclUpdateView(View, SingleObjectMixin): ...@@ -88,6 +88,11 @@ class AclUpdateView(View, SingleObjectMixin):
logger.warning('Tried to set permissions of %s by non-owner %s.', logger.warning('Tried to set permissions of %s by non-owner %s.',
unicode(instance), unicode(request.user)) unicode(instance), unicode(request.user))
raise PermissionDenied() raise PermissionDenied()
self.set_levels(request, instance)
self.add_levels(request, instance)
return redirect(instance)
def set_levels(self, request, instance):
for key, value in request.POST.items(): for key, value in request.POST.items():
m = re.match('perm-([ug])-(\d+)', key) m = re.match('perm-([ug])-(\d+)', key)
if m: if m:
...@@ -98,17 +103,22 @@ class AclUpdateView(View, SingleObjectMixin): ...@@ -98,17 +103,22 @@ class AclUpdateView(View, SingleObjectMixin):
unicode(entity), unicode(instance), unicode(entity), unicode(instance),
value, unicode(request.user)) value, unicode(request.user))
def add_levels(self, request, instance):
name = request.POST['perm-new-name'] name = request.POST['perm-new-name']
value = request.POST['perm-new'] value = request.POST['perm-new']
if name: if not name:
return
try: try:
entity = User.objects.get(username=name) entity = User.objects.get(username=name)
except User.DoesNotExist: except User.DoesNotExist:
entity = None
try:
entity = Group.objects.get(name=name) entity = Group.objects.get(name=name)
except Group.DoesNotExist: except Group.DoesNotExist:
warning(request, _('User or group "%s" not found.') % name) warning(request, _('User or group "%s" not found.') % name)
return return
instance.set_level(entity, value)
logger.info("Set %s's new acl level for %s to %s by %s.", logger.info("Set %s's new acl level for %s to %s by %s.",
unicode(entity), unicode(instance), unicode(entity), unicode(instance),
value, unicode(request.user)) value, unicode(request.user))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment