docbrown/app/services/moderator/banish_user.rb
Michael Kohl 09828853f6
✂✂✂ Remove Connect (#14734)
* Remove Connect

* Remove more Connect specs

* Remove a lot more Connect code

* 🚮

* It all has to go

* Explicitly add httpclient

* Update application layout

* Remove messages association from User

* Start fixing specs

* reintroduce util function and refactor references

* Remove Connect Cypress test

* Fix more specs

* Remove Connect from listings

* Ignore contact_via_connect column on listings

* Remove contact_via_connect usages

* Ignore mod_chat_channel_id on tags

* Drop Connect tables

* Remove email_connect_messages from user notification settings

* Re-add httpclient 2.8.3

This was mistakenly removed as a merge conflict

* Don't need to exclude removed chat channel file

* Remove unneeded style for chat channels

* Remove unneeded channel list prop type

* Remove chat channels index/connect-link from getPageEntries

* Re-add comment from httpclient in Gemfile

* Remove connect references from mailers

Tag Moderators no longer have a chat channel

No longer will users be notified about new messages (there won't be
any)

No longer will users be notified about channel invites (you can't
invite anyone anymore)

* Don't configure Pusher and remove PUSHER_* from .env_sample

since it's removed from gemfile, the Pusher constant will not resolve, if this is
configured in the environment variables we'll fail to boot.

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
Co-authored-by: Dan Uber <dan@forem.com>
2021-11-18 08:21:00 -06:00

51 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
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)
EdgeCache::Bust.call("/#{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