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-5610 notify users when a bookmark or series they have created is hidden #4760

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
29bf722
Create series notification mailer action
walshyb Mar 1, 2024
a7130a0
Create series model admin_hidden update handler
walshyb Mar 1, 2024
ecd02f8
Add series mailer content and en translation
walshyb Mar 1, 2024
c64d3b8
remove unnecessary end
walshyb Mar 1, 2024
611b27d
Add hidden bookmark notification email
walshyb Oct 12, 2024
8d7fe01
Remove explicit html_safe call
walshyb Oct 12, 2024
bc5800f
Merge master
walshyb Oct 12, 2024
9974615
Add hidden bookmark mailer and preview
walshyb Oct 12, 2024
1fbd9eb
Update hidden bookmark mailer locale
walshyb Oct 12, 2024
787407d
Update hidden series mailer locale and add preview
walshyb Oct 12, 2024
87af757
Remove explicit html_safe
walshyb Oct 12, 2024
a67f8c5
Fix incorrect filename
walshyb Oct 12, 2024
0518c97
Remove unnecessary parentheses
walshyb Oct 12, 2024
34558af
Linting fixes
walshyb Oct 12, 2024
65899ff
Merge branch 'master' into AO3-5610-Notify-users-when-a-bookmark-or-s…
walshyb Jan 10, 2025
305d684
Move placement of after_update callback
walshyb Jan 10, 2025
5c300ea
Move after_update callback
walshyb Jan 10, 2025
1224b15
Remove unnecessary single quote
walshyb Jan 10, 2025
208da7d
Create user for hidden bookmark mailer test
walshyb Jan 10, 2025
a079f72
Create user for hidden series mailer test
walshyb Jan 10, 2025
2de2360
Change var from bookmark_url to bookmark_link
walshyb Jan 10, 2025
7251c16
Merge branch 'AO3-5610-Notify-users-when-a-bookmark-or-series-they-ha…
walshyb Jan 10, 2025
695a6ca
Change var from bookmark_url to bookmark_link
walshyb Jan 10, 2025
6b0784a
Update hidden bookmark mailer text to include bookmark title
walshyb Jan 10, 2025
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
24 changes: 24 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,30 @@ def admin_deleted_work_notification(user, work)
end
end

def admin_hidden_bookmark_notification(creation_id, user_id)
@user = User.find_by(id: user_id)
@bookmark = Bookmark.find_by(id: creation_id)

I18n.with_locale(@user.preference.locale.iso) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in the model where admin_hidden_bookmark_notification is called and surround that call there, to make the locale selector in the preview work.

Same for the other mail.

mail(
to: @user.email,
subject: default_i18n_subject(app_name: ArchiveConfig.APP_SHORT_NAME)
)
end
end

def admin_hidden_series_notification(creation_id, user_id)
walshyb marked this conversation as resolved.
Show resolved Hide resolved
@user = User.find_by(id: user_id)
@series = Series.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)
walshyb marked this conversation as resolved.
Show resolved Hide resolved
)
end
end

# Sends email to creators when a creation is hidden by an admin
def admin_hidden_work_notification(creation_id, user_id)
@user = User.find_by(id: user_id)
Expand Down
12 changes: 12 additions & 0 deletions app/models/bookmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def check_new_external_work
end
end

after_update :admin_hidden_bookmark_notification, if: :hidden_by_admin_changed?
walshyb marked this conversation as resolved.
Show resolved Hide resolved

# renaming scope :public -> :is_public because otherwise it overlaps with the "public" keyword
scope :is_public, -> { where(private: false, hidden_by_admin: false) }
scope :not_public, -> { where(private: true) }
Expand Down Expand Up @@ -213,4 +215,14 @@ def bookmarkable_date
bookmarkable.updated_at
end
end

private

def admin_hidden_bookmark_notification
return unless hidden_by_admin?

users.each do |user|
UserMailer.send_bookmark_hidden_notification(id, user.id).deliver_later
end
end
end
12 changes: 12 additions & 0 deletions app/models/series.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Series < ApplicationRecord
maximum: ArchiveConfig.TITLE_MAX,
too_long: ts("must be less than %{max} letters long.", max: ArchiveConfig.TITLE_MAX)

after_update :admin_hidden_series_notification, if: :hidden_by_admin_changed?
walshyb marked this conversation as resolved.
Show resolved Hide resolved

# return title.html_safe to overcome escaping done by sanitiser
def title
read_attribute(:title).try(:html_safe)
Expand Down Expand Up @@ -307,4 +309,14 @@ def creators
def work_types
works.map(&:work_types).flatten.uniq
end

private

def admin_hidden_series_notification
return unless hidden_by_admin?

users.each do |user|
UserMailer.send_series_hidden_notification(id, user.id).deliver_later
end
end
end
13 changes: 13 additions & 0 deletions app/views/user_mailer/admin_hidden_bookmark_notification.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% content_for :message do %>
<p><%= t("mailer.general.greeting.formal_html", name: style_bold(@user.login)) %></p>

<p><%= t(".hidden.html", bookmark_url: style_creation_link("bookmark", @bookmark)) %></p>
walshyb marked this conversation as resolved.
Show resolved Hide resolved

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

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

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

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

<%= t(".hidden.text", bookmark_url: bookmark_url(@bookmark)) %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text here should be Your bookmark of "<%= @bookmark.bookmarkable.title %>" (<%= bookmark_url(@bookmark) %>) has ... so something similar to what you did for the series.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the same thing that I did for the series mailer. Is this new change good?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text is good now, but the variable name is incorrect. I left a comment on the line in the yml file.


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

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

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

<%= t(".help.text", contact_abuse_url: new_abuse_report_url) %>
<% end %>
13 changes: 13 additions & 0 deletions app/views/user_mailer/admin_hidden_series_notification.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% content_for :message do %>
<p><%= t("mailer.general.greeting.formal_html", name: style_bold(@user.login)) %></p>

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

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

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

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

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

<%= t(".hidden.text", title: @series.title, series_url: series_url(@series)) %>

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

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

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

<%= t(".help.text", contact_abuse_url: new_abuse_report_url) %>
<% end %>
30 changes: 30 additions & 0 deletions config/locales/mailers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,36 @@ en:
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}).
admin_hidden_bookmark_notification:
access: While your bookmark is hidden, you will still be able to access it through the link provided above, but it will not be listed on your bookmarks 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 bookmark was hidden.
contact_abuse: contact Policy & Abuse
help:
html: If you are uncertain why your bookmark was hidden, and you have not received further communication regarding this matter, please %{contact_abuse_link} directly.
text: 'If you are uncertain why your bookmark was hidden, and you have not received further communication regarding this matter, please contact Policy & Abuse directly: %{contact_abuse_url}.'
hidden:
html: Your %{bookmark_url} has been hidden by the Policy & Abuse team and is no longer publicly accessible.
text: Your bookmark (%{bookmark_url}) has been hidden by the Policy & Abuse team and is no longer publicly accessible.
subject: "[%{app_name}] Your bookmark has been hidden by the Policy & Abuse team"
tos: Terms of Service
tos_violation:
html: If your bookmark 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 bookmark into compliance with the Terms of Service may lead to your bookmark being deleted from the Archive.
text: If your bookmark 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 bookmark into compliance with the Terms of Service may lead to your bookmark being deleted from the Archive.
admin_hidden_series_notification:
access: While your series is hidden, you will still be able to access it through the link provided above, but it will not be listed on your series' page, and it won't be available to other users of the Archive.
walshyb marked this conversation as resolved.
Show resolved Hide resolved
check_email: Please check your email, including your spam folder, as the Policy & Abuse team may have already contacted you explaining why your series was hidden.
contact_abuse: contact Policy & Abuse
help:
html: If you are uncertain why your series was hidden, and you have not received further communication regarding this matter, please %{contact_abuse_link} directly.
text: 'If you are uncertain why your series was hidden, and you have not received further communication regarding this matter, please contact Policy & Abuse directly: %{contact_abuse_url}.'
hidden:
html: Your series %{title} has been hidden by the Policy & Abuse team and is no longer publicly accessible.
text: Your series "%{title}" (%{series_url}) has been hidden by the Policy & Abuse team and is no longer publicly accessible.
subject: "[%{app_name}] Your series has been hidden by the Policy & Abuse team"
tos: Terms of Service
tos_violation:
html: If your series 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 series into compliance with the Terms of Service may lead to your series being deleted from the Archive.
text: If your series 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 series into compliance with the Terms of Service may lead to your series being deleted from the Archive.
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
12 changes: 12 additions & 0 deletions test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ def claim_notification_registered
UserMailer.claim_notification(creator_id, [work.id], true)
end

def admin_hidden_bookmark_notification
bookmark = create(:bookmark)
creator_id = bookmark.pseud.user_id
UserMailer.admin_hidden_bookmark_notification(bookmark.id, creator_id)
walshyb marked this conversation as resolved.
Show resolved Hide resolved
end

def admin_hidden_series_notification
series = create(:series)
creator_id = series.pseuds.first.user_id
UserMailer.admin_hidden_series_notification(series.id, creator_id)
walshyb marked this conversation as resolved.
Show resolved Hide resolved
end

private

def creatorship_notification_data(creation_type)
Expand Down
Loading