def test_has_permission_with_two_roles(self):
        user = mommy.make(get_user_model())

        assign_role(user, 'buyer')

        self.assertEquals(get_user_roles(user), [Buyer])
        self.assertTrue(has_permission(user, 'offersale_can_create'))

        assign_role(user, 'admin_read_only')

        self.assertEquals(set(get_user_roles(user)),
                          set([Buyer, AdminReadOnly]))
        self.assertTrue(has_permission(user, 'offersale_can_create'))
    def test_grant_permission_for_role_by_name(self):
        user = self.user

        self.assertTrue(
            grant_permission(user, 'permission6', ShoRole3.get_name()))

        self.assertTrue(
            has_permission(user, 'permission6', ShoRole3.get_name()))
 def wrapper(request, *args, **kwargs):
     user = request.user
     if user.is_authenticated():
         if has_permission(user, permission_name, role_name):
             return dispatch(request, *args, **kwargs)
     if hasattr(settings, 'ROLEPERMISSIONS_REDIRECT_TO_LOGIN'):
         return redirect_to_login(request.get_full_path())
     raise PermissionDenied
def can_template_tag(user, args):
    # Throws RoleDoesNotExist if an invalid role has been passed
    args = args.split(":")
    permission = args[0]
    role = None
    if len(args) > 1:
        role = retrieve_role_safely(args[1])

        if not role:
            raise RoleDoesNotExist

    return has_permission(user, permission, role)
Beispiel #5
0
def available_perm_status(user):
    from giaola_role_permissions.verifications import has_permission

    roles = get_user_roles(user)

    permission_hash = {}

    if roles:
        for role in roles:
            permission_names = role.get_available_permissions_names_list()
            for permission_name in permission_names:
                has_perm = has_permission(user, permission_name, role)
                permission_hash\
                    .setdefault(role.get_name(), {})\
                    .setdefault(permission_name, has_perm)

    return permission_hash
    def test_has_VerRole1_and_VerRole2_permission(self):
        user = self.user

        VerRole2.assign_role_to_user(user)

        self.assertTrue(has_permission(user, 'permission1'))
    def test_has_VerRole1_permission(self):
        user = self.user

        self.assertTrue(has_permission(user, 'permission1'))
 def test_none_user_param(self):
     self.assertFalse(has_permission(None, 'ver_role1'))
    def test_user_with_no_role(self):
        user = mommy.make(get_user_model())

        self.assertFalse(has_permission(user, 'permission1'))
    def test_not_existent_permission(self):
        user = self.user

        self.assertFalse(has_permission(user, 'not_a_permission'))
    def test_dos_not_have_VerRole1_permission(self):
        user = self.user

        self.assertFalse(has_permission(user, 'permission6'))
    def test_revoke_revoked_permission(self):
        user = self.user

        self.assertTrue(revoke_permission(user, 'permission4'))

        self.assertFalse(has_permission(user, 'permission4'))
    def test_grant_granted_permission(self):
        user = self.user

        self.assertTrue(grant_permission(user, 'permission3'))

        self.assertTrue(has_permission(user, 'permission3'))
    def test_grant_permission_for_role(self):
        user = self.user

        self.assertTrue(grant_permission(user, 'permission5', ShoRole3))

        self.assertTrue(has_permission(user, 'permission5', ShoRole3))