From 411383031f5c642337fc61f8b188a27a6651088b Mon Sep 17 00:00:00 2001 From: charludo Date: Mon, 5 Feb 2024 15:08:10 +0100 Subject: [PATCH] Update page link before submitting page form --- integreat_cms/cms/models/users/user.py | 14 ++++++++ .../cms/templates/events/event_form.html | 15 +++++--- .../cms/templates/imprint/imprint_form.html | 3 +- .../cms/templates/pages/page_form.html | 15 +++++--- .../cms/templates/pois/poi_form.html | 9 +++-- .../cms/views/pages/page_tree_view.py | 11 ++---- integreat_cms/cms/views/utils/slugify_ajax.py | 26 +++++++++----- .../js/forms/prevent-premature-submission.ts | 34 +++++++++++++++++++ .../static/src/js/forms/update-permalink.ts | 16 +++++---- tests/cms/views/view_config.py | 3 ++ 10 files changed, 109 insertions(+), 37 deletions(-) create mode 100644 integreat_cms/static/src/js/forms/prevent-premature-submission.ts diff --git a/integreat_cms/cms/models/users/user.py b/integreat_cms/cms/models/users/user.py index 358295ac2a..08d4b3b1cf 100644 --- a/integreat_cms/cms/models/users/user.py +++ b/integreat_cms/cms/models/users/user.py @@ -26,6 +26,7 @@ from ..abstract_base_model import AbstractBaseModel from ..chat.chat_message import ChatMessage from ..decorators import modify_fields +from ..pages.page import Page from ..regions.region import Region from .organization import Organization @@ -209,6 +210,19 @@ def update_chat_last_visited(self) -> datetime: ) return previous_chat_last_visited + def access_granted_pages(self, region: Region) -> QuerySet[Page]: + """ + Get a list of all pages the user has been given explicit rights to edit + """ + access_granted_pages = Page.objects.filter( + models.Q(authors=self) | models.Q(editors=self) + ).filter(region=region) + if self.organization: + access_granted_pages = access_granted_pages.union( + Page.objects.filter(organization=self.organization) + ) + return access_granted_pages + def __str__(self) -> str: """ This overwrites the default Django :meth:`~django.db.models.Model.__str__` method which would return ``User object (id)``. diff --git a/integreat_cms/cms/templates/events/event_form.html b/integreat_cms/cms/templates/events/event_form.html index c8c46455bd..693e3b2223 100644 --- a/integreat_cms/cms/templates/events/event_form.html +++ b/integreat_cms/cms/templates/events/event_form.html @@ -41,10 +41,14 @@

{% include "generic_auto_save_note.html" with form_instance=event_form.instance %} {% if perms.cms.publish_event %} - - {% else %} - {% endif %} @@ -67,7 +73,8 @@

{% if event_translation_form.instance.id %} diff --git a/integreat_cms/cms/templates/imprint/imprint_form.html b/integreat_cms/cms/templates/imprint/imprint_form.html index 0af3435c28..def5b7df8e 100644 --- a/integreat_cms/cms/templates/imprint/imprint_form.html +++ b/integreat_cms/cms/templates/imprint/imprint_form.html @@ -43,8 +43,7 @@

-