diff --git a/rolepermissions/decorators.py b/rolepermissions/decorators.py index 998cc51..3780c18 100644 --- a/rolepermissions/decorators.py +++ b/rolepermissions/decorators.py @@ -7,6 +7,7 @@ from django.core.exceptions import PermissionDenied from rolepermissions.checkers import has_role, has_permission +from rolepermissions.utils import user_is_authenticated def has_role_decorator(role): @@ -14,7 +15,7 @@ def request_decorator(dispatch): @wraps(dispatch) def wrapper(request, *args, **kwargs): user = request.user - if user.is_authenticated(): + if user_is_authenticated(user): if has_role(user, role): return dispatch(request, *args, **kwargs) if hasattr(settings, 'ROLEPERMISSIONS_REDIRECT_TO_LOGIN'): @@ -29,7 +30,7 @@ def request_decorator(dispatch): @wraps(dispatch) def wrapper(request, *args, **kwargs): user = request.user - if user.is_authenticated(): + if user_is_authenticated(user): if has_permission(user, permission_name): return dispatch(request, *args, **kwargs) if hasattr(settings, 'ROLEPERMISSIONS_REDIRECT_TO_LOGIN'): diff --git a/rolepermissions/utils.py b/rolepermissions/utils.py index 61c7a52..dde3bd4 100644 --- a/rolepermissions/utils.py +++ b/rolepermissions/utils.py @@ -1,10 +1,20 @@ from __future__ import unicode_literals import re +import collections + + +def user_is_authenticated(user): + if isinstance(user.is_authenticated, collections.Callable): + authenticated = user.is_authenticated() + else: + authenticated = user.is_authenticated + + return authenticated def camelToSnake(s): - """ + """ https://gist.github.com/jaytaylor/3660565 Is it ironic that this function is written in camel case, yet it converts to snake case? hmm..