diff --git a/cms/admin/pageadmin.py b/cms/admin/pageadmin.py index a9b706d2655..17f0e19bb97 100644 --- a/cms/admin/pageadmin.py +++ b/cms/admin/pageadmin.py @@ -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. diff --git a/cms/tests/test_permmod.py b/cms/tests/test_permmod.py index a0337a18812..aed82d1f9f4 100644 --- a/cms/tests/test_permmod.py +++ b/cms/tests/test_permmod.py @@ -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 @@ -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):