Wagtail per page user permission

岁酱吖の 提交于 2019-12-04 17:01:58

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

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