Skip to content

Commit

Permalink
AO3-6042 Fix that emails ignored the locale preference feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilka2 committed Jan 6, 2024
1 parent c69fdb2 commit a12dcd6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/mailers/archive_devise_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def reset_password_instructions(record, token, options = {})
devise_mail(record, :reset_password_instructions,
options.merge(subject: subject))
else
I18n.with_locale(Locale.find(@user.preference.preferred_locale).iso) do
I18n.with_locale(@user.preference.locale_for_emails) do
subject = t("users.mailer.reset_password_instructions.subject",
app_name: ArchiveConfig.APP_SHORT_NAME)
devise_mail(record, :reset_password_instructions,
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/comment_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class CommentMailer < ApplicationMailer
def comment_notification(user, comment)
@comment = comment
@owner = user
I18n.with_locale(Locale.find(user.preference.preferred_locale).iso) do
I18n.with_locale(user.preference.locale_for_emails) do
mail(
to: user.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
Expand All @@ -14,7 +14,7 @@ def comment_notification(user, comment)
# Sends email to an owner of the top-level commentable when a comment is edited
def edited_comment_notification(user, comment)
@comment = comment
I18n.with_locale(Locale.find(user.preference.preferred_locale).iso) do
I18n.with_locale(user.preference.locale_for_emails) do
mail(
to: user.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Edited comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/kudo_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def batch_kudo_notification(user_id, user_kudos)
user = User.find(user_id)
kudos_hash = JSON.parse(user_kudos)

I18n.with_locale(Locale.find(user.preference.preferred_locale).iso) do
I18n.with_locale(user.preference.locale_for_emails) do
kudos_hash.each_pair do |commentable_info, kudo_givers_hash|
# Parse the key to extract the type and id of the commentable so we can
# weed out any commentables that no longer exist.
Expand Down
28 changes: 14 additions & 14 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def anonymous_or_unrevealed_notification(user_id, work_id, collection_id, option
:unrevealed
end

I18n.with_locale(Locale.find(@user.preference.preferred_locale).iso) do
I18n.with_locale(@user.preference.locale_for_emails) do
mail(
to: @user.email,
subject: t(".subject.#{@status}",
Expand Down Expand Up @@ -95,7 +95,7 @@ def invitation_to_claim(invitation_id, archivist_login)
def claim_notification(creator_id, claimed_work_ids, is_user=false)
if is_user
creator = User.find(creator_id)
locale = Locale.find(creator.preference.preferred_locale).iso
locale = creator.preference.locale_for_emails
else
creator = ExternalAuthor.find(creator_id)
locale = I18n.default_locale
Expand Down Expand Up @@ -145,7 +145,7 @@ def batch_subscription_notification(subscription_id, entries)
if @creations.count > 1
subject += " and #{@creations.count - 1} more"
end
I18n.with_locale(Locale.find(@subscription.user.preference.preferred_locale).iso) do
I18n.with_locale(@subscription.user.preference.locale_for_emails) do
mail(
to: @subscription.user.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] #{subject}"
Expand All @@ -157,7 +157,7 @@ def batch_subscription_notification(subscription_id, entries)
def invite_increase_notification(user_id, total)
@user = User.find(user_id)
@total = total
I18n.with_locale(Locale.find(@user.preference.preferred_locale).iso) do
I18n.with_locale(@user.preference.locale_for_emails) do
mail(
to: @user.email,
subject: "#{t 'user_mailer.invite_increase_notification.subject', app_name: ArchiveConfig.APP_SHORT_NAME}"
Expand All @@ -170,7 +170,7 @@ def invite_request_declined(user_id, total, reason)
@user = User.find(user_id)
@total = total
@reason = reason
I18n.with_locale(Locale.find(@user.preference.preferred_locale).iso) do
I18n.with_locale(@user.preference.locale_for_emails) do
mail(
to: @user.email,
subject: t('user_mailer.invite_request_declined.subject', app_name: ArchiveConfig.APP_SHORT_NAME)
Expand Down Expand Up @@ -213,7 +213,7 @@ def challenge_assignment_notification(collection_id, assigned_user_id, assignmen
@assigned_user = User.find(assigned_user_id)
assignment = ChallengeAssignment.find(assignment_id)
@request = (assignment.request_signup || assignment.pinch_request_signup)
I18n.with_locale(Locale.find(@assigned_user.preference.preferred_locale).iso) do
I18n.with_locale(@assigned_user.preference.locale_for_emails) do
mail(
to: @assigned_user.email,
# i18n-tasks-use t('user_mailer.challenge_assignment_notification.subject')
Expand All @@ -225,7 +225,7 @@ def challenge_assignment_notification(collection_id, assigned_user_id, assignmen
# Asks a user to validate and activate their new account
def signup_notification(user_id)
@user = User.find(user_id)
I18n.with_locale(Locale.find(@user.preference.preferred_locale).iso) do
I18n.with_locale(@user.preference.locale_for_emails) do
mail(
to: @user.email,
subject: t('user_mailer.signup_notification.subject', app_name: ArchiveConfig.APP_SHORT_NAME)
Expand All @@ -238,7 +238,7 @@ def change_email(user_id, old_email, new_email)
@user = User.find(user_id)
@old_email = old_email
@new_email = new_email
I18n.with_locale(Locale.find(@user.preference.preferred_locale).iso) do
I18n.with_locale(@user.preference.locale_for_emails) do
mail(
to: @old_email,
subject: t('user_mailer.change_email.subject', app_name: ArchiveConfig.APP_SHORT_NAME)
Expand Down Expand Up @@ -293,7 +293,7 @@ def related_work_notification(user_id, related_work_id)
@related_work = RelatedWork.find(related_work_id)
@related_parent_link = url_for(controller: :works, action: :show, id: @related_work.parent)
@related_child_link = url_for(controller: :works, action: :show, id: @related_work.work)
I18n.with_locale(Locale.find(@user.preference.preferred_locale).iso) do
I18n.with_locale(@user.preference.locale_for_emails) do
mail(
to: @user.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Related work notification"
Expand All @@ -306,7 +306,7 @@ def recipient_notification(user_id, work_id, collection_id = nil)
@user = User.find(user_id)
@work = Work.find(work_id)
@collection = Collection.find(collection_id) if collection_id
I18n.with_locale(Locale.find(@user.preference.preferred_locale).iso) do
I18n.with_locale(@user.preference.locale_for_emails) do
subject = if @collection
t("user_mailer.recipient_notification.subject.collection",
app_name: ArchiveConfig.APP_SHORT_NAME,
Expand All @@ -328,7 +328,7 @@ def prompter_notification(work_id, collection_id=nil)
@collection = Collection.find(collection_id) if collection_id
@work.challenge_claims.each do |claim|
user = User.find(claim.request_signup.pseud.user.id)
I18n.with_locale(Locale.find(user.preference.preferred_locale).iso) do
I18n.with_locale(user.preference.locale_for_emails) do
mail(
to: user.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] A response to your prompt"
Expand All @@ -349,7 +349,7 @@ def delete_work_notification(user, work)
attachments["#{download.file_name}.html"] = { content: html, encoding: "base64" }
attachments["#{download.file_name}.txt"] = { content: html, encoding: "base64" }

I18n.with_locale(Locale.find(@user.preference.preferred_locale).iso) do
I18n.with_locale(@user.preference.locale_for_emails) do
mail(
to: user.email,
subject: t('user_mailer.delete_work_notification.subject', app_name: ArchiveConfig.APP_SHORT_NAME)
Expand All @@ -369,7 +369,7 @@ def admin_deleted_work_notification(user, work)
attachments["#{download.file_name}.html"] = { content: html, encoding: "base64" }
attachments["#{download.file_name}.txt"] = { content: html, encoding: "base64" }

I18n.with_locale(Locale.find(@user.preference.preferred_locale).iso) do
I18n.with_locale(@user.preference.locale_for_emails) do
mail(
to: user.email,
subject: t('user_mailer.admin_deleted_work_notification.subject', app_name: ArchiveConfig.APP_SHORT_NAME)
Expand All @@ -382,7 +382,7 @@ 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(Locale.find(@user.preference.preferred_locale).iso) do
I18n.with_locale(@user.preference.locale_for_emails) do
mail(
to: @user.email,
# i18n-tasks-use t('user_mailer.admin_hidden_work_notification.subject')
Expand Down
2 changes: 1 addition & 1 deletion app/models/creatorship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def notify_creator
pseud.user != User.current_user &&
pseud.user != User.orphan_account

I18n.with_locale(Locale.find(pseud.user.preference.preferred_locale).iso) do
I18n.with_locale(pseud.user.preference.locale_for_emails) do
if approved?
if User.current_user.try(:is_archivist?)
UserMailer.creatorship_notification_archivist(id, User.current_user.id).deliver_later
Expand Down
6 changes: 6 additions & 0 deletions app/models/preference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ def can_use_skin

errors.add(:base, "You don't have permission to use that skin!")
end

def locale_for_emails
return Locale.find(preferred_locale).iso if $rollout.active?(:set_locale_preference, user)

Locale.default.iso
end
end

0 comments on commit a12dcd6

Please sign in to comment.