最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

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

发布评论

评论列表(0)

  1. 暂无评论