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-6728 Delete comments properly for spammer bans #4855

Merged
merged 5 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion app/controllers/admin/admin_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,23 @@ def confirm_delete_user_creations

def destroy_user_creations
authorize @user
creations = @user.works + @user.bookmarks + @user.sole_owned_collections + @user.comments

creations = @user.works + @user.bookmarks + @user.sole_owned_collections
creations.each do |creation|
AdminActivity.log_action(current_admin, creation, action: "destroy spam", summary: creation.inspect)
creation.mark_as_spam! if creation.respond_to?(:mark_as_spam!)
creation.destroy
end

# comments are special and needs to be handled separately
@user.comments.each do |comment|
AdminActivity.log_action(current_admin, comment, action: "destroy spam", summary: comment.inspect)
# Submit spam sample to Akismet if in production mode
# comment.mark_as_spam cannot be used here because it also sets :approved to false, which would hide the whole thread
Akismetor.submit_spam(akismet_attributes) if Rails.env.production?
EchoEkhi marked this conversation as resolved.
Show resolved Hide resolved
comment.destroy_or_mark_deleted # comments with replies cannot be destroyed, mark deleted instead
end

flash[:notice] = ts("All creations by user %{login} have been deleted.", login: @user.login)
EchoEkhi marked this conversation as resolved.
Show resolved Hide resolved
redirect_to(admin_users_path)
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
EchoEkhi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,10 @@
# Prevents banned and suspended users from adding/editing content
def check_user_status
if current_user.is_a?(User) && (current_user.suspended? || current_user.banned?)
if current_user.suspended?

Check warning on line 392 in app/controllers/application_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Use the return of the conditional for variable assignment and comparison. Raw Output: app/controllers/application_controller.rb:392:7: C: Style/ConditionalAssignment: Use the return of the conditional for variable assignment and comparison.
flash[:error] = t("suspension_notice", default: "Your account has been suspended until %{suspended_until}. You may not add or edit content until your suspension has been resolved. Please <a href=\"#{new_abuse_report_path}\">contact Abuse</a> for more information.", suspended_until: localize(current_user.suspended_until)).html_safe
flash[:error] = t("suspension_notice", default: "Your account has been suspended until %{suspended_until}. You may not add or edit content until your suspension has been resolved. Please <a href=\"#{new_abuse_report_path}\">contact Abuse</a> for more information.".html_safe, suspended_until: localize(current_user.suspended_until))

Check warning on line 393 in app/controllers/application_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer setting a translation in the appropriate `en.yml` locale file instead of using `default` Raw Output: app/controllers/application_controller.rb:393:48: C: I18n/DefaultTranslation: Prefer setting a translation in the appropriate `en.yml` locale file instead of using `default`
else
flash[:error] = t("ban_notice", default: "Your account has been banned. You are not permitted to add or edit archive content. Please <a href=\"#{new_abuse_report_path}\">contact Abuse</a> for more information.").html_safe
flash[:error] = t("ban_notice", default: "Your account has been banned. You are not permitted to add or edit archive content. Please <a href=\"#{new_abuse_report_path}\">contact Abuse</a> for more information.".html_safe)

Check warning on line 395 in app/controllers/application_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer setting a translation in the appropriate `en.yml` locale file instead of using `default` Raw Output: app/controllers/application_controller.rb:395:41: C: I18n/DefaultTranslation: Prefer setting a translation in the appropriate `en.yml` locale file instead of using `default`
end
redirect_to current_user
end
Expand All @@ -402,7 +402,7 @@
def check_user_not_suspended
return unless current_user.is_a?(User) && current_user.suspended?

flash[:error] = t("suspension_notice", default: "Your account has been suspended until %{suspended_until}. You may not add or edit content until your suspension has been resolved. Please <a href=\"#{new_abuse_report_path}\">contact Abuse</a> for more information.", suspended_until: localize(current_user.suspended_until)).html_safe
flash[:error] = t("suspension_notice", default: "Your account has been suspended until %{suspended_until}. You may not add or edit content until your suspension has been resolved. Please <a href=\"#{new_abuse_report_path}\">contact Abuse</a> for more information.".html_safe, suspended_until: localize(current_user.suspended_until))

Check warning on line 405 in app/controllers/application_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer setting a translation in the appropriate `en.yml` locale file instead of using `default` Raw Output: app/controllers/application_controller.rb:405:44: C: I18n/DefaultTranslation: Prefer setting a translation in the appropriate `en.yml` locale file instead of using `default`
redirect_to current_user
end

Expand Down
18 changes: 18 additions & 0 deletions features/admins/users/admin_abuse_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,24 @@ Feature: Admin Abuse actions
And there should be no bookmarks on the work "Not Spam"
And there should be no comments on the work "Not Spam"

Scenario: A permabanned spammer's comments' replies from others should stay visible
Given I have a work "Generic Work"
And a comment "I like spam" by "Spamster" on the work "Generic Work"
And a reply "I don't :(" by "NotSpamster" on the work "Generic Work"
EchoEkhi marked this conversation as resolved.
Show resolved Hide resolved
When I am logged in as a "policy_and_abuse" admin
And I go to the user administration page for "Spamster"
And I choose "Spammer: ban and delete all creations"
And I press "Update"
Then I should see "permanently suspended"
And the user "Spamster" should be permanently banned
And I should see "I like spam"
When I press "Yes, Delete All Spammer Creations"
Then I should see "All creations by user Spamster have been deleted."
When I go to the work comments page for "Generic Work"
Then I should not see "I like spam"
And I should see "(Previous comment deleted.)"
And I should see "I don't :("
EchoEkhi marked this conversation as resolved.
Show resolved Hide resolved

Scenario: A user's works cannot be destroyed unless they are banned
Given I am logged in as "Spamster"
And I post the work "Loads of Spam"
Expand Down
Loading