Commit 90fe50ac by Őry Máté

acl: add AclBase.set_level(whom, None)

parent c616998b
......@@ -67,8 +67,8 @@ class AclBase(Model):
:param whom: user or group the level is set for
:type whom: User or Group
:param level: codename of level to set
:type level: Level or str or unicode
:param level: codename of level to set, or None
:type level: Level or str or unicode or NoneType
"""
if isinstance(whom, User):
self.set_user_level(whom, level)
......@@ -83,17 +83,21 @@ class AclBase(Model):
:param whom: user the level is set for
:type whom: User
:param level: codename of level to set
:type level: Level or str or unicode
:param level: codename of level to set, or None
:type level: Level or str or unicode or NoneType
"""
logger.info('%s.set_user_level(%s, %s) called',
*[unicode(p) for p in [self, user, level]])
if isinstance(level, basestring):
level = self.get_level_object(level)
if not self.object_level_set.filter(level_id=level.pk).exists():
self.object_level_set.create(level=level)
if level is None:
pk = None
else:
if isinstance(level, basestring):
level = self.get_level_object(level)
if not self.object_level_set.filter(level_id=level.pk).exists():
self.object_level_set.create(level=level)
pk = level.pk
for i in self.object_level_set.all():
if i.level_id != level.pk:
if i.level_id != pk:
i.users.remove(user)
else:
i.users.add(user)
......@@ -110,13 +114,17 @@ class AclBase(Model):
"""
logger.info('%s.set_group_level(%s, %s) called',
*[unicode(p) for p in [self, group, level]])
if isinstance(level, basestring):
level = self.get_level_object(level)
#self.object_level_set.get_or_create(level=level, content_object=self)
if not self.object_level_set.filter(level_id=level.pk).exists():
self.object_level_set.create(level=level)
if level is None:
pk = None
else:
if isinstance(level, basestring):
level = self.get_level_object(level)
#self.object_level_set.get_or_create(level=level, content_object=self)
if not self.object_level_set.filter(level_id=level.pk).exists():
self.object_level_set.create(level=level)
pk = level.pk
for i in self.object_level_set.all():
if i.level_id != level.pk:
if i.level_id != pk:
i.groups.remove(group)
else:
i.groups.add(group)
......
......@@ -133,3 +133,17 @@ class AclUserTest(TestCase):
i1 = TestModel.objects.create(normal_field='Hello')
i1.set_level(self.g1, 'bravo')
unicode(ObjectLevel.objects.all()[0])
def test_set_user_level_none(self):
i = TestModel.objects.create(normal_field='Hello')
i.set_level(self.u1, 'alfa')
self.assertTrue(i.has_level(self.u1, 'alfa'))
i.set_level(self.u1, None)
self.assertFalse(i.has_level(self.u1, 'alfa'))
def test_set_group_level_none(self):
i = TestModel.objects.create(normal_field='Hello')
i.set_level(self.g1, 'alfa')
self.assertTrue(i.has_level(self.u1, 'alfa'))
i.set_level(self.g1, None)
self.assertFalse(i.has_level(self.u1, 'alfa'))
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