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-6810 Don't send "Automatically flagged as spam" email when hiding works manually #4947

Open
wants to merge 8 commits 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
5 changes: 4 additions & 1 deletion app/controllers/admin/user_creations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ def set_spam
action = "mark as " + (params[:spam] == "true" ? "spam" : "not spam")
AdminActivity.log_action(current_admin, @creation, action: action, summary: @creation.inspect)
if params[:spam] == "true"
unless @creation.hidden_by_admin
@creation.notify_of_hiding_for_spam if @creation_class == Work
@creation.hidden_by_admin = true
end
@creation.mark_as_spam!
@creation.update_attribute(:hidden_by_admin, true)
EchoEkhi marked this conversation as resolved.
Show resolved Hide resolved
flash[:notice] = ts("Work was marked as spam and hidden.")
else
@creation.mark_as_ham!
Expand Down
1 change: 1 addition & 0 deletions app/models/moderated_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def self.bulk_review(ids)
where(id: ids).update_all(reviewed: true, approved: false)
# Ensure works are hidden and spam if they weren't already
Work.joins(:moderated_work).where("moderated_works.id IN (?)", ids).each do |work|
work.notify_of_hiding_for_spam unless work.hidden_by_admin?
work.update(hidden_by_admin: true, spam: true)
end
end
Expand Down
21 changes: 16 additions & 5 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def create_stat_counter
attr_accessor :new_gifts
attr_accessor :preview_mode

# Virtual attribute for whether the hidden-for-spam email has been sent, so the normal work-hidden email should not be sent
attr_accessor :notified_of_hiding_for_spam

# return title.html_safe to overcome escaping done by sanitiser
def title
read_attribute(:title).try(:html_safe)
Expand Down Expand Up @@ -1121,7 +1124,10 @@ def hide_spam
return unless spam?
admin_settings = AdminSetting.current
if admin_settings.hide_spam?
return if self.hidden_by_admin

self.hidden_by_admin = true
notify_of_hiding_for_spam
end
end

Expand All @@ -1145,13 +1151,18 @@ def mark_as_ham!

def notify_of_hiding
return unless hidden_by_admin? && saved_change_to_hidden_by_admin?
return if notified_of_hiding_for_spam

users.each do |user|
if spam?
UserMailer.admin_spam_work_notification(id, user.id).deliver_after_commit
else
UserMailer.admin_hidden_work_notification(id, user.id).deliver_after_commit
end
UserMailer.admin_hidden_work_notification(id, user.id).deliver_after_commit
end
end

def notify_of_hiding_for_spam
users.each do |user|
UserMailer.admin_spam_work_notification(id, user.id).deliver_after_commit
end
self.notified_of_hiding_for_spam = true
end

#############################################################################
Expand Down
35 changes: 33 additions & 2 deletions features/admins/admin_spam.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ Feature: Admin spam management
As an an admin
I want to be able to view and update works marked as spam

Scenario: Review spam
Given the spam work "Spammity Spam"
Scenario: Review spam when spam works are already hidden
Given the following admin settings are configured:
| hide_spam | 1 |
And the spam work "Spammity Spam"
And the spam work "Totally Legit"
And the work "Spammity Spam" should be hidden
And the work "Totally Legit" should be hidden
And I am logged in as a "superadmin" admin
And all emails have been delivered
Then I should see "Spam"
When I follow "Spam"
Then I should see "Works Marked as Spam"
Expand All @@ -20,3 +25,29 @@ Scenario: Review spam
And I should not see "Totally Legit"
And the work "Spammity Spam" should be hidden
And the work "Totally Legit" should not be hidden
And 0 emails should be delivered


Scenario: Review spam when spam works are not already hidden
Given the following admin settings are configured:
| hide_spam | 0 |
And the spam work "Spammity Spam"
And the spam work "Totally Legit"
And the work "Spammity Spam" should not be hidden
And the work "Totally Legit" should not be hidden
And I am logged in as a "superadmin" admin
And all emails have been delivered
Then I should see "Spam"
When I follow "Spam"
Then I should see "Works Marked as Spam"
And I should see "Spammity"
And I should see "Totally Legit"
When I check "spam_3"
And I check "ham_4"
And I press "Update Works"
Then I should not see "Spammity"
And I should not see "Totally Legit"
And the work "Spammity Spam" should be hidden
And the work "Totally Legit" should not be hidden
And 1 email should be delivered
And the email should contain "has been flagged by our automated system as spam"
25 changes: 25 additions & 0 deletions features/admins/admin_works.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ Feature: Admin Actions for Works, Comments, Series, Bookmarks
| superadmin |
| legal |
| policy_and_abuse |

Scenario Outline: Can hide works already marked as spam
Given I am logged in as "regular_user"
And I post the work "ToS Violation + Spam"
And the work "ToS Violation + Spam" is marked as spam
When I am logged in as a "<role>" admin
And all emails have been delivered
And I view the work "ToS Violation + Spam"
And I follow "Hide Work"
Then I should see "Item has been hidden."
And logged out users should not see the hidden work "ToS Violation + Spam" by "regular_user"
And logged in users should not see the hidden work "ToS Violation + Spam" by "regular_user"
And "regular_user" should see their work "ToS Violation + Spam" is hidden
And 1 email should be delivered
And the email should contain "you will be required to take action to correct the violation"

Examples:
| role |
| superadmin |
| legal |
| policy_and_abuse |

Scenario Outline: Can unhide works
Given I am logged in as "regular_user"
Expand Down Expand Up @@ -361,12 +382,16 @@ Feature: Admin Actions for Works, Comments, Series, Bookmarks
Given the work "Spammity Spam"
And I am logged in as a "policy_and_abuse" admin
And I view the work "Spammity Spam"
And all emails have been delivered
Then I should see "Mark As Spam"
When I follow "Mark As Spam"
Then I should see "marked as spam and hidden"
And I should see "Mark Not Spam"
And the work "Spammity Spam" should be marked as spam
And the work "Spammity Spam" should be hidden
And 1 email should be delivered
And the email should contain "has been flagged by our automated system as spam"


Scenario: can mark a spam work as not-spam
Given the spam work "Spammity Spam"
Expand Down
2 changes: 1 addition & 1 deletion features/other_a/hit_counts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Feature: Hit Counts
Then I should see "Hits: 0"

Scenario: Viewing a work hidden by an admin doesn't increment the hit count
Given the spam work "Hit Count Test"
Given the hidden work "Hit Count Test"
And I am logged in as an admin
And all hit count information is reset
When I go to the work "Hit Count Test"
Expand Down
15 changes: 13 additions & 2 deletions features/step_definitions/work_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,25 @@
step %{I am logged in as "#{work.users.first.login}"}
end

Given /^the spam work "([^\"]*)"$/ do |work|
Given "the spam work {string}" do |work|
step %{I have a work "#{work}"}
step %{I log out}
w = Work.find_by_title(work)
w = Work.find_by(title: work)
w.update_attribute(:spam, true)
end

Given "the hidden work {string}" do |work|
step %{I have a work "#{work}"}
step %{I log out}
w = Work.find_by(title: work)
w.update_attribute(:hidden_by_admin, true)
end

Given "the work {string} is marked as spam" do |work|
w = Work.find_by(title: work)
w.update_attribute(:spam, true)
end

Given "the user-defined tag limit is {int}" do |count|
allow(ArchiveConfig).to receive(:USER_DEFINED_TAGS_MAX).and_return(count)
end
Expand Down
Loading