Revert banisher (#1274)
* remove stalebot from milestone issues * simplify banisher
This commit is contained in:
parent
9cb4eea43e
commit
f96bc7c6f3
4 changed files with 38 additions and 105 deletions
2
.github/stale.yml
vendored
2
.github/stale.yml
vendored
|
|
@ -14,7 +14,7 @@ exemptLabels:
|
|||
exemptProjects: false
|
||||
|
||||
# Set to true to ignore issues in a milestone (defaults to false)
|
||||
exemptMilestones: false
|
||||
exemptMilestones: true
|
||||
|
||||
# Label to use when marking as stale
|
||||
staleLabel: stale
|
||||
|
|
|
|||
|
|
@ -96,62 +96,14 @@ class Internal::UsersController < Internal::ApplicationController
|
|||
|
||||
def banish
|
||||
@user = User.find(params[:id])
|
||||
Moderator::Banisher.call(admin: current_user, offender: @user)
|
||||
begin
|
||||
Moderator::Banisher.call(admin: current_user, offender: @user)
|
||||
rescue StandardError => e
|
||||
flash[:error] = e.message
|
||||
end
|
||||
redirect_to "/internal/users/#{@user.id}/edit"
|
||||
end
|
||||
|
||||
def strip_user(user)
|
||||
return unless user.comments.where("created_at < ?", 150.days.ago).empty?
|
||||
new_name = "spam_#{rand(10000)}"
|
||||
new_username = "spam_#{rand(10000)}"
|
||||
if User.find_by(name: new_name) || User.find_by(username: new_username)
|
||||
new_name = "spam_#{rand(10000)}"
|
||||
new_username = "spam_#{rand(10000)}"
|
||||
end
|
||||
user.name = new_name
|
||||
user.username = new_username
|
||||
user.twitter_username = ""
|
||||
user.github_username = ""
|
||||
user.website_url = ""
|
||||
user.summary = ""
|
||||
user.location = ""
|
||||
user.remote_profile_image_url = "https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png" if Rails.env.production?
|
||||
user.education = ""
|
||||
user.employer_name = ""
|
||||
user.employer_url = ""
|
||||
user.employment_title = ""
|
||||
user.mostly_work_with = ""
|
||||
user.currently_learning = ""
|
||||
user.currently_hacking_on = ""
|
||||
user.available_for = ""
|
||||
user.email_public = false
|
||||
user.facebook_url = nil
|
||||
user.dribbble_url = nil
|
||||
user.medium_url = nil
|
||||
user.stackoverflow_url = nil
|
||||
user.behance_url = nil
|
||||
user.linkedin_url = nil
|
||||
user.gitlab_url = nil
|
||||
user.mastodon_url = nil
|
||||
user.add_role :banned
|
||||
unless user.notes.where(reason: "banned").any?
|
||||
user.notes.
|
||||
create!(reason: "banned", content: "spam account", author_id: current_user.id)
|
||||
end
|
||||
user.comments.each do |comment|
|
||||
comment.reactions.each { |rxn| rxn.delay.destroy! }
|
||||
comment.delay.destroy!
|
||||
end
|
||||
user.follows.each { |follow| follow.delay.destroy! }
|
||||
user.articles.each { |article| article.delay.destroy! }
|
||||
user.remove_from_index!
|
||||
user.save!
|
||||
CacheBuster.new.bust("/#{user.old_username}")
|
||||
user.update!(old_username: nil)
|
||||
rescue StandardError => e
|
||||
flash[:error] = e.message
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_params
|
||||
|
|
|
|||
|
|
@ -12,53 +12,7 @@ module Moderator
|
|||
end
|
||||
|
||||
def banish
|
||||
# return unless user.comments.where("created_at < ?", 7.days.ago).empty?
|
||||
ban_offender
|
||||
strip_user_profile
|
||||
destroy_dependents
|
||||
user.remove_from_index!
|
||||
end
|
||||
|
||||
def destroy_dependents
|
||||
destroy_reactions
|
||||
destroy_comments
|
||||
destroy_articles
|
||||
destroy_follows
|
||||
end
|
||||
|
||||
def ban_offender
|
||||
user.add_role :banned
|
||||
unless user.notes.where(reason: "banned").any?
|
||||
user.notes.
|
||||
create!(reason: "banned", content: "spam account", author_id: admin.id)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_follows
|
||||
user.follows.destroy_all
|
||||
end
|
||||
handle_asynchronously :destroy_follows
|
||||
|
||||
def destroy_reactions
|
||||
user.reactions.destroy_all
|
||||
end
|
||||
|
||||
def destroy_comments
|
||||
user.comments.destroy_all
|
||||
end
|
||||
handle_asynchronously :destroy_comments
|
||||
|
||||
def destroy_articles
|
||||
user.articles.destroy_all
|
||||
end
|
||||
handle_asynchronously :destroy_articles
|
||||
|
||||
def bust_user_cache(old_username)
|
||||
CacheBuster.new.bust("/#{old_username}")
|
||||
end
|
||||
|
||||
def strip_user_profile
|
||||
bust_user_cache(user.username)
|
||||
return unless user.comments.where("created_at < ?", 150.days.ago).empty?
|
||||
new_name = "spam_#{rand(10000)}"
|
||||
new_username = "spam_#{rand(10000)}"
|
||||
if User.find_by(name: new_name) || User.find_by(username: new_username)
|
||||
|
|
@ -72,6 +26,7 @@ module Moderator
|
|||
user.website_url = ""
|
||||
user.summary = ""
|
||||
user.location = ""
|
||||
user.remote_profile_image_url = "https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png" if Rails.env.production?
|
||||
user.education = ""
|
||||
user.employer_name = ""
|
||||
user.employer_url = ""
|
||||
|
|
@ -87,8 +42,23 @@ module Moderator
|
|||
user.stackoverflow_url = nil
|
||||
user.behance_url = nil
|
||||
user.linkedin_url = nil
|
||||
user.save
|
||||
user.update_columns(old_username: nil)
|
||||
user.gitlab_url = nil
|
||||
user.mastodon_url = nil
|
||||
user.add_role :banned
|
||||
unless user.notes.where(reason: "banned").any?
|
||||
user.notes.
|
||||
create!(reason: "banned", content: "spam account", author: admin)
|
||||
end
|
||||
user.comments.each do |comment|
|
||||
comment.reactions.each { |rxn| rxn.delay.destroy! }
|
||||
comment.delay.destroy!
|
||||
end
|
||||
user.follows.each { |follow| follow.delay.destroy! }
|
||||
user.articles.each { |article| article.delay.destroy! }
|
||||
user.remove_from_index!
|
||||
user.save!
|
||||
CacheBuster.new.bust("/#{user.old_username}")
|
||||
user.update!(old_username: nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ RSpec.describe "internal/users", type: :request do
|
|||
|
||||
def banish_user
|
||||
post "/internal/users/#{user.id}/banish"
|
||||
Delayed::Worker.new(quiet: false).work_off
|
||||
Delayed::Worker.new(quiet: true).work_off
|
||||
user.reload
|
||||
end
|
||||
|
||||
|
|
@ -39,7 +39,18 @@ RSpec.describe "internal/users", type: :request do
|
|||
Delayed::Worker.new(quiet: true).work_off
|
||||
end
|
||||
|
||||
context "when offender is a spam user" do
|
||||
it "works" do
|
||||
create(:reaction, reactable: article, reactable_type: "Article", user: user)
|
||||
create(:comment, commentable_type: "Article", commentable: article, user: user)
|
||||
Delayed::Worker.new(quiet: true).work_off
|
||||
banish_user
|
||||
expect(user.username).to include("spam_")
|
||||
expect(Article.count).to eq(0)
|
||||
expect(Comment.count).to eq(0)
|
||||
expect(Reaction.count).to eq(0)
|
||||
end
|
||||
|
||||
xcontext "when offender is a spam user" do
|
||||
before do
|
||||
create(:reaction, reactable: article, reactable_type: "Article", user: user)
|
||||
create(:comment, commentable_type: "Article", commentable: article, user: user)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue