Restrict pages visible in admin for users.

339 views
Skip to first unread message

Wojtek Nowak

unread,
Mar 17, 2016, 9:53:58 AM3/17/16
to Wagtail support
Hello!

I have simple workflow:
  1. site has several users, 
  2. each user have his own wagtail site, 
  3. each site has it's own:
    • root_page 
    • Moderators group with Permission(codename='access_admin') and GroupPagePermission(page=site.root_page, permission_type=['add', 'edit', 'publish'])
    • Editors group with Permission(codename='access_admin') and GroupPagePermission(page=site.root_page, permission_type=['add', 'edit'])
Currently when user is logged he can see all pages, but only edit his own.

Is there any wagtail-way to restrict Page explorer so that user can't see other pages in explorer and other places?


Structure of pages:

0001 - root

00010001 - subscriber1.localhost 

00010002 - subscriber2.localhost 

00010003 - subscriber3.localhost 


kind regards,

Wojtek




Daniel

unread,
Mar 17, 2016, 11:10:57 AM3/17/16
to Wagtail support
Hello,

I think  you can use the new hook introduced in wagtail 1.4

Take a look :)

Wojtek Nowak

unread,
Mar 17, 2016, 1:15:23 PM3/17/16
to Wagtail support
Hello! 

Thank you very much!

But actually it's partial solution to my problem.

@hooks.register('construct_explorer_page_queryset') works fine for filtering in /wagtail-admin/pages/.

What I also wanted to do is to filer pages in menu, which is on click ajax request to /wagtail-admin/explorer-nav/.
which calls in view -> get_navigation_menu_items() which is not filtred by any hook. (or i'm missing sth).

kind regards,
Wojtek

Robert Slotboom

unread,
Jun 2, 2016, 9:12:40 AM6/2/16
to Wagtail support
Hi Wojtek,

Interesting. I just posted a similar question.
Did you find any solution?

best regards,

Robert

Robert Slotboom

unread,
Jun 2, 2016, 11:14:58 AM6/2/16
to Wagtail support
Hi Wojtek,

One step further...

I added an extra entry to demo.urls.py:

from demo import views

urlpatterns
= [
    url
(r'^django-admin/', include(admin.site.urls)),
    url
(r'^admin/explorer-nav/$', views.explorer_nav, name='wagtailadmin_explorer_nav'),
    url
(r'^admin/', include(wagtailadmin_urls)),
    url
(r'', include(wagtail_urls)),
]


 and created a custom view in demo.views.py

def get_navigation_menu_items(request):
    site_root_page_id
= request.site.root_page_id
   
if site_root_page_id:
        site_root_page
= Page.objects.filter(id=site_root_page_id)
       
return [site_root_page,]
   
else:
       
return []

def explorer_nav(request):
   
return render(request, 'wagtailadmin/shared/explorer_nav.html', {
       
'nodes': get_navigation_menu_items(request),
   
}
)


As you can see the request is handed over to the view and used to call get_navigation_menu_items.
This setup works but I guess some checks have to be added.

@hooks.register('construct_explorer_page_queryset') can be used to restrict the result in

admin/pages/



Best regards,


Robert







 

Robert Slotboom

unread,
Jun 8, 2016, 9:39:21 AM6/8/16
to Wagtail support
Reply all
Reply to author
Forward
0 new messages