feat: Assign team with teams none option (#5871)
This commit is contained in:
parent
e85f998a08
commit
9bfbd528ef
7 changed files with 46 additions and 3 deletions
|
@ -54,6 +54,7 @@ export default {
|
||||||
mute_conversation: null,
|
mute_conversation: null,
|
||||||
snooze_conversation: null,
|
snooze_conversation: null,
|
||||||
resolve_conversation: null,
|
resolve_conversation: null,
|
||||||
|
remove_assigned_team: null,
|
||||||
send_webhook_event: params[0],
|
send_webhook_event: params[0],
|
||||||
send_message: params[0],
|
send_message: params[0],
|
||||||
send_email_transcript: params[0],
|
send_email_transcript: params[0],
|
||||||
|
|
|
@ -41,8 +41,8 @@ export default {
|
||||||
...mapGetters({
|
...mapGetters({
|
||||||
uiFlags: 'macros/getUIFlags',
|
uiFlags: 'macros/getUIFlags',
|
||||||
labels: 'labels/getLabels',
|
labels: 'labels/getLabels',
|
||||||
teams: 'teams/getTeams',
|
|
||||||
agents: 'agents/getAgents',
|
agents: 'agents/getAgents',
|
||||||
|
teams: 'teams/getTeams',
|
||||||
}),
|
}),
|
||||||
macroId() {
|
macroId() {
|
||||||
return this.$route.params.macroId;
|
return this.$route.params.macroId;
|
||||||
|
|
|
@ -84,7 +84,8 @@ export default {
|
||||||
return !(
|
return !(
|
||||||
prop.action_name === 'mute_conversation' ||
|
prop.action_name === 'mute_conversation' ||
|
||||||
prop.action_name === 'snooze_conversation' ||
|
prop.action_name === 'snooze_conversation' ||
|
||||||
prop.action_name === 'resolve_conversation'
|
prop.action_name === 'resolve_conversation' ||
|
||||||
|
prop.action_name === 'remove_assigned_team'
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
|
|
@ -19,6 +19,11 @@ export const MACRO_ACTION_TYPES = [
|
||||||
label: 'Remove a label',
|
label: 'Remove a label',
|
||||||
inputType: 'multi_select',
|
inputType: 'multi_select',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'remove_assigned_team',
|
||||||
|
label: 'Remove Assigned Team',
|
||||||
|
inputType: null,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'send_email_transcript',
|
key: 'send_email_transcript',
|
||||||
label: 'Send an email transcript',
|
label: 'Send an email transcript',
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Macro < ApplicationRecord
|
||||||
|
|
||||||
validate :json_actions_format
|
validate :json_actions_format
|
||||||
|
|
||||||
ACTIONS_ATTRS = %w[send_message add_label assign_team assign_agent mute_conversation change_status remove_label
|
ACTIONS_ATTRS = %w[send_message add_label assign_team assign_agent mute_conversation change_status remove_label remove_assigned_team
|
||||||
resolve_conversation snooze_conversation send_email_transcript send_attachment add_private_note].freeze
|
resolve_conversation snooze_conversation send_email_transcript send_attachment add_private_note].freeze
|
||||||
|
|
||||||
def set_visibility(user, params)
|
def set_visibility(user, params)
|
||||||
|
|
|
@ -41,11 +41,16 @@ class ActionService
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_team(team_ids = [])
|
def assign_team(team_ids = [])
|
||||||
|
return unassign_team if team_ids[0].zero?
|
||||||
return unless team_belongs_to_account?(team_ids)
|
return unless team_belongs_to_account?(team_ids)
|
||||||
|
|
||||||
@conversation.update!(team_id: team_ids[0])
|
@conversation.update!(team_id: team_ids[0])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_assigned_team(_params)
|
||||||
|
@conversation.update!(team_id: nil)
|
||||||
|
end
|
||||||
|
|
||||||
def send_email_transcript(emails)
|
def send_email_transcript(emails)
|
||||||
emails.each do |email|
|
emails.each do |email|
|
||||||
ConversationReplyMailer.with(account: @conversation.account).conversation_transcript(@conversation, email)&.deliver_later
|
ConversationReplyMailer.with(account: @conversation.account).conversation_transcript(@conversation, email)&.deliver_later
|
||||||
|
|
|
@ -78,6 +78,9 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
||||||
'action_name': :add_label,
|
'action_name': :add_label,
|
||||||
'action_params': %w[support priority_customer]
|
'action_params': %w[support priority_customer]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'action_name': :remove_assigned_team
|
||||||
|
},
|
||||||
{
|
{
|
||||||
'action_name': :send_message,
|
'action_name': :send_message,
|
||||||
'action_params': ['Welcome to the chatwoot platform.']
|
'action_params': ['Welcome to the chatwoot platform.']
|
||||||
|
@ -379,6 +382,34 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
||||||
expect(conversation.messages.last.sender).to eq(administrator)
|
expect(conversation.messages.last.sender).to eq(administrator)
|
||||||
expect(conversation.messages.last.private).to be_truthy
|
expect(conversation.messages.last.private).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'Assign the team if team_ids are present' do
|
||||||
|
expect(conversation.team).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.reload.team_id).to eq(team.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'Unassign the team' do
|
||||||
|
macro.update!(actions: [
|
||||||
|
{ 'action_name' => 'remove_assigned_team' }
|
||||||
|
])
|
||||||
|
conversation.update!(team_id: team.id)
|
||||||
|
expect(conversation.reload.team).not_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.reload.team_id).to be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue