Skip to content
Browse files

Merge branch 'erobit-publisherfix'

  • Loading branch information...
2 parents 1a23ce9 + df5bc00 commit 8ab5ffac125e358444d9ca42ca07c9111a103b87 Jonas Obrist committed
Showing with 215 additions and 9 deletions.
  1. +1 −0 cms/admin/pageadmin.py
  2. +15 −0 cms/models/pluginmodel.py
  3. +1 −0 cms/tests/base.py
  4. +198 −9 cms/tests/plugins.py
View
1 cms/admin/pageadmin.py
@@ -1278,6 +1278,7 @@ def remove_plugin(self, request):
raise Http404
if page and settings.CMS_MODERATOR and page.is_under_moderation():
+ # delete the draft version of the plugin
plugin.delete()
else:
plugin.delete_with_public()
View
15 cms/models/pluginmodel.py
@@ -220,6 +220,7 @@ def copy_plugin(self, target_placeholder, target_language, plugin_tree):
new_plugin.level = None
new_plugin.language = target_language
new_plugin.plugin_type = self.plugin_type
+ new_plugin.position = self.position
new_plugin.save()
if plugin_instance:
plugin_instance.pk = new_plugin.pk
@@ -231,6 +232,7 @@ def copy_plugin(self, target_placeholder, target_language, plugin_tree):
plugin_instance.level = new_plugin.level
plugin_instance.cmsplugin_ptr = new_plugin
plugin_instance.language = target_language
+ plugin_instance.position = new_plugin.position # added to retain the position when creating a public copy of a plugin
plugin_instance.save()
old_instance = plugin_instance.__class__.objects.get(pk=self.pk)
plugin_instance.copy_relations(old_instance)
@@ -241,6 +243,19 @@ def copy_relations(self, old_instance):
Handle copying of any relations attached to this plugin
"""
+ def delete_with_public(self):
+ """
+ Delete the public copy of this plugin,
+ then delete the draft
+ """
+ position = self.position
+ slot = self.placeholder.slot
+ if self.page and getattr(self.page, 'publisher_public'):
+ placeholder = Placeholder.objects.get(page=self.page.publisher_public, slot=slot)
+ public_plugin = CMSPlugin.objects.get(placeholder=placeholder, position=position)
+ public_plugin.delete()
+ self.delete()
+
def has_change_permission(self, request):
page = get_page_from_placeholder_if_exists(self.placeholder)
if page:
View
1 cms/tests/base.py
@@ -13,6 +13,7 @@
URL_CMS_PAGE_CHANGE = URL_CMS_PAGE + "%d/"
URL_CMS_PLUGIN_ADD = URL_CMS_PAGE + "add-plugin/"
URL_CMS_PLUGIN_EDIT = URL_CMS_PAGE + "edit-plugin/"
+URL_CMS_PLUGIN_REMOVE = URL_CMS_PAGE + "remove-plugin/"
class _Warning(object):
def __init__(self, message, category, filename, lineno):
View
207 cms/tests/plugins.py
@@ -4,8 +4,9 @@
from django.template import TemplateDoesNotExist
from django.contrib.auth.models import User
from cms.tests.base import CMSTestCase, URL_CMS_PAGE, URL_CMS_PAGE_ADD,\
- URL_CMS_PLUGIN_ADD, URL_CMS_PLUGIN_EDIT, URL_CMS_PAGE_CHANGE
-from cms.models import Page, Title
+ URL_CMS_PLUGIN_ADD, URL_CMS_PLUGIN_EDIT, URL_CMS_PAGE_CHANGE, \
+ URL_CMS_PLUGIN_REMOVE
+from cms.models import Page, Title, Placeholder
from cms.models.pluginmodel import CMSPlugin
from cms.plugins.text.models import Text
from cms.plugins.link.models import Link
@@ -14,12 +15,46 @@
class PluginsTestCase(CMSTestCase):
def setUp(self):
- u = User(username="test", is_staff = True, is_active = True, is_superuser = True)
- u.set_password("test")
- u.save()
+ self.super_user = User(username="test", is_staff = True, is_active = True, is_superuser = True)
+ self.super_user.set_password("test")
+ self.super_user.save()
- self.login_user(u)
-
+ self.slave = User(username="slave", is_staff=True, is_active=True, is_superuser=False)
+ self.slave.set_password("slave")
+ self.slave.save()
+
+ self.login_user(self.super_user)
+
+# REFACTOR - the publish and appove methods exist in this file and in permmod.py - should they be in base?
+ def publish_page(self, page, approve=False, user=None, published_check=True):
+ if user:
+ self.login_user(user)
+
+ # publish / approve page by master
+ response = self.client.post(URL_CMS_PAGE + "%d/change-status/" % page.pk, {1 :1})
+ self.assertEqual(response.status_code, 200)
+
+ if not approve:
+ return self.reload_page(page)
+
+ # approve
+ page = self.approve_page(page)
+
+ if published_check:
+ # must have public object now
+ assert(page.publisher_public)
+ # and public object must be published
+ assert(page.publisher_public.published)
+
+ return page
+
+ def approve_page(self, page):
+ response = self.client.get(URL_CMS_PAGE + "%d/approve/" % page.pk)
+ self.assertRedirects(response, URL_CMS_PAGE)
+ # reload page
+ return self.reload_page(page)
+
+
def test_01_add_edit_plugin(self):
"""
Test that you can add a text plugin
@@ -27,7 +62,6 @@ def test_01_add_edit_plugin(self):
# add a new text plugin
page_data = self.get_new_page_data()
response = self.client.post(URL_CMS_PAGE_ADD, page_data)
-# self.assertRedirects(response, URL_CMS_PAGE)
page = Page.objects.all()[0]
plugin_data = {
'plugin_type':"TextPlugin",
@@ -121,5 +155,160 @@ def test_02_copy_plugins(self):
self.assertNotEqual(link.parent, None)
for text in Text.objects.all():
self.assertEquals(text.body, "Hello World")
+
+ def test_03_remove_plugin_before_published(self):
+ """
+ When removing a draft plugin we would expect the public copy of the plugin to also be removed
+ """
+ # add a page
+ page_data = self.get_new_page_data()
+ response = self.client.post(URL_CMS_PAGE_ADD, page_data)
+ page = Page.objects.all()[0]
+
+ # add a plugin
+ plugin_data = {
+ 'plugin_type':"TextPlugin",
+ 'language':settings.LANGUAGES[0][0],
+ 'placeholder':page.placeholders.get(slot="body").pk,
+ }
+ response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)
+ self.assertEquals(response.status_code, 200)
+ self.assertEquals(int(response.content), CMSPlugin.objects.all()[0].pk)
+ # there should be only 1 plugin
+ self.assertEquals(1, CMSPlugin.objects.all().count())
+
+ # delete the plugin
+ plugin_data = {
+ 'plugin_id': int(response.content)
+ }
+ remove_url = URL_CMS_PLUGIN_REMOVE
+ response = self.client.post(remove_url, plugin_data)
+ self.assertEquals(response.status_code, 200)
+ # there should be no plugins
+ self.assertEquals(0, CMSPlugin.objects.all().count())
+
+
+ def test_04_remove_plugin_after_published(self):
+ # add a page
+ page_data = self.get_new_page_data()
+ response = self.client.post(URL_CMS_PAGE_ADD, page_data)
+ page = Page.objects.all()[0]
+
+ # add a plugin
+ plugin_data = {
+ 'plugin_type':"TextPlugin",
+ 'language':settings.LANGUAGES[0][0],
+ 'placeholder':page.placeholders.get(slot="body").pk,
+ }
+ response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)
+ self.assertEquals(response.status_code, 200)
+ self.assertEquals(int(response.content), CMSPlugin.objects.all()[0].pk)
+ # there should be only 1 plugin
+ self.assertEquals(1, CMSPlugin.objects.all().count())
+
+ # publish page
+ page = self.publish_page(page)
+
+ # there should now be two plugins - 1 draft, 1 public
+ self.assertEquals(2, CMSPlugin.objects.all().count())
+
+ # delete the plugin
+ plugin_data = {
+ 'plugin_id': int(response.content)
+ }
+ remove_url = URL_CMS_PLUGIN_REMOVE
+ response = self.client.post(remove_url, plugin_data)
+ self.assertEquals(response.status_code, 200)
+
+ # there should be no plugins
+ self.assertEquals(0, CMSPlugin.objects.all().count())
+
+ def test_05_remove_plugin_after_published_under_moderation(self):
+ # create content as limited rights user
+ self.login_user(self.super_user)
+ page = self.create_page()
+
+ # add a plugin
+ plugin_data = {
+ 'plugin_type':"TextPlugin",
+ 'language':settings.LANGUAGES[0][0],
+ 'placeholder':page.placeholders.get(slot="body").pk,
+ }
+ response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)
+ self.assertEquals(response.status_code, 200)
+ self.assertEquals(int(response.content), CMSPlugin.objects.all()[0].pk)
+
+ # there should be only 1 plugin
+ self.assertEquals(1, CMSPlugin.objects.all().count())
+
+ # check publish box
+ page = self.publish_page(page, published_check=False)
+
+ # there should now be two plugins - 1 draft, 1 public
+ self.assertEquals(2, CMSPlugin.objects.all().count())
+
+ # --------------------------------------------
+ # Login as slave user and delete the plugin
+ # --------------------------------------------
+ self.login_user(self.super_user)
+ # delete the plugin
+ plugin_data = {
+ 'plugin_id': int(response.content)
+ }
+ remove_url = URL_CMS_PLUGIN_REMOVE
+ response = self.client.post(remove_url, plugin_data)
+ self.assertEquals(response.status_code, 200)
+
+ # there should still be 2 plugins - 1 draft, 1 public until approval
+ self.assertEquals(0, CMSPlugin.objects.all().count())
+
+ # login as super user and approve the page
+ self.login_user(self.super_user)
+ page = self.approve_page(page)
+
+ # there should now be 0 plugins
+ self.assertEquals(0, CMSPlugin.objects.all().count())
+
+ def test_06_remove_plugin_not_associated_to_page(self):
+ """
+ Test case for PlaceholderField
+ """
+ page_data = self.get_new_page_data()
+ response = self.client.post(URL_CMS_PAGE_ADD, page_data)
+ page = Page.objects.all()[0]
+
+ # add a plugin
+ plugin_data = {
+ 'plugin_type':"TextPlugin",
+ 'language':settings.LANGUAGES[0][0],
+ 'placeholder':page.placeholders.get(slot="body").pk,
+ }
+ response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)
+
+ self.assertEquals(response.status_code, 200)
+ self.assertEquals(int(response.content), CMSPlugin.objects.all()[0].pk)
+ # there should be only 1 plugin
+ self.assertEquals(1, CMSPlugin.objects.all().count())
+
+ ph = Placeholder(slot="subplugin")
+ ph.save()
+
+ plugin_data = {
+ 'plugin_type':"TextPlugin",
+ 'language':settings.LANGUAGES[0][0],
+ 'placeholder': ph.pk,
+ 'parent': int(response.content)
+ }
+
+ response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)
+
+ plugin_data = {
+ 'plugin_id': int(response.content)
+ }
+
+ remove_url = URL_CMS_PLUGIN_REMOVE
+
+ response = response.client.post(remove_url, plugin_data)
+ self.assertEquals(response.status_code, 200)
-
+

0 comments on commit 8ab5ffa

Please sign in to comment.
Something went wrong with that request. Please try again.