8000 Fixed #6149 -- Don't render aliased plugins/placeholders if the host … · django-cms/django-cms@9acbf6a · GitHub
[go: up one dir, main page]

Skip to content

Commit 9acbf6a

Browse files
authored
Fixed #6149 -- Don't render aliased plugins/placeholders if the host page is unpublished (#6150)
1 parent e9d419f commit 9acbf6a

File tree

4 files changed

+97
-3
lines changed

4 files changed

+97
-3
lines changed

CHANGELOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Page rendering will now use the draft page instead of public page for logged in
88
users with change permissions, unless the ``preview`` GET parameter is used.
99
* Fixed "Expand all / Collapse all" not reflecting real state of the placeholder tree
10+
* Fixed a bug where Aliased plugins would render even if their host page was unpublished.
1011

1112

1213
=== 3.4.5 (2017-10-12) ===

cms/cms_plugins.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ def render(self, context, instance, placeholder):
4848
if not request or instance.is_recursive():
4949
return context
5050

51-
if instance.plugin_id:
51+
source = (instance.plugin or instance.alias_placeholder)
52+
53+
if source and source.page:
54+
# this is bad but showing unpublished content is worse
55+
can_see_content = source.page.is_published(instance.language)
56+
else:
57+
can_see_content = True
58+
59+
if can_see_content and instance.plugin:
5260
plugins = instance.plugin.get_descendants().order_by('placeholder', 'path')
5361
plugins = [instance.plugin] + list(plugins)
5462
plugins = downcast_plugins(plugins, request=request)
@@ -57,7 +65,7 @@ def render(self, context, instance, placeholder):
5765
plugins = build_plugin_tree(plugins)
5866
context['plugins'] = plugins
5967

60-
if instance.alias_placeholder_id:
68+
if can_see_content and instance.alias_placeholder:
6169
toolbar = get_toolbar_from_request(request)
6270
renderer = toolbar.content_renderer
6371
content = renderer.render_placeholder(

cms/models/pagemodel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ def is_new_dirty(self):
843843
return True
844844

845845
def is_published(self, language, force_reload=False):
846-
title_obj = self.get_title_obj(language, False, force_reload=force_reload)
846+
title_obj = self.get_title_obj(language, fallback=False, force_reload=force_reload)
847847
return title_obj.published and title_obj.publisher_state != PUBLISHER_STATE_PENDING
848848

849849
def is_reachable(self):

cms/tests/test_alias.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,91 @@ def test_alias_recursion(self):
7171
self.assertEqual(response.status_code, 200)
7272
self.assertContains(response, '<div class="info">', html=True)
7373

74+
def test_alias_ref_plugin_on_unpublished_page(self):
75+
superuser = self.get_superuser()
76+
source_page = api.create_page(
77+
"Alias plugin",
78+
"col_two.html",
79+
"en",
80+
published=False,
81+
)
82+
source_plugin = api.add_plugin(
83+
source_page.placeholders.get(slot="col_left"),
84+
'LinkPlugin',
85+
language='en',
86+
name='A Link',
87+
external_link='https://www.django-cms.org',
88+
)
89+
target_page = api.create_page(
90+
"Alias plugin",
91+
"col_two.html",
92+
"en",
93+
published=False,
94+
)
95+
api.add_plugin(
96+
target_page.placeholders.get(slot="col_left"),
97+
'AliasPlugin',
98+
language='en',
99+
plugin=source_plugin,
100+
)
101+
102+
with self.login_user_context(superuser):
103+
# Source page is unpublished. Alias plugin should not render anything.
104+
response = self.client.get(target_page.get_absolute_url() + '?edit')
105+
self.assertEqual(response.status_code, 200)
106+
self.assertNotContains(response, '<a href="https://www.django-cms.org" >A Link</a>', html=True)
107+
108+
source_page.publish('en')
109+
110+
with self.login_user_context(superuser):
111+
# Source page is published. Alias plugin should render normally.
112+
response = self.client.get(target_page.get_absolute_url() + '?edit')
113+
self.assertEqual(response.status_code, 200)
114+
self.assertContains(response, '<a href="https://www.django-cms.org" >A Link</a>', html=True)
115+
116+
def test_alias_ref_placeholder_on_unpublished_page(self):
117+
superuser = self.get_superuser()
118+
source_page = api.create_page(
119+
"Alias plugin",
120+
"col_two.html",
121+
"en",
122+
published=False,
123+
)
124+
source_placeholder = source_page.placeholders.get(slot="col_left")
125+
api.add_plugin(
126+
source_placeholder,
127+
'LinkPlugin',
128+
language='en',
129+
name='A Link',
130+
external_link='https://www.django-cms.org',
131+
)
132+
target_page = api.create_page(
133+
"Alias plugin",
134+
"col_two.html",
135+
"en",
136+
published=False,
137+
)
138+
api.add_plugin(
139+
target_page.placeholders.get(slot="col_left"),
140+
'AliasPlugin',
141+
language='en',
142+
alias_placeholder=source_placeholder,
143+
)
144+
145+
with self.login_user_context(superuser):
146+
# Source page is unpublished. Alias plugin should not render anything.
147+
response = self.client.get(target_page.get_absolute_url() + '?edit')
148+
self.assertEqual(response.status_code, 200)
149+
self.assertNotContains(response, '<a href="https://www.django-cms.org" >A Link</a>', html=True)
150+
151+
source_page.publish('en')
152+
153+
with self.login_user_context(superuser):
154+
# Source page is published. Alias plugin should render normally.
155+
response = self.client.get(target_page.get_absolute_url() + '?edit')
156+
self.assertEqual(response.status_code, 200)
157+
self.assertContains(response, '<a href="https://www.django-cms.org" >A Link</a>', html=True)
158+
74159
def test_alias_placeholder_is_not_editable(self):
75160
"""
76161
When a placeholder is aliased, it shouldn't render as editable

0 commit comments

Comments
 (0)
0