Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/yellow-eggs-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/rest-typings": patch
---

Fixes an issue that prevented the action of removing an agent when editing a department to work.
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/lib/departmentsLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export async function saveDepartmentAgents(
departmentAgents: {
upsert?: (Pick<ILivechatDepartmentAgents, 'agentId' | 'username'> & {
count?: number;
sort?: number;
order?: number;
})[];
remove?: Pick<ILivechatDepartmentAgents, 'agentId' | 'username'>[];
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { IDepartmentAgent } from '../definitions';

export const formatAgentListPayload = (oldAgentList: IDepartmentAgent[], newAgentList: IDepartmentAgent[]) => {
const upsert: IDepartmentAgent[] = [];
const remove: IDepartmentAgent[] = [];
const upsert: Pick<IDepartmentAgent, 'agentId' | 'username' | 'count' | 'order'>[] = [];
const remove: Pick<IDepartmentAgent, 'agentId' | 'username'>[] = [];

for (const agent of newAgentList) {
const initialAgent = agent._id ? oldAgentList.find((initialAgent) => initialAgent._id === agent._id) : undefined;

if (!initialAgent || agent.count !== initialAgent.count || agent.order !== initialAgent.order) {
upsert.push(agent);
upsert.push({ agentId: agent.agentId, username: agent.username, count: agent.count, order: agent.order });
}
}

for (const initialAgent of oldAgentList) {
if (!newAgentList.some((agent) => initialAgent._id === agent._id)) {
remove.push(initialAgent);
remove.push({ agentId: initialAgent.agentId, username: initialAgent.username });
}
}

Expand Down
24 changes: 24 additions & 0 deletions apps/meteor/tests/end-to-end/api/livechat/10-departments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,30 @@ import { IS_EE } from '../../../e2e/config/constants';
.send({ upsert: [{ agentId: agent._id, username: agent.username, name: agent.name }], remove: [] })
.expect(200);
expect(res.body).to.have.property('success', true);
});
it('should successfully remove an agent from a department', async () => {
const [dep, agent] = await Promise.all([createDepartment(), createAgent()]);
const res = await request
.post(api(`livechat/department/${dep._id}/agents`))
.set(credentials)
// UI sends the whole agent object, but API only needs agentId and username
.send({
remove: [
{
agentId: agent._id,
username: agent.username,
name: agent.name,
count: 0,
order: 0,
departmentId: 'afdsfads',
_id: 'afsdfadsfaf',
_updatedAt: new Date(),
},
],
upsert: [],
})
.expect(200);
expect(res.body).to.have.property('success', true);
await deleteDepartment(dep._id);
});
});
Expand Down
4 changes: 4 additions & 0 deletions packages/rest-typings/src/v1/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ const LivechatDepartmentDepartmentIdAgentsPOSTSchema = {
order: {
type: 'number',
},
departmentEnabled: { type: 'boolean' },
departmentId: { type: 'string' },
_id: { type: 'string' },
_updatedAt: { type: 'string' },
},
required: ['agentId', 'username'],
additionalProperties: false,
Expand Down
Loading