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!
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!
Share Improve this question asked Mar 2 at 7:01 StefanStefan 233 bronze badges1 Answer
Reset to default 0The 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