Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90b165b624 | ||
|
|
ca9bedfba1 | ||
|
|
4edf626af2 | ||
|
|
e86222034e | ||
|
|
2b37fef0e0 | ||
|
|
44b32eacec | ||
|
|
5b7430f376 | ||
|
|
5c00a1601a |
+3
-3
@@ -193,7 +193,7 @@ GEM
|
|||||||
climate_control (1.2.0)
|
climate_control (1.2.0)
|
||||||
coderay (1.1.3)
|
coderay (1.1.3)
|
||||||
commonmarker (0.23.10)
|
commonmarker (0.23.10)
|
||||||
concurrent-ruby (1.3.5)
|
concurrent-ruby (1.3.7)
|
||||||
connection_pool (2.5.5)
|
connection_pool (2.5.5)
|
||||||
crack (1.0.0)
|
crack (1.0.0)
|
||||||
bigdecimal
|
bigdecimal
|
||||||
@@ -304,7 +304,7 @@ GEM
|
|||||||
railties (>= 5.0.0)
|
railties (>= 5.0.0)
|
||||||
faker (3.2.0)
|
faker (3.2.0)
|
||||||
i18n (>= 1.8.11, < 2)
|
i18n (>= 1.8.11, < 2)
|
||||||
faraday (2.14.2)
|
faraday (2.14.3)
|
||||||
faraday-net_http (>= 2.0, < 3.5)
|
faraday-net_http (>= 2.0, < 3.5)
|
||||||
json
|
json
|
||||||
logger
|
logger
|
||||||
@@ -474,7 +474,7 @@ GEM
|
|||||||
rails-dom-testing (>= 1, < 3)
|
rails-dom-testing (>= 1, < 3)
|
||||||
railties (>= 4.2.0)
|
railties (>= 4.2.0)
|
||||||
thor (>= 0.14, < 2.0)
|
thor (>= 0.14, < 2.0)
|
||||||
json (2.19.8)
|
json (2.19.9)
|
||||||
json_refs (0.1.8)
|
json_refs (0.1.8)
|
||||||
hana
|
hana
|
||||||
json_schemer (0.2.24)
|
json_schemer (0.2.24)
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
|
|||||||
@assignable_agents = @inbox.assignable_agents
|
@assignable_agents = @inbox.assignable_agents
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assignable_owners
|
||||||
|
@assignable_agents = @inbox.assignable_agents.select(&:confirmed?)
|
||||||
|
@agent_bots = AgentBot.accessible_to(Current.account)
|
||||||
|
end
|
||||||
|
|
||||||
def campaigns
|
def campaigns
|
||||||
@campaigns = @inbox.campaigns
|
@campaigns = @inbox.campaigns
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -62,9 +62,10 @@ class ConversationApi extends ApiClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
assignAgent({ conversationId, agentId }) {
|
assignAgent({ conversationId, agentId, assigneeType }) {
|
||||||
return axios.post(`${this.url}/${conversationId}/assignments`, {
|
return axios.post(`${this.url}/${conversationId}/assignments`, {
|
||||||
assignee_id: agentId,
|
assignee_id: agentId,
|
||||||
|
assignee_type: assigneeType,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ class Inboxes extends CacheEnabledApiClient {
|
|||||||
return axios.get(`${this.url}/${inboxId}/campaigns`);
|
return axios.get(`${this.url}/${inboxId}/campaigns`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAssignableOwners(inboxId) {
|
||||||
|
return axios.get(`${this.url}/${inboxId}/assignable_owners`);
|
||||||
|
}
|
||||||
|
|
||||||
deleteInboxAvatar(inboxId) {
|
deleteInboxAvatar(inboxId) {
|
||||||
return axios.delete(`${this.url}/${inboxId}/avatar`);
|
return axios.delete(`${this.url}/${inboxId}/avatar`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,11 +90,16 @@ describe('#ConversationAPI', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('#assignAgent', () => {
|
it('#assignAgent', () => {
|
||||||
conversationAPI.assignAgent({ conversationId: 12, agentId: 34 });
|
conversationAPI.assignAgent({
|
||||||
|
conversationId: 12,
|
||||||
|
agentId: 34,
|
||||||
|
assigneeType: 'AgentBot',
|
||||||
|
});
|
||||||
expect(axiosMock.post).toHaveBeenCalledWith(
|
expect(axiosMock.post).toHaveBeenCalledWith(
|
||||||
`/api/v1/conversations/12/assignments`,
|
`/api/v1/conversations/12/assignments`,
|
||||||
{
|
{
|
||||||
assignee_id: 34,
|
assignee_id: 34,
|
||||||
|
assignee_type: 'AgentBot',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ describe('#InboxesAPI', () => {
|
|||||||
expect(inboxesAPI).toHaveProperty('create');
|
expect(inboxesAPI).toHaveProperty('create');
|
||||||
expect(inboxesAPI).toHaveProperty('update');
|
expect(inboxesAPI).toHaveProperty('update');
|
||||||
expect(inboxesAPI).toHaveProperty('delete');
|
expect(inboxesAPI).toHaveProperty('delete');
|
||||||
|
expect(inboxesAPI).toHaveProperty('getAssignableOwners');
|
||||||
expect(inboxesAPI).toHaveProperty('getCampaigns');
|
expect(inboxesAPI).toHaveProperty('getCampaigns');
|
||||||
expect(inboxesAPI).toHaveProperty('getAgentBot');
|
expect(inboxesAPI).toHaveProperty('getAgentBot');
|
||||||
expect(inboxesAPI).toHaveProperty('setAgentBot');
|
expect(inboxesAPI).toHaveProperty('setAgentBot');
|
||||||
@@ -37,6 +38,13 @@ describe('#InboxesAPI', () => {
|
|||||||
expect(axiosMock.get).toHaveBeenCalledWith('/api/v1/inboxes/2/campaigns');
|
expect(axiosMock.get).toHaveBeenCalledWith('/api/v1/inboxes/2/campaigns');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('#getAssignableOwners', () => {
|
||||||
|
inboxesAPI.getAssignableOwners(2);
|
||||||
|
expect(axiosMock.get).toHaveBeenCalledWith(
|
||||||
|
'/api/v1/inboxes/2/assignable_owners'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('#deleteInboxAvatar', () => {
|
it('#deleteInboxAvatar', () => {
|
||||||
inboxesAPI.deleteInboxAvatar(2);
|
inboxesAPI.deleteInboxAvatar(2);
|
||||||
expect(axiosMock.delete).toHaveBeenCalledWith('/api/v1/inboxes/2/avatar');
|
expect(axiosMock.delete).toHaveBeenCalledWith('/api/v1/inboxes/2/avatar');
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const mockUseMapGetter = (overrides = {}) => {
|
|||||||
getSelectedChat: ref({ inbox_id: 1, meta: { assignee: true } }),
|
getSelectedChat: ref({ inbox_id: 1, meta: { assignee: true } }),
|
||||||
getCurrentAccountId: ref(1),
|
getCurrentAccountId: ref(1),
|
||||||
'inboxAssignableAgents/getAssignableAgents': ref(() => allAgentsData),
|
'inboxAssignableAgents/getAssignableAgents': ref(() => allAgentsData),
|
||||||
|
'inboxAssignableAgents/getAssignableOwners': ref(() => []),
|
||||||
};
|
};
|
||||||
|
|
||||||
const mergedGetters = { ...defaultGetters, ...overrides };
|
const mergedGetters = { ...defaultGetters, ...overrides };
|
||||||
@@ -75,6 +76,32 @@ describe('useAgentsList', () => {
|
|||||||
expect(agentsList.value.length).toBe(formattedAgentsData.slice(1).length);
|
expect(agentsList.value.length).toBe(formattedAgentsData.slice(1).length);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('includes agent bots when includeAgentBots is true', () => {
|
||||||
|
mockUseMapGetter({
|
||||||
|
'inboxAssignableAgents/getAssignableOwners': ref(() => [
|
||||||
|
{ id: 2, name: 'Agent', assignee_type: 'User' },
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: 'Bot',
|
||||||
|
thumbnail: '',
|
||||||
|
assignee_type: 'AgentBot',
|
||||||
|
icon: 'i-lucide-bot',
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
});
|
||||||
|
|
||||||
|
const { agentsList } = useAgentsList(true, true);
|
||||||
|
|
||||||
|
expect(agentsList.value).toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: 1,
|
||||||
|
name: 'Bot',
|
||||||
|
assignee_type: 'AgentBot',
|
||||||
|
icon: 'i-lucide-bot',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('handles empty assignable agents', () => {
|
it('handles empty assignable agents', () => {
|
||||||
mockUseMapGetter({
|
mockUseMapGetter({
|
||||||
'inboxAssignableAgents/getAssignableAgents': ref(() => []),
|
'inboxAssignableAgents/getAssignableAgents': ref(() => []),
|
||||||
|
|||||||
@@ -10,14 +10,21 @@ import {
|
|||||||
* A composable function that provides a list of agents for assignment.
|
* A composable function that provides a list of agents for assignment.
|
||||||
*
|
*
|
||||||
* @param {boolean} [includeNoneAgent=true] - Whether to include a 'None' agent option.
|
* @param {boolean} [includeNoneAgent=true] - Whether to include a 'None' agent option.
|
||||||
|
* @param {boolean} [includeAgentBots=false] - Whether to include agent bots as assignment options.
|
||||||
* @returns {Object} An object containing the agents list and assignable agents.
|
* @returns {Object} An object containing the agents list and assignable agents.
|
||||||
*/
|
*/
|
||||||
export function useAgentsList(includeNoneAgent = true) {
|
export function useAgentsList(
|
||||||
|
includeNoneAgent = true,
|
||||||
|
includeAgentBots = false
|
||||||
|
) {
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const currentUser = useMapGetter('getCurrentUser');
|
const currentUser = useMapGetter('getCurrentUser');
|
||||||
const currentChat = useMapGetter('getSelectedChat');
|
const currentChat = useMapGetter('getSelectedChat');
|
||||||
const currentAccountId = useMapGetter('getCurrentAccountId');
|
const currentAccountId = useMapGetter('getCurrentAccountId');
|
||||||
const assignable = useMapGetter('inboxAssignableAgents/getAssignableAgents');
|
const assignable = useMapGetter('inboxAssignableAgents/getAssignableAgents');
|
||||||
|
const assignableOwners = useMapGetter(
|
||||||
|
'inboxAssignableAgents/getAssignableOwners'
|
||||||
|
);
|
||||||
|
|
||||||
const inboxId = computed(() => currentChat.value?.inbox_id);
|
const inboxId = computed(() => currentChat.value?.inbox_id);
|
||||||
const isAgentSelected = computed(() => currentChat.value?.meta?.assignee);
|
const isAgentSelected = computed(() => currentChat.value?.meta?.assignee);
|
||||||
@@ -42,11 +49,22 @@ export function useAgentsList(includeNoneAgent = true) {
|
|||||||
return inboxId.value ? assignable.value(inboxId.value) : [];
|
return inboxId.value ? assignable.value(inboxId.value) : [];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const owners = computed(() => {
|
||||||
|
return includeAgentBots && inboxId.value
|
||||||
|
? assignableOwners.value(inboxId.value)
|
||||||
|
: [];
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {import('vue').ComputedRef<Array>}
|
* @type {import('vue').ComputedRef<Array>}
|
||||||
*/
|
*/
|
||||||
const agentsList = computed(() => {
|
const agentsList = computed(() => {
|
||||||
const agents = assignableAgents.value || [];
|
const agents = includeAgentBots
|
||||||
|
? owners.value.filter(owner => owner.assignee_type === 'User')
|
||||||
|
: assignableAgents.value || [];
|
||||||
|
const bots = owners.value.filter(
|
||||||
|
owner => owner.assignee_type === 'AgentBot'
|
||||||
|
);
|
||||||
const agentsByUpdatedPresence = getAgentsByUpdatedPresence(
|
const agentsByUpdatedPresence = getAgentsByUpdatedPresence(
|
||||||
agents,
|
agents,
|
||||||
currentUser.value,
|
currentUser.value,
|
||||||
@@ -60,6 +78,7 @@ export function useAgentsList(includeNoneAgent = true) {
|
|||||||
return [
|
return [
|
||||||
...(includeNoneAgent && isAgentSelected.value ? [createNoneAgent()] : []),
|
...(includeNoneAgent && isAgentSelected.value ? [createNoneAgent()] : []),
|
||||||
...filteredAgentsByAvailability,
|
...filteredAgentsByAvailability,
|
||||||
|
...bots,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
const { agentsList } = useAgentsList();
|
const { agentsList } = useAgentsList(true, true);
|
||||||
return {
|
return {
|
||||||
agentsList,
|
agentsList,
|
||||||
};
|
};
|
||||||
@@ -81,18 +81,27 @@ export default {
|
|||||||
},
|
},
|
||||||
assignedAgent: {
|
assignedAgent: {
|
||||||
get() {
|
get() {
|
||||||
return this.currentChat.meta.assignee;
|
const assignee = this.currentChat.meta.assignee;
|
||||||
|
if (!assignee) return assignee;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...assignee,
|
||||||
|
assignee_type: this.currentChat.meta.assignee_type || 'User',
|
||||||
|
};
|
||||||
},
|
},
|
||||||
set(agent) {
|
set(agent) {
|
||||||
const agentId = agent ? agent.id : null;
|
const agentId = agent ? agent.id : null;
|
||||||
|
const assigneeType = agent ? agent.assignee_type || 'User' : null;
|
||||||
this.$store.dispatch('setCurrentChatAssignee', {
|
this.$store.dispatch('setCurrentChatAssignee', {
|
||||||
conversationId: this.currentChat.id,
|
conversationId: this.currentChat.id,
|
||||||
assignee: agent,
|
assignee: agent,
|
||||||
|
assigneeType,
|
||||||
});
|
});
|
||||||
this.$store
|
this.$store
|
||||||
.dispatch('assignAgent', {
|
.dispatch('assignAgent', {
|
||||||
conversationId: this.currentChat.id,
|
conversationId: this.currentChat.id,
|
||||||
agentId,
|
agentId,
|
||||||
|
assigneeType,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
useAlert(this.$t('CONVERSATION.CHANGE_AGENT'));
|
useAlert(this.$t('CONVERSATION.CHANGE_AGENT'));
|
||||||
@@ -158,6 +167,12 @@ export default {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
this.$store.dispatch(
|
||||||
|
'inboxAssignableAgents/fetchAssignableOwners',
|
||||||
|
this.currentChat.inbox_id
|
||||||
|
);
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onSelfAssign() {
|
onSelfAssign() {
|
||||||
const {
|
const {
|
||||||
@@ -174,6 +189,7 @@ export default {
|
|||||||
account_id,
|
account_id,
|
||||||
availability_status,
|
availability_status,
|
||||||
available_name,
|
available_name,
|
||||||
|
assignee_type: 'User',
|
||||||
email,
|
email,
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
@@ -183,7 +199,14 @@ export default {
|
|||||||
this.assignedAgent = selfAssign;
|
this.assignedAgent = selfAssign;
|
||||||
},
|
},
|
||||||
onClickAssignAgent(selectedItem) {
|
onClickAssignAgent(selectedItem) {
|
||||||
if (this.assignedAgent && this.assignedAgent.id === selectedItem.id) {
|
const currentAssigneeType = this.assignedAgent?.assignee_type || 'User';
|
||||||
|
const selectedAssigneeType = selectedItem.assignee_type || 'User';
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.assignedAgent &&
|
||||||
|
this.assignedAgent.id === selectedItem.id &&
|
||||||
|
currentAssigneeType === selectedAssigneeType
|
||||||
|
) {
|
||||||
this.assignedAgent = null;
|
this.assignedAgent = null;
|
||||||
} else {
|
} else {
|
||||||
this.assignedAgent = selectedItem;
|
this.assignedAgent = selectedItem;
|
||||||
|
|||||||
@@ -208,23 +208,31 @@ const actions = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
assignAgent: async ({ dispatch }, { conversationId, agentId }) => {
|
assignAgent: async (
|
||||||
|
{ dispatch },
|
||||||
|
{ conversationId, agentId, assigneeType }
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
const response = await ConversationApi.assignAgent({
|
const response = await ConversationApi.assignAgent({
|
||||||
conversationId,
|
conversationId,
|
||||||
agentId,
|
agentId,
|
||||||
|
assigneeType,
|
||||||
});
|
});
|
||||||
dispatch('setCurrentChatAssignee', {
|
dispatch('setCurrentChatAssignee', {
|
||||||
conversationId,
|
conversationId,
|
||||||
assignee: response.data,
|
assignee: response.data,
|
||||||
|
assigneeType,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Handle error
|
// Handle error
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setCurrentChatAssignee({ commit }, { conversationId, assignee }) {
|
setCurrentChatAssignee(
|
||||||
commit(types.ASSIGN_AGENT, { conversationId, assignee });
|
{ commit },
|
||||||
|
{ conversationId, assignee, assigneeType }
|
||||||
|
) {
|
||||||
|
commit(types.ASSIGN_AGENT, { conversationId, assignee, assigneeType });
|
||||||
},
|
},
|
||||||
|
|
||||||
assignTeam: async ({ dispatch }, { conversationId, teamId }) => {
|
assignTeam: async ({ dispatch }, { conversationId, teamId }) => {
|
||||||
|
|||||||
@@ -108,10 +108,16 @@ export const mutations = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
[types.ASSIGN_AGENT](_state, { conversationId, assignee }) {
|
[types.ASSIGN_AGENT](_state, { conversationId, assignee, assigneeType }) {
|
||||||
const chat = getConversationById(_state)(conversationId);
|
const chat = getConversationById(_state)(conversationId);
|
||||||
if (chat) {
|
if (chat) {
|
||||||
chat.meta.assignee = assignee;
|
chat.meta.assignee = assignee;
|
||||||
|
chat.meta.assignee_type = assigneeType;
|
||||||
|
if (assigneeType === 'AgentBot') {
|
||||||
|
chat.status = 'pending';
|
||||||
|
} else if (assignee) {
|
||||||
|
chat.status = 'open';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import AssignableAgentsAPI from '../../api/assignableAgents';
|
import AssignableAgentsAPI from '../../api/assignableAgents';
|
||||||
|
import InboxesAPI from '../../api/inboxes';
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
records: {},
|
records: {},
|
||||||
|
ownerRecords: {},
|
||||||
uiFlags: {
|
uiFlags: {
|
||||||
isFetching: false,
|
isFetching: false,
|
||||||
},
|
},
|
||||||
@@ -10,6 +12,7 @@ const state = {
|
|||||||
export const types = {
|
export const types = {
|
||||||
SET_INBOX_ASSIGNABLE_AGENTS_UI_FLAG: 'SET_INBOX_ASSIGNABLE_AGENTS_UI_FLAG',
|
SET_INBOX_ASSIGNABLE_AGENTS_UI_FLAG: 'SET_INBOX_ASSIGNABLE_AGENTS_UI_FLAG',
|
||||||
SET_INBOX_ASSIGNABLE_AGENTS: 'SET_INBOX_ASSIGNABLE_AGENTS',
|
SET_INBOX_ASSIGNABLE_AGENTS: 'SET_INBOX_ASSIGNABLE_AGENTS',
|
||||||
|
SET_INBOX_ASSIGNABLE_OWNERS: 'SET_INBOX_ASSIGNABLE_OWNERS',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
@@ -18,6 +21,7 @@ export const getters = {
|
|||||||
const verifiedAgents = allAgents.filter(record => record.confirmed);
|
const verifiedAgents = allAgents.filter(record => record.confirmed);
|
||||||
return verifiedAgents;
|
return verifiedAgents;
|
||||||
},
|
},
|
||||||
|
getAssignableOwners: $state => inboxId => $state.ownerRecords[inboxId] || [],
|
||||||
getUIFlags($state) {
|
getUIFlags($state) {
|
||||||
return $state.uiFlags;
|
return $state.uiFlags;
|
||||||
},
|
},
|
||||||
@@ -40,6 +44,15 @@ export const actions = {
|
|||||||
commit(types.SET_INBOX_ASSIGNABLE_AGENTS_UI_FLAG, { isFetching: false });
|
commit(types.SET_INBOX_ASSIGNABLE_AGENTS_UI_FLAG, { isFetching: false });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async fetchAssignableOwners({ commit }, inboxId) {
|
||||||
|
const {
|
||||||
|
data: { payload },
|
||||||
|
} = await InboxesAPI.getAssignableOwners(inboxId);
|
||||||
|
commit(types.SET_INBOX_ASSIGNABLE_OWNERS, {
|
||||||
|
inboxId,
|
||||||
|
owners: payload,
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
@@ -55,6 +68,12 @@ export const mutations = {
|
|||||||
[inboxId]: members,
|
[inboxId]: members,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
[types.SET_INBOX_ASSIGNABLE_OWNERS]: ($state, { inboxId, owners }) => {
|
||||||
|
$state.ownerRecords = {
|
||||||
|
...$state.ownerRecords,
|
||||||
|
[inboxId]: owners,
|
||||||
|
};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@@ -357,11 +357,12 @@ describe('#actions', () => {
|
|||||||
});
|
});
|
||||||
await actions.assignAgent(
|
await actions.assignAgent(
|
||||||
{ dispatch },
|
{ dispatch },
|
||||||
{ conversationId: 1, agentId: 1 }
|
{ conversationId: 1, agentId: 1, assigneeType: 'AgentBot' }
|
||||||
);
|
);
|
||||||
expect(dispatch).toHaveBeenCalledWith('setCurrentChatAssignee', {
|
expect(dispatch).toHaveBeenCalledWith('setCurrentChatAssignee', {
|
||||||
conversationId: 1,
|
conversationId: 1,
|
||||||
assignee: { id: 1, name: 'User' },
|
assignee: { id: 1, name: 'User' },
|
||||||
|
assigneeType: 'AgentBot',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -371,6 +372,7 @@ describe('#actions', () => {
|
|||||||
const payload = {
|
const payload = {
|
||||||
conversationId: 1,
|
conversationId: 1,
|
||||||
assignee: { id: 1, name: 'User' },
|
assignee: { id: 1, name: 'User' },
|
||||||
|
assigneeType: 'AgentBot',
|
||||||
};
|
};
|
||||||
await actions.setCurrentChatAssignee({ commit }, payload);
|
await actions.setCurrentChatAssignee({ commit }, payload);
|
||||||
expect(commit).toHaveBeenCalledTimes(1);
|
expect(commit).toHaveBeenCalledTimes(1);
|
||||||
|
|||||||
@@ -699,11 +699,11 @@ describe('#mutations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#ASSIGN_AGENT', () => {
|
describe('#ASSIGN_AGENT', () => {
|
||||||
it('should assign agent to the correct conversation by ID', () => {
|
it('should assign agent bot to the correct conversation by ID', () => {
|
||||||
const assignee = { id: 1, name: 'Agent' };
|
const assignee = { id: 1, name: 'Agent' };
|
||||||
const state = {
|
const state = {
|
||||||
allConversations: [
|
allConversations: [
|
||||||
{ id: 1, meta: {} },
|
{ id: 1, meta: {}, status: 'open' },
|
||||||
{ id: 2, meta: {} },
|
{ id: 2, meta: {} },
|
||||||
],
|
],
|
||||||
selectedChatId: 2,
|
selectedChatId: 2,
|
||||||
@@ -712,10 +712,28 @@ describe('#mutations', () => {
|
|||||||
mutations[types.ASSIGN_AGENT](state, {
|
mutations[types.ASSIGN_AGENT](state, {
|
||||||
conversationId: 1,
|
conversationId: 1,
|
||||||
assignee,
|
assignee,
|
||||||
|
assigneeType: 'AgentBot',
|
||||||
});
|
});
|
||||||
expect(state.allConversations[0].meta.assignee).toEqual(assignee);
|
expect(state.allConversations[0].meta.assignee).toEqual(assignee);
|
||||||
|
expect(state.allConversations[0].meta.assignee_type).toEqual('AgentBot');
|
||||||
|
expect(state.allConversations[0].status).toEqual('pending');
|
||||||
expect(state.allConversations[1].meta.assignee).toBeUndefined();
|
expect(state.allConversations[1].meta.assignee).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should open the conversation when assigning a user', () => {
|
||||||
|
const assignee = { id: 1, name: 'Agent' };
|
||||||
|
const state = {
|
||||||
|
allConversations: [{ id: 1, meta: {}, status: 'pending' }],
|
||||||
|
};
|
||||||
|
|
||||||
|
mutations[types.ASSIGN_AGENT](state, {
|
||||||
|
conversationId: 1,
|
||||||
|
assignee,
|
||||||
|
assigneeType: 'User',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(state.allConversations[0].status).toEqual('open');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#ASSIGN_PRIORITY', () => {
|
describe('#ASSIGN_PRIORITY', () => {
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import InboxesAPI from 'dashboard/api/inboxes';
|
||||||
import { actions, types } from '../../inboxAssignableAgents';
|
import { actions, types } from '../../inboxAssignableAgents';
|
||||||
import agentsData from './fixtures';
|
import agentsData from './fixtures';
|
||||||
|
|
||||||
const commit = vi.fn();
|
const commit = vi.fn();
|
||||||
global.axios = axios;
|
global.axios = axios;
|
||||||
vi.mock('axios');
|
vi.mock('axios');
|
||||||
|
vi.mock('dashboard/api/inboxes');
|
||||||
|
|
||||||
describe('#actions', () => {
|
describe('#actions', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
describe('#fetch', () => {
|
describe('#fetch', () => {
|
||||||
it('sends correct actions if API is success', async () => {
|
it('sends correct actions if API is success', async () => {
|
||||||
axios.get.mockResolvedValue({
|
axios.get.mockResolvedValue({
|
||||||
@@ -33,4 +39,20 @@ describe('#actions', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#fetchAssignableOwners', () => {
|
||||||
|
it('stores assignable owners for the inbox', async () => {
|
||||||
|
InboxesAPI.getAssignableOwners.mockResolvedValue({
|
||||||
|
data: { payload: agentsData },
|
||||||
|
});
|
||||||
|
|
||||||
|
await actions.fetchAssignableOwners({ commit }, 1);
|
||||||
|
|
||||||
|
expect(InboxesAPI.getAssignableOwners).toHaveBeenCalledWith(1);
|
||||||
|
expect(commit).toHaveBeenCalledWith(types.SET_INBOX_ASSIGNABLE_OWNERS, {
|
||||||
|
inboxId: 1,
|
||||||
|
owners: agentsData,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,4 +13,16 @@ describe('#mutations', () => {
|
|||||||
expect(state.records).toEqual({ 1: agentsData });
|
expect(state.records).toEqual({ 1: agentsData });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#SET_INBOX_ASSIGNABLE_OWNERS', () => {
|
||||||
|
it('adds inbox owners to ownerRecords', () => {
|
||||||
|
const state = { ownerRecords: {} };
|
||||||
|
mutations[types.SET_INBOX_ASSIGNABLE_OWNERS](state, {
|
||||||
|
owners: [...agentsData],
|
||||||
|
inboxId: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(state.ownerRecords).toEqual({ 1: agentsData });
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -67,7 +67,13 @@ export default {
|
|||||||
this.$refs.searchbar.focus();
|
this.$refs.searchbar.focus();
|
||||||
},
|
},
|
||||||
isActive(option) {
|
isActive(option) {
|
||||||
return this.selectedItems.some(item => item && option.id === item.id);
|
return this.selectedItems.some(item => {
|
||||||
|
if (!item || option.id !== item.id) return false;
|
||||||
|
|
||||||
|
return (
|
||||||
|
(option.assignee_type || 'User') === (item.assignee_type || 'User')
|
||||||
|
);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -88,7 +94,10 @@ export default {
|
|||||||
<div class="flex items-start justify-start flex-auto overflow-auto mt-2">
|
<div class="flex items-start justify-start flex-auto overflow-auto mt-2">
|
||||||
<div class="w-full max-h-[10rem]">
|
<div class="w-full max-h-[10rem]">
|
||||||
<WootDropdownMenu>
|
<WootDropdownMenu>
|
||||||
<WootDropdownItem v-for="option in filteredOptions" :key="option.id">
|
<WootDropdownItem
|
||||||
|
v-for="option in filteredOptions"
|
||||||
|
:key="`${option.assignee_type || 'User'}-${option.id}`"
|
||||||
|
>
|
||||||
<NextButton
|
<NextButton
|
||||||
slate
|
slate
|
||||||
:variant="isActive(option) ? 'faded' : 'ghost'"
|
:variant="isActive(option) ? 'faded' : 'ghost'"
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ class InboxPolicy < ApplicationPolicy
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assignable_owners?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def agent_bot?
|
def agent_bot?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class Conversations::AssignmentService
|
|||||||
def assign_agent
|
def assign_agent
|
||||||
conversation.assignee = assignee
|
conversation.assignee = assignee
|
||||||
conversation.assignee_agent_bot = nil
|
conversation.assignee_agent_bot = nil
|
||||||
|
conversation.status = :open if assignee
|
||||||
conversation.save!
|
conversation.save!
|
||||||
assignee
|
assignee
|
||||||
end
|
end
|
||||||
@@ -25,6 +26,7 @@ class Conversations::AssignmentService
|
|||||||
|
|
||||||
conversation.assignee = nil
|
conversation.assignee = nil
|
||||||
conversation.assignee_agent_bot = agent_bot
|
conversation.assignee_agent_bot = agent_bot
|
||||||
|
conversation.status = :pending
|
||||||
conversation.save!
|
conversation.save!
|
||||||
agent_bot
|
agent_bot
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
owners = @assignable_agents.map { |agent| { type: 'User', resource: agent } }
|
||||||
|
owners += @agent_bots.map { |agent_bot| { type: 'AgentBot', resource: agent_bot } }
|
||||||
|
|
||||||
|
json.payload do
|
||||||
|
json.array! owners do |owner|
|
||||||
|
if owner[:type] == 'User'
|
||||||
|
json.partial! 'api/v1/models/agent', formats: [:json], resource: owner[:resource]
|
||||||
|
json.assignee_type 'User'
|
||||||
|
else
|
||||||
|
json.partial! 'api/v1/models/agent_bot_slim', formats: [:json], resource: owner[:resource]
|
||||||
|
json.assignee_type 'AgentBot'
|
||||||
|
json.icon 'i-lucide-bot'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -254,6 +254,7 @@ Rails.application.routes.draw do
|
|||||||
resources :custom_filters, only: [:index, :show, :create, :update, :destroy]
|
resources :custom_filters, only: [:index, :show, :create, :update, :destroy]
|
||||||
resources :inboxes, only: [:index, :show, :create, :update, :destroy] do
|
resources :inboxes, only: [:index, :show, :create, :update, :destroy] do
|
||||||
get :assignable_agents, on: :member
|
get :assignable_agents, on: :member
|
||||||
|
get :assignable_owners, on: :member
|
||||||
get :campaigns, on: :member
|
get :campaigns, on: :member
|
||||||
get :agent_bot, on: :member
|
get :agent_bot, on: :member
|
||||||
post :set_agent_bot, on: :member
|
post :set_agent_bot, on: :member
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class Api::V1::Accounts::CompaniesController < Api::V1::Accounts::EnterpriseAcco
|
|||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@company.destroy!
|
Companies::DeleteJob.perform_later(company_id: @company.id)
|
||||||
head :ok
|
head :ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+13
@@ -29,6 +29,19 @@ module Enterprise::DeviseOverrides::OmniauthCallbacksController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def create_account_for_user
|
||||||
|
super
|
||||||
|
record_marketing_attribution
|
||||||
|
end
|
||||||
|
|
||||||
|
def record_marketing_attribution
|
||||||
|
return if @account.blank?
|
||||||
|
|
||||||
|
Internal::Accounts::MarketingAttributionService.new(account: @account, cookies: cookies).perform
|
||||||
|
rescue StandardError => e
|
||||||
|
ChatwootExceptionTracker.new(e).capture_exception
|
||||||
|
end
|
||||||
|
|
||||||
def handle_saml_auth
|
def handle_saml_auth
|
||||||
account_id = extract_saml_account_id
|
account_id = extract_saml_account_id
|
||||||
relay_state = saml_relay_state
|
relay_state = saml_relay_state
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
class Companies::DeleteJob < ApplicationJob
|
||||||
|
queue_as :low
|
||||||
|
|
||||||
|
BATCH_SIZE = 1000
|
||||||
|
CONTACT_COMPANY_CLEAR_SQL = <<~SQL.squish.freeze
|
||||||
|
company_id = NULL,
|
||||||
|
additional_attributes = COALESCE(additional_attributes, '{}'::jsonb) - 'company_name'
|
||||||
|
SQL
|
||||||
|
|
||||||
|
def perform(company_id:)
|
||||||
|
company = Company.find_by(id: company_id)
|
||||||
|
return if company.blank?
|
||||||
|
|
||||||
|
clear_contact_company_names(company)
|
||||||
|
company.destroy!
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Avoid contact callbacks so this cleanup does not dispatch contact automations/webhooks.
|
||||||
|
# rubocop:disable Rails/SkipsModelValidations
|
||||||
|
def clear_contact_company_names(company)
|
||||||
|
company.contacts.in_batches(of: BATCH_SIZE) do |contacts|
|
||||||
|
contacts.update_all(CONTACT_COMPANY_CLEAR_SQL)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# rubocop:enable Rails/SkipsModelValidations
|
||||||
|
end
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
class Companies::SyncContactNamesJob < ApplicationJob
|
||||||
|
queue_as :low
|
||||||
|
|
||||||
|
BATCH_SIZE = 1000
|
||||||
|
CONTACT_COMPANY_NAME_UPDATE_SQL = <<~SQL.squish.freeze
|
||||||
|
additional_attributes = jsonb_set(
|
||||||
|
COALESCE(additional_attributes, '{}'::jsonb),
|
||||||
|
'{company_name}',
|
||||||
|
?::jsonb,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
SQL
|
||||||
|
|
||||||
|
def perform(company_id:)
|
||||||
|
return if company_id.blank?
|
||||||
|
|
||||||
|
company = Company.find_by(id: company_id)
|
||||||
|
return if company.blank?
|
||||||
|
|
||||||
|
sync_company_name(company)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Denormalized display field sync; avoid contact validations, callbacks, and webhook/automation side effects.
|
||||||
|
# rubocop:disable Rails/SkipsModelValidations
|
||||||
|
def sync_company_name(company)
|
||||||
|
company.contacts.in_batches(of: BATCH_SIZE) do |contacts|
|
||||||
|
contacts.update_all([CONTACT_COMPANY_NAME_UPDATE_SQL, company.name.to_json])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# rubocop:enable Rails/SkipsModelValidations
|
||||||
|
end
|
||||||
@@ -39,6 +39,7 @@ class Company < ApplicationRecord
|
|||||||
has_many :contacts, dependent: :nullify
|
has_many :contacts, dependent: :nullify
|
||||||
before_validation :prepare_jsonb_attributes
|
before_validation :prepare_jsonb_attributes
|
||||||
after_create_commit :fetch_favicon, if: -> { domain.present? }
|
after_create_commit :fetch_favicon, if: -> { domain.present? }
|
||||||
|
after_update_commit :enqueue_contact_company_name_sync, if: :saved_change_to_name?
|
||||||
|
|
||||||
scope :ordered_by_name, -> { order(:name) }
|
scope :ordered_by_name, -> { order(:name) }
|
||||||
scope :search_by_name_or_domain, lambda { |query|
|
scope :search_by_name_or_domain, lambda { |query|
|
||||||
@@ -76,4 +77,8 @@ class Company < ApplicationRecord
|
|||||||
def fetch_favicon
|
def fetch_favicon
|
||||||
Avatar::AvatarFromFaviconJob.set(wait: 5.seconds).perform_later(self)
|
Avatar::AvatarFromFaviconJob.set(wait: 5.seconds).perform_later(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def enqueue_contact_company_name_sync
|
||||||
|
Companies::SyncContactNamesJob.perform_later(company_id: id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+1
-1
@@ -69,7 +69,7 @@
|
|||||||
"countries-and-timezones": "^3.6.0",
|
"countries-and-timezones": "^3.6.0",
|
||||||
"date-fns": "2.21.1",
|
"date-fns": "2.21.1",
|
||||||
"date-fns-tz": "^1.3.3",
|
"date-fns-tz": "^1.3.3",
|
||||||
"dompurify": "3.4.0",
|
"dompurify": "3.4.11",
|
||||||
"flag-icons": "^7.2.3",
|
"flag-icons": "^7.2.3",
|
||||||
"floating-vue": "^5.2.2",
|
"floating-vue": "^5.2.2",
|
||||||
"highlight.js": "^11.10.0",
|
"highlight.js": "^11.10.0",
|
||||||
|
|||||||
Generated
+15
-7
@@ -130,8 +130,8 @@ importers:
|
|||||||
specifier: ^1.3.3
|
specifier: ^1.3.3
|
||||||
version: 1.3.8(date-fns@2.21.1)
|
version: 1.3.8(date-fns@2.21.1)
|
||||||
dompurify:
|
dompurify:
|
||||||
specifier: 3.4.0
|
specifier: 3.4.11
|
||||||
version: 3.4.0
|
version: 3.4.11
|
||||||
flag-icons:
|
flag-icons:
|
||||||
specifier: ^7.2.3
|
specifier: ^7.2.3
|
||||||
version: 7.2.3
|
version: 7.2.3
|
||||||
@@ -1635,6 +1635,11 @@ packages:
|
|||||||
engines: {node: '>=0.4.0'}
|
engines: {node: '>=0.4.0'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
|
acorn@8.17.0:
|
||||||
|
resolution: {integrity: sha512-xRQbDb9BnwDafYNn6Vwl839DYVjqXYb1XVGtWAZ1kcDc6iwAL4hg3B1dZlRiuENFeO2H53gFG3in621AdERVAg==}
|
||||||
|
engines: {node: '>=0.4.0'}
|
||||||
|
hasBin: true
|
||||||
|
|
||||||
activestorage@5.2.8:
|
activestorage@5.2.8:
|
||||||
resolution: {integrity: sha512-bueFOxBGIAUdrjbLyBZ8Xlkcecy8vr05sCk5VV37BbFi+RehPoEjfvKX3iYYPY7RFVhl+L43W9/ZbN3xNNLPtQ==}
|
resolution: {integrity: sha512-bueFOxBGIAUdrjbLyBZ8Xlkcecy8vr05sCk5VV37BbFi+RehPoEjfvKX3iYYPY7RFVhl+L43W9/ZbN3xNNLPtQ==}
|
||||||
|
|
||||||
@@ -2218,8 +2223,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==}
|
resolution: {integrity: sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==}
|
||||||
engines: {node: '>= 4'}
|
engines: {node: '>= 4'}
|
||||||
|
|
||||||
dompurify@3.4.0:
|
dompurify@3.4.11:
|
||||||
resolution: {integrity: sha512-nolgK9JcaUXMSmW+j1yaSvaEaoXYHwWyGJlkoCTghc97KgGDDSnpoU/PlEnw63Ah+TGKFOyY+X5LnxaWbCSfXg==}
|
resolution: {integrity: sha512-zhlUV12GsaRzMsf9q5M254YhA4+VuF0fG+QFqu6aYpoGlKtz+w8//jBcGVYBgQkR5GHjUomejY84AV+/uPbWdw==}
|
||||||
|
|
||||||
domutils@3.1.0:
|
domutils@3.1.0:
|
||||||
resolution: {integrity: sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==}
|
resolution: {integrity: sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==}
|
||||||
@@ -6380,6 +6385,9 @@ snapshots:
|
|||||||
|
|
||||||
acorn@8.16.0: {}
|
acorn@8.16.0: {}
|
||||||
|
|
||||||
|
acorn@8.17.0:
|
||||||
|
optional: true
|
||||||
|
|
||||||
activestorage@5.2.8:
|
activestorage@5.2.8:
|
||||||
dependencies:
|
dependencies:
|
||||||
spark-md5: 3.0.2
|
spark-md5: 3.0.2
|
||||||
@@ -6999,7 +7007,7 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
domelementtype: 2.3.0
|
domelementtype: 2.3.0
|
||||||
|
|
||||||
dompurify@3.4.0:
|
dompurify@3.4.11:
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@types/trusted-types': 2.0.7
|
'@types/trusted-types': 2.0.7
|
||||||
|
|
||||||
@@ -9511,7 +9519,7 @@ snapshots:
|
|||||||
terser@5.33.0:
|
terser@5.33.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@jridgewell/source-map': 0.3.11
|
'@jridgewell/source-map': 0.3.11
|
||||||
acorn: 8.16.0
|
acorn: 8.17.0
|
||||||
commander: 2.20.3
|
commander: 2.20.3
|
||||||
source-map-support: 0.5.21
|
source-map-support: 0.5.21
|
||||||
optional: true
|
optional: true
|
||||||
@@ -9898,7 +9906,7 @@ snapshots:
|
|||||||
|
|
||||||
vue-dompurify-html@5.3.0(vue@3.5.12(typescript@5.6.2)):
|
vue-dompurify-html@5.3.0(vue@3.5.12(typescript@5.6.2)):
|
||||||
dependencies:
|
dependencies:
|
||||||
dompurify: 3.4.0
|
dompurify: 3.4.11
|
||||||
vue: 3.5.12(typescript@5.6.2)
|
vue: 3.5.12(typescript@5.6.2)
|
||||||
|
|
||||||
vue-eslint-parser@9.4.3(eslint@8.57.0):
|
vue-eslint-parser@9.4.3(eslint@8.57.0):
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ RSpec.describe 'Conversation Assignment API', type: :request do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'assigns a user to the conversation' do
|
it 'assigns a user to the conversation' do
|
||||||
|
conversation.update!(status: :pending)
|
||||||
params = { assignee_id: agent.id }
|
params = { assignee_id: agent.id }
|
||||||
|
|
||||||
post api_v1_account_conversation_assignments_url(account_id: account.id, conversation_id: conversation.display_id),
|
post api_v1_account_conversation_assignments_url(account_id: account.id, conversation_id: conversation.display_id),
|
||||||
@@ -52,10 +53,13 @@ RSpec.describe 'Conversation Assignment API', type: :request do
|
|||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
expect(conversation.reload.assignee).to eq(agent)
|
conversation.reload
|
||||||
|
expect(conversation.assignee).to eq(agent)
|
||||||
|
expect(conversation.status).to eq('open')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'assigns an agent bot to the conversation' do
|
it 'assigns an agent bot to the conversation' do
|
||||||
|
conversation.update!(status: :open)
|
||||||
params = { assignee_id: agent_bot.id, assignee_type: 'AgentBot' }
|
params = { assignee_id: agent_bot.id, assignee_type: 'AgentBot' }
|
||||||
|
|
||||||
expect(Conversations::AssignmentService).to receive(:new)
|
expect(Conversations::AssignmentService).to receive(:new)
|
||||||
@@ -72,6 +76,7 @@ RSpec.describe 'Conversation Assignment API', type: :request do
|
|||||||
conversation.reload
|
conversation.reload
|
||||||
expect(conversation.assignee_agent_bot).to eq(agent_bot)
|
expect(conversation.assignee_agent_bot).to eq(agent_bot)
|
||||||
expect(conversation.assignee).to be_nil
|
expect(conversation.assignee).to be_nil
|
||||||
|
expect(conversation.status).to eq('pending')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'assigns a team to the conversation' do
|
it 'assigns a team to the conversation' do
|
||||||
|
|||||||
@@ -251,6 +251,28 @@ RSpec.describe 'Inboxes API', type: :request do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'GET /api/v1/accounts/{account.id}/inboxes/{inbox.id}/assignable_owners' do
|
||||||
|
let(:inbox) { create(:inbox, account: account) }
|
||||||
|
let!(:account_bot) { create(:agent_bot, account: account, name: 'Account bot') }
|
||||||
|
let!(:global_bot) { create(:agent_bot, account: nil, name: 'Global bot') }
|
||||||
|
|
||||||
|
before do
|
||||||
|
create(:inbox_member, user: agent, inbox: inbox)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns assignable agents and accessible agent bots' do
|
||||||
|
get "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/assignable_owners",
|
||||||
|
headers: admin.create_new_auth_token,
|
||||||
|
as: :json
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
|
||||||
|
response_data = response.parsed_body['payload']
|
||||||
|
expect(response_data.pluck('assignee_type')).to include('User', 'AgentBot')
|
||||||
|
expect(response_data.pluck('name')).to include(agent.name, admin.name, account_bot.name, global_bot.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'GET /api/v1/accounts/{account.id}/inboxes/{inbox.id}/campaigns' do
|
describe 'GET /api/v1/accounts/{account.id}/inboxes/{inbox.id}/campaigns' do
|
||||||
let(:inbox) { create(:inbox, account: account) }
|
let(:inbox) { create(:inbox, account: account) }
|
||||||
|
|
||||||
|
|||||||
@@ -385,13 +385,13 @@ RSpec.describe 'Companies API', type: :request do
|
|||||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||||
let(:company) { create(:company, account: account) }
|
let(:company) { create(:company, account: account) }
|
||||||
|
|
||||||
it 'deletes the company' do
|
it 'enqueues company deletion' do
|
||||||
company
|
|
||||||
expect do
|
expect do
|
||||||
delete "/api/v1/accounts/#{account.id}/companies/#{company.id}",
|
delete "/api/v1/accounts/#{account.id}/companies/#{company.id}",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
end.to change(Company, :count).by(-1)
|
end.to have_enqueued_job(Companies::DeleteJob).with(company_id: company.id)
|
||||||
|
|
||||||
expect(response).to have_http_status(:ok)
|
expect(response).to have_http_status(:ok)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
require 'base64'
|
||||||
|
|
||||||
|
RSpec.describe 'Enterprise Google OAuth attribution', type: :request do
|
||||||
|
let(:email_validation_service) { instance_double(Account::SignUpEmailValidationService) }
|
||||||
|
let(:email) { 'oauth-attribution@example.com' }
|
||||||
|
let(:account_builder) { double }
|
||||||
|
let(:account) { create(:account) }
|
||||||
|
let(:first_touch_cookie) { encoded_cookie('source' => 'reddit', 'source_type' => 'paid_social') }
|
||||||
|
let(:last_touch_cookie) { encoded_cookie('source' => 'github', 'source_type' => 'referral') }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(ChatwootApp).to receive(:enterprise?).and_return(true)
|
||||||
|
allow(ChatwootApp).to receive(:chatwoot_cloud?).and_return(true)
|
||||||
|
allow(Account::SignUpEmailValidationService).to receive(:new).and_return(email_validation_service)
|
||||||
|
allow(email_validation_service).to receive(:perform).and_return(true)
|
||||||
|
allow(AccountBuilder).to receive(:new).and_return(account_builder)
|
||||||
|
allow(account_builder).to receive(:perform) do
|
||||||
|
[create(:user, email: email, account: account), account]
|
||||||
|
end
|
||||||
|
|
||||||
|
OmniAuth.config.test_mode = true
|
||||||
|
OmniAuth.config.mock_auth[:google_oauth2] = OmniAuth::AuthHash.new(
|
||||||
|
provider: 'google',
|
||||||
|
uid: '123545',
|
||||||
|
info: {
|
||||||
|
name: 'OAuth Attribution',
|
||||||
|
email: email,
|
||||||
|
image: 'https://example.com/image.jpg'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'records marketing attribution for Google OAuth signups' do
|
||||||
|
cookies[Internal::Accounts::MarketingAttributionService::FIRST_TOUCH_COOKIE] = first_touch_cookie
|
||||||
|
cookies[Internal::Accounts::MarketingAttributionService::LAST_TOUCH_COOKIE] = last_touch_cookie
|
||||||
|
|
||||||
|
with_modified_env ENABLE_ACCOUNT_SIGNUP: 'true', FRONTEND_URL: 'http://www.example.com' do
|
||||||
|
get '/omniauth/google_oauth2/callback'
|
||||||
|
follow_redirect!
|
||||||
|
end
|
||||||
|
|
||||||
|
attribution = account.reload.internal_attributes['marketing_attribution']
|
||||||
|
|
||||||
|
expect(attribution['captured_from']).to eq('cookie')
|
||||||
|
expect(attribution['first_touch']).to include('source' => 'reddit', 'source_type' => 'paid_social')
|
||||||
|
expect(attribution['last_touch']).to include('source' => 'github', 'source_type' => 'referral')
|
||||||
|
end
|
||||||
|
|
||||||
|
def encoded_cookie(payload)
|
||||||
|
Base64.urlsafe_encode64(payload.to_json, padding: false)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Companies::DeleteJob, type: :job do
|
||||||
|
describe '#perform' do
|
||||||
|
it 'unlinks contacts, clears company names, and deletes the company' do
|
||||||
|
account = create(:account)
|
||||||
|
company = create(:company, account: account, name: 'Acme')
|
||||||
|
contact = create(:contact, account: account, company: company, additional_attributes: { 'company_name' => 'Acme', 'city' => 'Berlin' })
|
||||||
|
other_contact = create(:contact, account: account, additional_attributes: { 'company_name' => 'Acme' })
|
||||||
|
|
||||||
|
described_class.perform_now(company_id: company.id)
|
||||||
|
|
||||||
|
expect { company.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||||
|
expect(contact.reload.company_id).to be_nil
|
||||||
|
expect(contact.additional_attributes).to eq('city' => 'Berlin')
|
||||||
|
expect(other_contact.reload.additional_attributes).to eq('company_name' => 'Acme')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Companies::SyncContactNamesJob, type: :job do
|
||||||
|
let(:account) { create(:account) }
|
||||||
|
let(:company) { create(:company, account: account, name: 'Acme') }
|
||||||
|
|
||||||
|
describe '#perform' do
|
||||||
|
it 'updates linked contact company names' do
|
||||||
|
contact = create(:contact, account: account, company: company, additional_attributes: { 'company_name' => 'Acme', 'city' => 'Berlin' })
|
||||||
|
|
||||||
|
company.update!(name: 'Acme Labs')
|
||||||
|
|
||||||
|
described_class.perform_now(company_id: company.id)
|
||||||
|
|
||||||
|
expect(contact.reload.additional_attributes).to eq('company_name' => 'Acme Labs', 'city' => 'Berlin')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'uses the current company name when a stale rename job runs' do
|
||||||
|
contact = create(:contact, account: account, company: company, additional_attributes: { 'company_name' => 'Acme' })
|
||||||
|
company.update!(name: 'Acme Labs')
|
||||||
|
|
||||||
|
described_class.perform_now(company_id: company.id)
|
||||||
|
|
||||||
|
expect(contact.reload.additional_attributes).to eq('company_name' => 'Acme Labs')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not save contacts while syncing the denormalized company name' do
|
||||||
|
contact = create(:contact, account: account, company: company, additional_attributes: { 'company_name' => 'Acme' })
|
||||||
|
original_updated_at = contact.reload.updated_at
|
||||||
|
|
||||||
|
company.update!(name: 'Acme Labs')
|
||||||
|
|
||||||
|
described_class.perform_now(company_id: company.id)
|
||||||
|
|
||||||
|
expect(contact.reload.updated_at).to eq(original_updated_at)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -46,4 +46,15 @@ RSpec.describe Company, type: :model do
|
|||||||
expect(company.reload.last_activity_at).to be_within(1.second).of(original_activity_at)
|
expect(company.reload.last_activity_at).to be_within(1.second).of(original_activity_at)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'contact company name sync' do
|
||||||
|
let(:account) { create(:account) }
|
||||||
|
let(:company) { create(:company, account: account, name: 'Acme') }
|
||||||
|
|
||||||
|
it 'enqueues contact company name sync when the company name changes' do
|
||||||
|
expect do
|
||||||
|
company.update!(name: 'Acme Labs')
|
||||||
|
end.to have_enqueued_job(Companies::SyncContactNamesJob).with(company_id: company.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,16 +23,17 @@ describe Conversations::AssignmentService do
|
|||||||
|
|
||||||
context 'when assigning a user' do
|
context 'when assigning a user' do
|
||||||
before do
|
before do
|
||||||
conversation.update!(assignee_agent_bot: agent_bot, assignee: nil)
|
conversation.update!(assignee_agent_bot: agent_bot, assignee: nil, status: :pending)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the agent and clears agent bot' do
|
it 'sets the agent, clears agent bot and opens the conversation' do
|
||||||
result = described_class.new(conversation: conversation, assignee_id: agent.id).perform
|
result = described_class.new(conversation: conversation, assignee_id: agent.id).perform
|
||||||
|
|
||||||
conversation.reload
|
conversation.reload
|
||||||
expect(result).to eq(agent)
|
expect(result).to eq(agent)
|
||||||
expect(conversation.assignee_id).to eq(agent.id)
|
expect(conversation.assignee_id).to eq(agent.id)
|
||||||
expect(conversation.assignee_agent_bot_id).to be_nil
|
expect(conversation.assignee_agent_bot_id).to be_nil
|
||||||
|
expect(conversation.status).to eq('open')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -45,8 +46,8 @@ describe Conversations::AssignmentService do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the agent bot and clears human assignee' do
|
it 'sets the agent bot, clears human assignee and marks the conversation pending' do
|
||||||
conversation.update!(assignee: agent, assignee_agent_bot: nil)
|
conversation.update!(assignee: agent, assignee_agent_bot: nil, status: :open)
|
||||||
|
|
||||||
result = service.perform
|
result = service.perform
|
||||||
|
|
||||||
@@ -54,6 +55,7 @@ describe Conversations::AssignmentService do
|
|||||||
expect(result).to eq(agent_bot)
|
expect(result).to eq(agent_bot)
|
||||||
expect(conversation.assignee_agent_bot_id).to eq(agent_bot.id)
|
expect(conversation.assignee_agent_bot_id).to eq(agent_bot.id)
|
||||||
expect(conversation.assignee_id).to be_nil
|
expect(conversation.assignee_id).to be_nil
|
||||||
|
expect(conversation.status).to eq('pending')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user