Exemplo n.º 1
0
 def test_has_perm_starts_with_correct(self):
     new_group = AbakusGroup.objects.create(name='new',
                                            permissions=['/sudo/admin/'])
     new_group.add_user(self.test_user)
     self.assertTrue(
         KeywordPermissions.has_perm(self.test_user,
                                     '/sudo/admin/does/not/exist'))
Exemplo n.º 2
0
    def has_perm(self, user_obj, perm, obj=None):
        if not user_obj.is_anonymous and not user_obj.is_active:
            return False

        if obj is None:
            # Take a shortcut and check KeywordPermissions only if no object are defined.
            return KeywordPermissions.has_perm(user_obj, perm)

        if isinstance(obj, models.Model):
            permission_handler = get_permission_handler(obj)
            return permission_handler.has_perm(user_obj, perm, obj=obj)
        elif isinstance(obj, models.QuerySet):
            permission_handler = get_permission_handler(obj.model)
            return permission_handler.has_perm(user_obj, perm, queryset=obj)
        elif issubclass(obj, models.Model):
            permission_handler = get_permission_handler(obj)
            return permission_handler.has_perm(user_obj, perm, queryset=obj.objects.none())

        return False
Exemplo n.º 3
0
 def test_has_perm_incorrect(self):
     has_perm = KeywordPermissions.has_perm(self.test_user, "/sudo")
     self.assertFalse(has_perm)
Exemplo n.º 4
0
 def test_has_perm_exact(self):
     has_perm = KeywordPermissions.has_perm(
         self.test_user, "/sudo/admin/users/list/"
     )
     self.assertTrue(has_perm)