Check if a user has permission to view another page in Django CMS

I would like to check if a user has the permissions (is part of the groups necessary) to view a different page than the current one.

from cms.models.permissionmodels import PagePermission
if PagePermission.objects.filter(page=page_to_check, user=request.user, can_view=True).exists():

always returns false.

How can I check if the user should be able to view the page_to_check?

Thank you!

The easiest way to check for a user to have the permission to view a page is using cms.utils.page_permissions:

from cms.utils.page_permissions import has_generic_permission

if has_generic_permission(page_to_check, user, "view_page"):
    ...

This reflects both global and per-page CMS permissions. Also, permissions caches are used - good for performance reasons.

Other actions you can check for are:

  • add_page

  • change_page

  • change_page_advanced_settings

  • change_page_permissions

  • delete_page

  • delete_page_translation

  • publish_page

  • move_page

  • view_page

Back to Top