|
@@ -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)
|