mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:44:49 +08:00
DEV add modifiers to message_builder so plugins can customize subject/body/html (#26867)
This commit is contained in:
parent
2cfcb4042e
commit
6df2f94bbc
|
@ -760,6 +760,7 @@ class UserNotifications < ActionMailer::Base
|
|||
subject_pm: subject_pm,
|
||||
participants: participants,
|
||||
include_respond_instructions: !(user.suspended? || user.staged?),
|
||||
notification_type: notification_type,
|
||||
template: template,
|
||||
use_topic_title_subject: use_topic_title_subject,
|
||||
site_description: SiteSetting.site_description,
|
||||
|
|
|
@ -126,7 +126,7 @@ module Email
|
|||
else
|
||||
subject = @opts[:subject]
|
||||
end
|
||||
subject
|
||||
DiscoursePluginRegistry.apply_modifier(:message_builder_subject, subject, @opts)
|
||||
end
|
||||
|
||||
def html_part
|
||||
|
@ -164,6 +164,7 @@ module Email
|
|||
html_body: html_override.html_safe,
|
||||
},
|
||||
)
|
||||
html = DiscoursePluginRegistry.apply_modifier(:message_builder_html_part, html, @opts)
|
||||
|
||||
Mail::Part.new do
|
||||
content_type "text/html; charset=UTF-8"
|
||||
|
@ -184,8 +185,7 @@ module Email
|
|||
body << "\n"
|
||||
body << @template_args[:unsubscribe_instructions]
|
||||
end
|
||||
|
||||
body
|
||||
DiscoursePluginRegistry.apply_modifier(:message_builder_body, body, @opts)
|
||||
end
|
||||
|
||||
def build_args
|
||||
|
|
|
@ -10,6 +10,9 @@ RSpec.describe Email::MessageBuilder do
|
|||
let(:build_args) { builder.build_args }
|
||||
let(:header_args) { builder.header_args }
|
||||
let(:allow_reply_header) { described_class::ALLOW_REPLY_BY_EMAIL_HEADER }
|
||||
let(:subject_modifier_block) { Proc.new { |subject, opts| "modified subject" } }
|
||||
|
||||
let(:body_modifier_block) { Proc.new { |subject, opts| "modified body" } }
|
||||
|
||||
it "has the correct to address" do
|
||||
expect(build_args[:to]).to eq(to_address)
|
||||
|
@ -23,6 +26,30 @@ RSpec.describe Email::MessageBuilder do
|
|||
expect(builder.body).to eq(body)
|
||||
end
|
||||
|
||||
it "uses the message_builder subject modifier properly" do
|
||||
plugin_instance = Plugin::Instance.new
|
||||
plugin_instance.register_modifier(:message_builder_subject, &subject_modifier_block)
|
||||
expect(builder.subject).to eq("modified subject")
|
||||
ensure
|
||||
DiscoursePluginRegistry.unregister_modifier(
|
||||
plugin_instance,
|
||||
:message_builder_subject,
|
||||
&subject_modifier_block
|
||||
)
|
||||
end
|
||||
|
||||
it "uses the message_builder body modifier properly" do
|
||||
plugin_instance = Plugin::Instance.new
|
||||
plugin_instance.register_modifier(:message_builder_body, &body_modifier_block)
|
||||
expect(builder.body).to eq("modified body")
|
||||
ensure
|
||||
DiscoursePluginRegistry.unregister_modifier(
|
||||
plugin_instance,
|
||||
:message_builder_body,
|
||||
&body_modifier_block
|
||||
)
|
||||
end
|
||||
|
||||
it "has a utf-8 charset" do
|
||||
expect(builder.build_args[:charset]).to eq("UTF-8")
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user