Skip to content

Commit

Permalink
Fix publishing static placeholders outside of CMS
Browse files Browse the repository at this point in the history
Fix #6433
Fix #6812
  • Loading branch information
Adrien Delhorme committed Mar 1, 2022
1 parent a412870 commit 8f2908f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -6,6 +6,8 @@ Changelog
unreleased
==========

* Fix publishing of static placeholders outside of CMS pages

3.9.0 (2021-06-30)
==================

Expand Down Expand Up @@ -52,7 +54,7 @@ Bug Fixes:
* Fix styles issues, caused by switching to the ``display: flex`` on the page tree renderer.
* Fixed missing builtin arguments on main ``cms`` management command causing it to crash
* Fixed template label nested translation
* Fixed a bug where the fallback page title whould be returned instead of the one from the current language
* Fixed a bug where the fallback page title whould be returned instead of the one from the current language
* Fixed an issue when running migrations on a multi database project
* Fixes #7033: also check for Django 3.2, now that 3.9 supports it. (#7054) (02083f2dc) -- Marco Bonetti

Expand Down
15 changes: 8 additions & 7 deletions cms/cms_toolbars.py
Expand Up @@ -316,18 +316,19 @@ def get_title(self):
return None

def has_publish_permission(self):
if self.page:
publish_permission = page_permissions.user_can_publish_page(
if self.page is not None:
has_publish_permission = page_permissions.user_can_publish_page(
self.request.user,
page=self.page,
site=self.current_site
site=self.current_site,
)
else:
publish_permission = False
has_publish_permission = False

if (has_publish_permission or self.page is None) and self.statics:
has_publish_permission = all(sp.has_publish_permission(self.request) for sp in self.dirty_statics)

if publish_permission and self.statics:
publish_permission = all(sp.has_publish_permission(self.request) for sp in self.dirty_statics)
return publish_permission
return has_publish_permission

def has_unpublish_permission(self):
return self.has_publish_permission()
Expand Down
26 changes: 25 additions & 1 deletion cms/tests/test_toolbar.py
Expand Up @@ -8,6 +8,7 @@
from django.contrib.admin.models import CHANGE, LogEntry
from django.contrib.auth.models import AnonymousUser, Permission
from django.contrib.contenttypes.models import ContentType
from django.template import RequestContext
from django.template.defaultfilters import truncatewords
from django.test import TestCase
from django.test.client import RequestFactory
Expand All @@ -24,7 +25,7 @@
DEFAULT_HELP_MENU_ITEMS, HELP_MENU_IDENTIFIER, LANGUAGE_MENU_IDENTIFIER)
from cms.middleware.toolbar import ToolbarMiddleware
from cms.constants import PUBLISHER_STATE_DIRTY
from cms.models import Page, UserSettings, PagePermission
from cms.models import Page, UserSettings, PagePermission, StaticPlaceholder
from cms.test_utils.project.placeholderapp.models import Example1, CharPksExample
from cms.test_utils.project.placeholderapp.views import detail_view, detail_view_char, ClassDetail
from cms.test_utils.testcases import (
Expand Down Expand Up @@ -661,6 +662,29 @@ def test_publish_button(self):
items = toolbar.get_left_items() + toolbar.get_right_items()
self.assertEqual(len(items), 8)

def test_publish_button_no_page(self):
static_placeholder = StaticPlaceholder.objects.create(name="foo", code='bar', site_id=1)
request = self.get_page_request(None, self.get_superuser(), '/', edit=True)

# Add content to static placeholder, and mark as dirty
plugin = add_plugin(
static_placeholder.draft, "TextPlugin", "en",
body="01",
)
plugin.save()
static_placeholder.dirty = True
static_placeholder.save()

toolbar = CMSToolbar(request)
renderer = toolbar.get_content_renderer()
renderer.render_static_placeholder(static_placeholder, RequestContext(request))
toolbar.populate()
toolbar.post_template_populate()

items = toolbar.get_left_items() + toolbar.get_right_items()
self.assertTrue(toolbar.edit_mode_active)
self.assertEqual(len(items), 7)

def test_no_publish_button(self):
page = create_page('test', 'nav_playground.html', 'en', published=True)
user = self.get_staff()
Expand Down

0 comments on commit 8f2908f

Please sign in to comment.