jcuot
jcuot

Reputation: 951

Wagtail set additional permissions for MyPage

Wagtail newbie here.

I am trying to add some additional permissions to specific models, but nothing shows up into the "wagtail admin". I can do this the "django" way but I have the impression that wagtail could handle this type of permissions. I could not find any hints in the wagtail documentation.

I have a new model named "MyPage":

class MyPage(Page):
    [...]

    class Meta:
        permissions = (
        ('view_restricted_document', 'can view restricted documents'),
    )

How do I make this permission available in the groups section of the wagtail admin?

Upvotes: 3

Views: 1413

Answers (1)

jcuot
jcuot

Reputation: 951

It turns out that there is a wagtail hook which does just that: "register_permsissions".

Create a file named "wagtail_hooks.py" if it does not exist in your app and enter the following:

from wagtail.wagtailcore import hooks
from django.contrib.auth.models import Permission

@hooks.register('register_permissions')
def view_restricted_page():
    return Permission.objects.filter(codename="view_restricted_document")

That's it. Now if I browse the groups section, under "Other Permissions" I can view the additional option "can view restricted document".

Upvotes: 6

Related Questions