From f5a58cd9fe03556c8b8722462375a863cf536e8c Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Mon, 20 Apr 2020 11:54:09 +0200 Subject: [PATCH] Include account type in slack messages. #475 --- app/models/concerns/mailable.rb | 16 +++++++---- spec/concerns/mailable_spec.rb | 2 +- .../send_notification_to_slack/succeeds.yml | 28 ++++++------------- .../Mailable/send_welcome_email.yml | 28 ++++++------------- 4 files changed, 29 insertions(+), 45 deletions(-) diff --git a/app/models/concerns/mailable.rb b/app/models/concerns/mailable.rb index 6640c096c..f727701d9 100644 --- a/app/models/concerns/mailable.rb +++ b/app/models/concerns/mailable.rb @@ -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) @@ -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) diff --git a/spec/concerns/mailable_spec.rb b/spec/concerns/mailable_spec.rb index 056b6aad2..b038859a3 100644 --- a/spec/concerns/mailable_spec.rb +++ b/spec/concerns/mailable_spec.rb @@ -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 diff --git a/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml b/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml index bd279cb0e..4d93e4e03 100644 --- a/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml +++ b/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml @@ -5,7 +5,7 @@ http_interactions: uri: "" body: encoding: US-ASCII - string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22TEST%3A+new+client+account+DATACITE.DATACITE+created.%22%2C%22text%22%3A%22Using+contact+email+test%40datacite.org.%22%2C%22color%22%3A%22good%22%7D%5D%7D + string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22TEST%3A+new+client+account+DATACITE.DATACITE+created.%22%2C%22text%22%3A%22Using+system+email+test%40datacite.org.%22%2C%22color%22%3A%22good%22%7D%5D%7D headers: Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 @@ -20,14 +20,8 @@ http_interactions: code: 200 message: OK headers: - Content-Type: - - text/html - Content-Length: - - '22' - Connection: - - keep-alive Date: - - Sat, 28 Mar 2020 07:53:12 GMT + - Mon, 20 Apr 2020 09:51:19 GMT Server: - Apache Vary: @@ -37,24 +31,20 @@ http_interactions: Referrer-Policy: - no-referrer X-Slack-Backend: - - h + - r X-Frame-Options: - SAMEORIGIN Access-Control-Allow-Origin: - "*" + Content-Length: + - '22' + Content-Type: + - text/html X-Via: - - haproxy-www-23wl - X-Cache: - - Miss from cloudfront - Via: - - 1.1 3c2fca5c3988bc152e874a83fac74f4a.cloudfront.net (CloudFront) - X-Amz-Cf-Pop: - - DUS51-C1 - X-Amz-Cf-Id: - - uQ48lYHrWcla25FwUtK7uNbwAgIqhVIp2Klth3f21F2D3Zs6o7nFXA== + - haproxy-www-9hkc body: encoding: ASCII-8BIT string: ok http_version: null - recorded_at: Sat, 28 Mar 2020 07:53:12 GMT + recorded_at: Mon, 20 Apr 2020 09:51:19 GMT recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml b/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml index 35fc020a9..e9ecaf7cf 100644 --- a/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml +++ b/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml @@ -5,7 +5,7 @@ http_interactions: uri: "" body: encoding: US-ASCII - string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22DataCite+Fabrica%3A+New+Account%22%2C%22color%22%3A%22good%22%2C%22fields%22%3A%5B%7B%22title%22%3A%22Account+ID%22%2C%22value%22%3A%22DATACITE.DATACITE%22%7D%2C%7B%22title%22%3A%22Contact+name%22%2C%22value%22%3A%22DataCite+Repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Contact+email%22%2C%22value%22%3A%22test%40datacite.org%22%2C%22short%22%3Atrue%7D%5D%7D%5D%7D + string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22DataCite+Fabrica%3A+New+Account%22%2C%22color%22%3A%22good%22%2C%22fields%22%3A%5B%7B%22title%22%3A%22Account+ID%22%2C%22value%22%3A%22DATACITE.DATACITE%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Account+type%22%2C%22value%22%3A%22repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Account+name%22%2C%22value%22%3A%22DataCite+Repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22System+email%22%2C%22value%22%3A%22test%40datacite.org%22%2C%22short%22%3Atrue%7D%5D%7D%5D%7D headers: Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 @@ -20,14 +20,8 @@ http_interactions: code: 200 message: OK headers: - Content-Type: - - text/html - Content-Length: - - '22' - Connection: - - keep-alive Date: - - Sat, 28 Mar 2020 07:53:10 GMT + - Mon, 20 Apr 2020 09:51:18 GMT Server: - Apache Vary: @@ -37,24 +31,20 @@ http_interactions: Referrer-Policy: - no-referrer X-Slack-Backend: - - h + - r X-Frame-Options: - SAMEORIGIN Access-Control-Allow-Origin: - "*" + Content-Length: + - '22' + Content-Type: + - text/html X-Via: - - haproxy-www-itvd - X-Cache: - - Miss from cloudfront - Via: - - 1.1 e8640ab30463560abfb6a2665bafb393.cloudfront.net (CloudFront) - X-Amz-Cf-Pop: - - DUS51-C1 - X-Amz-Cf-Id: - - fRUDXsnGgVVW90DuHGE5mmv8Vhm65hUIZrCk5kKvQARvmg0oxt24mw== + - haproxy-www-y6ft body: encoding: ASCII-8BIT string: ok http_version: null - recorded_at: Sat, 28 Mar 2020 07:53:10 GMT + recorded_at: Mon, 20 Apr 2020 09:51:18 GMT recorded_with: VCR 5.1.0