Rename `WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK` to `WAGTAILADMIN_GLOBAL_EDIT_LOCK`

pull/9763/head
Sage Abdullah 2022-12-09 12:32:50 +00:00
rodzic 10dbbddaf3
commit 1a09e2d70e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: EB1A33CC51CC0217
6 zmienionych plików z 60 dodań i 11 usunięć

Wyświetl plik

@ -259,11 +259,15 @@ WAGTAIL_AUTO_UPDATE_PREVIEW_INTERVAL = 500
The interval (in milliseconds) to check for changes made in the page editor before updating the preview. The default value is `500`.
(wagtailadmin_global_page_edit_lock)=
(wagtailadmin_global_edit_lock)=
### `WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK`
### `WAGTAILADMIN_GLOBAL_EDIT_LOCK`
`WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK` can be set to `True` to prevent users from editing pages that they have locked.
`WAGTAILADMIN_GLOBAL_EDIT_LOCK` can be set to `True` to prevent users from editing pages and snippets that they have locked.
```{versionchanged} 4.2
This setting was previously named ``WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK``, using ``WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK`` will be removed in a future release.
```
(wagtailadmin_unsafe_page_deletion_limit)=

Wyświetl plik

@ -139,3 +139,7 @@ If these are used within packages or customisations they will need to be updated
The (internal, undocumented) `InlinePanel` JavaScript function, used to initialise client-side behaviour for inline panels, has been converted to a class. Any user code that calls this function should now replace `InlinePanel(...)` calls with `new InlinePanel(...)`. Additionally, child form controls are now initialised automatically, and so it is no longer necessary to call `initChildControls`, `updateChildCount`, `updateMoveButtonDisabledStates` or `updateAddButtonState`.
Python code that uses the `InlinePanel` panel type is not affected by this change.
### `WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK` setting is now `WAGTAILADMIN_GLOBAL_EDIT_LOCK`
The `WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK` setting has been renamed to [`WAGTAILADMIN_GLOBAL_EDIT_LOCK`](wagtailadmin_global_edit_lock).

Wyświetl plik

@ -1,3 +1,5 @@
from warnings import warn
from django.conf import settings
from django.utils.html import format_html
from django.utils.safestring import mark_safe
@ -5,6 +7,7 @@ from django.utils.text import capfirst
from django.utils.translation import gettext as _
from wagtail.admin.utils import get_latest_str
from wagtail.utils.deprecation import RemovedInWagtail60Warning
class BaseLock:
@ -38,14 +41,22 @@ class BasicLock(BaseLock):
A lock that is enabled when the "locked" attribute of an object is True.
The object may be editable by a user depending on whether the locked_by field is set
and if WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK is not set to True.
and if WAGTAILADMIN_GLOBAL_EDIT_LOCK is not set to True.
"""
def for_user(self, user):
if getattr(settings, "WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK", False):
return True
else:
return user.pk != self.object.locked_by_id
global_edit_lock = getattr(settings, "WAGTAILADMIN_GLOBAL_EDIT_LOCK", None)
if global_edit_lock is None and hasattr(
settings, "WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK"
):
warn(
"settings.WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK has been renamed to "
"settings.WAGTAILADMIN_GLOBAL_EDIT_LOCK",
category=RemovedInWagtail60Warning,
)
global_edit_lock = settings.WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK
return global_edit_lock or user.pk != self.object.locked_by_id
def get_message(self, user):
title = get_latest_str(self.object)

Wyświetl plik

@ -361,7 +361,7 @@ class TestEditLockedSnippet(BaseLockingTestCase):
# Check that the snippet is edited
self.assertEqual(self.snippet.text, "Edited while locked")
@override_settings(WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK=True)
@override_settings(WAGTAILADMIN_GLOBAL_EDIT_LOCK=True)
def test_edit_post_locked_by_self_with_global_lock_enabled(self):
"""A user cannot edit a snippet that is locked by themselves if the setting is enabled."""
# Lock the snippet

Wyświetl plik

@ -67,6 +67,7 @@ from wagtail.test.testapp.models import (
TaggedPage,
)
from wagtail.test.utils import WagtailTestUtils
from wagtail.utils.deprecation import RemovedInWagtail60Warning
def get_ct(model):
@ -3675,7 +3676,7 @@ class TestGetLock(TestCase):
"<b>Page 'Christmas' is locked</b> by <b>you</b>.",
)
@override_settings(WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK=True)
@override_settings(WAGTAILADMIN_GLOBAL_EDIT_LOCK=True)
def test_when_locked_globally(self):
moderator = get_user_model().objects.get(email="eventmoderator@example.com")
@ -3697,6 +3698,35 @@ class TestGetLock(TestCase):
"<b>Page 'Christmas' was locked</b> by <b>you</b> on <b>29 Jul 2022 12:19</b>.",
)
@override_settings(WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK=True)
def test_when_locked_globally_with_old_setting_name(self):
moderator = get_user_model().objects.get(email="eventmoderator@example.com")
christmas_event = EventPage.objects.get(url_path="/home/events/christmas/")
christmas_event.locked = True
christmas_event.locked_by = moderator
christmas_event.locked_at = datetime.datetime(2022, 7, 29, 12, 19, 0)
lock = christmas_event.get_lock()
self.assertIsInstance(lock, BasicLock)
with self.assertWarnsMessage(
RemovedInWagtail60Warning,
"settings.WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK has been renamed to "
"settings.WAGTAILADMIN_GLOBAL_EDIT_LOCK",
):
self.assertTrue(lock.for_user(christmas_event.owner))
self.assertTrue(lock.for_user(moderator))
self.assertEqual(
lock.get_message(christmas_event.owner),
f"<b>Page 'Christmas' was locked</b> by <b>{str(moderator)}</b> on <b>29 Jul 2022 12:19</b>.",
)
self.assertEqual(
lock.get_message(moderator),
"<b>Page 'Christmas' was locked</b> by <b>you</b> on <b>29 Jul 2022 12:19</b>.",
)
def test_when_locked_by_workflow(self):
moderator = get_user_model().objects.get(email="eventmoderator@example.com")

Wyświetl plik

@ -758,7 +758,7 @@ class TestPagePermission(TestCase):
other_perms = UserPagePermissionsProxy(other_user).for_page(christmas_page)
self.assertTrue(other_perms.page_locked())
@override_settings(WAGTAILADMIN_GLOBAL_PAGE_EDIT_LOCK=True)
@override_settings(WAGTAILADMIN_GLOBAL_EDIT_LOCK=True)
def test_page_locked_for_locked_page_with_global_lock_enabled(self):
user = get_user_model().objects.get(email="eventmoderator@example.com")
christmas_page = EventPage.objects.get(url_path="/home/events/christmas/")