Skip to content

fix: Allow viewing page settings even if page cannot be changed #7921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cms/admin/pageadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,24 @@ def has_change_permission(self, request, obj=None):
)
return can_change_page

def has_view_permission(self, request, obj=None):
"""
Return true if the current user has permission on the page.
Return the string 'All' if the user has all rights.
"""
# Identical to has_change_permission, but will remain untouched by any subclassing
# as done, e.g., by djangocms-versioning
site = get_site(request)

if obj:
return page_permissions.user_can_change_page(request.user, page=obj.page, site=site)
can_view_page = page_permissions.user_can_change_at_least_one_page(
user=request.user,
site=get_site(request),
use_cache=False,
)
return can_view_page

def has_delete_permission(self, request, obj=None):
"""
Returns True if the current user has permission to delete the page.
Expand Down
4 changes: 2 additions & 2 deletions cms/tests/test_permmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def test_emulate_admin_index(self):
with self.assertNumQueries(FuzzyInt(3, max_queries)):
# internally this calls PageAdmin.has_[add|change|delete|view]_permission()
expected_perms = {'add': True, 'change': True, 'delete': False}
expected_perms.update({'view': False}) # Why
expected_perms.update({'view': expected_perms['change']})
self.assertEqual(expected_perms, site._registry[PageContent].get_model_perms(request))

# can't use the above loop for this test, as we're testing that
Expand Down Expand Up @@ -619,7 +619,7 @@ def test_emulate_admin_index(self):
request.current_page = None
request.session = {}
expected_perms = {'add': True, 'change': True, 'delete': False}
expected_perms.update({'view': False})
expected_perms.update({'view': expected_perms['change']})
self.assertEqual(expected_perms, site._registry[PageContent].get_model_perms(request))

def test_has_page_add_permission_with_target(self):
Expand Down