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 4 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
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
12 changes: 6 additions & 6 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,11 +389,11 @@ def use_caching?
# 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?
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
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
end
flash[:error] = if current_user.suspended?
t("users.status.suspension_notice_html", contact_abuse_link: view_context.link_to(t("users.status.contact_abuse"), new_abuse_report_path), suspended_until: localize(current_user.suspended_until))
else
t("users.status.ban_notice_html", contact_abuse_link: view_context.link_to(t("users.status.contact_abuse"), new_abuse_report_path))
end
redirect_to current_user
end
end
Expand All @@ -402,7 +402,7 @@ def check_user_status
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("users.status.suspension_notice_html", contact_abuse_link: view_context.link_to(t("users.status.contact_abuse"), new_abuse_report_path), suspended_until: localize(current_user.suspended_until))
redirect_to current_user
end

Expand Down
3 changes: 0 additions & 3 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ ignore_missing:
- no_email # should be admin.admin_invitations.create.no_email
- sent # should be admin.admin_invitations.create.sent
- user_not_found # should be admin.admin_invitations.find.user_not_found
# File: app/controllers/application_controller.rb
- ban_notice # should be application.check_user_status.ban_notice
- suspension_notice # should be application.check_user_status.suspension_notice
# File: app/controllers/challenge_assignments_controller.rb
- challenge_assignments.assignments_not_sent
- challenge_assignments.assignments_sent
Expand Down
4 changes: 4 additions & 0 deletions config/locales/controllers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ en:
one: You may reset your password %{count} more time.
other: You may reset your password %{count} more times.
user_not_found: We couldn't find an account with that email address or username. Please try again.
status:
ban_notice_html: Your account has been banned. You are not permitted to add or edit archive content. Please %{contact_abuse_link} for more information.
contact_abuse: contact Abuse
suspension_notice_html: Your account has been suspended until %{suspended_until}. You may not add or edit content until your suspension has been resolved. Please %{contact_abuse_link} for more information.
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