diff --git a/tests/admin_pages/test_workflow.py b/tests/admin_pages/test_workflow.py index cbb564134..62ad52185 100644 --- a/tests/admin_pages/test_workflow.py +++ b/tests/admin_pages/test_workflow.py @@ -959,6 +959,31 @@ def test_workflows_edit_email_action(pub): sendmail = Workflow.get(workflow.id).get_status(st1.id).items[0] assert sendmail.condition == {'type': 'python', 'value': 'True'} + # check "custom_from" is not advertised + resp = app.get(item_url) + assert 'custom_from' not in resp.text + + # check it's advertised if the appropriate site option is set + pub.site_options.set('options', 'include-sendmail-custom-from-option', 'true') + with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd: + pub.site_options.write(fd) + + resp = app.get(item_url) + assert 'custom_from' in resp.text + resp.form['custom_from$value_text'] = 'test@localhost' + resp = resp.form.submit('submit') + sendmail = Workflow.get(workflow.id).get_status(st1.id).items[0] + assert sendmail.custom_from == 'test@localhost' + + # keep option displayed if it has a value + pub.site_options.set('options', 'include-sendmail-custom-from-option', 'false') + with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd: + pub.site_options.write(fd) + + resp = app.get(item_url) + assert 'custom_from' in resp.text + assert resp.form['custom_from$value_text'].value == 'test@localhost' + def test_workflows_edit_jump_previous(pub): create_superuser(pub) diff --git a/wcs/workflows.py b/wcs/workflows.py index 9e1cf2664..9457fb1a1 100644 --- a/wcs/workflows.py +++ b/wcs/workflows.py @@ -2968,7 +2968,13 @@ class SendmailWorkflowStatusItem(WorkflowStatusItem): return _('not completed') def get_parameters(self): - return ('to', 'mail_template', 'subject', 'body', 'attachments', 'custom_from', 'condition') + parameters = ('to', 'mail_template', 'subject', 'body', 'attachments', 'custom_from', 'condition') + if ( + not get_publisher().has_site_option('include-sendmail-custom-from-option') + and not self.custom_from + ): + parameters = tuple(x for x in parameters if x != 'custom_from') + return parameters def add_parameters_widgets(self, form, parameters, prefix='', formdef=None, **kwargs): super().add_parameters_widgets(form, parameters, prefix=prefix, formdef=formdef, **kwargs)