fallback to sms template when slack not found
Test Plan: - Tests pass - notifications function as normal - slack notifications still look like sms templated ones Change-Id: I9025e72fb0085626aa22b586b630bd4cb8b40290 Reviewed-on: https://gerrit.instructure.com/210297 Tested-by: Jenkins Reviewed-by: Matthew Lemon <mlemon@instructure.com> QA-Review: Steven Burnett <sburnett@instructure.com> Product-Review: Steven Burnett <sburnett@instructure.com>
This commit is contained in:
parent
08f9b7bd31
commit
25beca17cc
|
@ -441,6 +441,7 @@ class Message < ActiveRecord::Base
|
|||
path = Canvas::MessageHelper.find_message_path(filename)
|
||||
|
||||
if !(File.exist?(path) rescue false)
|
||||
return false if filename.include?('slack')
|
||||
filename = self.notification.name.downcase.gsub(/\s/, '_') + ".email.erb"
|
||||
path = Canvas::MessageHelper.find_message_path(filename)
|
||||
end
|
||||
|
@ -499,8 +500,7 @@ class Message < ActiveRecord::Base
|
|||
# Returns message body
|
||||
def populate_body(message_body_template, path_type, binding, filename)
|
||||
# Build the body content based on the path type
|
||||
self.body = eval(Erubi::Engine.new(message_body_template,
|
||||
bufvar: '@output_buffer').src, binding, filename)
|
||||
self.body = eval(Erubi::Engine.new(message_body_template, bufvar: '@output_buffer').src, binding, filename)
|
||||
self.html_body = apply_html_template(binding) if path_type == 'email'
|
||||
|
||||
# Append a footer to the body if the path type is email
|
||||
|
@ -545,8 +545,12 @@ class Message < ActiveRecord::Base
|
|||
path_type ||= communication_channel.try(:path_type) || 'email'
|
||||
|
||||
# Determine the message template file to be used in the message
|
||||
filename = path_type == 'slack' ? template_filename('sms') : template_filename(path_type)
|
||||
filename = template_filename(path_type)
|
||||
message_body_template = get_template(filename)
|
||||
if !message_body_template && path_type == 'slack'
|
||||
filename = template_filename('sms')
|
||||
message_body_template = get_template(filename)
|
||||
end
|
||||
|
||||
context, asset, user, delayed_messages, data = [self.context,
|
||||
self.context, self.user, @delayed_messages, @data]
|
||||
|
|
|
@ -70,6 +70,35 @@ describe Message do
|
|||
expect(msg.html_body.index('<!DOCTYPE')).to eq 0
|
||||
end
|
||||
|
||||
it "should use slack template if present" do
|
||||
@au = AccountUser.create(:account => account_model)
|
||||
course_with_student
|
||||
alert = @course.alerts.create!(recipients: [:student],
|
||||
criteria: [
|
||||
criterion_type: 'Interaction',
|
||||
threshold: 7
|
||||
])
|
||||
mock_template = "slack template"
|
||||
expect_any_instance_of(Message).to receive(:get_template).with('alert.slack.erb').and_return(mock_template)
|
||||
msg = generate_message(:alert, :slack, alert)
|
||||
expect(msg.body).to eq mock_template
|
||||
end
|
||||
|
||||
it "should sms template if no slack template present" do
|
||||
@au = AccountUser.create(:account => account_model)
|
||||
course_with_student
|
||||
alert = @course.alerts.create!(recipients: [:student],
|
||||
criteria: [
|
||||
criterion_type: 'Interaction',
|
||||
threshold: 7
|
||||
])
|
||||
mock_template = "sms template"
|
||||
expect_any_instance_of(Message).to receive(:get_template).with('alert.slack.erb').and_return(nil)
|
||||
expect_any_instance_of(Message).to receive(:get_template).with('alert.sms.erb').and_return(mock_template)
|
||||
msg = generate_message(:alert, :slack, alert)
|
||||
expect(msg.body).to eq mock_template
|
||||
end
|
||||
|
||||
it "should not html escape the subject" do
|
||||
assignment_model(:title => "hey i have weird&<stuff> in my name but that's okay")
|
||||
msg = generate_message(:assignment_created, :email, @assignment)
|
||||
|
|
Loading…
Reference in New Issue