From 5cea68f5f85d1c8d664746fba1032655162f10dc 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:57:10 +0200
Subject: [PATCH 2/5] misc: remove mail-templates site option (#57260)

---
 tests/test_mail_templates.py | 31 +++++--------------------------
 wcs/admin/workflows.py       |  3 +--
 wcs/qommon/publisher.py      |  1 -
 wcs/workflows.py             |  8 ++------
 4 files changed, 8 insertions(+), 35 deletions(-)

diff --git a/tests/test_mail_templates.py b/tests/test_mail_templates.py
index 951793ef..046a22e0 100644
--- a/tests/test_mail_templates.py
+++ b/tests/test_mail_templates.py
@@ -58,16 +58,6 @@ def superuser(pub):
     return user1
 
 
-@pytest.fixture
-def mail_templates_option(pub):
-    if not pub.site_options.has_section('options'):
-        pub.site_options.add_section('options')
-    pub.site_options.set('options', 'mail-templates', 'true')
-    with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
-        pub.site_options.write(fd)
-    return pub
-
-
 @pytest.fixture
 def mail_template():
     MailTemplate.wipe()
@@ -78,18 +68,7 @@ def mail_template():
     return mail_template
 
 
-def test_mail_templates_disabled(pub, superuser):
-    if not pub.site_options.has_section('options'):
-        pub.site_options.add_section('options')
-    pub.site_options.set('options', 'mail-templates', 'false')
-    with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
-        pub.site_options.write(fd)
-    app = login(get_app(pub))
-    resp = app.get('/backoffice/workflows/')
-    assert 'Mail Templates' not in resp
-
-
-def test_mail_templates_basics(pub, superuser, mail_templates_option):
+def test_mail_templates_basics(pub, superuser):
     MailTemplate.wipe()
 
     app = login(get_app(pub))
@@ -143,7 +122,7 @@ def test_mail_templates_basics(pub, superuser, mail_templates_option):
     assert 'first mail template' in resp
 
 
-def test_mail_template_in_use(pub, superuser, mail_templates_option):
+def test_mail_template_in_use(pub, superuser):
     Workflow.wipe()
     MailTemplate.wipe()
     workflow = Workflow(name='test workflow')
@@ -177,7 +156,7 @@ def test_mail_template_in_use(pub, superuser, mail_templates_option):
     assert 'still used' in resp.text
 
 
-def test_admin_workflow_edit(pub, superuser, mail_templates_option):
+def test_admin_workflow_edit(pub, superuser):
     Workflow.wipe()
     MailTemplate.wipe()
     mail_template = MailTemplate(name='test mail template')
@@ -206,7 +185,7 @@ def test_admin_workflow_edit(pub, superuser, mail_templates_option):
     assert workflow.possible_status[0].items[0].mail_template == 'test-mail-template'
 
 
-def test_workflow_send_mail_template_with_sql(superuser, mail_templates_option, emails):
+def test_workflow_send_mail_template_with_sql(superuser, emails):
     pub = create_temporary_pub(sql_mode=True)
     req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
     pub.set_app_dir(req)
@@ -261,7 +240,7 @@ def test_workflow_send_mail_template_with_sql(superuser, mail_templates_option,
     assert logged_error.summary == 'reference to invalid mail template test-mail-template in status Status1'
 
 
-def test_workflow_send_mail_template_attachments(pub, superuser, mail_templates_option, emails):
+def test_workflow_send_mail_template_attachments(pub, superuser, emails):
     Workflow.wipe()
     MailTemplate.wipe()
 
diff --git a/wcs/admin/workflows.py b/wcs/admin/workflows.py
index e91f9c5a..f70af1b2 100644
--- a/wcs/admin/workflows.py
+++ b/wcs/admin/workflows.py
@@ -1909,8 +1909,7 @@ class WorkflowsDirectory(Directory):
         r += htmltext('<h2>%s</h2>') % _('Workflows')
         r += htmltext('<span class="actions">')
         if is_global_accessible():
-            if get_publisher().has_site_option('mail-templates'):
-                r += htmltext('<a href="mail-templates/">%s</a>') % _('Mail Templates')
+            r += htmltext('<a href="mail-templates/">%s</a>') % _('Mail Templates')
             r += htmltext('<a href="data-sources/">%s</a>') % _('Data sources')
             r += htmltext('<a href="categories/">%s</a>') % _('Categories')
         r += htmltext('<a href="import" rel="popup">%s</a>') % _('Import')
diff --git a/wcs/qommon/publisher.py b/wcs/qommon/publisher.py
index acc864cf..5f66cda1 100644
--- a/wcs/qommon/publisher.py
+++ b/wcs/qommon/publisher.py
@@ -391,7 +391,6 @@ class QommonPublisher(Publisher):
     def has_site_option(self, option):
         defaults = {
             'studio': True,
-            'mail-templates': True,
             'external-workflow': True,
             'complex-data': True,
         }
diff --git a/wcs/workflows.py b/wcs/workflows.py
index 697e20f3..b8287cbe 100644
--- a/wcs/workflows.py
+++ b/wcs/workflows.py
@@ -2968,7 +2968,7 @@ class SendmailWorkflowStatusItem(WorkflowStatusItem):
         super().add_parameters_widgets(form, parameters, prefix=prefix, formdef=formdef, **kwargs)
         subject_body_attrs = {}
         if 'subject' in parameters or 'body' in parameters:
-            if get_publisher().has_site_option('mail-templates') and MailTemplate.count():
+            if MailTemplate.count():
                 subject_body_attrs = {
                     'data-dynamic-display-value': '',
                     'data-dynamic-display-child-of': '%smail_template' % prefix,
@@ -2997,11 +2997,7 @@ class SendmailWorkflowStatusItem(WorkflowStatusItem):
                 size=40,
                 attrs=subject_body_attrs,
             )
-        if (
-            'mail_template' in parameters
-            and get_publisher().has_site_option('mail-templates')
-            and MailTemplate.count()
-        ):
+        if 'mail_template' in parameters and MailTemplate.count():
             form.add(
                 SingleSelectWidget,
                 '%smail_template' % prefix,
-- 
2.33.0

