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-6771 Fix that claim_notification didn't respect user's locale preference #4921

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 6 additions & 14 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,14 @@ def invitation_to_claim(invitation_id, archivist_login)
end

# Notifies a writer that their imported works have been claimed
def claim_notification(creator_id, claimed_work_ids, is_user=false)
if is_user
creator = User.find(creator_id)
locale = creator.preference.locale.iso
else
creator = ExternalAuthor.find(creator_id)
locale = I18n.default_locale
end
def claim_notification(creator_id, claimed_work_ids)
creator = User.find(creator_id)
@external_email = creator.email
@claimed_works = Work.where(id: claimed_work_ids)
I18n.with_locale(locale) do
mail(
to: creator.email,
subject: t("user_mailer.claim_notification.subject", app_name: ArchiveConfig.APP_SHORT_NAME)
)
end
mail(
to: creator.email,
subject: default_i18n_subject(app_name: ArchiveConfig.APP_SHORT_NAME)
)
end

# Sends a batched subscription notification
Expand Down
4 changes: 3 additions & 1 deletion app/models/external_author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def block_import

def notify_user_of_claim(claimed_work_ids)
# send announcement to user of the stories they have been given
UserMailer.claim_notification(self.id, claimed_work_ids).deliver_later
I18n.with_locale(self.user.preference.locale.iso) do
UserMailer.claim_notification(self.user_id, claimed_work_ids).deliver_later
end
end

def find_or_invite(archivist = nil)
Expand Down
17 changes: 17 additions & 0 deletions features/importing/work_import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,20 @@ Feature: Import Works
And I should not see "This chapter is a draft and hasn't been posted yet!"
When I follow "Next Chapter"
Then I should not see "This chapter is a draft and hasn't been posted yet!"

Scenario: Importing as an archivist for an existing Archive author should send translated claim email
Given a locale with translated emails
And the following activated users exist
| login | email |
| sam | [email protected] |
| notsam | [email protected] |
And the user "sam" enables translated emails
And all emails have been delivered
When I import the mock work "http://import-site-without-tags" by "sam" with email "[email protected]" and by "notsam" with email "[email protected]"
Then I should see import confirmation
And 1 email should be delivered to "[email protected]"
And the email should contain claim information
And the email to "sam" should be translated
And 1 email should be delivered to "[email protected]"
And the email should contain claim information
And the email to "notsam" should be non-translated
11 changes: 11 additions & 0 deletions features/step_definitions/work_import_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ def mock_external
step %{I select "English" from "Choose a language"}
end

When "I import the mock work {string} by {string} with email {string} and by {string} with email {string}" do |url, creator_name, creator_email, cocreator_name, cocreator_email|
step(%{I start importing "#{url}" with a mock website as an archivist})
step(%{I check "Import for others ONLY with permission"})
step(%{I fill in "external_author_name" with "#{creator_name}"})
step(%{I fill in "external_author_email" with "#{creator_email}"})
step(%{I fill in "external_coauthor_name" with "#{cocreator_name}"})
step(%{I fill in "external_coauthor_email" with "#{cocreator_email}"})
step(%{I check "Post without previewing"})
step(%{I press "Import"})
end

When /^I import "(.*)"( with a mock website)?$/ do |url, mock|
step %{I start importing "#{url}"#{mock}}
step %{I press "Import"}
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
title = "Façade"
title2 = Faker::Book.title

subject(:email) { UserMailer.claim_notification(author.id, [work.id, work2.id], true) }
subject(:email) { UserMailer.claim_notification(author.id, [work.id, work2.id]) }

let(:author) { create(:user) }
let(:work) { create(:work, title: title, authors: [author.pseuds.first]) }
Expand Down
4 changes: 2 additions & 2 deletions test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def feedback
UserMailer.feedback(feedback.id)
end

def claim_notification_registered
def claim_notification
work = create(:work)
creator_id = work.pseuds.first.user.id
UserMailer.claim_notification(creator_id, [work.id], true)
UserMailer.claim_notification(creator_id, [work.id])
end

private
Expand Down
Loading