From 54d69790b75d6c7cd104d278459da0fed2dccd7f Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 1 Jan 2018 17:08:33 +0100 Subject: [PATCH] Gestion de la page des logs avec has_perm --- logs/acl.py | 2 +- logs/views.py | 2 +- re2o/acl.py | 2 +- re2o/templatetags/acl.py | 4 ++-- users/migrations/0066_grouppermissions.py | 8 ++++++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/logs/acl.py b/logs/acl.py index 9a61d602..fc980db4 100644 --- a/logs/acl.py +++ b/logs/acl.py @@ -35,5 +35,5 @@ def can_view(user): A couple (allowed, msg) where allowed is a boolean which is True if viewing is granted and msg is a message (can be None). """ - can = user.has_module_perms('logs') + can = user.has_module_perms('admin') return can, None if can else "Vous ne pouvez pas voir cette application." diff --git a/logs/views.py b/logs/views.py index 850790da..d899d2f6 100644 --- a/logs/views.py +++ b/logs/views.py @@ -408,7 +408,7 @@ def stats_users(request): num=Count('whitelist') ).order_by('-num')[:10], 'Droits': User.objects.annotate( - num=Count('right') + num=Count('groups') ).order_by('-num')[:10], }, 'Etablissement': { diff --git a/re2o/acl.py b/re2o/acl.py index 3226ec7c..bfacd573 100644 --- a/re2o/acl.py +++ b/re2o/acl.py @@ -222,7 +222,7 @@ def can_view_app(app_name): def can_edit_history(view): """Decorator to check if an user can edit history.""" def wrapper(request, *args, **kwargs): - if request.user.has_perms(('admin',)): + if request.user.has_perm('admin.change_logentry'): return view(request, *args, **kwargs) messages.error( request, diff --git a/re2o/templatetags/acl.py b/re2o/templatetags/acl.py index 4c2ea15d..79bdbc5f 100644 --- a/re2o/templatetags/acl.py +++ b/re2o/templatetags/acl.py @@ -183,9 +183,9 @@ def get_callback(tag_name, obj=None): if tag_name == 'cannot_view_app': return acl_fct(sys.modules[obj].can_view, True) if tag_name == 'can_edit_history': - return acl_fct(lambda user:(user.has_perms(('admin',)),None),False) + return acl_fct(lambda user:(user.has_perm('admin.change_logentry'),None),False) if tag_name == 'cannot_edit_history': - return acl_fct(lambda user:(user.has_perms(('admin',)),None),True) + return acl_fct(lambda user:(user.has_perm('admin.change_logentry'),None),True) raise template.TemplateSyntaxError( "%r tag is not a valid can_xxx tag" % tag_name diff --git a/users/migrations/0066_grouppermissions.py b/users/migrations/0066_grouppermissions.py index 28e40206..4ac325a1 100644 --- a/users/migrations/0066_grouppermissions.py +++ b/users/migrations/0066_grouppermissions.py @@ -68,7 +68,8 @@ class Migration(migrations.Migration): 'change_whitelist', 'delete_whitelist', 'view_whitelist'], - 'cableur': ['view_article', + 'cableur': ['add_logentry', + 'view_article', 'add_banque', 'change_banque', 'delete_banque', @@ -185,7 +186,10 @@ class Migration(migrations.Migration): 'change_vente', 'delete_vente', 'view_vente'], - 'admin': ['add_assooption', + 'admin': ['add_logentry', + 'change_logentry', + 'delete_logentry', + 'add_assooption', 'change_assooption', 'delete_assooption', 'view_assooption',