Commits

Kai Diefenbach committed 55fa27d

Bugfix: check for an object before trying to add local role; issue #3

Comments (0)

Files changed (2)

permissions/tests.py

         self.user = User.objects.create(username="john")
         self.group = Group.objects.create(name="brights")
 
+        self.user.groups.add(self.group)
+
         self.page_1 = FlatPage.objects.create(url="/page-1/", title="Page 1")
         self.page_2 = FlatPage.objects.create(url="/page-1/", title="Page 2")
-    
+
     def test_getter(self):
         """
         """
 
         result = permissions.utils.get_user(42)
         self.assertEqual(result, None)
-        
+
     def test_global_roles_user(self):
         """
         """
         # Remove roles
         result = permissions.utils.remove_roles(self.user)
         self.assertEqual(result, True)
-        
+
         result = permissions.utils.get_roles(self.user)
         self.assertEqual(result, [])
 
 
         result = permissions.utils.get_roles(self.group)
         self.assertEqual(result, [])
-        
+
         # Remove roles
         result = permissions.utils.remove_roles(self.group)
         self.assertEqual(result, False)
 
         result = permissions.utils.get_local_roles(self.page_1, self.group)
         self.assertEqual(result, [])
-    
+
     def test_remove_local_roles_user(self):
         """
         """
 
         result = permissions.utils.get_local_roles(self.page_1, self.user)
         self.assertEqual(result, [self.role_1, self.role_2])
-        
+
         # Remove all local roles
         result = permissions.utils.remove_local_roles(self.page_1, self.user)
         self.assertEqual(result, True)
-        
+
         result = permissions.utils.get_local_roles(self.page_1, self.user)
         self.assertEqual(result, [])
 
         # Remove all local roles again
         result = permissions.utils.remove_local_roles(self.page_1, self.user)
         self.assertEqual(result, False)
-        
+
 class PermissionTestCase(TestCase):
     """
     """
         self.page_2 = FlatPage.objects.create(url="/page-1/", title="Page 2")
 
         self.permission = permissions.utils.register_permission("View", "view")
-    
+
     def test_add_permissions(self):
         """
         """
         # Add per object
         result = permissions.utils.grant_permission(self.page_1, self.role_1, self.permission)
         self.assertEqual(result, True)
-        
+
         # Add per codename
         result = permissions.utils.grant_permission(self.page_1, self.role_1, "view")
         self.assertEqual(result, True)
-        
+
         # Add ermission which does not exist
         result = permissions.utils.grant_permission(self.page_1, self.role_1, "hurz")
         self.assertEqual(result, False)
-    
+
     def test_remove_permission(self):
         """
         """
         # Add
         result = permissions.utils.grant_permission(self.page_1, self.role_1, "view")
         self.assertEqual(result, True)
-        
+
         # Remove
         result = permissions.utils.remove_permission(self.page_1, self.role_1, "view")
         self.assertEqual(result, True)
         # Remove again
         result = permissions.utils.remove_permission(self.page_1, self.role_1, "view")
         self.assertEqual(result, False)
-        
+
     def test_has_permission_role(self):
         """
         """
         """
         result = permissions.utils.is_inherited(self.page_1, "view")
         self.assertEqual(result, True)
-        
+
         # per permission
         permissions.utils.add_inheritance_block(self.page_1, self.permission)
 
 
         result = permissions.utils.is_inherited(self.page_1, "view")
         self.assertEqual(result, True)
-        
+
         # per codename
         permissions.utils.add_inheritance_block(self.page_1, "view")
 
         opb = ObjectPermissionInheritanceBlock.objects.get(permission=self.permission)
 
         self.assertEqual(opb.__unicode__(), "View (view) / flat page - 1")
-    
+
     def test_reset(self):
         """
         """
 
         result = permissions.utils.is_inherited(self.page_1, "view")
         self.assertEqual(result, False)
-        
+
         permissions.utils.reset(self.page_1)
 
         result = permissions.utils.has_permission(self.page_1, self.user, "view")
         self.assertEqual(result, True)
 
         permissions.utils.reset(self.page_1)
-        
+
 class RegistrationTestCase(TestCase):
     """Tests the registration of different components.
     """

permissions/utils.py

 
     if isinstance(principal, User):
         for group in principal.groups.all():
-            roles.extend(get_local_roles(obj, group))
+            if obj is not None:
+                roles.extend(get_local_roles(obj, group))
             roles.extend(get_roles(group))
 
     return roles
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.