def login_as_baker(self): # Create group with access to admin and Chooser permission on one Collection, but not another. bakers_group = Group.objects.create(name="Bakers") access_admin_perm = Permission.objects.get( content_type__app_label="wagtailadmin", codename="access_admin") bakers_group.permissions.add(access_admin_perm) # Create the "Bakery" Collection and grant "choose" permission to the Bakers group. root = Collection.objects.get(id=get_root_collection_id()) bakery_collection = root.add_child(instance=Collection(name="Bakery")) GroupCollectionPermission.objects.create( group=bakers_group, collection=bakery_collection, permission=Permission.objects.get( content_type__app_label="wagtaildocs", codename="choose_document"), ) # Create the "Office" Collection and _don't_ grant any permissions to the Bakers group. root.add_child(instance=Collection(name="Office")) # Create a Baker user. user = self.create_user(username="******", password="******") user.groups.add(bakers_group) # Log in as the baker. self.login(user)
def test_results_no_collection_docs_upload_forbidden(self): # given an editor with access to admin panel self.login_as_editor() # and a document in a collection root_id = get_root_collection_id() root = Collection.objects.get(id=root_id) Document.objects.create(collection=root) # when searching for documents in another collection at chooser panel non_root_id = root_id + 10**10 response = self.get({"q": "", "collection_id": non_root_id}) # then results template is used self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "wagtaildocs/chooser/results.html") # and hint "You haven't uploaded any documents in this collection." is displayed self.assertContains(response, self._NO_COLLECTION_DOCS_TEXT) self.assertNotContains(response, self._UPLOAD_ONE_TEXT)
def test_results_no_collection_docs_upload_allowed(self): # given a superuser self.login_as_superuser() # and a document in a collection root_id = get_root_collection_id() root = Collection.objects.get(id=root_id) doc_title = "document.pdf" Document.objects.create(title=doc_title, collection=root) # when searching for documents in another collection at chooser panel non_root_id = root_id + 10**10 response = self.get({"q": "", "collection_id": non_root_id}) # then results template is used self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "wagtaildocs/chooser/results.html") # and the following hint is displayed: # "You haven't uploaded any documents in this collection. Why not upload one now?" self.assertContains(response, self._NO_COLLECTION_DOCS_TEXT) self.assertContains(response, self._UPLOAD_ONE_TEXT)