This commit is contained in:
Karel Pičman 2023-12-15 09:03:35 +01:00
parent 8faae7fa46
commit 6dbbb31848
3 changed files with 19 additions and 5 deletions

View File

@ -134,7 +134,7 @@ class CustomWorkflow < ApplicationRecord
object.instance_eval(self[event]) if respond_to?(event) && self[event]
rescue RedmineCustomWorkflows::Errors::WorkflowError => _e
# Do nothing
rescue StandardError => e
rescue StandardError, ScriptError => e
errors.add event, :invalid_script, error: e
end

View File

@ -37,8 +37,8 @@ class CustomWorkflowMailer < Mailer
template_params = headers.delete(:template_params) || {}
if text_body || html_body
mail headers do |format|
format.text { render text: text_body } if text_body
format.html { render text: html_body } if html_body
format.text { render plain: text_body } if text_body.present?
format.html { render plain: html_body } if html_body.present? && !Setting.plain_text_mail?
end
elsif template_name
template_params.each { |k, v| instance_variable_set("@#{k}", v) }

View File

@ -42,8 +42,22 @@ class CustomWorkflowMailerTest < RedmineCustomWorkflows::Test::UnitTest
def test_custom_email
CustomWorkflowMailer.deliver_custom_email @user2, subject: 'Subject', text_body: 'Body', html_body: 'Body'
email = last_email
assert text_part(email).body.include? 'Body'
assert html_part(email).body.include? 'Body'
text = text_part(email).body
html = html_part(email).body
assert text.include?('Body'), "'Body' expected\n'#{text}' present'"
assert html.include?('Body'), "'Body' expected\n'#{html}' present'"
end
def test_custom_email_template
CustomWorkflowMailer.deliver_custom_email @user2,
subject: 'Subject',
template_name: 'mailer/test_email',
template_params: { url: Setting.host_name }
email = last_email
text = text_part(email).body
html = html_part(email).body
assert text.include?(Setting.host_name), "'#{Setting.host_name} expected\n'#{text}' present'"
assert html.include?(Setting.host_name), "'#{Setting.host_name} expected\n'#{html}' present'"
end
private