Restructure omni services and add Chatwoot research snapshot
This commit is contained in:
37
research/chatwoot/app/jobs/agents/destroy_job.rb
Normal file
37
research/chatwoot/app/jobs/agents/destroy_job.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
class Agents::DestroyJob < ApplicationJob
|
||||
queue_as :low
|
||||
|
||||
def perform(account, user)
|
||||
ActiveRecord::Base.transaction do
|
||||
destroy_notification_setting(account, user)
|
||||
remove_user_from_teams(account, user)
|
||||
remove_user_from_inboxes(account, user)
|
||||
unassign_conversations(account, user)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remove_user_from_inboxes(account, user)
|
||||
inboxes = account.inboxes.all
|
||||
inbox_members = user.inbox_members.where(inbox_id: inboxes.pluck(:id))
|
||||
inbox_members.destroy_all
|
||||
end
|
||||
|
||||
def remove_user_from_teams(account, user)
|
||||
teams = account.teams.all
|
||||
team_members = user.team_members.where(team_id: teams.pluck(:id))
|
||||
team_members.destroy_all
|
||||
end
|
||||
|
||||
def destroy_notification_setting(account, user)
|
||||
setting = user.notification_settings.find_by(account_id: account.id)
|
||||
setting&.destroy!
|
||||
end
|
||||
|
||||
def unassign_conversations(account, user)
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
user.assigned_conversations.where(account: account).in_batches.update_all(assignee_id: nil)
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user