From faed7691d3653ef03446f3898db6632a379c2927 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Fri, 24 Sep 2021 14:54:41 +0200
Subject: [PATCH 1/5] misc: remove fields-blocks site option (#57260)

---
 tests/admin_pages/test_block.py         | 16 ++++-----
 tests/backoffice_pages/test_carddata.py |  2 +-
 tests/conftest.py                       |  5 ---
 tests/form_pages/test_block.py          | 48 ++++++++++++-------------
 tests/test_formdata.py                  |  2 +-
 tests/test_snapshots.py                 |  2 +-
 tests/workflow/test_all.py              |  2 +-
 wcs/admin/forms.py                      |  3 +-
 wcs/admin/settings.py                   |  3 +-
 wcs/backoffice/cards.py                 |  3 +-
 wcs/fields.py                           |  4 +--
 wcs/qommon/publisher.py                 |  1 -
 12 files changed, 40 insertions(+), 51 deletions(-)

diff --git a/tests/admin_pages/test_block.py b/tests/admin_pages/test_block.py
index deb57d53..6bcaccbf 100644
--- a/tests/admin_pages/test_block.py
+++ b/tests/admin_pages/test_block.py
@@ -34,7 +34,7 @@ def teardown_module(module):
     clean_temporary_pub()
 
 
-def test_block_404(pub, blocks_feature):
+def test_block_404(pub):
     create_superuser(pub)
     create_role(pub)
     BlockDef.wipe()
@@ -42,7 +42,7 @@ def test_block_404(pub, blocks_feature):
     app.get('/backoffice/forms/blocks/1/', status=404)
 
 
-def test_block_new(pub, blocks_feature):
+def test_block_new(pub):
     create_superuser(pub)
     create_role(pub)
     BlockDef.wipe()
@@ -73,7 +73,7 @@ def test_block_new(pub, blocks_feature):
     assert str(BlockDef.get(1).fields[0].id) != '1'  # don't use integers
 
 
-def test_block_options(pub, blocks_feature):
+def test_block_options(pub):
     create_superuser(pub)
     BlockDef.wipe()
     block = BlockDef()
@@ -104,7 +104,7 @@ def test_block_options(pub, blocks_feature):
     resp = resp.follow()
 
 
-def test_block_options_digest_template(pub, blocks_feature):
+def test_block_options_digest_template(pub):
     create_superuser(pub)
     BlockDef.wipe()
     block = BlockDef()
@@ -130,7 +130,7 @@ def test_block_options_digest_template(pub, blocks_feature):
     assert block.digest_template == 'X{{foobar_var_foo}}Y'
 
 
-def test_block_export_import(pub, blocks_feature):
+def test_block_export_import(pub):
     create_superuser(pub)
     BlockDef.wipe()
     block = BlockDef()
@@ -177,7 +177,7 @@ def test_block_export_import(pub, blocks_feature):
     assert 'Invalid File' in resp
 
 
-def test_block_delete(pub, blocks_feature):
+def test_block_delete(pub):
     create_superuser(pub)
     BlockDef.wipe()
     FormDef.wipe()
@@ -213,7 +213,7 @@ def test_block_delete(pub, blocks_feature):
     assert 'This block is still used' in resp
 
 
-def test_block_edit_duplicate_delete_field(pub, blocks_feature):
+def test_block_edit_duplicate_delete_field(pub):
     create_superuser(pub)
     BlockDef.wipe()
     block = BlockDef()
@@ -241,7 +241,7 @@ def test_block_edit_duplicate_delete_field(pub, blocks_feature):
     assert len(BlockDef.get(block.id).fields) == 1
 
 
-def test_block_use_in_formdef(pub, blocks_feature):
+def test_block_use_in_formdef(pub):
     create_superuser(pub)
     FormDef.wipe()
     BlockDef.wipe()
diff --git a/tests/backoffice_pages/test_carddata.py b/tests/backoffice_pages/test_carddata.py
index 8328d1a1..7fe3e548 100644
--- a/tests/backoffice_pages/test_carddata.py
+++ b/tests/backoffice_pages/test_carddata.py
@@ -541,7 +541,7 @@ def test_backoffice_cards_wscall_failure_display(http_requests, pub):
     assert pub.loggederror_class.select()[0].get_formdata().data == {'1': 'plop'}
 
 
-def test_block_card_item_link(pub, blocks_feature):
+def test_block_card_item_link(pub):
     user = create_user(pub)
     CardDef.wipe()
     carddef = CardDef()
diff --git a/tests/conftest.py b/tests/conftest.py
index 92652a9f..0050687d 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -52,11 +52,6 @@ def welco_url(request, pub):
     return site_options(request, pub, 'options', 'welco_url', 'http://welco.example.net')
 
 
-@pytest.fixture
-def blocks_feature(request, pub):
-    return site_options(request, pub, 'options', 'fields-blocks', 'true')
-
-
 @pytest.fixture
 def emails():
     with EmailsMocking() as mock:
diff --git a/tests/form_pages/test_block.py b/tests/form_pages/test_block.py
index e4b403ca..711c058f 100644
--- a/tests/form_pages/test_block.py
+++ b/tests/form_pages/test_block.py
@@ -44,7 +44,7 @@ def teardown_module(module):
     clean_temporary_pub()
 
 
-def test_block_simple(pub, blocks_feature):
+def test_block_simple(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -79,7 +79,7 @@ def test_block_simple(pub, blocks_feature):
     assert '>bar<' in resp
 
 
-def test_block_required(pub, blocks_feature):
+def test_block_required(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -145,7 +145,7 @@ def test_block_required(pub, blocks_feature):
     assert 'Check values then click submit.' in resp.text
 
 
-def test_block_required_previous_page(pub, blocks_feature):
+def test_block_required_previous_page(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -243,7 +243,7 @@ def test_block_required_previous_page(pub, blocks_feature):
         assert formdata.data['1']['data'] == [{'123': 'foo', '234': 'bar'}, {'123': 'foo2', '234': 'bar2'}]
 
 
-def test_block_date(pub, blocks_feature):
+def test_block_date(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -273,7 +273,7 @@ def test_block_date(pub, blocks_feature):
     assert '>2020-06-16<' in resp
 
 
-def test_block_bool(pub, blocks_feature):
+def test_block_bool(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -309,7 +309,7 @@ def test_block_bool(pub, blocks_feature):
             assert '<div class="value">No</div>' in resp
 
 
-def test_block_autocomplete_list(pub, blocks_feature):
+def test_block_autocomplete_list(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -346,7 +346,7 @@ def test_block_autocomplete_list(pub, blocks_feature):
     assert '>Bar<' in resp
 
 
-def test_block_geoloc_prefill(pub, blocks_feature):
+def test_block_geoloc_prefill(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -376,7 +376,7 @@ def test_block_geoloc_prefill(pub, blocks_feature):
     assert resp.html.find('div', {'data-geolocation': 'road'})
 
 
-def test_block_string_prefill(pub, blocks_feature):
+def test_block_string_prefill(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -476,7 +476,7 @@ def test_block_string_prefill(pub, blocks_feature):
         assert resp.form['f3$element0$f123'].value == 'Foobar'
 
 
-def test_block_prefill_and_required(pub, blocks_feature):
+def test_block_prefill_and_required(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -526,7 +526,7 @@ def test_block_prefill_and_required(pub, blocks_feature):
     assert formdata.data['3']['data'][0]['234'] is True
 
 
-def test_block_locked_prefill(pub, blocks_feature):
+def test_block_locked_prefill(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -714,7 +714,7 @@ def test_workflow_form_block_prefill(pub):
     assert resp.form['fxxx_3$element0$f123'].value == 'foo@localhost'
 
 
-def test_block_title_and_comment(pub, blocks_feature):
+def test_block_title_and_comment(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -743,7 +743,7 @@ def test_block_title_and_comment(pub, blocks_feature):
     resp = resp.follow()
 
 
-def test_block_label(pub, blocks_feature):
+def test_block_label(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -787,7 +787,7 @@ def test_block_label(pub, blocks_feature):
     assert 'Block Label' not in resp.text
 
 
-def test_block_multipage(pub, blocks_feature):
+def test_block_multipage(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -828,7 +828,7 @@ def test_block_multipage(pub, blocks_feature):
     assert '>bar<' in resp
 
 
-def test_block_repeated(pub, blocks_feature):
+def test_block_repeated(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -895,7 +895,7 @@ def test_block_repeated(pub, blocks_feature):
     assert '>bar2<' in resp
 
 
-def test_block_repeated_over_limit(pub, blocks_feature):
+def test_block_repeated_over_limit(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -943,7 +943,7 @@ def test_block_repeated_over_limit(pub, blocks_feature):
     assert 'Too many elements (maximum: 2)' in resp
 
 
-def test_block_repeated_files(pub, blocks_feature):
+def test_block_repeated_files(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -1001,7 +1001,7 @@ def test_block_repeated_files(pub, blocks_feature):
 
 
 @pytest.mark.parametrize('removed_line', [0, 1, 2])
-def test_block_repeated_remove_line(pub, blocks_feature, removed_line):
+def test_block_repeated_remove_line(pub, removed_line):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -1079,7 +1079,7 @@ def test_block_repeated_remove_line(pub, blocks_feature, removed_line):
 
 
 @pytest.mark.parametrize('block_name', ['foobar', 'Foo bar'])
-def test_block_digest(pub, blocks_feature, block_name):
+def test_block_digest(pub, block_name):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -1139,7 +1139,7 @@ def test_block_digest(pub, blocks_feature, block_name):
     assert formdef.data_class().select()[0].data['1_display'] == 'XfooY, Xfoo2Y'
 
 
-def test_block_digest_item(pub, blocks_feature):
+def test_block_digest_item(pub):
     FormDef.wipe()
     BlockDef.wipe()
     NamedDataSource.wipe()
@@ -1210,7 +1210,7 @@ def test_block_digest_item(pub, blocks_feature):
     assert formdef.data_class().select()[0].data['1_display'] == 'XunY, XdeuxY'
 
 
-def test_block_post_condition_on_2nd_page(pub, blocks_feature):
+def test_block_post_condition_on_2nd_page(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -1253,7 +1253,7 @@ def test_block_post_condition_on_2nd_page(pub, blocks_feature):
 
 
 @mock.patch('wcs.qommon.misc.urlopen')
-def test_block_with_dynamic_item_field(mock_urlopen, pub, blocks_feature):
+def test_block_with_dynamic_item_field(mock_urlopen, pub):
     def data_source(url):
         url, query = url.split('?q=')
         payload = []
@@ -1333,7 +1333,7 @@ def test_block_with_dynamic_item_field(mock_urlopen, pub, blocks_feature):
     assert resp.form['f2'].value == '1'
 
 
-def test_block_used_in_later_prefill(pub, blocks_feature):
+def test_block_used_in_later_prefill(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -1375,7 +1375,7 @@ def test_block_used_in_later_prefill(pub, blocks_feature):
     assert resp.form['f3'].value == '9'
 
 
-def test_block_add_and_locked_field(pub, blocks_feature):
+def test_block_add_and_locked_field(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
@@ -1409,7 +1409,7 @@ def test_block_add_and_locked_field(pub, blocks_feature):
     resp = resp.form.submit('submit')  # -> submit
 
 
-def test_block_subfields_display_locations(pub, blocks_feature):
+def test_block_subfields_display_locations(pub):
     FormDef.wipe()
     BlockDef.wipe()
 
diff --git a/tests/test_formdata.py b/tests/test_formdata.py
index 9aa78feb..c7ff6260 100644
--- a/tests/test_formdata.py
+++ b/tests/test_formdata.py
@@ -3016,7 +3016,7 @@ def test_form_parent(pub):
     assert variables['form'].parent is not None
 
 
-def test_block_variables(pub, blocks_feature):
+def test_block_variables(pub):
     BlockDef.wipe()
     FormDef.wipe()
 
diff --git a/tests/test_snapshots.py b/tests/test_snapshots.py
index d7c01ac5..e3ecdd12 100644
--- a/tests/test_snapshots.py
+++ b/tests/test_snapshots.py
@@ -257,7 +257,7 @@ def test_form_snapshot_restore_with_import_error(pub):
     assert 'Can not restore snapshot (Unknown datasources [unknown])' in resp
 
 
-def test_block_snapshot_browse(pub, blocks_feature):
+def test_block_snapshot_browse(pub):
     create_superuser(pub)
     create_role(pub)
 
diff --git a/tests/workflow/test_all.py b/tests/workflow/test_all.py
index 4454bc0a..0572b20b 100644
--- a/tests/workflow/test_all.py
+++ b/tests/workflow/test_all.py
@@ -5639,7 +5639,7 @@ def test_set_backoffice_field_str_time_filter(two_pubs):
     formdata.store()
 
 
-def test_set_backoffice_field_block(two_pubs, blocks_feature):
+def test_set_backoffice_field_block(two_pubs):
     BlockDef.wipe()
     Workflow.wipe()
     FormDef.wipe()
diff --git a/wcs/admin/forms.py b/wcs/admin/forms.py
index 54e2455b..ef561b43 100644
--- a/wcs/admin/forms.py
+++ b/wcs/admin/forms.py
@@ -1792,8 +1792,7 @@ class FormsDirectory(AccessControlled, Directory):
             r += htmltext('<span class="actions">')
             if is_global_accessible('forms'):
                 r += htmltext('<a href="data-sources/">%s</a>') % _('Data sources')
-                if get_publisher().has_site_option('fields-blocks'):
-                    r += htmltext('<a href="blocks/">%s</a>') % _('Fields blocks')
+                r += htmltext('<a href="blocks/">%s</a>') % _('Fields blocks')
                 if get_publisher().get_backoffice_root().is_accessible('categories'):
                     r += htmltext('<a href="categories/">%s</a>') % _('Categories')
             r += htmltext('<a href="import" rel="popup">%s</a>') % _('Import')
diff --git a/wcs/admin/settings.py b/wcs/admin/settings.py
index d4ec78b9..77e4692a 100644
--- a/wcs/admin/settings.py
+++ b/wcs/admin/settings.py
@@ -988,8 +988,7 @@ class SettingsDirectory(QommonSettingsDirectory):
         if StudioDirectory.is_visible():
             form.add(CheckboxWidget, 'carddefs', title=_('Card Models'), value=True)
         form.add(CheckboxWidget, 'workflows', title=_('Workflows'), value=True)
-        if get_publisher().has_site_option('fields-blocks'):
-            form.add(CheckboxWidget, 'blockdefs', title=_('Fields Blocks'), value=True)
+        form.add(CheckboxWidget, 'blockdefs', title=_('Fields Blocks'), value=True)
         if not get_cfg('sp', {}).get('idp-manage-roles'):
             form.add(CheckboxWidget, 'roles', title=_('Roles'), value=True)
         form.add(CheckboxWidget, 'categories', title=_('Categories'), value=True)
diff --git a/wcs/backoffice/cards.py b/wcs/backoffice/cards.py
index d9c54be1..999627a8 100644
--- a/wcs/backoffice/cards.py
+++ b/wcs/backoffice/cards.py
@@ -254,8 +254,7 @@ class CardsDirectory(FormsDirectory):
         r += htmltext('<span class="actions">')
         if get_publisher().get_backoffice_root().is_global_accessible('forms'):
             r += htmltext('<a href="../forms/data-sources/">%s</a>') % _('Data sources')
-            if get_publisher().has_site_option('fields-blocks'):
-                r += htmltext('<a href="../forms/blocks/">%s</a>') % _('Fields blocks')
+            r += htmltext('<a href="../forms/blocks/">%s</a>') % _('Fields blocks')
         if get_publisher().get_backoffice_root().is_global_accessible('cards'):
             r += htmltext('<a href="categories/">%s</a>') % _('Categories')
         r += htmltext('<a href="import" rel="popup">%s</a>') % _('Import')
diff --git a/wcs/fields.py b/wcs/fields.py
index 5356a490..39c65f7b 100644
--- a/wcs/fields.py
+++ b/wcs/fields.py
@@ -3507,9 +3507,7 @@ def get_field_options(blacklisted_types):
         # add computed field in its own "section"
         options.extend([('', '—', ''), (ComputedField.key, ComputedField.description, ComputedField.key)])
 
-    if get_publisher().has_site_option('fields-blocks') and (
-        not blacklisted_types or 'blocks' not in blacklisted_types
-    ):
+    if not blacklisted_types or 'blocks' not in blacklisted_types:
         position = len(options)
         for blockdef in BlockDef.select(order_by='name'):
             options.append(('block:%s' % blockdef.slug, blockdef.name, 'block:%s' % blockdef.slug))
diff --git a/wcs/qommon/publisher.py b/wcs/qommon/publisher.py
index e6ca3fa0..acc864cf 100644
--- a/wcs/qommon/publisher.py
+++ b/wcs/qommon/publisher.py
@@ -393,7 +393,6 @@ class QommonPublisher(Publisher):
             'studio': True,
             'mail-templates': True,
             'external-workflow': True,
-            'fields-blocks': True,
             'complex-data': True,
         }
         if self.site_options is None:
-- 
2.33.0

