fix: Assign agent action changes (#5827)

This commit is contained in:
Tejaswini Chile 2022-11-15 13:15:27 +05:30 committed by GitHub
parent 38ab3c36db
commit 826a735cdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 35 additions and 15 deletions

View file

@ -5,7 +5,7 @@ export default {
case 'assign_team':
case 'send_email_to_team':
return this.teams;
case 'assign_best_agent':
case 'assign_agent':
return this.agents;
case 'add_label':
return this.labels.map(i => {

View file

@ -36,7 +36,7 @@ describe('webhookMixin', () => {
expect(wrapper.vm.getDropdownValues('assign_team')).toEqual(teams);
expect(wrapper.vm.getDropdownValues('send_email_to_team')).toEqual(teams);
expect(wrapper.vm.getDropdownValues('add_label')).toEqual(resolvedLabels);
expect(wrapper.vm.getDropdownValues('assign_best_agent')).toEqual(agents);
expect(wrapper.vm.getDropdownValues('assign_agent')).toEqual(agents);
expect(wrapper.vm.getDropdownValues()).toEqual([]);
});
});

View file

@ -49,7 +49,7 @@ export default {
const actionsMap = {
assign_team: resolveTeamIds(this.teams, params),
add_label: resolveLabels(this.labels, params),
assign_best_agent: resolveAgents(this.agents, params),
assign_agent: resolveAgents(this.agents, params),
mute_conversation: null,
snooze_conversation: null,
resolve_conversation: null,

View file

@ -5,7 +5,7 @@ export const MACRO_ACTION_TYPES = [
inputType: 'search_select',
},
{
key: 'assign_best_agent',
key: 'assign_agent',
label: 'Assign an agent',
inputType: 'search_select',
},

View file

@ -30,7 +30,7 @@ class AutomationRule < ApplicationRecord
scope :active, -> { where(active: true) }
CONDITIONS_ATTRS = %w[content email country_code status message_type browser_language assignee_id team_id referer city company inbox_id].freeze
ACTIONS_ATTRS = %w[send_message add_label send_email_to_team assign_team assign_best_agent send_webhook_event mute_conversation send_attachment
ACTIONS_ATTRS = %w[send_message add_label send_email_to_team assign_team assign_agent send_webhook_event mute_conversation send_attachment
change_status resolve_conversation snooze_conversation send_email_transcript].freeze
def file_base_data

View file

@ -30,7 +30,7 @@ class Macro < ApplicationRecord
validate :json_actions_format
ACTIONS_ATTRS = %w[send_message add_label assign_team assign_best_agent mute_conversation change_status
ACTIONS_ATTRS = %w[send_message add_label assign_team assign_agent mute_conversation change_status
resolve_conversation snooze_conversation send_email_transcript send_attachment add_private_note].freeze
def set_visibility(user, params)

View file

@ -25,8 +25,8 @@ class ActionService
@conversation.reload.add_labels(labels)
end
def assign_best_agent(agent_ids = [])
return unless agent_belongs_to_account?(agent_ids)
def assign_agent(agent_ids = [])
return unless agent_belongs_to_inbox?(agent_ids)
@agent = @account.users.find_by(id: agent_ids)
@ -47,8 +47,11 @@ class ActionService
private
def agent_belongs_to_account?(agent_ids)
@account.agents.pluck(:id).include?(agent_ids[0])
def agent_belongs_to_inbox?(agent_ids)
member_ids = @conversation.inbox.members.pluck(:user_id)
assignable_agent_ids = member_ids + @account.administrators.ids
assignable_agent_ids.include?(agent_ids[0])
end
def team_belongs_to_account?(team_ids)

View file

@ -263,12 +263,13 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
before do
create(:team_member, user: user_1, team: team)
create(:account_user, user: user_1, account: account)
create(:inbox_member, user: user_1, inbox: inbox)
macro.update!(actions:
[
{ 'action_name' => 'assign_team', 'action_params' => [team.id] },
{ 'action_name' => 'add_label', 'action_params' => %w[support priority_customer] },
{ 'action_name' => 'snooze_conversation' },
{ 'action_name' => 'assign_best_agent', 'action_params' => [user_1.id] },
{ 'action_name' => 'assign_agent', 'action_params' => [user_1.id] },
{ 'action_name' => 'send_message', 'action_params' => ['Send this message.'] },
{ 'action_name' => 'add_private_note', 'action_params': ['We are sending greeting message to customer.'] }
])
@ -297,7 +298,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
expect(conversation.messages.chat.last.sender).to eq(administrator)
end
it 'Assign the agent' do
it 'Assign the agent when he is inbox member' do
expect(conversation.assignee).to be_nil
perform_enqueued_jobs do
@ -309,6 +310,20 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
expect(conversation.messages.activity.last.content).to eq("Assigned to #{user_1.name} by #{administrator.name}")
end
it 'Assign the agent when he is not inbox member' do
InboxMember.last.destroy
expect(conversation.assignee).to be_nil
perform_enqueued_jobs do
post "/api/v1/accounts/#{account.id}/macros/#{macro.id}/execute",
params: { conversation_ids: [conversation.display_id] },
headers: administrator.create_new_auth_token
end
expect(conversation.messages.activity.last.content).not_to eq("Assigned to #{user_1.name} by #{administrator.name}")
end
it 'Assign the labels' do
expect(conversation.labels).to be_empty

View file

@ -12,7 +12,7 @@ FactoryBot.define do
},
{ 'action_name' => 'assign_team', 'action_params' => [1] },
{ 'action_name' => 'add_label', 'action_params' => %w[support priority_customer] },
{ 'action_name' => 'assign_best_agent', 'action_params' => [1, 2, 3, 4] }
{ 'action_name' => 'assign_agent', 'action_params' => [1, 2, 3, 4] }
]
end
end

View file

@ -30,6 +30,8 @@ describe AutomationRuleListener do
attribute_model: 'contact_attribute')
create(:team_member, user: user_1, team: team)
create(:team_member, user: user_2, team: team)
create(:inbox_member, user: user_1, inbox: inbox)
create(:inbox_member, user: user_2, inbox: inbox)
create(:account_user, user: user_2, account: account)
create(:account_user, user: user_1, account: account)
@ -45,7 +47,7 @@ describe AutomationRuleListener do
{ 'action_name' => 'assign_team', 'action_params' => [team.id] },
{ 'action_name' => 'add_label', 'action_params' => %w[support priority_customer] },
{ 'action_name' => 'send_webhook_event', 'action_params' => ['https://www.example.com'] },
{ 'action_name' => 'assign_best_agent', 'action_params' => [user_1.id] },
{ 'action_name' => 'assign_agent', 'action_params' => [user_1.id] },
{ 'action_name' => 'send_email_transcript', 'action_params' => ['new_agent@example.com'] },
{ 'action_name' => 'mute_conversation', 'action_params' => nil },
{ 'action_name' => 'change_status', 'action_params' => ['snoozed'] },

View file

@ -37,7 +37,7 @@ RSpec.describe AutomationRule, type: :model do
action_params: %w[support priority_customer]
},
{
action_name: :assign_best_agent,
action_name: :assign_agent,
action_params: [1]
}
]