Justin Porter
Justin Porter

Reputation: 33

Wagtail: set default page privacy

I would like to modify the default 'privacy level' of for a page class in Wagtail. In other words, when an admin panel user goes to create a new instance of MyPage, the default privacy would be accessible to logged-in users only, rather than completely public.

This seems like something that should have an obvious answer, but after quite a lot of googling, I can't seem to find any description of how this might be done.

Thanks!

Upvotes: 3

Views: 817

Answers (2)

Yannic Hamann
Yannic Hamann

Reputation: 5205

I have found out that if you set the page privacy of the parent page to private all subpages automatically appear as private. This may be sufficient for the most cases. At least it was for mine.

If you still want to handle the case on page creation you may create a PageViewRestriction by hooking into the save method of the model or WagtailAdminPageForm.

from wagtail.core.models import PageViewRestriction

your_page = YourPageModel.objects.all().first()
PageViewRestriction.objects.create(page=your_page, restriction_type='login')

Upvotes: 1

FlipperPA
FlipperPA

Reputation: 14311

AFAIK, there is not currently an option in Wagtail to set a default privacy level on pages. There doesn't seem to be an issue on GitHub for this either; perhaps add one?

https://github.com/wagtail/wagtail/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20privacy

Good luck!

Upvotes: 1

Related Questions