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 all 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 @@ -362,6 +362,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 @@ -125,6 +125,8 @@ def check_new_external_work
# Use the current user to determine what works are visible
scope :visible, -> { visible_to_user(User.current_user) }

after_update :admin_hidden_bookmark_notification, if: :hidden_by_admin_changed?

before_destroy :invalidate_bookmark_count
after_save :invalidate_bookmark_count, :update_pseud_index

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
11 changes: 11 additions & 0 deletions app/models/series.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def title
maximum: ArchiveConfig.NOTES_MAX,
too_long: ts("must be less than %{max} letters long.", max: ArchiveConfig.NOTES_MAX)

after_update :admin_hidden_series_notification, if: :hidden_by_admin_changed?
after_save :adjust_restricted
after_update_commit :expire_caches, :update_work_index

Expand Down Expand Up @@ -307,4 +308,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", title: style_creation_link(@bookmark.bookmarkable.title, @bookmark)) %></p>
Copy link
Contributor

Choose a reason for hiding this comment

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

And then to match the change in the yml file and also conform to this from Jira:

In the HTML email, the creation title inside the bookmark link should be bold and italicized.

Suggested change
<p><%= t(".hidden.html", title: style_creation_link(@bookmark.bookmarkable.title, @bookmark)) %></p>
<p><%= t(".hidden.html", bookmark_of_link: link_to(t(".hidden.bookmark_of", title: tag.em(tag.strong(@bookmark.bookmarkable.title))), @bookmark)) %></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_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", title: @bookmark.bookmarkable.title, bookmark_link: bookmark_url(@bookmark)) %>

<%= 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 %>
122 changes: 76 additions & 46 deletions config/locales/mailers/en.yml

Large diffs are not rendered by default.

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 @@ -54,6 +54,18 @@ def change_email
UserMailer.change_email(user.id, old_email, new_email)
end

def admin_hidden_bookmark_notification
creator = create(:user, :for_mailer_preview)
bookmark = create(:bookmark, pseud: creator.default_pseud)
UserMailer.admin_hidden_bookmark_notification(bookmark.id, creator.id)
end

def admin_hidden_series_notification
series = create(:series)
creator = create(:user, :for_mailer_preview)
UserMailer.admin_hidden_series_notification(series.id, creator.id)
end

private

def creatorship_notification_data(creation_type)
Expand Down
Loading