ソースを参照

Remove duplicate header in privacy dialog when a privacy setting is set on a parent page or collection

Matthias Brück 9 ヶ月 前
コミット
ebc77dda83

+ 1 - 0
CHANGELOG.txt

@@ -17,6 +17,7 @@ Changelog
  * Fix: Address layout issues in the title cell of universal listings (Sage Abdullah)
  * Fix: Support SVG icon id attributes with single quotes in the styleguide (Sage Abdullah)
  * Fix: Do not show delete button on model edit views if per-instance permissions prevent deletion (Matt Westcott)
+ * Fix: Remove duplicate header in privacy dialog when a privacy setting is set on a parent page or collection (Matthias Brück)
  * Docs: Remove duplicate section on frontend caching proxies from performance page (Jake Howard)
  * Docs: Document `restriction_type` field on PageViewRestriction (Shlomo Markowitz)
  * Docs: Document Wagtail's bug bounty policy (Jake Howard)

+ 1 - 0
CONTRIBUTORS.md

@@ -817,6 +817,7 @@
 * Alec Baron
 * Saksham Misra
 * Nigel van Keulen
+* Matthias Brück
 
 ## Translators
 

+ 1 - 0
docs/releases/6.2.md

@@ -31,6 +31,7 @@ depth: 1
  * Address layout issues in the title cell of universal listings (Sage Abdullah)
  * Support SVG icon id attributes with single quotes in the styleguide (Sage Abdullah)
  * Do not show delete button on model edit views if per-instance permissions prevent deletion (Matt Westcott)
+ * Remove duplicate header in privacy dialog when a privacy setting is set on a parent page or collection (Matthias Brück)
 
 
 ### Documentation

+ 2 - 6
wagtail/admin/templates/wagtailadmin/collection_privacy/ancestor_privacy.html

@@ -1,7 +1,3 @@
 {% load i18n %}
-{% include "wagtailadmin/shared/header.html" with title=_("Collection privacy") icon="no-view" %}
-
-<div class="nice-padding">
-    <p>{% trans "This collection has been made private by a parent collection." %}</p>
-    <p>{% trans "You can edit the privacy settings on:" %} <a href="{% url 'wagtailadmin_collections:edit' collection_with_restriction.id %}">{{ collection_with_restriction.name }}</a></p>
-</div>
+<p>{% trans "This collection has been made private by a parent collection." %}</p>
+<p>{% trans "You can edit the privacy settings on:" %} <a href="{% url 'wagtailadmin_collections:edit' collection_with_restriction.id %}">{{ collection_with_restriction.name }}</a></p>

+ 2 - 6
wagtail/admin/templates/wagtailadmin/page_privacy/ancestor_privacy.html

@@ -1,7 +1,3 @@
 {% load i18n %}
-{% include "wagtailadmin/shared/header.html" with title=_("Page privacy") icon="no-view" %}
-
-<div class="nice-padding">
-    <p>{% trans "This page has been made private by a parent page." %}</p>
-    <p>{% trans "You can edit the privacy settings on:" %} <a href="{% url 'wagtailadmin_pages:edit' page_with_restriction.id %}">{{ page_with_restriction.specific_deferred.get_admin_display_title }}</a></p>
-</div>
+<p>{% trans "This page has been made private by a parent page." %}</p>
+<p>{% trans "You can edit the privacy settings on:" %} <a href="{% url 'wagtailadmin_pages:edit' page_with_restriction.id %}">{{ page_with_restriction.specific_deferred.get_admin_display_title }}</a></p>

+ 49 - 1
wagtail/admin/tests/test_collections_views.py

@@ -1,3 +1,5 @@
+import json
+
 from django.contrib.auth.models import Group, Permission
 from django.contrib.contenttypes.models import ContentType
 from django.test import TestCase
@@ -5,7 +7,11 @@ from django.urls import reverse
 
 from wagtail.admin.admin_url_finder import AdminURLFinder
 from wagtail.documents.models import Document
-from wagtail.models import Collection, GroupCollectionPermission
+from wagtail.models import (
+    Collection,
+    CollectionViewRestriction,
+    GroupCollectionPermission,
+)
 from wagtail.test.utils import WagtailTestUtils
 from wagtail.test.utils.template_tests import AdminTemplateTestUtils
 
@@ -750,3 +756,45 @@ class TestDeleteCollection(CollectionInstanceTestUtils, WagtailTestUtils, TestCa
 
         # Check that the collection was not deleted
         self.assertTrue(Collection.objects.get(id=self.marketing_sub_collection.id))
+
+
+class TestSetCollectionPrivacy(CollectionInstanceTestUtils, WagtailTestUtils, TestCase):
+    def setUp(self):
+        super().setUp()
+        self.login()
+
+    def get(self, collection_id, params={}):
+        return self.client.get(
+            reverse("wagtailadmin_collections:set_privacy", args=(collection_id,)),
+            params,
+        )
+
+    def test_get_private_child(self):
+        CollectionViewRestriction.objects.create(
+            collection=self.root_collection,
+            restriction_type="password",
+            password="password123",
+        )
+        response = self.get(self.marketing_sub_collection.pk)
+        # Check response
+        self.assertEqual(response.status_code, 200)
+        self.assertTemplateUsed(
+            response, "wagtailadmin/collection_privacy/ancestor_privacy.html"
+        )
+        self.assertContains(
+            response,
+            "This collection has been made private by a parent collection.",
+        )
+
+        # Should render without any heading, as the dialog already has a heading
+        soup = self.get_soup(json.loads(response.content)["html"])
+        self.assertIsNone(soup.select_one("header"))
+        self.assertIsNone(soup.select_one("h1"))
+
+        # Should link to the edit page for the collection with the restriction
+        link = soup.select_one("a")
+        parent_edit_url = reverse(
+            "wagtailadmin_collections:edit",
+            args=(self.root_collection.pk,),
+        )
+        self.assertEqual(link.get("href"), parent_edit_url)

+ 17 - 0
wagtail/admin/tests/test_privacy.py

@@ -1,3 +1,5 @@
+import json
+
 from django.contrib.auth.models import Group
 from django.test import TestCase, override_settings
 from django.urls import reverse
@@ -117,9 +119,24 @@ class TestSetPrivacyView(WagtailTestUtils, TestCase):
         self.assertTemplateUsed(
             response, "wagtailadmin/page_privacy/ancestor_privacy.html"
         )
+        self.assertContains(
+            response, "This page has been made private by a parent page."
+        )
         self.assertEqual(
             response.context["page_with_restriction"].specific, self.private_page
         )
+        # Should render without any heading, as the dialog already has a heading
+        soup = self.get_soup(json.loads(response.content)["html"])
+        self.assertIsNone(soup.select_one("header"))
+        self.assertIsNone(soup.select_one("h1"))
+
+        # Should link to the edit page for the collection with the restriction
+        link = soup.select_one("a")
+        parent_edit_url = reverse(
+            "wagtailadmin_pages:edit",
+            args=(self.private_page.pk,),
+        )
+        self.assertEqual(link.get("href"), parent_edit_url)
 
     def test_set_password_restriction(self):
         """