From 6b8b5764529507ef604f1d101a4437e4074d9e09 Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Tue, 6 Mar 2018 16:31:02 +0100 Subject: [PATCH 1/6] Ajout du tag can_view_any_app et autorise de mettre plusieurs apps dans can_view_app --- re2o/templatetags/acl.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/re2o/templatetags/acl.py b/re2o/templatetags/acl.py index 28a7b4d3..c14fcbd6 100644 --- a/re2o/templatetags/acl.py +++ b/re2o/templatetags/acl.py @@ -180,13 +180,17 @@ def get_callback(tag_name, obj=None): if tag_name == 'cannot_view_all': return acl_fct(obj.can_view_all, True) if tag_name == 'can_view_app': - return acl_fct(sys.modules[obj].can_view, False) + return acl_fct(lambda x : (not any(not sys.modules[o].can_view(x) for o in obj), None), False) if tag_name == 'cannot_view_app': - return acl_fct(sys.modules[obj].can_view, True) + return acl_fct(lambda x : (not any(not sys.modules[o].can_view(x) for o in obj), None), True) if tag_name == 'can_edit_history': 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_perm('admin.change_logentry'),None),True) + if tag_name == 'can_view_any_app': + return acl_fct(lambda x : (any(sys.modules[o].can_view(x) for o in obj), None), False) + if tag_name == 'cannot_view_any_app': + return acl_fct(lambda x : (any(sys.modules[o].can_view(x) for o in obj), None), True) raise template.TemplateSyntaxError( "%r tag is not a valid can_xxx tag" % tag_name @@ -228,22 +232,25 @@ def acl_history_filter(parser, token): return AclNode(callback, oknodes, konodes) +@register.tag('can_view_any_app') +@register.tag('cannot_view_any_app') @register.tag('can_view_app') @register.tag('cannot_view_app') def acl_app_filter(parser, token): """Templatetag for acl checking on applications.""" try: - tag_name, app_name = token.split_contents() + tag_name, *app_name = token.split_contents() except ValueError: raise template.TemplateSyntaxError( - "%r tag require 1 argument : the application" + "%r tag require 1 argument : an application" % token.contents.split()[0] ) - if not app_name in sys.modules.keys(): - raise template.TemplateSyntaxError( - "%r is not a registered application for acl." - % app_name - ) + for name in app_name: + if not name in sys.modules.keys(): + raise template.TemplateSyntaxError( + "%r is not a registered application for acl." + % name + ) callback = get_callback(tag_name, app_name) From 0e282037d5d435bd5f8ab521912d12dcac200dc8 Mon Sep 17 00:00:00 2001 From: Yoann Pietri Date: Tue, 6 Mar 2018 16:38:47 +0100 Subject: [PATCH 2/6] Modification de la navbar --- re2o/acl.py | 87 ++++++++++++++++++++++++++------------------- templates/base.html | 45 +++++++++++++---------- 2 files changed, 77 insertions(+), 55 deletions(-) diff --git a/re2o/acl.py b/re2o/acl.py index f7fa75d0..a4c0027c 100644 --- a/re2o/acl.py +++ b/re2o/acl.py @@ -33,7 +33,13 @@ from django.contrib import messages from django.shortcuts import redirect from django.urls import reverse -import cotisations, logs, machines, preferences, search, topologie, users +import cotisations +import logs +import machines +import preferences +import search +import topologie +import users def can_create(model): @@ -46,7 +52,8 @@ def can_create(model): def wrapper(request, *args, **kwargs): can, msg = model.can_create(request.user, *args, **kwargs) if not can: - messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu") + messages.error( + request, msg or "Vous ne pouvez pas accéder à ce menu") return redirect(reverse('index')) return view(request, *args, **kwargs) return wrapper @@ -67,22 +74,25 @@ def can_edit(model, *field_list): except model.DoesNotExist: messages.error(request, u"Entrée inexistante") return redirect(reverse('users:profil', - kwargs={'userid':str(request.user.id)} - )) + kwargs={'userid': str(request.user.id)} + )) can, msg = instance.can_edit(request.user) if not can: - messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu") + messages.error( + request, msg or "Vous ne pouvez pas accéder à ce menu") return redirect(reverse('users:profil', - kwargs={'userid':str(request.user.id)} - )) + kwargs={'userid': str(request.user.id)} + )) for field in field_list: can_change = getattr(instance, 'can_change_' + field) can, msg = can_change(request.user, *args, **kwargs) if not can: - messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu") + messages.error( + request, msg or "Vous ne pouvez pas accéder à ce menu") return redirect(reverse('users:profil', - kwargs={'userid':str(request.user.id)} - )) + kwargs={'userid': str( + request.user.id)} + )) return view(request, instance, *args, **kwargs) return wrapper return decorator @@ -98,10 +108,12 @@ def can_change(model, *field_list): can_change = getattr(model, 'can_change_' + field) can, msg = can_change(request.user, *args, **kwargs) if not can: - messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu") + messages.error( + request, msg or "Vous ne pouvez pas accéder à ce menu") return redirect(reverse('users:profil', - kwargs={'userid':str(request.user.id)} - )) + kwargs={'userid': str( + request.user.id)} + )) return view(request, *args, **kwargs) return wrapper return decorator @@ -121,14 +133,15 @@ def can_delete(model): except model.DoesNotExist: messages.error(request, u"Entrée inexistante") return redirect(reverse('users:profil', - kwargs={'userid':str(request.user.id)} - )) + kwargs={'userid': str(request.user.id)} + )) can, msg = instance.can_delete(request.user) if not can: - messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu") + messages.error( + request, msg or "Vous ne pouvez pas accéder à ce menu") return redirect(reverse('users:profil', - kwargs={'userid':str(request.user.id)} - )) + kwargs={'userid': str(request.user.id)} + )) return view(request, instance, *args, **kwargs) return wrapper return decorator @@ -149,8 +162,8 @@ def can_delete_set(model): if not instances: messages.error(request, "Vous ne pouvez pas accéder à ce menu") return redirect(reverse('users:profil', - kwargs={'userid':str(request.user.id)} - )) + kwargs={'userid': str(request.user.id)} + )) return view(request, instances, *args, **kwargs) return wrapper return decorator @@ -170,14 +183,15 @@ def can_view(model): except model.DoesNotExist: messages.error(request, u"Entrée inexistante") return redirect(reverse('users:profil', - kwargs={'userid':str(request.user.id)} - )) + kwargs={'userid': str(request.user.id)} + )) can, msg = instance.can_view(request.user) if not can: - messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu") + messages.error( + request, msg or "Vous ne pouvez pas accéder à ce menu") return redirect(reverse('users:profil', - kwargs={'userid':str(request.user.id)} - )) + kwargs={'userid': str(request.user.id)} + )) return view(request, instance, *args, **kwargs) return wrapper return decorator @@ -190,10 +204,11 @@ def can_view_all(model): def wrapper(request, *args, **kwargs): can, msg = model.can_view_all(request.user) if not can: - messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu") + messages.error( + request, msg or "Vous ne pouvez pas accéder à ce menu") return redirect(reverse('users:profil', - kwargs={'userid':str(request.user.id)} - )) + kwargs={'userid': str(request.user.id)} + )) return view(request, *args, **kwargs) return wrapper return decorator @@ -203,16 +218,17 @@ def can_view_app(app_name): """Decorator to check if an user can view an application. """ assert app_name in sys.modules.keys() + def decorator(view): def wrapper(request, *args, **kwargs): app = sys.modules[app_name] - can,msg = app.can_view(request.user) + can, msg = app.can_view(request.user) if can: return view(request, *args, **kwargs) messages.error(request, msg) return redirect(reverse('users:profil', - kwargs={'userid':str(request.user.id)} - )) + kwargs={'userid': str(request.user.id)} + )) return wrapper return decorator @@ -223,11 +239,10 @@ def can_edit_history(view): if request.user.has_perm('admin.change_logentry'): return view(request, *args, **kwargs) messages.error( - request, - "Vous ne pouvez pas éditer l'historique." + request, + "Vous ne pouvez pas éditer l'historique." ) return redirect(reverse('users:profil', - kwargs={'userid':str(request.user.id)} - )) + kwargs={'userid': str(request.user.id)} + )) return wrapper - diff --git a/templates/base.html b/templates/base.html index 1b2adfcc..d49e0717 100644 --- a/templates/base.html +++ b/templates/base.html @@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc., + {# Load CSS and JavaScript #} {% bootstrap_css %} @@ -69,22 +70,28 @@ with this program; if not, write to the Free Software Foundation, Inc., From 97f1d927b30b12b097a28f023c07965265035bd6 Mon Sep 17 00:00:00 2001 From: matthieu Michelet Date: Tue, 6 Mar 2018 17:33:48 +0100 Subject: [PATCH 4/6] Chirac est un con --- contributors.py | 2 +- re2o/management/commands/gen_contrib.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/contributors.py b/contributors.py index 358fd27b..02a2015c 100644 --- a/contributors.py +++ b/contributors.py @@ -1,3 +1,3 @@ #!/usr/bin/env python3 -contributeurs = ['Gabriel Detraz', 'chirac', 'Maël Kervella', 'LEVY-FALK Hugo', 'Dalahro', 'lhark', 'root', 'Chirac', 'Hugo LEVY-FALK', 'guimoz', 'Mael Kervella', 'klafyvel', 'matthieu', 'Yoann Pietri', 'Simon Brélivet', 'chibrac', 'David Sinquin', 'Pierre Cadart', 'moamoak', 'Éloi Alain', 'FERNET Laouen', 'Hugo Levy-Falk', 'Yoann PIETRI', 'B', 'Daniel STAN', 'Eloi Alain', 'Guimoz', 'Hugo Hervieux', 'Joanne Steiner', 'Laouen Fernet', 'Lemesle', 'MICHELET matthieu', 'Nymous', 'Thibault de BOUTRAY', 'Tipunchetrhum', 'Éloi ALAIN'] \ No newline at end of file +contributeurs = ['Gabriel Detraz', 'chirac', 'Maël Kervella', 'LEVY-FALK Hugo', 'Dalahro', 'lhark', 'root', 'Hugo LEVY-FALK', 'Chirac', 'guimoz', 'Mael Kervella', 'klafyvel', 'matthieu', 'Yoann Pietri', 'Simon Brélivet', 'chibrac', 'David Sinquin', 'Pierre Cadart', 'moamoak', 'Éloi Alain', 'FERNET Laouen', 'Hugo Levy-Falk', 'Joanne Steiner', 'Matthieu Michelet', 'Yoann PIETRI', 'B', 'Daniel STAN', 'Eloi Alain', 'Guimoz', 'Hugo Hervieux', 'Laouen Fernet', 'Lemesle', 'MICHELET matthieu', 'Nymous', 'Thibault de BOUTRAY', 'Tipunchetrhum', 'Éloi ALAIN'] \ No newline at end of file diff --git a/re2o/management/commands/gen_contrib.py b/re2o/management/commands/gen_contrib.py index 7d7f1b02..d33b560d 100644 --- a/re2o/management/commands/gen_contrib.py +++ b/re2o/management/commands/gen_contrib.py @@ -23,8 +23,6 @@ Write in a python file the list of all contributors sorted by number of commits. This list is extracted from the FedeRez gitlab repository. """ -fous moi un truc adapté au dessus aussi - from django.core.management.base import BaseCommand, CommandError import os From 8cd7ed1a547bcf5ec7966bd4952f04518c35455e Mon Sep 17 00:00:00 2001 From: Yoann Pietri Date: Wed, 7 Mar 2018 11:45:03 +0100 Subject: [PATCH 5/6] Modification de la navbar et passage sous font awesome --- .../templates/cotisations/aff_article.html | 4 ++-- .../templates/cotisations/aff_banque.html | 4 ++-- .../cotisations/aff_cotisations.html | 8 +++---- .../templates/cotisations/aff_paiement.html | 4 ++-- .../templates/cotisations/control.html | 4 ++-- .../templates/cotisations/index_article.html | 4 ++-- .../templates/cotisations/index_banque.html | 4 ++-- .../templates/cotisations/index_paiement.html | 4 ++-- .../templates/cotisations/new_facture.html | 4 ++-- .../cotisations/new_facture_solde.html | 4 ++-- .../templates/cotisations/sidebar.html | 12 +++++----- logs/templates/logs/aff_stats_logs.html | 2 +- logs/templates/logs/aff_summary.html | 10 ++++---- logs/templates/logs/sidebar.html | 12 +++++----- machines/templates/machines/aff_machines.html | 18 +++++++------- machines/templates/machines/index_alias.html | 4 ++-- .../templates/machines/index_extension.html | 24 +++++++++---------- machines/templates/machines/index_iptype.html | 4 ++-- machines/templates/machines/index_ipv6.html | 2 +- .../templates/machines/index_machinetype.html | 4 ++-- machines/templates/machines/index_nas.html | 4 ++-- .../templates/machines/index_portlist.html | 4 ++-- .../templates/machines/index_service.html | 4 ++-- machines/templates/machines/index_vlan.html | 4 ++-- machines/templates/machines/sidebar.html | 16 ++++++------- .../preferences/display_preferences.html | 16 ++++++------- search/templates/search/sidebar.html | 4 ++-- templates/base.html | 10 ++++---- templates/buttons/add.html | 2 +- templates/buttons/edit.html | 2 +- templates/buttons/history.html | 2 +- templates/buttons/sort.html | 8 +++---- templates/buttons/suppr.html | 2 +- .../templates/topologie/aff_chambres.html | 6 ++--- .../topologie/aff_constructor_switch.html | 6 ++--- .../templates/topologie/aff_model_switch.html | 6 ++--- topologie/templates/topologie/aff_port.html | 6 ++--- topologie/templates/topologie/aff_stacks.html | 12 +++++----- .../templates/topologie/edit_stack_sw.html | 6 ++--- topologie/templates/topologie/index.html | 2 +- .../topologie/index_model_switch.html | 4 ++-- topologie/templates/topologie/index_p.html | 6 ++--- topologie/templates/topologie/index_room.html | 2 +- .../templates/topologie/index_stack.html | 2 +- topologie/templates/topologie/sidebar.html | 8 +++---- users/templates/users/aff_clubs.html | 10 ++++---- users/templates/users/aff_listright.html | 2 +- users/templates/users/aff_users.html | 8 +++---- users/templates/users/index_listright.html | 4 ++-- users/templates/users/index_schools.html | 4 ++-- users/templates/users/index_serviceusers.html | 2 +- users/templates/users/profil.html | 18 +++++++------- users/templates/users/sidebar.html | 20 ++++++++-------- 53 files changed, 175 insertions(+), 173 deletions(-) diff --git a/cotisations/templates/cotisations/aff_article.html b/cotisations/templates/cotisations/aff_article.html index f4880caf..833b7de0 100644 --- a/cotisations/templates/cotisations/aff_article.html +++ b/cotisations/templates/cotisations/aff_article.html @@ -45,11 +45,11 @@ with this program; if not, write to the Free Software Foundation, Inc., {% can_edit article %} - + {% acl_end %} - + diff --git a/cotisations/templates/cotisations/aff_banque.html b/cotisations/templates/cotisations/aff_banque.html index f31bf55a..1ef4cb76 100644 --- a/cotisations/templates/cotisations/aff_banque.html +++ b/cotisations/templates/cotisations/aff_banque.html @@ -37,11 +37,11 @@ with this program; if not, write to the Free Software Foundation, Inc., {% can_edit banque %} - + {% acl_end %} - + diff --git a/cotisations/templates/cotisations/aff_cotisations.html b/cotisations/templates/cotisations/aff_cotisations.html index 2e6eea3f..b73bc107 100644 --- a/cotisations/templates/cotisations/aff_cotisations.html +++ b/cotisations/templates/cotisations/aff_cotisations.html @@ -57,21 +57,21 @@ with this program; if not, write to the Free Software Foundation, Inc., {% if facture.valid %} - + PDF {% else %} diff --git a/cotisations/templates/cotisations/aff_paiement.html b/cotisations/templates/cotisations/aff_paiement.html index f2f9abe3..09e5acc3 100644 --- a/cotisations/templates/cotisations/aff_paiement.html +++ b/cotisations/templates/cotisations/aff_paiement.html @@ -37,11 +37,11 @@ with this program; if not, write to the Free Software Foundation, Inc., {% can_edit paiement %} - + {% acl_end %} - + diff --git a/cotisations/templates/cotisations/control.html b/cotisations/templates/cotisations/control.html index baa4938e..48071429 100644 --- a/cotisations/templates/cotisations/control.html +++ b/cotisations/templates/cotisations/control.html @@ -55,8 +55,8 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for form in controlform.forms %} {% bootstrap_form_errors form %} - - + + {{ form.instance.user.name }} {{ form.instance.user.surname }} diff --git a/cotisations/templates/cotisations/index_article.html b/cotisations/templates/cotisations/index_article.html index edc71c09..7803c2ca 100644 --- a/cotisations/templates/cotisations/index_article.html +++ b/cotisations/templates/cotisations/index_article.html @@ -31,9 +31,9 @@ with this program; if not, write to the Free Software Foundation, Inc., {% block content %}

Liste des types d'articles

{% can_create Article %} - Ajouter un type d'articles + Ajouter un type d'articles {% acl_end %} - Supprimer un ou plusieurs types d'articles + Supprimer un ou plusieurs types d'articles {% include "cotisations/aff_article.html" with article_list=article_list %}

diff --git a/cotisations/templates/cotisations/index_banque.html b/cotisations/templates/cotisations/index_banque.html index dda89843..77c23977 100644 --- a/cotisations/templates/cotisations/index_banque.html +++ b/cotisations/templates/cotisations/index_banque.html @@ -31,9 +31,9 @@ with this program; if not, write to the Free Software Foundation, Inc., {% block content %}

Liste des banques

{% can_create Banque %} - Ajouter une banque + Ajouter une banque {% acl_end %} - Supprimer une ou plusieurs banques + Supprimer une ou plusieurs banques {% include "cotisations/aff_banque.html" with banque_list=banque_list %}

diff --git a/cotisations/templates/cotisations/index_paiement.html b/cotisations/templates/cotisations/index_paiement.html index a27cb824..414c6b38 100644 --- a/cotisations/templates/cotisations/index_paiement.html +++ b/cotisations/templates/cotisations/index_paiement.html @@ -31,9 +31,9 @@ with this program; if not, write to the Free Software Foundation, Inc., {% block content %}

Liste des types de paiements

{% can_create Paiement %} - Ajouter un type de paiement + Ajouter un type de paiement {% acl_end %} - Supprimer un ou plusieurs types de paiements + Supprimer un ou plusieurs types de paiements {% include "cotisations/aff_paiement.html" with paiement_list=paiement_list %}

diff --git a/cotisations/templates/cotisations/new_facture.html b/cotisations/templates/cotisations/new_facture.html index c1206aa2..10aa69fd 100644 --- a/cotisations/templates/cotisations/new_facture.html +++ b/cotisations/templates/cotisations/new_facture.html @@ -49,7 +49,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,   {% endfor %} @@ -73,7 +73,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,   ` function add_article(){ diff --git a/cotisations/templates/cotisations/new_facture_solde.html b/cotisations/templates/cotisations/new_facture_solde.html index 2efd8e81..2c06fdb0 100644 --- a/cotisations/templates/cotisations/new_facture_solde.html +++ b/cotisations/templates/cotisations/new_facture_solde.html @@ -46,7 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,   {% endfor %} @@ -70,7 +70,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,   ` function add_article(){ diff --git a/cotisations/templates/cotisations/sidebar.html b/cotisations/templates/cotisations/sidebar.html index 3506e5e8..513eb60b 100644 --- a/cotisations/templates/cotisations/sidebar.html +++ b/cotisations/templates/cotisations/sidebar.html @@ -28,35 +28,35 @@ with this program; if not, write to the Free Software Foundation, Inc., {% block sidebar %} {% can_change Facture pdf %} - + Créer une facture - + Contrôler les factures {% acl_end %} {% can_view_all Facture %} - + Factures {% acl_end %} {% can_view_all Article %} - + Articles en vente {% acl_end %} {% can_view_all Banque %} - + Banques {% acl_end %} {% can_view_all Paiement %} - + Moyens de paiement {% acl_end %} diff --git a/logs/templates/logs/aff_stats_logs.html b/logs/templates/logs/aff_stats_logs.html index be0b5a41..77e9e9b4 100644 --- a/logs/templates/logs/aff_stats_logs.html +++ b/logs/templates/logs/aff_stats_logs.html @@ -51,7 +51,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% can_edit_history %} - + Annuler diff --git a/logs/templates/logs/aff_summary.html b/logs/templates/logs/aff_summary.html index c6eca27b..f743d637 100644 --- a/logs/templates/logs/aff_summary.html +++ b/logs/templates/logs/aff_summary.html @@ -54,7 +54,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% can_edit_history %} - + Annuler @@ -77,7 +77,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% can_edit_history%} - + Annuler @@ -96,7 +96,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% can_edit_history %} - + Annuler @@ -115,7 +115,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% can_edit_history %} - + Annuler @@ -134,7 +134,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% can_edit_history %} - + Annuler diff --git a/logs/templates/logs/sidebar.html b/logs/templates/logs/sidebar.html index fe7e63e7..0e3048e3 100644 --- a/logs/templates/logs/sidebar.html +++ b/logs/templates/logs/sidebar.html @@ -28,27 +28,27 @@ with this program; if not, write to the Free Software Foundation, Inc., {% block sidebar %} {% can_view_app logs %} - + Résumé - + Évènements - + Général - + Base de données - + Actions de cablage - + Utilisateurs {% acl_end %} diff --git a/machines/templates/machines/aff_machines.html b/machines/templates/machines/aff_machines.html index dbb3e40d..c286fcd6 100644 --- a/machines/templates/machines/aff_machines.html +++ b/machines/templates/machines/aff_machines.html @@ -46,9 +46,9 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for machine in machines_list %} - {{ machine.name|default:'Pas de nom' }} + {{ machine.name|default:'Pas de nom' }} - {{ machine.user }} + {{ machine.user }} @@ -92,7 +92,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,