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-6847 Create anonymous_or_unrevealed_notification mailer preview #5040

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
12 changes: 4 additions & 8 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ def anonymous_or_unrevealed_notification(user_id, work_id, collection_id, option
else
:unrevealed
end

I18n.with_locale(@user.preference.locale.iso) do
mail(
to: @user.email,
subject: t(".subject.#{@status}",
app_name: ArchiveConfig.APP_SHORT_NAME)
)
end
mail(
to: @user.email,
subject: t(".subject.#{@status}", app_name: ArchiveConfig.APP_SHORT_NAME)
)
end

# Sends an invitation to join the archive
Expand Down
10 changes: 6 additions & 4 deletions app/models/collection_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,12 @@ def notify_of_unrevealed_or_anonymous
return if item.users.include?(User.current_user)

item.users.each do |user|
UserMailer.anonymous_or_unrevealed_notification(
user.id, item.id, collection.id,
anonymous: newly_anonymous, unrevealed: newly_unrevealed
).deliver_after_commit
I18n.with_locale(user.preference.locale.iso) do
UserMailer.anonymous_or_unrevealed_notification(
user.id, item.id, collection.id,
anonymous: newly_anonymous, unrevealed: newly_unrevealed
).deliver_after_commit
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<p><%= t(".changed_status.#{@status}.html",
collection_link: style_link(@collection.title, collection_url(@collection)),
work_link: style_creation_link(@work.title, work_url(@work))).html_safe %></p>
work_link: style_creation_link(@work.title, work_url(@work))) %></p>

<% if @becoming_anonymous && @becoming_unrevealed %>
<p><%= t(".unrevealed_info") %></p>
Expand Down
64 changes: 63 additions & 1 deletion features/collections/collection_notification.feature
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,66 @@ Feature: Collectible items email
And I press "Add"
Then I should see "Added to collection(s): Open Doors Collection"
And 1 email should be delivered
And the email to "regular_user" should be translated
And the email to "regular_user" should be translated

Scenario: Translated email is sent when the status of a Collection item is changed to anonymous
Given a locale with translated emails
And the user "user1" exists and is activated
And the user "user1" enables translated emails
And all emails have been delivered
When I have the collection "Collection1"
And I am logged in as "user1"
And I post the work "Test work" in the collection "Collection1"
When I am logged in as the owner of "Collection1"
And I go to "Collection1" collection's page
And I follow "Collection Settings"
And I check the 1st checkbox with id matching "collection_collection_preference_attributes_anonymous"
And I press "Update"
When I view the approved collection items page for "Collection1"
And I check the 1st checkbox with id matching "collection_items_\d+_anonymous"
And I submit
Then "user1" should be emailed
And the email should have "Your work was made anonymous" in the subject
And the email to "user1" should be translated

Scenario: Translated email is sent when the status of a Collection item is changed to unrevealed
Given a locale with translated emails
And the user "user1" exists and is activated
And the user "user1" enables translated emails
And all emails have been delivered
When I have the collection "Collection1"
And I am logged in as "user1"
And I post the work "Test work" in the collection "Collection1"
When I am logged in as the owner of "Collection1"
And I go to "Collection1" collection's page
And I follow "Collection Settings"
And I check the 1st checkbox with id matching "collection_collection_preference_attributes_unrevealed"
And I press "Update"
When I view the approved collection items page for "Collection1"
And I check the 1st checkbox with id matching "collection_items_\d+_unrevealed"
And I submit
Then "user1" should be emailed
And the email should have "Your work was made unrevealed" in the subject
And the email to "user1" should be translated

Scenario: Translated email is sent when the status of a Collection item is changed to anonymous and unrevealed
Given a locale with translated emails
And the user "user1" exists and is activated
And the user "user1" enables translated emails
And all emails have been delivered
When I have the collection "Collection1"
And I am logged in as "user1"
And I post the work "Test work" in the collection "Collection1"
When I am logged in as the owner of "Collection1"
And I go to "Collection1" collection's page
And I follow "Collection Settings"
And I check the 1st checkbox with id matching "collection_collection_preference_attributes_unrevealed"
And I check the 1st checkbox with id matching "collection_collection_preference_attributes_anonymous"
And I press "Update"
When I view the approved collection items page for "Collection1"
And I check the 1st checkbox with id matching "collection_items_\d+_unrevealed"
And I check the 1st checkbox with id matching "collection_items_\d+_anonymous"
And I submit
Then "user1" should be emailed
And the email should have "Your work was made anonymous and unrevealed" in the subject
And the email to "user1" should be translated
40 changes: 40 additions & 0 deletions test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,39 @@ 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)
newly_anonymous = true
newly_unrevealed = true
UserMailer.anonymous_or_unrevealed_notification(
user.id, item.id, collection.id,
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)
newly_anonymous = true
newly_unrevealed = false
UserMailer.anonymous_or_unrevealed_notification(
user.id, item.id, collection.id,
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)
newly_anonymous = false
newly_unrevealed = true
UserMailer.anonymous_or_unrevealed_notification(
user.id, item.id, collection.id,
anonymous: newly_anonymous, unrevealed: newly_unrevealed
)
end

def invite_increase_notification
user = create(:user, :for_mailer_preview)
Expand All @@ -134,4 +167,11 @@ 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)
item = create(:work, authors: [user.default_pseud], collections: [collection])
[user, collection, item]
end
end
Loading