Fix privacy collection status label for children of private collections

Fixes #12972
pull/12879/head
smark-1 2025-03-16 16:06:54 -04:00 zatwierdzone przez LB (Ben Johnston)
rodzic 273d231992
commit c4922ccd39
4 zmienionych plików z 66 dodań i 15 usunięć

Wyświetl plik

@ -27,6 +27,7 @@ Changelog
* Fix: Fix setup.cfg syntax for setuptools v78 (Sage Abdullah)
* Fix: Ensure `ImproperlyConfigured` is thrown from `db_field` on unbound `FieldPanel`s as intended (Matt Westcott)
* Fix: Refine the positioning of the add comment button next to select, radio, checkbox fields and between field row columns (Srishti Jaiswal)
* Fix: Show the correct privacy status for child collections of private collections (Shlomo Markowitz)
* Docs: Add missing `django.contrib.admin` to list of apps in "add to Django project" guide (Mohamed Rabiaa)
* Docs: Add tutorial on deploying on Ubuntu to third-party tutorials (Mohammad Fathi Rahman)
* Docs: Document that request_or_site is optional on BaseGenericSetting.load (Matt Westcott)

Wyświetl plik

@ -42,6 +42,7 @@ This version adds formal support for Django 5.2.
* Fix setup.cfg syntax for setuptools v78 (Sage Abdullah)
* Ensure `ImproperlyConfigured` is thrown from `db_field` on unbound `FieldPanel`s as intended (Matt Westcott)
* Refine the positioning of the add comment button next to select, radio, checkbox fields and between field row columns (Srishti Jaiswal)
* Show the correct privacy status for child collections of private collections (Shlomo Markowitz)
### Documentation

Wyświetl plik

@ -54,7 +54,6 @@ from wagtail.coreutils import (
)
from wagtail.coreutils import cautious_slugify as _cautious_slugify
from wagtail.models import (
CollectionViewRestriction,
Locale,
Page,
PageViewRestriction,
@ -237,24 +236,14 @@ def classnames(*classes):
return " ".join([classname.strip() for classname in flattened if classname])
@register.simple_tag(takes_context=True)
def test_collection_is_public(context, collection):
@register.simple_tag()
def test_collection_is_public(collection):
"""
Usage: {% test_collection_is_public collection as is_public %}
Sets 'is_public' to True iff there are no collection view restrictions in place
Sets 'is_public' to True if there are no collection view restrictions in place
on this collection.
Caches the list of collection view restrictions in the context, to avoid repeated
DB queries on repeated calls.
"""
if "all_collection_view_restrictions" not in context:
context["all_collection_view_restrictions"] = (
CollectionViewRestriction.objects.select_related("collection").values_list(
"collection__name", flat=True
)
)
is_private = collection.name in context["all_collection_view_restrictions"]
is_private = collection.get_view_restrictions().exists()
return not is_private

Wyświetl plik

@ -810,3 +810,63 @@ class TestSetCollectionPrivacy(CollectionInstanceTestUtils, WagtailTestUtils, Te
args=(self.root_collection.pk,),
)
self.assertEqual(link.get("href"), parent_edit_url)
class TestCollectionPrivacyStatusLabels(WagtailTestUtils, TestCase):
def setUp(self):
self.user = self.login()
self.root_collection = Collection.get_first_root_node()
self.public_collection = self.root_collection.add_child(name="Public_photos1")
self.private_collection = self.root_collection.add_child(name="Private_photos1")
CollectionViewRestriction.objects.create(
collection=self.private_collection,
restriction_type=CollectionViewRestriction.LOGIN,
)
self.root_collection.refresh_from_db()
self.private_collection.refresh_from_db()
self.public_collection.refresh_from_db()
self.sub_private_collection = self.private_collection.add_child(
name="Sub_private_photos1"
)
self.sub_public_collection = self.public_collection.add_child(
name="Sub_public_photos1"
)
def test_admin_displays_private_tag_for_private_base_collections(self):
request = self.client.get(
reverse("wagtailadmin_collections:edit", args=[self.private_collection.pk])
)
self.assertTrue('class="privacy-indicator private"' in str(request.content))
self.assertFalse('class="privacy-indicator "' in str(request.content))
def test_admin_displays_private_tag_for_private_sub_collections(self):
request = self.client.get(
reverse(
"wagtailadmin_collections:edit", args=[self.sub_private_collection.pk]
)
)
self.assertTrue('class="privacy-indicator private"' in str(request.content))
self.assertFalse('class="privacy-indicator public"' in str(request.content))
def test_admin_displays_public_tag_for_public_base_collections(self):
request = self.client.get(
reverse("wagtailadmin_collections:edit", args=[self.public_collection.pk])
)
self.assertTrue('class="privacy-indicator public"' in str(request.content))
self.assertFalse('class="privacy-indicator private"' in str(request.content))
def test_admin_displays_public_tag_for_public_sub_collections(self):
request = self.client.get(
reverse(
"wagtailadmin_collections:edit", args=[self.sub_public_collection.pk]
)
)
self.assertTrue('class="privacy-indicator public"' in str(request.content))
self.assertFalse('class="privacy-indicator private"' in str(request.content))