From dfcea9d59ace798f8180f307c6afd488f8f55643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Andrei?= Date: Wed, 8 Sep 2021 12:08:33 +0200 Subject: [PATCH] Fix #97: Do not modify Publication behavior values when creating a new working copy. --- news/97.bugfix | 1 + plone/app/iterate/dexterity/copier.py | 18 ++++-------- plone/app/iterate/tests/test_iterate.py | 39 +++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 news/97.bugfix diff --git a/news/97.bugfix b/news/97.bugfix new file mode 100644 index 0000000..dd16af8 --- /dev/null +++ b/news/97.bugfix @@ -0,0 +1 @@ +Fixed issue with Publication behavior fields having different values in the baseline and working copy [ericof] \ No newline at end of file diff --git a/plone/app/iterate/dexterity/copier.py b/plone/app/iterate/dexterity/copier.py index d89a47f..2bc6995 100644 --- a/plone/app/iterate/dexterity/copier.py +++ b/plone/app/iterate/dexterity/copier.py @@ -64,12 +64,10 @@ def _replaceBaseline(self, baseline): except Exception: value = None - # TODO: We need a way to identify the DCFieldProperty - # fields and use the appropriate set_name/get_name if name == "effective": - baseline.effective_date = self.context.effective() + baseline.effective_date = self.context.effective_date elif name == "expires": - baseline.expiration_date = self.context.expires() + baseline.expiration_date = self.context.expiration_date elif name == "subjects": baseline.setSubject(self.context.Subject()) else: @@ -188,12 +186,10 @@ def _copyBaseline(self, container): except Exception: value = None - # TODO: We need a way to identify the DCFieldProperty - # fields and use the appropriate set_name/get_name if name == "effective": - obj.effective_date = self.context.effective() + obj.effective_date = self.context.effective_date elif name == "expires": - obj.expiration_date = self.context.expires() + obj.expiration_date = self.context.expiration_date elif name == "subjects": obj.setSubject(self.context.Subject()) else: @@ -231,12 +227,10 @@ def _replaceBaseline(self, baseline): except Exception: value = None - # TODO: We need a way to identify the DCFieldProperty - # fields and use the appropriate set_name/get_name if name == "effective": - baseline.effective_date = self.context.effective() + baseline.effective_date = self.context.effective_date elif name == "expires": - baseline.expiration_date = self.context.expires() + baseline.expiration_date = self.context.expiration_date elif name == "subjects": baseline.setSubject(self.context.Subject()) else: diff --git a/plone/app/iterate/tests/test_iterate.py b/plone/app/iterate/tests/test_iterate.py index f838f13..ecb4125 100644 --- a/plone/app/iterate/tests/test_iterate.py +++ b/plone/app/iterate/tests/test_iterate.py @@ -21,6 +21,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ################################################################## +from DateTime import DateTime from plone.app.iterate.browser.control import Control from plone.app.iterate.interfaces import ICheckinCheckoutPolicy from plone.app.iterate.testing import PLONEAPPITERATEDEX_INTEGRATION_TESTING @@ -51,6 +52,7 @@ def setUp(self): self.portal.invokeFactory("Folder", "docs") self.portal.docs.invokeFactory("Document", "doc1") self.portal.docs.invokeFactory("Document", "doc2") + self.portal.docs.invokeFactory("FolderishDocument", "doc3") # add a working copy folder self.portal.invokeFactory("Folder", "workarea") @@ -262,3 +264,40 @@ def test_baseline_relations_updated_on_checkin(self): # new baseline's relatedItems should be empty self.assertEqual(len(rels), 0) + + def test_publication_behavior_values_not_changed(self): + doc = self.portal.docs.doc1 + original_effective_date = doc.effective_date + original_expiration_date = doc.expiration_date + # Create a working copy + wc = ICheckinCheckoutPolicy(doc).checkout(self.portal.workarea) + # Check in without modifying the existing values + baseline = ICheckinCheckoutPolicy(wc).checkin("updated") + # Values should be the same of the original document + self.assertEqual(original_effective_date, baseline.effective_date) + self.assertEqual(original_expiration_date, baseline.expiration_date) + + def test_publication_behavior_values_not_changed_value_is_already_set(self): + doc = self.portal.docs.doc2 + effective_date = DateTime("2021/09/08 10:06:00 UTC") + doc.effective_date = effective_date + original_expiration_date = doc.expiration_date + # Create a working copy + wc = ICheckinCheckoutPolicy(doc).checkout(self.portal.workarea) + # Check in without modifying the existing values + baseline = ICheckinCheckoutPolicy(wc).checkin("updated") + # Values should be the same of the original document + self.assertEqual(effective_date, baseline.effective_date) + self.assertEqual(original_expiration_date, baseline.expiration_date) + + def test_publication_behavior_values_not_changed_folderish(self): + doc = self.portal.docs.doc3 + original_effective_date = doc.effective_date + original_expiration_date = doc.expiration_date + # Create a working copy + wc = ICheckinCheckoutPolicy(doc).checkout(self.portal.workarea) + # Check in without modifying the existing values + baseline = ICheckinCheckoutPolicy(wc).checkin("updated") + # Values should be the same of the original document + self.assertEqual(original_effective_date, baseline.effective_date) + self.assertEqual(original_expiration_date, baseline.expiration_date)