Sync Page.Meta.permissions with PAGE_PERMISSION_TYPES

pull/10616/head
Sage Abdullah 2023-06-15 17:05:32 +01:00 zatwierdzone przez Matt Westcott
rodzic 8203b4d83e
commit 40cd588de2
3 zmienionych plików z 21 dodań i 22 usunięć

Wyświetl plik

@ -14,9 +14,9 @@ class Migration(migrations.Migration):
name="page",
options={
"permissions": [
("publish_page", "Publish any page"),
("bulk_delete_page", "Delete pages with children"),
("lock_page", "Lock/unlock pages you've locked"),
("publish_page", "Publish any page"),
("unlock_page", "Unlock any page"),
],
"verbose_name": "page",

Wyświetl plik

@ -1099,6 +1099,20 @@ class AbstractPage(
abstract = True
# Make sure that this list is sorted by the codename (first item in the tuple)
# so that we can follow the same order when querying the Permission objects.
PAGE_PERMISSION_TYPES = [
("add_page", _("Add"), _("Add/edit pages you own")),
("bulk_delete_page", _("Bulk delete"), _("Delete pages with children")),
("change_page", _("Edit"), _("Edit any page")),
("lock_page", _("Lock"), _("Lock/unlock pages you've locked")),
("publish_page", _("Publish"), _("Publish any page")),
("unlock_page", _("Unlock"), _("Unlock any page")),
]
PAGE_PERMISSION_CODENAMES = [identifier for identifier, *_ in PAGE_PERMISSION_TYPES]
class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
title = models.CharField(
verbose_name=_("title"),
@ -2623,11 +2637,12 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
verbose_name = _("page")
verbose_name_plural = _("pages")
unique_together = [("translation_key", "locale")]
# Make sure that we auto-create Permission objects that are defined in
# PAGE_PERMISSION_TYPES, skipping the default_permissions from Django.
permissions = [
("publish_page", _("Publish any page")),
("bulk_delete_page", _("Delete pages with children")),
("lock_page", _("Lock/unlock pages you've locked")),
("unlock_page", _("Unlock any page")),
(codename, name)
for codename, _, name in PAGE_PERMISSION_TYPES
if codename not in {"add_page", "change_page", "delete_page", "view_page"}
]
@ -2882,18 +2897,6 @@ class Revision(models.Model):
]
PAGE_PERMISSION_TYPES = [
("add_page", _("Add"), _("Add/edit pages you own")),
("change_page", _("Edit"), _("Edit any page")),
("publish_page", _("Publish"), _("Publish any page")),
("bulk_delete_page", _("Bulk delete"), _("Delete pages with children")),
("lock_page", _("Lock"), _("Lock/unlock pages you've locked")),
("unlock_page", _("Unlock"), _("Unlock any page")),
]
PAGE_PERMISSION_CODENAMES = [identifier for identifier, *_ in PAGE_PERMISSION_TYPES]
class GroupPagePermissionManager(models.Manager):
def create(self, **kwargs):
# Simplify creation of GroupPagePermission objects by allowing the

Wyświetl plik

@ -310,11 +310,7 @@ class PagePermissionsForm(forms.Form):
class BaseGroupPagePermissionFormSet(forms.BaseFormSet):
# defined here for easy access from templates
permission_types = sorted(
PAGE_PERMISSION_TYPES,
# sort by the codename so that they are consistent with the queryset
key=lambda permission_type: permission_type[0],
)
permission_types = PAGE_PERMISSION_TYPES
def __init__(self, data=None, files=None, instance=None, prefix="page_permissions"):
if instance is None: