From d91e1e386aa961f2fb51cf77c90a5e490900213a Mon Sep 17 00:00:00 2001 From: Fares Sellaouti Date: Sun, 27 Oct 2024 21:55:06 +0100 Subject: [PATCH] Issue 317 : Restrict organization creation : use Django permissions --- pytition/petition/templates/layouts/nav-useractions.html | 2 ++ pytition/petition/templates/petition/account_settings.html | 2 ++ pytition/petition/templates/petition/user_org_list.html | 5 ++++- pytition/petition/views.py | 2 +- pytition/pytition/settings/base.py | 1 - 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pytition/petition/templates/layouts/nav-useractions.html b/pytition/petition/templates/layouts/nav-useractions.html index 836f1c4f..33be501b 100644 --- a/pytition/petition/templates/layouts/nav-useractions.html +++ b/pytition/petition/templates/layouts/nav-useractions.html @@ -26,10 +26,12 @@ {% trans "New Petition" %} + {% if not settings.RESTRICT_ORG_CREATION or perms.petition.add_organization %} {% trans "New Organization" %} + {% endif %} diff --git a/pytition/petition/templates/petition/account_settings.html b/pytition/petition/templates/petition/account_settings.html index ab6b84ed..0eddb95e 100644 --- a/pytition/petition/templates/petition/account_settings.html +++ b/pytition/petition/templates/petition/account_settings.html @@ -71,9 +71,11 @@
{{org.nam {% else %} {% trans "You are not part of any organization" %} {% endif %} + {% if not settings.RESTRICT_ORG_CREATION or perms.petition.add_organization %} + {% endif %}
diff --git a/pytition/petition/templates/petition/user_org_list.html b/pytition/petition/templates/petition/user_org_list.html index 6f68cf38..60563acd 100644 --- a/pytition/petition/templates/petition/user_org_list.html +++ b/pytition/petition/templates/petition/user_org_list.html @@ -2,7 +2,10 @@

 {% trans "Organizations" %} ({{ user.organization_set.all.count }})

- {% trans "New organization" %} + {% if not settings.RESTRICT_ORG_CREATION or perms.petition.add_organization %} + {% trans "New organization" %} + {% endif %}
    {% for org in user.organization_set.all %} diff --git a/pytition/petition/views.py b/pytition/petition/views.py index 4cbfa742..d5fafefa 100644 --- a/pytition/petition/views.py +++ b/pytition/petition/views.py @@ -1545,7 +1545,7 @@ def account_settings(request): # Create a new organization @login_required def org_create(request): - if settings.RESTRICT_ORG_CREATION and not request.user.is_superuser: + if settings.RESTRICT_ORG_CREATION and not request.user.has_perm('petition.add_organization'): messages.error(request, _("Only super users can create an organization.")) return redirect("user_dashboard") user = get_session_user(request) diff --git a/pytition/pytition/settings/base.py b/pytition/pytition/settings/base.py index d90c024b..415e4bae 100644 --- a/pytition/pytition/settings/base.py +++ b/pytition/pytition/settings/base.py @@ -265,7 +265,6 @@ DISABLE_USER_PETITION = False #:| If set to True, regular users won't be able to create new organizations. -#:| Only superusers will be allowed to RESTRICT_ORG_CREATION = False #:| Default address for 'Reply to' field in mail sent on account creation