def wrapper(request, *args, **kwargs):
     user = request.user
     if user.is_authenticated():
         if has_role(user, role):
             return dispatch(request, *args, **kwargs)
     if hasattr(settings, 'ROLEPERMISSIONS_REDIRECT_TO_LOGIN'):
         return redirect_to_login(request.get_full_path())
     raise PermissionDenied
def has_role_template_tag(user, role):
    role_list = role.split(',')
    return has_role(user, role_list)
 def test_none_user_param(self):
     self.assertFalse(has_role(None, 'ver_role1'))
    def test_not_existent_role(self):
        user = self.user

        self.assertFalse(has_role(user, 'not_a_role'))
    def test_user_has_VerRole1_and_VerRole3_by_name(self):
        user = self.user

        VerRole3.assign_role_to_user(user)

        self.assertTrue(has_role(user, ['ver_role1', 'ver_role3']))
    def test_has_role_by_name(self):
        user = self.user

        self.assertTrue(has_role(user, 'ver_role1'))
    def test_user_has_VerRole1_or_VerRole2(self):
        user = self.user

        self.assertTrue(has_role(user, [VerRole1, VerRole2]))
    def test_user_does_not_have_VerRole2(self):
        user = self.user

        self.assertFalse(has_role(user, VerRole2))
    def test_user_has_VerRole1(self):
        user = self.user

        self.assertTrue(has_role(user, VerRole1))