Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-6836 Create admin_deleted_work_notification mailer preview #5021

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,11 @@ def admin_deleted_work_notification(user, work)
html = ::Mail::Encodings::Base64.encode(html)
attachments["#{download.file_name}.html"] = { content: html, encoding: "base64" }
attachments["#{download.file_name}.txt"] = { content: html, encoding: "base64" }

I18n.with_locale(@user.preference.locale.iso) do
mail(

mail(
to: user.email,
subject: t("user_mailer.admin_deleted_work_notification.subject", app_name: ArchiveConfig.APP_SHORT_NAME)
)
end
end

# Sends email to creators when a creation is hidden by an admin
Expand Down
31 changes: 17 additions & 14 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,24 @@ def new_recipients_have_not_blocked_gift_giver

before_destroy :send_deleted_work_notification, prepend: true
def send_deleted_work_notification
if self.posted?
users = self.pseuds.collect(&:user).uniq
orphan_account = User.orphan_account
unless users.blank?
for user in users
next if user == orphan_account
# Check to see if this work is being deleted by an Admin
if User.current_user.is_a?(Admin)
# this has to use the synchronous version because the work is going to be destroyed
UserMailer.admin_deleted_work_notification(user, self).deliver_now
else
# this has to use the synchronous version because the work is going to be destroyed
UserMailer.delete_work_notification(user, self).deliver_now
end
return unless self.posted?

users = self.pseuds.collect(&:user).uniq
orphan_account = User.orphan_account
indesotw marked this conversation as resolved.
Show resolved Hide resolved
return if users.blank?

users.each do |user|
next if user == orphan_account

# Check to see if this work is being deleted by an Admin
if User.current_user.is_a?(Admin)
# this has to use the synchronous version because the work is going to be destroyed
I18n.with_locale(user.preference.locale.iso) do
UserMailer.admin_deleted_work_notification(user, self).deliver_now
end
else
# this has to use the synchronous version because the work is going to be destroyed
UserMailer.delete_work_notification(user, self).deliver_now
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<% content_for :message do %>
<p><%= t("mailer.general.greeting.formal_html", name: style_bold(@user.login)) %></p>

<p><%= t('.deleted.html', title: style_creation_title(@work.title)) %></p>
<p><%= t(".deleted.html", title: style_creation_title(@work.title)) %></p>

<p><%= t('.import_project.html', opendoors_link: opendoors_link(t '.opendoors')) %></p>
<p><%= t(".import_project.html", opendoors_link: opendoors_link(t(".opendoors"))) %></p>

<p><%= t(".html.tos_violation", contact_abuse_link: abuse_link(t(".contact_abuse"))).html_safe %></p>
<p><%= t(".tos_violation.html", contact_abuse_link: abuse_link(t(".contact_abuse"))) %></p>

<p><%= t '.bye' %></p>
<p><%= t(".bye") %></p>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<% content_for :message do %>
<%= t("mailer.general.greeting.formal_html", name: @user.login) %>

<%= t('.deleted.text', title: @work.title) %>
<%= t(".deleted.text", title: @work.title) %>

<%= t('.import_project.text', opendoors_link: 'http://opendoors.transformativeworks.org/contact-open-doors/') %>
<%= t(".import_project.text", opendoors_link: "http://opendoors.transformativeworks.org/contact-open-doors/") %>

<%= t(".text.tos_violation", contact_abuse_url: new_abuse_report_url) %>
<%= t(".tos_violation.text", contact_abuse_url: new_abuse_report_url) %>

<%= t '.bye' %>
<%= t(".bye") %>
<% end %>
7 changes: 3 additions & 4 deletions config/locales/mailers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,14 @@ en:
deleted:
html: Your work %{title} was deleted from the Archive by a site admin.
text: Your work "%{title}" was deleted from the Archive by a site admin.
html:
tos_violation: If it's possible your work violated the Archive's Terms of Service, please %{contact_abuse_link}.
import_project:
html: If your work was part of an import project managed by our Open Doors team, please %{opendoors_link} with any further questions.
text: If your work was part of an import project managed by our Open Doors team, please contact Open Doors (%{opendoors_link}) with any further questions.
opendoors: contact Open Doors
subject: "[%{app_name}] Your work has been deleted by an admin"
text:
tos_violation: If it's possible your work violated the Archive's Terms of Service, please contact our Policy & Abuse team (%{contact_abuse_url}).
tos_violation:
html: If it's possible your work violated the Archive's Terms of Service, please %{contact_abuse_link}.
text: If it's possible your work violated the Archive's Terms of Service, please contact our Policy & Abuse team (%{contact_abuse_url}).
admin_hidden_work_notification:
access: While your work is hidden, you will still be able to access it through the link provided above, but it will not be listed on your works page, and it won't be available to other users of the Archive.
check_email: Please check your email, including your spam folder, as the Policy & Abuse team may have already contacted you explaining why your work was hidden.
Expand Down
11 changes: 8 additions & 3 deletions features/admins/admin_works.feature
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,21 @@ Feature: Admin Actions for Works, Comments, Series, Bookmarks
Scenario: Deleting works as a Policy & Abuse admin
Given I am logged in as "regular_user"
And I post the work "ToS Violation"
And a locale with translated emails
And the user "regular_user" enables translated emails
And I add the co-author "Another" to the work "ToS Violation"
When I am logged in as a "policy_and_abuse" admin
# Don't let the admin password email mess up the count.
And all emails have been delivered
And I view the work "ToS Violation"
And I follow "Delete Work"
And all indexing jobs have been run
Then I should see "Item was successfully deleted."
And 1 email should be delivered
And the email should contain "deleted from the Archive by a site admin"
And the email should not contain "translation missing"
And 2 emails should be delivered
And the email to "regular_user" should contain "deleted from the Archive by a site admin"
And the email to "regular_user" should be translated
And the email to "Another" should contain "deleted from the Archive by a site admin"
And the email to "Another" should be non-translated
When I visit the last activities item
Then I should see "destroy"
And I should see "#<Work id"
Expand Down
6 changes: 6 additions & 0 deletions test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def change_email
UserMailer.change_email(user.id, old_email, new_email)
end

def admin_deleted_work_notification
work = create(:work)
user = create(:user, :for_mailer_preview)
UserMailer.admin_deleted_work_notification(user, work)
end

private

def creatorship_notification_data(creation_type)
Expand Down
Loading