Commit f7d7a415 authored by Hugo LEVY-FALK's avatar Hugo LEVY-FALK

Autorise plusieurs apps dans can_view_app

parent 84a901e3
...@@ -248,10 +248,11 @@ def can_view_all(*targets): ...@@ -248,10 +248,11 @@ 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.
""" """
assert app_name in sys.modules.keys() for app_name in apps_name:
assert app_name in sys.modules.keys()
def decorator(view): def decorator(view):
"""The decorator to use on a specific view """The decorator to use on a specific view
...@@ -259,15 +260,16 @@ def can_view_app(app_name): ...@@ -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
""" """
app = sys.modules[app_name] for app_name in apps_name:
can, msg = app.can_view(request.user) app = sys.modules[app_name]
if can: can, msg = app.can_view(request.user)
return view(request, *args, **kwargs) if not can:
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment