Skip to content

Commit

Permalink
Fixed otherMeetingConfigsClonableToFieldXXX field management when i…
Browse files Browse the repository at this point in the history
…t is empty, it was not emptying the value on new item, now it is the case except for `title` that can not be empty.

See #DLIBBDC-3402
  • Loading branch information
gbastien committed Dec 17, 2024
1 parent 20e37b3 commit adbe7da
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Changelog
- Prevent to unselect an organization in plonegroup that
is used by `MeetingConfig.usingGroups`.
[gbastien]
- Fixed `otherMeetingConfigsClonableToFieldXXX` field management when it is
empty, it was not emptying the value on new item, now it is the case except
for `title` that can not be empty.
[gbastien]

4.2.13 (2024-12-06)
-------------------
Expand Down
14 changes: 9 additions & 5 deletions src/Products/PloneMeeting/MeetingItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -7841,14 +7841,18 @@ def cloneToOtherMeetingConfig(self, destMeetingConfigId, automatically=False):

# handle 'otherMeetingConfigsClonableToFieldXXX' of original item
for other_mc_field_name in self.get_enable_clone_to_other_mc_fields(cfg):
# first check if original field not empty
if self.fieldIsEmpty(other_mc_field_name):
continue
other_mc_field = self.getField(other_mc_field_name)
other_mc_field_value = other_mc_field.get(self)
dest_field_name = other_mc_field_name.replace('otherMeetingConfigsClonableToField', '')
dest_field_name = dest_field_name[0].lower() + dest_field_name[1:]
dest_field = newItem.getField(dest_field_name)
# check that we will not empty a required field (case for "title" especially)
# and also that if field optional, it is used in destination config
if (self.fieldIsEmpty(other_mc_field_name) and
self.getField(dest_field_name).required) or \
(getattr(dest_field, 'optional', False) and
not newItem.attribute_is_used(dest_field_name)):
continue
other_mc_field = self.getField(other_mc_field_name)
other_mc_field_value = other_mc_field.get(self)
dest_field.set(newItem, other_mc_field_value)

# execute some transitions on the newItem if it was defined in the cfg
Expand Down
24 changes: 22 additions & 2 deletions src/Products/PloneMeeting/tests/testMeetingItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,7 @@ def test_pm_SendItemToOtherMCAutoReplacedFields(self):
cfg2 = self.meetingConfig2
cfg2Id = cfg2.getId()
self._enableField('category', cfg=cfg2, enable=False)
self._enableField('motivation', cfg=cfg2)
cfg.setMeetingConfigsToCloneTo(({'meeting_config': '%s' % cfg2Id,
'trigger_workflow_transitions_until': NO_TRIGGER_WF_TRANSITION_UNTIL},))
cfg.setItemManualSentToOtherMCStates(('itemcreated', ))
Expand All @@ -1676,8 +1677,9 @@ def test_pm_SendItemToOtherMCAutoReplacedFields(self):

self.changeUser('pmCreator1')
item = self.create('MeetingItem')
item.setTitle('Title')
item.setDecision('<p></p>')
item.setTitle('Original title')
item.setMotivation('<p>Original motivation</p>')
item.setDecision('<p>Original decision</p>')
item.setOtherMeetingConfigsClonableToFieldTitle('Field title')
item.setOtherMeetingConfigsClonableToFieldMotivation('<p>Field motivation</p>')
item.setOtherMeetingConfigsClonableToFieldDecision('<p>Field decision</p>')
Expand All @@ -1695,6 +1697,24 @@ def test_pm_SendItemToOtherMCAutoReplacedFields(self):
'otherMeetingConfigsClonableToFieldMotivation',
'otherMeetingConfigsClonableToFieldDecision'])

# when other_mc value is empty, it will only erase field value if field is not required
# disable motivation, it will not be initialized
self._enableField('motivation', cfg=cfg2, enable=False)
item.setOtherMeetingConfigsClonableToFieldTitle('')
item.setOtherMeetingConfigsClonableToFieldDecision('')
item.setOtherMeetingConfigsClonableTo((cfg2Id,))
self.assertEqual(item.Title(), 'Original title')
self.assertEqual(item.getMotivation(), '<p>Original motivation</p>')
self.assertEqual(item.getDecision(), '<p>Original decision</p>')
self.deleteAsManager(newItem.UID())
newItem = item.cloneToOtherMeetingConfig(cfg2Id)
self.assertEqual(newItem.Title(), 'Original title')
# motivation not used so empty on copied item
self.assertFalse(newItem.attribute_is_used('motivation'))
self.assertEqual(newItem.getMotivation(), '')
# was emptied
self.assertEqual(newItem.getDecision(), '')

def test_pm_CloneItemWithSetCurrentAsPredecessor(self):
'''When an item is cloned with option setCurrentAsPredecessor=True,
items are linked together, with an automatic link if option
Expand Down

0 comments on commit adbe7da

Please sign in to comment.