From 6b7bdfcd4d0582410f965e0ece5d7b4361625d12 Mon Sep 17 00:00:00 2001 From: Grollicus <cccvgitlab.db5c7b60@grollmann.eu> Date: Wed, 25 Dec 2024 15:27:40 +0100 Subject: [PATCH] only lock static pages the user can edit --- src/core/models/pages.py | 4 ++-- src/plainui/tests/test_views.py | 3 +++ src/plainui/views/static_pages.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/models/pages.py b/src/core/models/pages.py index b8b3164ab..6b5a1bd33 100644 --- a/src/core/models/pages.py +++ b/src/core/models/pages.py @@ -196,14 +196,14 @@ class StaticPageManager(models.Manager): def get_editable_page(self, user: PlatformUser, conference: Conference, language: str, slug: str, check=False) -> tuple['StaticPage | None', bool]: """ - Request to edit the Static Page with slug `slug` in the context of `user` and `conference` and in the language `langguage`. + Request to edit the Static Page with slug `slug` in the context of `user` and `conference` and in the language `language`. Returns a tuple `(static_page, exists)` with `static_page` the `StaticPage` instance (or `None`) and `exists` a boolean iff the `StaticPage` already exists in the database and the user has sufficient permission to create it. `static_page` will be `None` iff the user is not allowed to edit this Page (even if it does not exist). Otherwise, it will be a `StaticPage` instance for the Page. - If the Page does not yet exist in the database, the returned `StaticPage` is not stored in the database (`save()` needs to be called by the callee). + If the Page does not yet exist in the database, the returned `StaticPage` is not stored in the database (`save()` needs to be called by the caller). In this case, `exists` will be `False`. """ diff --git a/src/plainui/tests/test_views.py b/src/plainui/tests/test_views.py index d04f35c66..8873c9291 100644 --- a/src/plainui/tests/test_views.py +++ b/src/plainui/tests/test_views.py @@ -667,6 +667,7 @@ class ViewsTest(ViewsTestBase): self.assertEqual(resp.context_data['page'], sp) self.assertEqual(resp.context_data['page_slug'], sp.slug) self.assertEqual(resp.context_data['writeable'], False) + self.assertEqual(resp.context_data['lock_id'], '') self.assertEqual(resp.context_data['revision'], None) self.assertIsInstance(resp.context_data['form'], StaticPageBodyForm) self.assertEqual(resp.context_data['form']['title'].value(), r2.title) @@ -701,6 +702,7 @@ class ViewsTest(ViewsTestBase): self.assertEqual(resp.context_data['page'], sp) self.assertEqual(resp.context_data['page_slug'], sp.slug) self.assertEqual(resp.context_data['writeable'], False) + self.assertEqual(resp.context_data['lock_id'], '') self.assertEqual(resp.context_data['revision'], None) self.assertIsInstance(resp.context_data['form'], StaticPageBodyForm) self.assertEqual(resp.context_data['form']['title'].value(), r2.title) @@ -757,6 +759,7 @@ class ViewsTest(ViewsTestBase): self.assertEqual(resp.context_data['page_slug'], 'test-doesnotexist') self.assertEqual(resp.context_data['writeable'], True) self.assertEqual(resp.context_data['revision'], None) + self.assertEqual(resp.context_data['lock_id'], '') # no lock self.assertIsInstance(resp.context_data['form'], StaticPageBodyForm) self.assertEqual(resp.context_data['form']['title'].value(), 'test-doesnotexist') self.assertEqual(resp.context_data['form']['body'].value(), '') diff --git a/src/plainui/views/static_pages.py b/src/plainui/views/static_pages.py index 924a27684..a4da70392 100644 --- a/src/plainui/views/static_pages.py +++ b/src/plainui/views/static_pages.py @@ -152,7 +152,7 @@ class StaticPageEditView(ConferenceRequiredMixin, TemplateView): return redirect(reverse('plainui:static_page', kwargs={'page_slug': page_slug})) lock = '' - if page_exists: + if page_exists and writeable: lock, created = Lock.objects.select_for_update().get_or_create( content_type=ContentType.objects.get_for_model(StaticPage), object_id=static_page.pk, -- GitLab