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-6846 Add admin_hidden_work_notification mailer #5044

Merged
merged 6 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 4 additions & 6 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,10 @@ def admin_hidden_work_notification(creation_id, user_id)
@user = User.find_by(id: user_id)
@work = Work.find_by(id: creation_id)

I18n.with_locale(@user.preference.locale.iso) do
mail(
to: @user.email,
subject: default_i18n_subject(app_name: ArchiveConfig.APP_SHORT_NAME)
)
end
mail(
to: @user.email,
subject: default_i18n_subject(app_name: ArchiveConfig.APP_SHORT_NAME)
)
end

def admin_spam_work_notification(creation_id, user_id)
Expand Down
4 changes: 3 additions & 1 deletion app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,9 @@ def notify_of_hiding
return if notified_of_hiding_for_spam

users.each do |user|
UserMailer.admin_hidden_work_notification(id, user.id).deliver_after_commit
I18n.with_locale(user.preference.locale.iso) do
UserMailer.admin_hidden_work_notification(id, user.id).deliver_after_commit
end
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/views/user_mailer/admin_hidden_work_notification.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<% content_for :message do %>
<p><%= t("mailer.general.greeting.formal_html", name: style_bold(@user.login)) %></p>

<p><%= t(".html.hidden", title: style_creation_link(@work.title, @work)).html_safe %></p>
<p><%= t(".hidden.html", title: style_creation_link(@work.title, @work)) %></p>

<p><%= t(".access") %></p>

<p><%= t(".check_email") %></p>

<p><%= t(".html.tos_violation", tos_link: tos_link(t ".tos")).html_safe %></p>
<p><%= t(".tos_violation.html", tos_link: tos_link(t(".tos"))) %></p>

<p><%= t(".html.help", contact_abuse_link: abuse_link(t ".contact_abuse")).html_safe %></p>
<p><%= t(".help.html", contact_abuse_link: abuse_link(t(".contact_abuse"))) %></p>
<% end %>
6 changes: 3 additions & 3 deletions app/views/user_mailer/admin_hidden_work_notification.text.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<% content_for :message do %>
<%= t("mailer.general.greeting.formal_html", name: @user.login) %>

<%= t(".text.hidden", title: @work.title, work_url: work_url(@work)) %>
<%= t(".hidden.text", title: @work.title, work_url: work_url(@work)) %>

<%= t(".access") %>

<%= t(".check_email") %>

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

<%= t(".text.help", contact_abuse_url: new_abuse_report_url) %>
<%= t(".help.text", contact_abuse_url: new_abuse_report_url) %>
<% end %>
17 changes: 9 additions & 8 deletions config/locales/mailers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,17 @@ en:
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.
contact_abuse: contact Policy & Abuse
html:
help: If you are uncertain why your work was hidden, and you have not received further communication regarding this matter, please %{contact_abuse_link} directly.
hidden: Your work %{title} has been hidden by the Policy & Abuse team and is no longer publicly accessible.
tos_violation: If your work was hidden due to being in violation of the Archive of Our Own's %{tos_link}, you will be required to take action to correct the violation. Failure to bring your work into compliance with the Terms of Service may lead to your work being deleted from the Archive.
help:
html: If you are uncertain why your work was hidden, and you have not received further communication regarding this matter, please %{contact_abuse_link} directly.
text: 'If you are uncertain why your work was hidden, and you have not received further communication regarding this matter, please contact Policy & Abuse directly: %{contact_abuse_url}.'
hidden:
html: Your work %{title} has been hidden by the Policy & Abuse team and is no longer publicly accessible.
text: Your work "%{title}" (%{work_url}) has been hidden by the Policy & Abuse team and is no longer publicly accessible.
subject: "[%{app_name}] Your work has been hidden by the Policy & Abuse team"
text:
help: 'If you are uncertain why your work was hidden, and you have not received further communication regarding this matter, please contact Policy & Abuse directly: %{contact_abuse_url}.'
hidden: Your work "%{title}" (%{work_url}) has been hidden by the Policy & Abuse team and is no longer publicly accessible.
tos_violation: If your work was hidden due to being in violation of the Archive of Our Own's Terms of Service (%{tos_url}), you will be required to take action to correct the violation. Failure to bring your work into compliance with the Terms of Service may lead to your work being deleted from the Archive.
tos: Terms of Service
tos_violation:
html: If your work was hidden due to being in violation of the Archive of Our Own's %{tos_link}, you will be required to take action to correct the violation. Failure to bring your work into compliance with the Terms of Service may lead to your work being deleted from the Archive.
text: If your work was hidden due to being in violation of the Archive of Our Own's Terms of Service (%{tos_url}), you will be required to take action to correct the violation. Failure to bring your work into compliance with the Terms of Service may lead to your work being deleted from the Archive.
anonymous_or_unrevealed_notification:
anonymous_info: Anonymous works are included in tag listings, but not on your works page. On the work, your user name will be replaced with "Anonymous."
anonymous_unrevealed_info: The collection maintainers may later reveal your work but leave it anonymous. People who subscribe to you will not be notified of this change. Your work will be included in tag listings, but not on your works page. On the work, your user name will be replaced with "Anonymous."
Expand Down
13 changes: 9 additions & 4 deletions features/admins/admin_works.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ Feature: Admin Actions for Works, Comments, Series, Bookmarks
Scenario Outline: Can hide works
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 "<role>" admin
And all emails have been delivered
And I view the work "ToS Violation"
And I follow "Hide Work"
Then I should see "Item has been hidden."
And logged out users should not see the hidden work "ToS Violation" by "regular_user"
And logged in users should not see the hidden work "ToS Violation" by "regular_user"
And the work "ToS Violation" should be hidden
And "regular_user" should see their work "ToS Violation" is hidden
And 1 email should be delivered
And the email should contain "you will be required to take action to correct the violation"
And 2 emails should be delivered
And the email to "regular_user" should contain "you will be required to take action to correct the violation"
And the email to "regular_user" should be translated
And the email to "Another" should contain "you will be required to take action to correct the violation"
And the email to "Another" should be non-translated

Examples:
| role |
Expand Down
14 changes: 10 additions & 4 deletions test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def change_email
new_email = "new_email"
UserMailer.change_email(user.id, old_email, new_email)
end

# Sends email when collection item changes status: anonymous_unrevealed
def anonymous_or_unrevealed_notification_status_anonymous_and_unrevealed
user, collection, item = anonymous_or_unrevealed_data(:anonymous_unrevealed_collection)
Expand All @@ -123,7 +123,7 @@ def anonymous_or_unrevealed_notification_status_anonymous_and_unrevealed
anonymous: newly_anonymous, unrevealed: newly_unrevealed
)
end

# Sends email when collection item changes status: anonymous
def anonymous_or_unrevealed_notification_status_anonymous
user, collection, item = anonymous_or_unrevealed_data(:anonymous_collection)
Expand All @@ -134,7 +134,7 @@ def anonymous_or_unrevealed_notification_status_anonymous
anonymous: newly_anonymous, unrevealed: newly_unrevealed
)
end

# Sends email when collection item changes status: unrevealed
def anonymous_or_unrevealed_notification_status_unrevealed
user, collection, item = anonymous_or_unrevealed_data(:unrevealed_collection)
Expand All @@ -159,6 +159,12 @@ def archivist_added_to_collection_notification
UserMailer.archivist_added_to_collection_notification(user.id, work.id, collection.id)
end

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

private

def creatorship_notification_data(creation_type)
Expand All @@ -167,7 +173,7 @@ def creatorship_notification_data(creation_type)
creation = create(creation_type, authors: [first_creator.default_pseud, second_creator.default_pseud])
[creation.creatorships.last, first_creator]
end

def anonymous_or_unrevealed_data(status)
user = create(:user, :for_mailer_preview)
collection = create(status)
Expand Down
Loading