mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
factorise les can_view_app
This commit is contained in:
parent
664fb7ae00
commit
5c254fa026
1 changed files with 7 additions and 20 deletions
27
re2o/acl.py
27
re2o/acl.py
|
@ -111,7 +111,7 @@ ModelC)
|
||||||
current_target = None
|
current_target = None
|
||||||
current_fields = []
|
current_fields = []
|
||||||
for target in targets:
|
for target in targets:
|
||||||
if isinstance(target, type) and issubclass(target, Model):
|
if not isinstance(target, str):
|
||||||
if current_target:
|
if current_target:
|
||||||
yield (current_target, current_fields)
|
yield (current_target, current_fields)
|
||||||
current_target = target
|
current_target = target
|
||||||
|
@ -146,6 +146,7 @@ ModelC)
|
||||||
for field in fields:
|
for field in fields:
|
||||||
can_change_fct = getattr(target, 'can_change_' + field)
|
can_change_fct = getattr(target, 'can_change_' + field)
|
||||||
yield can_change_fct(request.user, *args, **kwargs)
|
yield can_change_fct(request.user, *args, **kwargs)
|
||||||
|
|
||||||
error_messages = [
|
error_messages = [
|
||||||
x[1] for x in chain.from_iterable(
|
x[1] for x in chain.from_iterable(
|
||||||
process_target(x[0], x[1]) for x in group_targets()
|
process_target(x[0], x[1]) for x in group_targets()
|
||||||
|
@ -251,25 +252,11 @@ def can_view_app(*apps_name):
|
||||||
"""
|
"""
|
||||||
for app_name in apps_name:
|
for app_name in apps_name:
|
||||||
assert app_name in sys.modules.keys()
|
assert app_name in sys.modules.keys()
|
||||||
|
return acl_base_decorator(
|
||||||
def decorator(view):
|
'can_view',
|
||||||
"""The decorator to use on a specific view
|
*chain(sys.modules[app_name] for app_name in apps_name),
|
||||||
"""
|
on_instance=False
|
||||||
def wrapper(request, *args, **kwargs):
|
)
|
||||||
"""The wrapper used for a specific request
|
|
||||||
"""
|
|
||||||
for app_name in apps_name:
|
|
||||||
app = sys.modules[app_name]
|
|
||||||
can, msg = app.can_view(request.user)
|
|
||||||
if not can:
|
|
||||||
messages.error(request, msg)
|
|
||||||
return redirect(reverse(
|
|
||||||
'users:profil',
|
|
||||||
kwargs={'userid': str(request.user.id)}
|
|
||||||
))
|
|
||||||
return view(request, *args, **kwargs)
|
|
||||||
return wrapper
|
|
||||||
return decorator
|
|
||||||
|
|
||||||
|
|
||||||
def can_edit_history(view):
|
def can_edit_history(view):
|
||||||
|
|
Loading…
Reference in a new issue