Skip to content

Commit

Permalink
makes is_authenticated checking compatible with Django 11
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeximenes committed Mar 23, 2017
1 parent f9c9337 commit 9373ba0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions rolepermissions/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
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):
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'):
Expand All @@ -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'):
Expand Down
12 changes: 11 additions & 1 deletion rolepermissions/utils.py
Original file line number Diff line number Diff line change
@@ -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..
Expand Down

0 comments on commit 9373ba0

Please sign in to comment.