chore: Assign the conversation to agent who opens the conversation (#3925)
This commit is contained in:
parent
7b2ff2f112
commit
4ae9ed8f94
2 changed files with 28 additions and 0 deletions
|
@ -61,6 +61,7 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
|
||||||
else
|
else
|
||||||
@status = @conversation.toggle_status
|
@status = @conversation.toggle_status
|
||||||
end
|
end
|
||||||
|
assign_conversation if @conversation.status == 'open' && Current.user.is_a?(User) && Current.user&.agent?
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_typing_status
|
def toggle_typing_status
|
||||||
|
@ -93,6 +94,11 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
|
||||||
@conversation.snoozed_until = parse_date_time(params[:snoozed_until].to_s) if params[:snoozed_until]
|
@conversation.snoozed_until = parse_date_time(params[:snoozed_until].to_s) if params[:snoozed_until]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assign_conversation
|
||||||
|
@agent = Current.account.users.find(current_user.id)
|
||||||
|
@conversation.update_assignee(@agent)
|
||||||
|
end
|
||||||
|
|
||||||
def trigger_typing_event(event, is_private)
|
def trigger_typing_event(event, is_private)
|
||||||
user = current_user.presence || @resource
|
user = current_user.presence || @resource
|
||||||
Rails.configuration.dispatcher.dispatch(event, Time.zone.now, conversation: @conversation, user: user, is_private: is_private)
|
Rails.configuration.dispatcher.dispatch(event, Time.zone.now, conversation: @conversation, user: user, is_private: is_private)
|
||||||
|
|
|
@ -314,6 +314,7 @@ RSpec.describe 'Conversations API', type: :request do
|
||||||
|
|
||||||
context 'when it is an authenticated user' do
|
context 'when it is an authenticated user' do
|
||||||
let(:agent) { create(:user, account: account, role: :agent) }
|
let(:agent) { create(:user, account: account, role: :agent) }
|
||||||
|
let(:administrator) { create(:user, account: account, role: :administrator) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create(:inbox_member, user: agent, inbox: conversation.inbox)
|
create(:inbox_member, user: agent, inbox: conversation.inbox)
|
||||||
|
@ -341,6 +342,27 @@ RSpec.describe 'Conversations API', type: :request do
|
||||||
expect(conversation.reload.status).to eq('open')
|
expect(conversation.reload.status).to eq('open')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'self assign if agent changes the conversation status to open' do
|
||||||
|
conversation.update!(status: 'pending')
|
||||||
|
post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/toggle_status",
|
||||||
|
headers: agent.create_new_auth_token,
|
||||||
|
as: :json
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
expect(conversation.reload.status).to eq('open')
|
||||||
|
expect(conversation.reload.assignee_id).to eq(agent.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'disbale self assign if admin changes the conversation status to open' do
|
||||||
|
conversation.update!(status: 'pending')
|
||||||
|
conversation.update!(assignee_id: nil)
|
||||||
|
post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/toggle_status",
|
||||||
|
headers: administrator.create_new_auth_token,
|
||||||
|
as: :json
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
expect(conversation.reload.status).to eq('open')
|
||||||
|
expect(conversation.reload.assignee_id).not_to eq(administrator.id)
|
||||||
|
end
|
||||||
|
|
||||||
it 'toggles the conversation status to specific status when parameter is passed' do
|
it 'toggles the conversation status to specific status when parameter is passed' do
|
||||||
expect(conversation.status).to eq('open')
|
expect(conversation.status).to eq('open')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue