mirror of
https://github.com/anteo/redmine_custom_workflows.git
synced 2026-01-26 00:04:20 +00:00
#330 Email templates
This commit is contained in:
parent
f3644a5d49
commit
8faae7fa46
10
CHANGELOG.md
10
CHANGELOG.md
@ -4,6 +4,16 @@ Changelog for Custom Workflows
|
|||||||
2.1.1 *????-??-??*
|
2.1.1 *????-??-??*
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
IMPORTANT: Parameters of *CustomWorkflowMailer.deliver_custom_email* method has changed.
|
||||||
|
|
||||||
|
before: `CustomWorkflowMailer.deliver_custom_email(user, subject, text)`
|
||||||
|
|
||||||
|
now: `CustomWorkflowMailer.deliver_custom_email(user, headers = {})`
|
||||||
|
|
||||||
|
To achieve the same behaviour you have to modify an existing callig as follows
|
||||||
|
|
||||||
|
`CustomWorkflowMailer.deliver_custom_email(user, subject: subject, text_body: text)`
|
||||||
|
|
||||||
2.1.0 *2023-11-15*
|
2.1.0 *2023-11-15*
|
||||||
------------------
|
------------------
|
||||||
Member as an observable object
|
Member as an observable object
|
||||||
|
|||||||
@ -122,6 +122,14 @@ E.g.:
|
|||||||
self.custom_workflow_env[:remote_ip]
|
self.custom_workflow_env[:remote_ip]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
An email can be sent from within a script.
|
||||||
|
|
||||||
|
E.g.:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
CustomWorkflowMailer.deliver_custom_email(user, subject: subject, text_body: text)
|
||||||
|
```
|
||||||
|
|
||||||
Enabling custom workflows for projects
|
Enabling custom workflows for projects
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -25,13 +25,29 @@ require 'mailer'
|
|||||||
class CustomWorkflowMailer < Mailer
|
class CustomWorkflowMailer < Mailer
|
||||||
layout 'mailer'
|
layout 'mailer'
|
||||||
|
|
||||||
def self.deliver_custom_email(user, subject, text)
|
def self.deliver_custom_email(user, headers = {})
|
||||||
custom_email(user, subject, text).deliver_later
|
custom_email(user, headers).deliver_later
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_email(user, subject, text)
|
def custom_email(user, headers)
|
||||||
set_language_if_valid user.language
|
headers[:to] = user.mail if user
|
||||||
@text = text
|
text_body = headers.delete :text_body
|
||||||
mail to: user, subject: subject
|
html_body = headers.delete :html_body
|
||||||
|
template_name = headers.delete :template_name
|
||||||
|
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
|
||||||
|
end
|
||||||
|
elsif template_name
|
||||||
|
template_params.each { |k, v| instance_variable_set("@#{k}", v) }
|
||||||
|
mail headers do |format|
|
||||||
|
format.text { render template_name }
|
||||||
|
format.html { render template_name } unless Setting.plain_text_mail?
|
||||||
|
end
|
||||||
|
else
|
||||||
|
raise 'Not :text_body, :html_body or :template_name specified'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -40,7 +40,7 @@ class CustomWorkflowMailerTest < RedmineCustomWorkflows::Test::UnitTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_custom_email
|
def test_custom_email
|
||||||
CustomWorkflowMailer.deliver_custom_email @user2, 'Subject', 'Body'
|
CustomWorkflowMailer.deliver_custom_email @user2, subject: 'Subject', text_body: 'Body', html_body: 'Body'
|
||||||
email = last_email
|
email = last_email
|
||||||
assert text_part(email).body.include? 'Body'
|
assert text_part(email).body.include? 'Body'
|
||||||
assert html_part(email).body.include? 'Body'
|
assert html_part(email).body.include? 'Body'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user