workflows: do not add evolution in edit carddata action if no changes (#75793)
gitea/wcs/pipeline/head This commit looks good
Details
gitea/wcs/pipeline/head This commit looks good
Details
This commit is contained in:
parent
2abebbf429
commit
96a3b1f295
|
@ -19,7 +19,7 @@ from wcs.qommon.ident.password_accounts import PasswordAccount
|
|||
from wcs.qommon.upload_storage import PicklableUpload
|
||||
from wcs.wf.backoffice_fields import SetBackofficeFieldsWorkflowStatusItem
|
||||
from wcs.wf.create_formdata import Mapping
|
||||
from wcs.workflows import ContentSnapshotPart, Workflow, WorkflowBackofficeFieldsFormDef
|
||||
from wcs.workflows import ContentSnapshotPart, EvolutionPart, Workflow, WorkflowBackofficeFieldsFormDef
|
||||
|
||||
from .utilities import clean_temporary_pub, create_temporary_pub, get_app, login
|
||||
|
||||
|
@ -905,6 +905,38 @@ def test_workflow_carddata_edit(pub):
|
|||
dt2 = carddata.evolution[1].parts[0].datetime
|
||||
assert dt2 > dt1
|
||||
|
||||
# no changes; no new evolution
|
||||
formdata.store()
|
||||
formdata.perform_workflow()
|
||||
carddata.refresh_from_storage()
|
||||
assert len(carddata.evolution) == 2
|
||||
|
||||
# but last evolution has a comment, so add a new evolution
|
||||
carddata.evolution[-1].comment = 'foobar'
|
||||
carddata.store()
|
||||
carddata.refresh_from_storage()
|
||||
formdata.store()
|
||||
formdata.perform_workflow()
|
||||
carddata.refresh_from_storage()
|
||||
assert len(carddata.evolution) == 3
|
||||
|
||||
# last evolution is not empty, but contains only a ContentSnapshotPart; no new evolution
|
||||
part = ContentSnapshotPart(formdata=formdata, old_data={})
|
||||
carddata.evolution[-1].add_part(part)
|
||||
carddata.store()
|
||||
formdata.store()
|
||||
formdata.perform_workflow()
|
||||
carddata.refresh_from_storage()
|
||||
assert len(carddata.evolution) == 3
|
||||
|
||||
# last evolution is not empty, add a new evolution
|
||||
carddata.evolution[-1].add_part(EvolutionPart())
|
||||
carddata.store()
|
||||
formdata.store()
|
||||
formdata.perform_workflow()
|
||||
carddata.refresh_from_storage()
|
||||
assert len(carddata.evolution) == 4
|
||||
|
||||
|
||||
def test_workflow_set_backoffice_field(http_requests, pub):
|
||||
Workflow.wipe()
|
||||
|
|
|
@ -653,6 +653,7 @@ def test_edit_carddata_with_data_sourced_object(pub):
|
|||
carddata.data = {'0': 'Foo', '1': 'Bar', '2': 'l'}
|
||||
carddata.data['2_display'] = carddef.fields[2].store_display_value(carddata.data, '2')
|
||||
carddata.data['2_structured'] = carddef.fields[2].store_structured_value(carddata.data, '2')
|
||||
carddata.just_created()
|
||||
carddata.store()
|
||||
|
||||
wf = Workflow(name='Card update')
|
||||
|
@ -677,7 +678,6 @@ def test_edit_carddata_with_data_sourced_object(pub):
|
|||
|
||||
formdata = formdef.data_class()()
|
||||
formdata.data = {'0': '1', '1': 'c'}
|
||||
formdata.store()
|
||||
formdata.just_created()
|
||||
formdata.store()
|
||||
formdata.perform_workflow()
|
||||
|
@ -808,6 +808,7 @@ def test_edit_carddata_manual_targeting(pub):
|
|||
'1': 'Last name %s' % i,
|
||||
'2': '0',
|
||||
}
|
||||
carddata.just_created()
|
||||
carddata.store()
|
||||
|
||||
# formdef workflow that will update carddata
|
||||
|
|
|
@ -56,19 +56,25 @@ class EditCarddataWorkflowStatusItem(CreateCarddataWorkflowStatusItem, ExternalW
|
|||
old_data = copy.deepcopy(target_data.data)
|
||||
self.apply_mappings(dest=target_data, src=formdata)
|
||||
with get_publisher().substitutions.freeze():
|
||||
# record a workflow event with a link to current workflow & action
|
||||
target_data.record_workflow_event(
|
||||
'workflow-edited',
|
||||
external_workflow_id=self.parent.parent.id,
|
||||
external_status_id=self.parent.id,
|
||||
external_item_id=self.id,
|
||||
)
|
||||
last_evo = target_data.evolution[-1]
|
||||
evo = Evolution()
|
||||
evo.time = time.localtime()
|
||||
evo.status = target_data.status
|
||||
target_data.evolution.append(evo)
|
||||
ContentSnapshotPart.take(formdata=target_data, old_data=old_data)
|
||||
target_data.store()
|
||||
part = ContentSnapshotPart.take(formdata=target_data, old_data=old_data)
|
||||
if (
|
||||
part.has_changes
|
||||
or last_evo.comment
|
||||
or [x for x in last_evo.parts or [] if not isinstance(x, ContentSnapshotPart)]
|
||||
):
|
||||
# record a workflow event with a link to current workflow & action
|
||||
target_data.record_workflow_event(
|
||||
'workflow-edited',
|
||||
external_workflow_id=self.parent.parent.id,
|
||||
external_status_id=self.parent.id,
|
||||
external_item_id=self.id,
|
||||
)
|
||||
target_data.store()
|
||||
|
||||
# update local object as it may have modified itself
|
||||
formdata.refresh_from_storage()
|
||||
|
|
|
@ -416,8 +416,9 @@ class ContentSnapshotPart(EvolutionPart):
|
|||
@classmethod
|
||||
def take(cls, formdata, old_data):
|
||||
part = cls(formdata, old_data)
|
||||
if part.old_data != part.new_data:
|
||||
if part.has_changes:
|
||||
formdata.evolution[-1].add_part(part)
|
||||
return part
|
||||
|
||||
def __getstate__(self):
|
||||
odict = copy.copy(self.__dict__)
|
||||
|
@ -430,6 +431,10 @@ class ContentSnapshotPart(EvolutionPart):
|
|||
if hasattr(self, '_formdef'):
|
||||
delattr(self, '_formdef')
|
||||
|
||||
@property
|
||||
def has_changes(self):
|
||||
return self.old_data != self.new_data
|
||||
|
||||
@property
|
||||
def formdef(self):
|
||||
if not hasattr(self, '_formdef'):
|
||||
|
|
Loading…
Reference in New Issue