Skip to content

Commit

Permalink
Fix #97: Do not modify Publication behavior values when creating a ne…
Browse files Browse the repository at this point in the history
…w working copy.
  • Loading branch information
ericof committed Sep 8, 2021
1 parent c6c5e89 commit dfcea9d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
1 change: 1 addition & 0 deletions news/97.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed issue with Publication behavior fields having different values in the baseline and working copy [ericof]
18 changes: 6 additions & 12 deletions plone/app/iterate/dexterity/copier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
39 changes: 39 additions & 0 deletions plone/app/iterate/tests/test_iterate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)

0 comments on commit dfcea9d

Please sign in to comment.