mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
context_processor: Cache whether user is admin (Closes: #781)
This commit is contained in:
1 parent
0adfae26d8
commit
6a53dd015e
5 files changed
+15
-7
No files matched your search
+10
-2
@@ -52,6 +52,14 @@ def non_admin_view(func):
|
||||
return func
|
||||
|
||||
|
||||
def is_user_admin(user):
|
||||
def is_user_admin(request, cached=False):
|
||||
"""Return whether user is an administrator."""
|
||||
return user.groups.filter(name='admin').exists()
|
||||
if not request.user.is_authenticated():
|
||||
return False
|
||||
|
||||
if 'cache_user_is_admin' in request.session and cached:
|
||||
return request.session['cache_user_is_admin']
|
||||
|
||||
user_is_admin = request.user.groups.filter(name='admin').exists()
|
||||
request.session['cache_user_is_admin'] = user_is_admin
|
||||
return user_is_admin
|
||||
Reference in new issue
Block a user