Commit d400a069 by Őry Máté

acl: fix and test auto-owner functionality

parent 61deebe3
...@@ -214,10 +214,10 @@ class AclBase(Model): ...@@ -214,10 +214,10 @@ class AclBase(Model):
return cls.objects.filter(clsfilter) return cls.objects.filter(clsfilter)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if 'owner' in self and self.owner and 'owner' in self.ACL_LEVELS:
self.set_user_level(self.owner, 'owner')
super(AclBase, self).save(*args, **kwargs) super(AclBase, self).save(*args, **kwargs)
if 'owner' in dict(self.ACL_LEVELS) and (hasattr(self, 'owner')
and self.owner):
self.set_user_level(self.owner, 'owner')
class Meta: class Meta:
abstract = True abstract = True
...@@ -22,4 +22,5 @@ class Test2Model(AclBase): ...@@ -22,4 +22,5 @@ class Test2Model(AclBase):
('one', 'One'), ('one', 'One'),
('two', 'Two'), ('two', 'Two'),
('three', 'Three'), ('three', 'Three'),
('owner', 'owner'),
) )
...@@ -180,3 +180,33 @@ class AclUserTest(TestCase): ...@@ -180,3 +180,33 @@ class AclUserTest(TestCase):
TestModel.get_objects_with_group_level('alfa', self.g1), [i1, i2]) TestModel.get_objects_with_group_level('alfa', self.g1), [i1, i2])
self.assertItemsEqual( self.assertItemsEqual(
TestModel.get_objects_with_group_level('alfa', self.g2), [i2]) TestModel.get_objects_with_group_level('alfa', self.g2), [i2])
def test_owner(self):
i = Test2Model.objects.create(normal2_field='Hello',
owner=self.u1)
self.assertTrue(i.has_level(self.u1, 'one'))
self.assertTrue(i.has_level(self.u1, 'owner'))
self.assertFalse(i.has_level(self.u2, 'owner'))
def test_owner_change(self):
i = Test2Model.objects.create(normal2_field='Hello',
owner=self.u1)
self.assertTrue(i.has_level(self.u1, 'one'))
self.assertTrue(i.has_level(self.u1, 'owner'))
self.assertFalse(i.has_level(self.u2, 'owner'))
i.owner = self.u2
i.save()
self.assertTrue(i.has_level(self.u1, 'one'))
self.assertTrue(i.has_level(self.u1, 'owner'))
self.assertTrue(i.has_level(self.u2, 'owner'))
def test_owner_change_from_none(self):
i = Test2Model.objects.create(normal2_field='Hello')
self.assertFalse(i.has_level(self.u1, 'one'))
self.assertFalse(i.has_level(self.u1, 'owner'))
self.assertFalse(i.has_level(self.u2, 'owner'))
i.owner = self.u2
i.save()
self.assertFalse(i.has_level(self.u1, 'one'))
self.assertFalse(i.has_level(self.u1, 'owner'))
self.assertTrue(i.has_level(self.u2, 'owner'))
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