Skip to content

Commit

Permalink
send email and slack message when account gets deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Nov 14, 2018
1 parent 261fa90 commit 7517619
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def index
elsif params[:ids].present?
response = Client.find_by_ids(params[:ids], page: page, sort: sort)
else
response = Client.query(params[:query], year: params[:year], provider_id: params[:provider_id], include_deleted: params[:include_deleted], fields: params[:fields], page: page, sort: sort)
response = Client.query(params[:query], year: params[:year], provider_id: params[:provider_id], fields: params[:fields], page: page, sort: sort)
end

total = response.results.total
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def index
elsif params[:ids].present?
response = Provider.find_by_ids(params[:ids], page: page, sort: sort)
else
response = Provider.query(params[:query], year: params[:year], region: params[:region], organization_type: params[:organization_type], focus_area: params[:focus_area], include_deleted: params[:include_deleted], fields: params[:fields], page: page, sort: sort)
response = Provider.query(params[:query], year: params[:year], region: params[:region], organization_type: params[:organization_type], focus_area: params[:focus_area], fields: params[:fields], page: page, sort: sort)
end

total = response.results.total
Expand Down
1 change: 1 addition & 0 deletions app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Client < ActiveRecord::Base
before_save { self.updated = Time.zone.now.utc.iso8601 }

after_create :send_welcome_email, unless: Proc.new { Rails.env.test? }
before_delete :send_delete_email, unless: Proc.new { Rails.env.test? }

attr_accessor :target_id

Expand Down
18 changes: 18 additions & 0 deletions app/models/concerns/mailable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ def send_welcome_email

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

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

response
end

def send_delete_email
title = Rails.env.stage? ? "DataCite DOI Fabrica Test" : "DataCite DOI Fabrica"
subject = "#{title}: Account Deleted"
text = User.format_message_text(template: "users/delete.text.erb", title: title, contact_name: contact_name, name: symbol)
html = User.format_message_html(template: "users/delete.html.erb", title: title, contact_name: contact_name, name: symbol)

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

fields = [
{ title: "Account ID", value: symbol},
{ title: "Contact name", value: contact_name, short: true },
Expand Down
1 change: 1 addition & 0 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Provider < ActiveRecord::Base
before_save { self.updated = Time.zone.now.utc.iso8601 }

after_create :send_welcome_email, unless: Proc.new { Rails.env.test? }
before_delete :send_delete_email, unless: Proc.new { Rails.env.test? }

accepts_nested_attributes_for :prefixes

Expand Down
47 changes: 47 additions & 0 deletions app/views/users/delete.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<span class="preheader">Use this link to generate a password. The link is only valid for 24 hours.</span>
<table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table class="email-content" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="email-masthead">
<a href="<%= ENV['BRACCO_URL'] %>" class="email-masthead_name"><%= @title %></a>
</td>
</tr>
<!-- Email Body -->
<tr>
<td class="email-body" width="100%" cellpadding="0" cellspacing="0">
<table class="email-body_inner" align="center" width="570" cellpadding="0" cellspacing="0">
<!-- Body content -->
<tr>
<td class="content-cell">
<h1>Dear <%= @contact_name %>,</h1>
<p>The <%= @title %> account named <%= @name %> has been deleted. If this was done in error, please
reach out to DataCite Support and we can re-enable the <%= @name %> account.
</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0">
<tr>
<td class="content-cell" align="center">
<p class="sub align-center">
DataCite
<br>Am Welfengarten 1B
<br>30167 Hannover
<br>Germany
<br><a href="mailto:[email protected]">[email protected]</a>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
17 changes: 17 additions & 0 deletions app/views/users/delete.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Dear <%= @contact_name %>,

The <%= @title %> account named <%= @name %>
has been deleted. If this was done in error, please
reach out to DataCite Support and we can re-enable the
<%= @name %> account.

Thanks,

The DataCite Support Team


DataCite
Am Welfengarten 1B
30167 Hannover
Germany
Email: [email protected]

0 comments on commit 7517619

Please sign in to comment.