Skip to content

Commit

Permalink
Allow use permissions with missed cache
Browse files Browse the repository at this point in the history
  • Loading branch information
matllubos committed Feb 1, 2022
1 parent a8f1047 commit 12ea296
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions fperms_iscore/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ def _get_perm_slug(perm):
return _get_perm_slug_from_data(perm.type, perm.codename, perm.content_type_id, perm.object_id)


def get_cache():
return caches[settings.IS_CORE_PERM_CACHE_NAME] if settings.IS_CORE_PERM_USE_CACHE else None
def get_cache(request):
if not hasattr(request, 'session') or not settings.IS_CORE_PERM_USE_CACHE:
return None
return caches[settings.IS_CORE_PERM_CACHE_NAME]


def get_all_user_perm_slugs(request):
Expand All @@ -49,11 +51,9 @@ def get_all_user_perm_slugs(request):

cache_key = None
perm_slugs = None
cache = get_cache()
cache = get_cache(request)

if cache:
assert hasattr(request, 'session'), 'The cached permissions requres session middleware to be installed, ' \
'and come before the message middleware in the MIDDLEWARE list'
cache_key = f'fperms_is_core-{request.user.pk}-{request.session.session_key}'
perm_slugs = cache.get(cache_key)

Expand Down

0 comments on commit 12ea296

Please sign in to comment.