Skip to content

fix: Sites menu was empty in the page tree #8064

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 14 commits into from
Nov 6, 2024
Merged
9 changes: 9 additions & 0 deletions cms/admin/pageadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,14 @@ def has_delete_translation_permission(self, request, language, obj=None):
)
return has_perm

def get_sites_for_user(self, user):
sites = Site.objects.order_by('name')

if not get_cms_setting('PERMISSION') or user.is_superuser:
return sites
_has_perm = page_permissions.user_can_change_at_least_one_page
return [site for site in sites if _has_perm(user, site)]

def changelist_view(self, request, extra_context=None):
from django.contrib.admin.views.main import ERROR_FLAG

Expand Down Expand Up @@ -1090,6 +1098,7 @@ def changelist_view(self, request, extra_context=None):
'admin': self,
'tree': {
'site': site,
'sites': self.get_sites_for_user(request.user),
'query': query,
'is_filtered': changelist_form.is_filtered(),
'items': pages,
Expand Down
2 changes: 1 addition & 1 deletion cms/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ def test_tree_view_queries(self):

user = self.get_superuser()
with self.login_user_context(user):
with self.assertNumQueries(6):
with self.assertNumQueries(7):
force_str(self.client.get(self.get_pages_admin_list_uri('en')))

def test_smart_link_pages(self):
Expand Down
Loading