Commit ca0b8a5e by Őry Máté

acl: fixing bugs discovered by tests

parent 110d579b
...@@ -54,10 +54,11 @@ class AclBase(Model): ...@@ -54,10 +54,11 @@ class AclBase(Model):
"""Define permission levels for Users/Groups per object.""" """Define permission levels for Users/Groups per object."""
object_level_set = GenericRelation(ObjectLevel) object_level_set = GenericRelation(ObjectLevel)
def get_level_object(self, level): @classmethod
def get_level_object(cls, level):
"""Get Level object for this model by codename.""" """Get Level object for this model by codename."""
ct = ContentType.objects.get_for_model(self) ct = ContentType.objects.get_for_model(cls)
return Level.objects.get(codename=level, content_type=ct) return Level.objects.get(codename=level, content_type=ct)
def set_level(self, whom, level): def set_level(self, whom, level):
...@@ -133,17 +134,11 @@ class AclBase(Model): ...@@ -133,17 +134,11 @@ class AclBase(Model):
object_levels = self.object_level_set.filter( object_levels = self.object_level_set.filter(
level__weight__gte=level.weight).all() level__weight__gte=level.weight).all()
if group_also: groups = user.groups.values_list('id', flat=True) if group_also else []
try:
groups = user.group_set.values_list('id', flat=True)
except AttributeError:
pass # e.g. AnyonymousUser doesn't have group_set
else:
for i in object_levels: for i in object_levels:
if i.users.filter(pk=user.pk).exists(): if i.users.filter(pk=user.pk).exists():
return True return True
if (group_also and if group_also and i.groups.filter(pk__in=groups).exists():
i.groups.filter(pk__in=groups).exists()):
return True return True
return False return False
......
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