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,
|
||||
snooze_conversation: null,
|
||||
resolve_conversation: null,
|
||||
remove_assigned_team: null,
|
||||
send_webhook_event: params[0],
|
||||
send_message: params[0],
|
||||
send_email_transcript: params[0],
|
||||
|
|
|
@ -41,8 +41,8 @@ export default {
|
|||
...mapGetters({
|
||||
uiFlags: 'macros/getUIFlags',
|
||||
labels: 'labels/getLabels',
|
||||
teams: 'teams/getTeams',
|
||||
agents: 'agents/getAgents',
|
||||
teams: 'teams/getTeams',
|
||||
}),
|
||||
macroId() {
|
||||
return this.$route.params.macroId;
|
||||
|
|
|
@ -84,7 +84,8 @@ export default {
|
|||
return !(
|
||||
prop.action_name === 'mute_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',
|
||||
inputType: 'multi_select',
|
||||
},
|
||||
{
|
||||
key: 'remove_assigned_team',
|
||||
label: 'Remove Assigned Team',
|
||||
inputType: null,
|
||||
},
|
||||
{
|
||||
key: 'send_email_transcript',
|
||||
label: 'Send an email transcript',
|
||||
|
|
|
@ -30,7 +30,7 @@ class Macro < ApplicationRecord
|
|||
|
||||
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
|
||||
|
||||
def set_visibility(user, params)
|
||||
|
|
|
@ -41,11 +41,16 @@ class ActionService
|
|||
end
|
||||
|
||||
def assign_team(team_ids = [])
|
||||
return unassign_team if team_ids[0].zero?
|
||||
return unless team_belongs_to_account?(team_ids)
|
||||
|
||||
@conversation.update!(team_id: team_ids[0])
|
||||
end
|
||||
|
||||
def remove_assigned_team(_params)
|
||||
@conversation.update!(team_id: nil)
|
||||
end
|
||||
|
||||
def send_email_transcript(emails)
|
||||
emails.each do |email|
|
||||
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_params': %w[support priority_customer]
|
||||
},
|
||||
{
|
||||
'action_name': :remove_assigned_team
|
||||
},
|
||||
{
|
||||
'action_name': :send_message,
|
||||
'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.private).to be_truthy
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue