Skip to content

Commit

Permalink
fix: update relations on Check-In fix #89
Browse files Browse the repository at this point in the history
  • Loading branch information
2silver committed May 19, 2021
1 parent ee12c16 commit 2273192
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plone/app/iterate/dexterity/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from zope.component import adapter
from zope.component import queryAdapter
from zope.event import notify
from zope.lifecycleevent import ObjectModifiedEvent


@adapter(IDexterityIterateAware)
Expand All @@ -34,6 +35,10 @@ def checkin(self, checkin_message):
new_baseline = copier.merge()
# don't need to unlock the lock disappears with old baseline deletion
notify(AfterCheckinEvent(new_baseline, checkin_message))

# update our new_baseline, ex. for all References ( and BackReferences)
notify(ObjectModifiedEvent(new_baseline))

return new_baseline

def _get_relation_to_baseline(self):
Expand Down
54 changes: 54 additions & 0 deletions plone/app/iterate/tests/test_iterate.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,57 @@ def test_relationship_deleted_on_cancel_checkout(self):
rels = list(catalog.findRelations({"from_id": obj_id}))

self.assertEqual(len(rels), 0)

def test_baseline_relations_updated_on_checkin(self):
# Ensure that relations between the baseline and
# and other objects are up-to-date on checkin
from zope.event import notify
from zope.lifecycleevent import ObjectModifiedEvent
from z3c.relationfield import RelationValue

folder = self.portal.docs
baseline = folder.doc1
target = folder.doc2

intids = component.getUtility(IIntIds)
catalog = component.getUtility(ICatalog)

target_id = intids.getId(target)
target_rel = [RelationValue(target_id)]

# Test, if nothing is present in the relation catalog
rels = list(catalog.findRelations({'to_id': target_id}))
self.assertEqual(len(rels), 0)

# set relatedItems on baseline
baseline.relatedItems = target_rel
notify(ObjectModifiedEvent(baseline))

# Test, if relation is present in the relation catalog
rels = list(catalog.findRelations({'to_id': target_id}))
self.assertEqual(len(rels), 1)

# proof for empty relations
# baseline.relatedItems = []
# notify(ObjectModifiedEvent(baseline))
# rels = list(catalog.findRelations({'to_id': target_id}))
# self.assertEqual(len(rels), 0)

# make a workingcopy from baseline
wc = ICheckinCheckoutPolicy(baseline).checkout(folder)

# remove relations on wc
wc.relatedItems = []
notify(ObjectModifiedEvent(wc))

# baseline -> target relation should be still there, we are on wc
rels = list(catalog.findRelations({'to_id': target_id}))
self.assertEqual(len(rels), 1)

# baseline -> target relation should be empty now
# because we replaced our baseline with our wc (with empty relations)
baseline = ICheckinCheckoutPolicy(wc).checkin("updated")
rels = list(catalog.findRelations({'to_id': target_id}))

# new baseline's relatedItems should be empty
self.assertEqual(len(rels), 0)

0 comments on commit 2273192

Please sign in to comment.