fix: un-assign agent from conversation after removal (#5417)
Unassign agents from the conversation when they are removed from the account. Fixes: #4555
This commit is contained in:
@@ -6,6 +6,7 @@ class Agents::DestroyService
|
||||
destroy_notification_setting
|
||||
remove_user_from_teams
|
||||
remove_user_from_inboxes
|
||||
unassign_conversations
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,4 +28,8 @@ class Agents::DestroyService
|
||||
setting = user.notification_settings.find_by(account_id: account.id)
|
||||
setting&.destroy!
|
||||
end
|
||||
|
||||
def unassign_conversations
|
||||
user.assigned_conversations.where(account: account).find_each(&:update_assignee)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,15 +9,17 @@ describe Agents::DestroyService do
|
||||
before do
|
||||
create(:team_member, team: team1, user: user)
|
||||
create(:inbox_member, inbox: inbox, user: user)
|
||||
create(:conversation, account: account, assignee: user, inbox: inbox)
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
it 'remove inboxes and teams when removed from account' do
|
||||
it 'remove inboxes, teams, and conversations when removed from account' do
|
||||
described_class.new(account: account, user: user).perform
|
||||
user.reload
|
||||
expect(user.teams.length).to eq 0
|
||||
expect(user.inboxes.length).to eq 0
|
||||
expect(user.notification_settings.length).to eq 0
|
||||
expect(user.assigned_conversations.where(account: account).length).to eq 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user