From 55bd2323f0a6d0deb1a7197284887c18ac083716 Mon Sep 17 00:00:00 2001 From: Mara Karagianni Date: Tue, 16 Jan 2024 09:37:35 +0200 Subject: [PATCH 1/2] euth, dashboard: disable projects dashboard for non-admins --- .python-version | 1 + .../templates/euth_dashboard/dropdown.html | 4 +++ euth/dashboard/urls.py | 24 ++++++++++++++- euth/dashboard/views.py | 28 ++++++++++++++++++ euth/projects/rules.py | 6 ++++ .../templates/euth_users/indicator_menu.html | 4 +++ .../templates/a4dashboard/base_dashboard.html | 2 ++ .../templates/a4dashboard/blueprint_list.html | 18 +++++++----- .../templates/a4dashboard/project_list.html | 2 ++ tests/dashboard/test_dashboard_views.py | 29 ++++--------------- 10 files changed, 86 insertions(+), 32 deletions(-) create mode 100644 .python-version create mode 100644 euth/dashboard/views.py create mode 100644 euth/projects/rules.py diff --git a/.python-version b/.python-version new file mode 100644 index 000000000..0afbac8eb --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +opin diff --git a/euth/dashboard/templates/euth_dashboard/dropdown.html b/euth/dashboard/templates/euth_dashboard/dropdown.html index 0e39c0586..2f2a73502 100644 --- a/euth/dashboard/templates/euth_dashboard/dropdown.html +++ b/euth/dashboard/templates/euth_dashboard/dropdown.html @@ -16,7 +16,11 @@ diff --git a/euth/dashboard/urls.py b/euth/dashboard/urls.py index 163e42298..269b87201 100644 --- a/euth/dashboard/urls.py +++ b/euth/dashboard/urls.py @@ -1,6 +1,7 @@ from django.urls import re_path from adhocracy4.dashboard.urls import urlpatterns as a4dashboard_urlpatterns +from euth.dashboard import views from euth.organisations.views import DashboardOrganisationUpdateView app_name = 'a4dashboard' @@ -8,5 +9,26 @@ urlpatterns = [ re_path(r'^organisations/(?P[-\w_]+)/settings/$', DashboardOrganisationUpdateView.as_view(), - name='organisation-edit') + name='organisation-edit'), + re_path( + r"^organisations/(?P[-\w_]+)/blueprints/$", + views.BlueprintAdminListView.as_view(), + name="blueprint-list", + ), + re_path( + r"^organisations/(?P[-\w_]+)/projects/$", + views.ProjectAdminListView.as_view(), + name="project-list", + ), + re_path( + r"^organisations/(?P[-\w_]+)/blueprints/" + r"(?P[-\w_]+)/$", + views.ProjectAdminCreateView.as_view(), + name="project-create", + ), + re_path( + r"^publish/project/(?P[-\w_]+)/$", + views.ProjectAdminPublishView.as_view(), + name="project-publish", + ), ] + a4dashboard_urlpatterns diff --git a/euth/dashboard/views.py b/euth/dashboard/views.py new file mode 100644 index 000000000..57fbb750e --- /dev/null +++ b/euth/dashboard/views.py @@ -0,0 +1,28 @@ +from adhocracy4.dashboard.views import BlueprintListView +from adhocracy4.dashboard.views import ProjectCreateView +from adhocracy4.dashboard.views import ProjectListView +from adhocracy4.dashboard.views import ProjectPublishView + + +class ProjectAdminListView(ProjectListView): + """Only admins can view dashboard""" + + permission_required = "euth_projects.add_project" + + +class ProjectAdminCreateView(ProjectCreateView): + """Only admins can create new projects""" + + permission_required = "euth_projects.add_project" + + +class ProjectAdminPublishView(ProjectPublishView): + """Only admins can publish new projects""" + + permission_required = "euth_projects.change_project" + + +class BlueprintAdminListView(BlueprintListView): + """Only admins can view list of blueprints""" + + permission_required = "euth_projects.add_project" diff --git a/euth/projects/rules.py b/euth/projects/rules.py new file mode 100644 index 000000000..f0ac03efd --- /dev/null +++ b/euth/projects/rules.py @@ -0,0 +1,6 @@ +import rules +from rules.predicates import is_superuser + +rules.add_perm("euth_projects.add_project", is_superuser) + +rules.add_perm("euth_projects.change_project", is_superuser) diff --git a/euth/users/templates/euth_users/indicator_menu.html b/euth/users/templates/euth_users/indicator_menu.html index d167fc264..167388ad1 100644 --- a/euth/users/templates/euth_users/indicator_menu.html +++ b/euth/users/templates/euth_users/indicator_menu.html @@ -24,7 +24,11 @@ {% for organisation in request.user.organisations %}
  • + {% if request.user.is_superuser %} + {% else %} + + {% endif %} {{ organisation.name }}
  • diff --git a/euth_wagtail/templates/a4dashboard/base_dashboard.html b/euth_wagtail/templates/a4dashboard/base_dashboard.html index 0a8d301d4..b543382c0 100644 --- a/euth_wagtail/templates/a4dashboard/base_dashboard.html +++ b/euth_wagtail/templates/a4dashboard/base_dashboard.html @@ -20,7 +20,9 @@