Skip to content

Commit

Permalink
Include account type in slack messages. #475
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 20, 2020
1 parent c6a2215 commit f5a58cd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 45 deletions.
16 changes: 10 additions & 6 deletions app/models/concerns/mailable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ def send_welcome_email
reset_url = ENV['BRACCO_URL'] + "/reset"
title = Rails.env.stage? ? "DataCite Fabrica Test" : "DataCite Fabrica"
subject = "#{title}: New Account"
account_type = self.class.name == "Provider" ? member_type : client_type
text = User.format_message_text(template: "users/welcome.text.erb", title: title, contact_name: name, name: symbol, url: url, reset_url: reset_url)
html = User.format_message_html(template: "users/welcome.html.erb", title: title, contact_name: name, name: symbol, url: url, reset_url: reset_url)

response = User.send_message(name: name, email: system_email, subject: subject, text: text, html: html)

fields = [
{ title: "Account ID", value: symbol},
{ title: "Contact name", value: name, short: true },
{ title: "Contact email", value: system_email, short: true }
{ title: "Account ID", value: symbol, short: true },
{ title: "Account type", value: account_type, short: true },
{ title: "Account name", value: name, short: true },
{ title: "System email", value: system_email, short: true }
]
User.send_notification_to_slack(nil, title: subject, level: "good", fields: fields)

Expand All @@ -46,15 +48,17 @@ def send_welcome_email
def send_delete_email
title = Rails.env.stage? ? "DataCite Fabrica Test" : "DataCite Fabrica"
subject = "#{title}: Account Deleted"
account_type = self.class.name == "Provider" ? member_type : client_type
text = User.format_message_text(template: "users/delete.text.erb", title: title, contact_name: name, name: symbol)
html = User.format_message_html(template: "users/delete.html.erb", title: title, contact_name: name, name: symbol)

response = User.send_message(name: name, email: system_email, subject: subject, text: text, html: html)

fields = [
{ title: "Account ID", value: symbol},
{ title: "Contact name", value: name, short: true },
{ title: "Contact email", value: system_email, short: true }
{ title: "Account ID", value: symbol, short: true },
{ title: "Account type", value: account_type, short: true },
{ title: "Account name", value: name, short: true },
{ title: "System email", value: system_email, short: true }
]
User.send_notification_to_slack(nil, title: subject, level: "warning", fields: fields)

Expand Down
2 changes: 1 addition & 1 deletion spec/concerns/mailable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

context "send_notification_to_slack" do
it "succeeds" do
text = "Using contact email #{client.system_email}."
text = "Using system email #{client.system_email}."
options = { title: "TEST: new client account #{client.symbol} created." }
expect(Client.send_notification_to_slack(text, options)).to eq("ok")
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 9 additions & 19 deletions spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f5a58cd

Please sign in to comment.