mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 08:32:26 +00:00
Autorise plusieurs apps dans can_view_app
This commit is contained in:
parent
84a901e3fc
commit
f7d7a41586
1 changed files with 14 additions and 12 deletions
10
re2o/acl.py
10
re2o/acl.py
|
@ -248,9 +248,10 @@ def can_view_all(*targets):
|
||||||
return acl_base_decorator('can_view_all', *targets, on_instance=False)
|
return acl_base_decorator('can_view_all', *targets, on_instance=False)
|
||||||
|
|
||||||
|
|
||||||
def can_view_app(app_name):
|
def can_view_app(*apps_name):
|
||||||
"""Decorator to check if an user can view an application.
|
"""Decorator to check if an user can view the applications.
|
||||||
"""
|
"""
|
||||||
|
for app_name in apps_name:
|
||||||
assert app_name in sys.modules.keys()
|
assert app_name in sys.modules.keys()
|
||||||
|
|
||||||
def decorator(view):
|
def decorator(view):
|
||||||
|
@ -259,15 +260,16 @@ def can_view_app(app_name):
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
"""The wrapper used for a specific request
|
"""The wrapper used for a specific request
|
||||||
"""
|
"""
|
||||||
|
for app_name in apps_name:
|
||||||
app = sys.modules[app_name]
|
app = sys.modules[app_name]
|
||||||
can, msg = app.can_view(request.user)
|
can, msg = app.can_view(request.user)
|
||||||
if can:
|
if not can:
|
||||||
return view(request, *args, **kwargs)
|
|
||||||
messages.error(request, msg)
|
messages.error(request, msg)
|
||||||
return redirect(reverse(
|
return redirect(reverse(
|
||||||
'users:profil',
|
'users:profil',
|
||||||
kwargs={'userid': str(request.user.id)}
|
kwargs={'userid': str(request.user.id)}
|
||||||
))
|
))
|
||||||
|
return view(request, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue