* Prepare to drop profile columns from user * Update code and factory * Also remove unused constant * Move validation from user to profile * Remove Profiles::ExtractData service object * Add more comments * Simplify sameAs attribute generation * Obey me machine, I am your master * Fix condition order in guard clause * Temporarily disable callback * Fix specs * Reduce usage of Profile#refresh_attributes! * Remove leftover comment * Handle social media links differently * More spec fixes * Fix specs for admin profile fields controller * Fix specs after merge * Fix remaining specs * Update user show request spec * Add comment for follow_hiring_tag * Only save profile when user is valid * Fix seeds.rb for profile fields * Switch from before_save to after_save * Undo unrelated formattin change * Update spec/fixtures/files/profile_fields.csv Co-authored-by: Molly Struve <mollylbs@gmail.com> * Remove data update script and spec * Fix spec * Fix typo in comment * Fix typo in comment * Move article resave logic to service object * Move profile field creation to before(:suite) * Refactor error handling in Profiles::Update * Fix Profiles::Update specs and refactor * Temporarily disable spec * Add ProfileValidator * Clean up * Move DB ready check into app/lib * Refresh attributes after importing from CSV * Fix specs * Remove unused file * A girl has no name. A profile neither. * Fix specs * Add responds_to? check * Spec fix * Add name to user fields in profile settings page Co-authored-by: Molly Struve <mollylbs@gmail.com>
52 lines
1.5 KiB
Ruby
52 lines
1.5 KiB
Ruby
module Moderator
|
|
class BanishUser < ManageActivityAndRoles
|
|
DEFAULT_PROFILE_IMAGE =
|
|
"https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png".freeze
|
|
|
|
attr_reader :user, :admin
|
|
|
|
def self.call(admin:, user:)
|
|
new(user: user, admin: admin).banish
|
|
end
|
|
|
|
def initialize(admin:, user:)
|
|
super(user: user, admin: admin, user_params: {})
|
|
end
|
|
|
|
def banish
|
|
BanishedUser.create(username: user.username, banished_by: admin)
|
|
user.unsubscribe_from_newsletters if user.email?
|
|
remove_profile_info
|
|
handle_user_status("Suspend", "spam account")
|
|
delete_user_activity
|
|
delete_comments
|
|
delete_articles
|
|
Users::CleanupChatChannels.call(user)
|
|
reassign_and_bust_username
|
|
delete_vomit_reactions
|
|
end
|
|
|
|
private
|
|
|
|
def reassign_and_bust_username
|
|
new_name = "spam_#{rand(1_000_000)}"
|
|
new_username = "spam_#{rand(1_000_000)}"
|
|
if User.find_by(name: new_name) || User.find_by(username: new_username)
|
|
new_name = "spam_#{rand(1_000_000)}"
|
|
new_username = "spam_#{rand(1_000_000)}"
|
|
end
|
|
user.update_columns(name: new_name, username: new_username, old_username: user.username,
|
|
profile_updated_at: Time.current)
|
|
CacheBuster.bust("/#{user.old_username}")
|
|
end
|
|
|
|
def remove_profile_info
|
|
user.profile.clear!
|
|
user.update_columns(profile_image: DEFAULT_PROFILE_IMAGE)
|
|
end
|
|
|
|
def delete_vomit_reactions
|
|
Reaction.where(reactable: user, category: "vomit").delete_all
|
|
end
|
|
end
|
|
end
|