From f65c3a991a4007a07450d290d6695398b7d69b1c Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Mon, 6 Sep 2021 15:38:25 +0200 Subject: [PATCH] =?UTF-8?q?Rajoute=20une=20page=20listant=20les=20admins?= =?UTF-8?q?=20et=20des=20ic=C3=B4nes=20pour=20voir=20plus=20facilement=20l?= =?UTF-8?q?es=20permissions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/auth/urls.py | 1 + shared/auth/views.py | 41 +++++++-- shared/locale/en/LC_MESSAGES/django.mo | Bin 17676 -> 17858 bytes shared/locale/en/LC_MESSAGES/django.po | 78 ++++++++++-------- shared/templates/auth/account-list.html | 76 ++++++++++++----- shared/templates/auth/admin-accounts.html | 72 ++++++++++++++++ .../templates/auth/permission-management.html | 12 +-- shared/templates/kadenios.html | 7 +- 8 files changed, 214 insertions(+), 73 deletions(-) create mode 100644 shared/templates/auth/admin-accounts.html diff --git a/shared/auth/urls.py b/shared/auth/urls.py index e3e15ff..2cf428e 100644 --- a/shared/auth/urls.py +++ b/shared/auth/urls.py @@ -14,4 +14,5 @@ urlpatterns = [ "permissions", views.PermissionManagementView.as_view(), name="auth.permissions" ), path("accounts", views.AccountListView.as_view(), name="auth.accounts"), + path("admins", views.AdminAccountsView.as_view(), name="auth.admins"), ] diff --git a/shared/auth/views.py b/shared/auth/views.py index 6260bfa..da17358 100644 --- a/shared/auth/views.py +++ b/shared/auth/views.py @@ -1,7 +1,7 @@ from django.contrib.auth import get_user_model from django.contrib.auth import views as auth_views from django.contrib.auth.hashers import make_password -from django.contrib.auth.mixins import UserPassesTestMixin +from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin from django.contrib.auth.models import Permission from django.contrib.messages.views import SuccessMessageMixin from django.urls import reverse, reverse_lazy @@ -13,6 +13,8 @@ from .utils import generate_password User = get_user_model() +election_perm = Permission.objects.get(codename="election_admin") +faq_perm = Permission.objects.get(codename="faq_admin") # ############################################################################# # Mixin to restrict access to staff members @@ -89,6 +91,12 @@ class AccountListView(StaffMemberMixin, ListView): ctx["cas_users"] = qs.filter(username__startswith="cas__") ctx["pwd_users"] = qs.filter(username__startswith="pwd__") + ctx["e_manager"] = User.objects.with_perm( + election_perm, backend="shared.auth.backends.PwdBackend" + ) + ctx["f_manager"] = User.objects.with_perm( + faq_perm, backend="shared.auth.backends.PwdBackend" + ) return ctx @@ -133,18 +141,37 @@ class PermissionManagementView(StaffMemberMixin, SuccessMessageMixin, FormView): user.is_staff = form.cleaned_data["full_admin"] # Election admin - perm_election = Permission.objects.get(codename="election_admin") if form.cleaned_data["election_admin"]: - perm_election.user_set.add(user) + election_perm.user_set.add(user) else: - perm_election.user_set.remove(user) + election_perm.user_set.remove(user) # FAQ admin - perm_faq = Permission.objects.get(codename="faq_admin") if form.cleaned_data["faq_admin"]: - perm_faq.user_set.add(user) + faq_perm.user_set.add(user) else: - perm_faq.user_set.remove(user) + faq_perm.user_set.remove(user) user.save() return super().form_valid(form) + + +# ############################################################################# +# List of special accounts +# ############################################################################# + + +class AdminAccountsView(LoginRequiredMixin, TemplateView): + template_name = "auth/admin-accounts.html" + + def get_context_data(self, **kwargs): + ctx = super().get_context_data(**kwargs) + + ctx["admin"] = User.objects.filter(is_staff=True) + ctx["e_manager"] = User.objects.with_perm( + election_perm, backend="shared.auth.backends.PwdBackend" + ) + ctx["f_manager"] = User.objects.with_perm( + faq_perm, backend="shared.auth.backends.PwdBackend" + ) + return ctx diff --git a/shared/locale/en/LC_MESSAGES/django.mo b/shared/locale/en/LC_MESSAGES/django.mo index 82a70a66013de6d50952f87754d3d3cd7091e56f..94f7d504dd4217ff10819dcd6c067b572fea8ac2 100644 GIT binary patch delta 4653 zcmZA44^-9V9mny96i`4(G!&J%XhJ9`3X0$#{)joVv|KE0IlaJD?m}Q(&_MG#|J9OE zbQLa_e=w5`bV@pP4HI-z$hNiCY3lJfkEi`fm#2A7+u25Yf9~(0I(tsv`+A<|_xnBn ze?P45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#}en@hcpQ&BUJgIbD`(x7*z573ZI!#Y%l9jFVu zjJn`4Ou%!f0bju}_%W*EZ&5Qiy3BjdC*yeP52NT5w)JERn%|rs~{1j9N85oa~Q3ILlKCeb~v;sBowWuX%Ld`&M3k5%ggQ&IY zMSbCY)MmPZY4{mx0K<5gb)j*n7flB0yj;|cl%bZY0(JgUOu~B9jJ2Z9@AB$F>!pxP zLm#GMX|AxTOqle++Eed&h z{%@kNo9rW{B%SCOOV*N&s&M>>)Q|~;Ylr^T1fl;sFgbRXaJkT-nY@pj^s4{+tpSIR zxfE*kg(t}_*Ln_LBwB)>l6y!cIYYE=UF1!&hP*<;$ANGGkCBz6hdfFalkjnz!X&bX zyi9_7`K99*gvUAbcs!3kAmQU@u5b&MyK)s?APYz$36NrhmY@2C?QXfWn>=F z(Howy?NlnrPe>~XA8$~|C8xp-c#yn9Hjr+jO{YVfO-BQ{KUDJm4(R=G-qpo3#IFL! zI4#%`3d=)Pv&ZpSSDugjX|UJG56PV*l1wFUlcgky=+L8>Knh6_(K{i0WKlRwF1m&( z_+z3?`jpmR&+EfvKY5x&k#~uXYLZW0C!5K0gpXfS*hXF@+VMIb@d*8^=liZa z1EWbB+2q=Sw^5iw^b*l=FS#pJ;#qd;dHy9yCLLre`5yT>=|{px8ihKN5^iwrz($hs zf9*M1|GR0NO}3CG(o8bRG_smpBEKR!9`mqSsQ0>#qvUq-0BI*WR**Q-NluUn_{|;`>O`}inH?z{P~lnJEo@j{tMZwxe)*W diff --git a/shared/locale/en/LC_MESSAGES/django.po b/shared/locale/en/LC_MESSAGES/django.po index 5f85c4b..e1c6d4a 100644 --- a/shared/locale/en/LC_MESSAGES/django.po +++ b/shared/locale/en/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-08-24 23:14+0200\n" -"PO-Revision-Date: 2021-08-24 23:14+0200\n" +"POT-Creation-Date: 2021-09-06 15:37+0200\n" +"PO-Revision-Date: 2021-09-05 17:31+0200\n" "Last-Translator: Test Translator \n" "Language-Team: \n" "Language: en\n" @@ -226,7 +226,7 @@ msgstr "" #: elections/templates/elections/admin/option.html:12 #: elections/templates/elections/admin/question.html:29 -#: elections/templates/elections/election_admin.html:156 +#: elections/templates/elections/election_admin.html:153 #: faqs/templates/faqs/faq.html:22 msgid "Modifier" msgstr "Edit" @@ -241,7 +241,7 @@ msgstr "Change the question" #: elections/templates/elections/admin/question.html:59 #: elections/templates/elections/admin/question.html:63 -#: elections/templates/elections/election_admin.html:276 +#: elections/templates/elections/election_admin.html:273 msgid "Rajouter une option" msgstr "Add an option" @@ -334,55 +334,51 @@ msgstr "Invisible election" msgid "Élection visible" msgstr "Visible election" -#: elections/templates/elections/election_admin.html:115 -msgid "Actions" -msgstr "Actions" - -#: elections/templates/elections/election_admin.html:127 +#: elections/templates/elections/election_admin.html:124 msgid "Vue classique" msgstr "Classic view" -#: elections/templates/elections/election_admin.html:138 +#: elections/templates/elections/election_admin.html:135 msgid "Rendre l'élection visible" msgstr "Make the election visible" -#: elections/templates/elections/election_admin.html:147 +#: elections/templates/elections/election_admin.html:144 msgid "Exporter les votant·e·s" msgstr "Export the list of voters" -#: elections/templates/elections/election_admin.html:165 +#: elections/templates/elections/election_admin.html:162 #: elections/templates/elections/election_upload_voters.html:32 msgid "Gestion de la liste de votant·e·s" msgstr "Management of the voters' list" -#: elections/templates/elections/election_admin.html:177 +#: elections/templates/elections/election_admin.html:174 #: elections/templates/elections/election_voters.html:76 msgid "Liste des votant·e·s" msgstr "Voters' list" -#: elections/templates/elections/election_admin.html:185 +#: elections/templates/elections/election_admin.html:182 msgid "Dépouiller" msgstr "Count" -#: elections/templates/elections/election_admin.html:197 +#: elections/templates/elections/election_admin.html:194 msgid "Publier" msgstr "Publish" -#: elections/templates/elections/election_admin.html:199 +#: elections/templates/elections/election_admin.html:196 msgid "Dépublier" msgstr "De-publish" -#: elections/templates/elections/election_admin.html:209 +#: elections/templates/elections/election_admin.html:206 msgid "Télécharger les résultats" msgstr "Download the results" -#: elections/templates/elections/election_admin.html:218 +#: elections/templates/elections/election_admin.html:215 msgid "Archiver" msgstr "Archive" -#: elections/templates/elections/election_admin.html:280 -#: elections/templates/elections/election_admin.html:285 -#: elections/templates/elections/election_admin.html:289 +#: elections/templates/elections/election_admin.html:277 +#: elections/templates/elections/election_admin.html:282 +#: elections/templates/elections/election_admin.html:286 msgid "Rajouter une question" msgstr "Add a question" @@ -392,7 +388,7 @@ msgstr "Add a question" #: elections/templates/elections/vote.html:49 #: shared/templates/auth/create-user.html:32 #: shared/templates/auth/election_login.html:34 -#: shared/templates/auth/permission-management.html:48 +#: shared/templates/auth/permission-management.html:38 #: shared/templates/authens/pwd_login.html:34 #: shared/templates/authens/pwd_reset.html:34 #: shared/templates/forms/common-form.html:25 @@ -560,7 +556,7 @@ msgstr "Vote for the question:" #: elections/templates/elections/vote.html:40 #: shared/templates/auth/create-user.html:23 #: shared/templates/auth/election_login.html:25 -#: shared/templates/auth/permission-management.html:39 +#: shared/templates/auth/permission-management.html:29 #: shared/templates/authens/pwd_login.html:25 #: shared/templates/authens/pwd_reset_confirm.html:25 #: shared/templates/forms/modal-form.html:23 @@ -703,7 +699,7 @@ msgstr "Question deleted!" msgid "Option supprimée !" msgstr "Option deleted!" -#: elections/views.py:521 +#: elections/views.py:522 msgid "Votre choix a bien été enregistré !" msgstr "Your choice has been recorded!" @@ -803,11 +799,11 @@ msgstr "Invalid username format, only CAS or password accounts are editable" msgid "Pas d'utilisateur·rice avec ce login" msgstr "No user with this username" -#: shared/auth/views.py:68 +#: shared/auth/views.py:70 msgid "Compte créé avec succès" msgstr "Account successfully created" -#: shared/auth/views.py:104 +#: shared/auth/views.py:112 msgid "Permissions modifiées avec succès !" msgstr "Permissions successfully modified!" @@ -838,24 +834,37 @@ msgstr "500 error" msgid "Erreur interne du serveur." msgstr "Internal server error." -#: shared/templates/auth/account-list.html:35 +#: shared/templates/auth/account-list.html:33 #: shared/templates/auth/admin-panel.html:31 msgid "Liste des comptes" msgstr "List of accounts" -#: shared/templates/auth/account-list.html:42 +#: shared/templates/auth/account-list.html:40 msgid "Comptes avec mot de passe" msgstr "Password accounts" -#: shared/templates/auth/account-list.html:47 -#: shared/templates/auth/account-list.html:74 +#: shared/templates/auth/account-list.html:45 +#: shared/templates/auth/account-list.html:90 msgid "Search" msgstr "" -#: shared/templates/auth/account-list.html:69 +#: shared/templates/auth/account-list.html:85 msgid "Comptes CAS" msgstr "CAS accounts" +#: shared/templates/auth/admin-accounts.html:6 +#: shared/templates/kadenios.html:14 +msgid "Liste des comptes spéciaux" +msgstr "List of special accounts" + +#: shared/templates/auth/admin-accounts.html:10 +msgid "Gestionnaires de Kadenios" +msgstr "Kadenios managers" + +#: shared/templates/auth/admin-accounts.html:32 +msgid "Gestionnaires d'élections" +msgstr "Election managers" + #: shared/templates/auth/admin-panel.html:7 msgid "Gestion de Kadenios" msgstr "Kadenios Management" @@ -874,11 +883,11 @@ msgstr "Create a password account" msgid "Connexion par mot de passe" msgstr "Password login" -#: shared/templates/auth/permission-management.html:17 +#: shared/templates/auth/permission-management.html:7 msgid "Gestion des permissions" msgstr "Permission management" -#: shared/templates/auth/permission-management.html:22 +#: shared/templates/auth/permission-management.html:12 msgid "" "Pour modifier un compte CAS, le nom d'utilisateur doit commencer par " "cas__, pour un compte avec mot de passe, pwd__." @@ -997,6 +1006,9 @@ msgstr "Log back in" msgid "Accueil" msgstr "Home" +#~ msgid "Actions" +#~ msgstr "Actions" + #~ msgid "Modification d'une option" #~ msgstr "Editing an option" diff --git a/shared/templates/auth/account-list.html b/shared/templates/auth/account-list.html index df788a8..5cdb117 100644 --- a/shared/templates/auth/account-list.html +++ b/shared/templates/auth/account-list.html @@ -2,29 +2,27 @@ {% load i18n %} -{% block extra_head %} +{% block custom_js %} {% endblock %} @@ -54,10 +52,28 @@ {# List of users #} {% for u in pwd_users %} - - - - {{ u.full_name }} ({{ u.base_username }}) +
+
+ + + + {{ u.full_name }} ({{ u.base_username }}) +
+ +
+ + + + + + + + + + + +
+
{% endfor %} @@ -81,10 +97,28 @@ {# List of users #} {% for u in cas_users %} - - - - {{ u.full_name }} ({{ u.base_username }}) +
+
+ + + + {{ u.full_name }} ({{ u.base_username }}) +
+ +
+ + + + + + + + + + + +
+
{% endfor %} diff --git a/shared/templates/auth/admin-accounts.html b/shared/templates/auth/admin-accounts.html new file mode 100644 index 0000000..ed72d5a --- /dev/null +++ b/shared/templates/auth/admin-accounts.html @@ -0,0 +1,72 @@ +{% extends "base.html" %} +{% load i18n %} + + +{% block content %} +

{% trans "Liste des comptes spéciaux" %}

+
+ +
+

{% trans "Gestionnaires de Kadenios" %}

+ +
+ {% for a in admin %} +
+ + {{ a.full_name }} + {% comment %} + + + + + + {% endcomment %} + +
+ {% endfor %} +
+
+ +
+

{% trans "Gestionnaires d'élections" %}

+ +
+ {% for m in e_manager %} +
+ + {{ m.full_name }} + {% comment %} + + + + + + {% endcomment %} + +
+ {% endfor %} +
+
+ +{% comment %} +
+

{% trans "Gestionnaires de FAQs" %}

+ +
+ {% for m in f_manager %} +
+ + {{ m.full_name }} + + + + + + +
+ {% endfor %} +
+
+{% endcomment %} + +{% endblock %} diff --git a/shared/templates/auth/permission-management.html b/shared/templates/auth/permission-management.html index 0d51a23..02dd7c8 100644 --- a/shared/templates/auth/permission-management.html +++ b/shared/templates/auth/permission-management.html @@ -2,16 +2,6 @@ {% load i18n %} -{% block extra_head %} - - -{% endblock %} - - {% block content %}

{% trans "Gestion des permissions" %}

@@ -41,7 +31,7 @@