Narnik Gamarnik
Narnik Gamarnik

Reputation: 1121

Wagtail per page user permission

My task is to enable users to edit their own page.

I see how to give permissions to a particular page to a group, but how do I do this for the user?

I'd tried use django guardian:

UserObjectPermission.objects.assign_perm('change_custompage', user, obj=custompage)

but this wasn't given me results

I also found the wagtailcore_grouppagepermission table and realized that the permissions principle is not the same as used in django auth_permission

I want to give permissions to edit, and access wagtail admin, I do not need anything else

In this particular task, wagtail I need because of the struct_blocks, I think this is a terrific concept.

Now I see two options: either an override template and the ability to use all the power of the struct_block outside the wagtail, or something to solve with permissions.

Upvotes: 2

Views: 3236

Answers (2)

Narnik Gamarnik
Narnik Gamarnik

Reputation: 1121

Thanks to the help and advice of @gasman, I did this as follows:

  1. Created two models:

first:

class PersonsIndexPage(RoutablePageMixin, Page):
    ...
    @route(r'^$')
    def index_view(self, request):
        pages = PersonPage.objects.live().all()
        return render(request, 'myapp/person_index_page.html', {
            'page': self,
            'pages': pages,
        })
    ...
    subpage_types = ['PersonPage']

second:

class PersonPage(Page):
    ...
    parent_page_types = ['PersonsIndexPage']
    subpage_types = [] 
  1. For the group add access to wagtail admin, as well as gave permissions to create PersonsIndexPage

  2. Since I create personal pages from Django admin, I created a simple action that creates a page for selected users:

I do not know if bulk_create is possible

def create_person_page(modeladmin, request, queryset):
    root_page = PersonIndexPage.objects.first()
    for user in queryset:
        page = PersonPage(title=username), owner=user)
        root_page.add_child(instance=page)

create_person_page.short_description = 'Create person page'

Upvotes: 2

gasman
gasman

Reputation: 25292

Two possibilities:

  • Create a group for each user - might not seem like a very sophisticated approach, but easily achievable with a bit of scripting...
  • Put your users in a group that has add permission, but not edit permission, on the parent page that contains all of your users' pages. In Wagtail's permission model http://docs.wagtail.io/en/v1.10.1/topics/permissions.html, 'add' permission also includes the ability to edit pages that you have created yourself. (If you'd rather have the pages created in advance, rather than having your users create them, then you need to set the owner field of the page record to the relevant user.)

Upvotes: 3

Related Questions