From b2c55b824a69d2bac79c8667c29d687542656838 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Fri, 7 Jan 2022 23:58:40 +0100 Subject: [PATCH] Fixe un bug de migration si on n'a pas de db initiale --- shared/auth/views.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/shared/auth/views.py b/shared/auth/views.py index da17358..b63f001 100644 --- a/shared/auth/views.py +++ b/shared/auth/views.py @@ -13,8 +13,6 @@ 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 @@ -92,10 +90,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" + Permission.objects.get(codename="election_admin"), + backend="shared.auth.backends.PwdBackend", ) ctx["f_manager"] = User.objects.with_perm( - faq_perm, backend="shared.auth.backends.PwdBackend" + Permission.objects.get(codename="faq_admin"), + backend="shared.auth.backends.PwdBackend", ) return ctx @@ -141,12 +141,14 @@ class PermissionManagementView(StaffMemberMixin, SuccessMessageMixin, FormView): user.is_staff = form.cleaned_data["full_admin"] # Election admin + election_perm = Permission.objects.get(codename="election_admin") if form.cleaned_data["election_admin"]: election_perm.user_set.add(user) else: election_perm.user_set.remove(user) # FAQ admin + faq_perm = Permission.objects.get(codename="faq_admin") if form.cleaned_data["faq_admin"]: faq_perm.user_set.add(user) else: @@ -169,9 +171,11 @@ class AdminAccountsView(LoginRequiredMixin, TemplateView): ctx["admin"] = User.objects.filter(is_staff=True) ctx["e_manager"] = User.objects.with_perm( - election_perm, backend="shared.auth.backends.PwdBackend" + Permission.objects.get(codename="election_admin"), + backend="shared.auth.backends.PwdBackend", ) ctx["f_manager"] = User.objects.with_perm( - faq_perm, backend="shared.auth.backends.PwdBackend" + Permission.objects.get(codename="faq_admin"), + backend="shared.auth.backends.PwdBackend", ) return ctx