Wagtail per page user permission

≡放荡痞女 提交于 2019-12-06 10:34:15

问题


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.


回答1:


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



回答2:


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'


来源:https://stackoverflow.com/questions/44079327/wagtail-per-page-user-permission

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!