From 12db246ba16b8e08113becadf5ff322cbb18c5ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Thu, 17 Nov 2022 09:26:11 +0100
Subject: [PATCH] backoffice: do not show bo fields in data history (#71385)

---
 tests/test_content_snapshots.py | 17 +++++++++++++++++
 wcs/workflows.py                |  2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/tests/test_content_snapshots.py b/tests/test_content_snapshots.py
index 26fd133ba..a0e9ca2e3 100644
--- a/tests/test_content_snapshots.py
+++ b/tests/test_content_snapshots.py
@@ -363,6 +363,14 @@ def test_backoffice_show_history(pub, user, formdef_class):
     ]
     block.store()
 
+    wf = Workflow(name='xxx')
+    wf.backoffice_fields_formdef = WorkflowBackofficeFieldsFormDef(wf)
+    wf.backoffice_fields_formdef.fields = [
+        fields.StringField(id='bo1', label='Backoffice field', type='string'),
+    ]
+    st1 = wf.add_status('Status1')
+    wf.store()
+
     formdef_class.wipe()
     formdef = formdef_class()
     formdef.name = 'foo'
@@ -389,6 +397,7 @@ def test_backoffice_show_history(pub, user, formdef_class):
         '_editor': user.roles[0],
     }
     formdef.backoffice_submission_roles = user.roles[:]
+    formdef.workflow_id = wf.id
     formdef.store()
 
     upload1 = PicklableUpload('test.txt', 'text/plain')
@@ -431,6 +440,7 @@ def test_backoffice_show_history(pub, user, formdef_class):
             ],
             'schema': {'5': 'file'},
         },
+        'bo1': 'foobar',
     }
     formdata.just_created()
     formdata.store()
@@ -485,6 +495,7 @@ def test_backoffice_show_history(pub, user, formdef_class):
             ],
             'schema': {'5': 'file'},
         },
+        'bo1': 'foobar',
     }
     evo.add_part(part2)
     part3 = ContentSnapshotPart(formdata=formdata, old_data=copy.deepcopy(part2.new_data))
@@ -522,6 +533,7 @@ def test_backoffice_show_history(pub, user, formdef_class):
             ],
             'schema': {'5': 'file'},
         },
+        'bo1': 'foobar',
     }
     evo.add_part(part3)
     part4 = ContentSnapshotPart(formdata=formdata, old_data=copy.deepcopy(part3.new_data))
@@ -556,6 +568,7 @@ def test_backoffice_show_history(pub, user, formdef_class):
             ],
             'schema': {'5': 'file'},
         },
+        'bo1': 'foobar',
     }
     evo.add_part(part4)
     formdata.store()
@@ -594,6 +607,7 @@ def test_backoffice_show_history(pub, user, formdef_class):
     assert resp.pyquery('%s li[data-field-id="12_9"]' % ul1_el0).text() == '"Map" set'
     assert len(resp.pyquery('%s li[data-field-id="12_10"]' % ul1_el0)) == 0
     assert len(resp.pyquery('%s li[data-field-id="12_11"]' % ul1_el0)) == 0
+    assert len(resp.pyquery('%s li[data-field-id="bo1"]' % ul1)) == 0
 
     assert resp.pyquery(
         '#evolutions fieldset[data-datetime="%s"] legend' % part2.datetime.isoformat()
@@ -641,6 +655,7 @@ def test_backoffice_show_history(pub, user, formdef_class):
     assert resp.pyquery('%s li[data-field-id="12_9"]' % ul2_el1).text() == '"Map" set'
     assert len(resp.pyquery('%s li[data-field-id="12_10"]' % ul2_el1)) == 0
     assert len(resp.pyquery('%s li[data-field-id="12_11"]' % ul2_el1)) == 0
+    assert len(resp.pyquery('%s li[data-field-id="bo1"]' % ul2)) == 0
 
     assert resp.pyquery(
         '#evolutions fieldset[data-datetime="%s"] legend' % part3.datetime.isoformat()
@@ -698,6 +713,7 @@ def test_backoffice_show_history(pub, user, formdef_class):
     assert resp.pyquery('%s li[data-field-id="12_9"]' % ul3_el1).text() == '"Map" unset'
     assert len(resp.pyquery('%s li[data-field-id="12_10"]' % ul3_el1)) == 0
     assert len(resp.pyquery('%s li[data-field-id="12_11"]' % ul3_el1)) == 0
+    assert len(resp.pyquery('%s li[data-field-id="bo1"]' % ul3)) == 0
 
     assert resp.pyquery(
         '#evolutions fieldset[data-datetime="%s"] legend' % part4.datetime.isoformat()
@@ -715,6 +731,7 @@ def test_backoffice_show_history(pub, user, formdef_class):
     assert len(resp.pyquery('%s li[data-field-id="10"]' % ul4)) == 0
     assert len(resp.pyquery('%s li[data-field-id="11"]' % ul4)) == 0
     assert len(resp.pyquery('%s li[data-field-id="12"]' % ul4)) == 0
+    assert len(resp.pyquery('%s li[data-field-id="bo1"]' % ul4)) == 0
 
 
 def test_workflow_formdata_create(pub):
diff --git a/wcs/workflows.py b/wcs/workflows.py
index 2157559f2..f0f0e6679 100644
--- a/wcs/workflows.py
+++ b/wcs/workflows.py
@@ -625,7 +625,7 @@ class ContentSnapshotPart(EvolutionPart):
                     continue
                 yield from diff_field(field, old_data, new_data, block_field=block_field)
 
-        value_diffs = list(diff_fields(self.formdef.get_all_fields(), self.old_data, self.new_data))
+        value_diffs = list(diff_fields(self.formdef.fields or [], self.old_data, self.new_data))
         if value_diffs:
             return template.render(
                 ['wcs/backoffice/content-snapshot-part.html'],
-- 
2.35.1

