Skip to content

Commit b71f838

Browse files
authored
fix: Persist userId when updating a canned response (RocketChat#37277)
1 parent 9828d5c commit b71f838

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

.changeset/long-melons-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/meteor': patch
3+
---
4+
5+
Fixes an issue where updating a private canned response wasn't being shown on canned-response contextualbar.

apps/meteor/ee/app/canned-responses/server/methods/saveCannedResponse.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ export const saveCannedResponse = async (
9999
});
100100
}
101101

102-
result = await CannedResponse.updateCannedResponse(_id, { ...responseData, createdBy: cannedResponse.createdBy });
102+
result = await CannedResponse.updateCannedResponse(_id, {
103+
...responseData,
104+
...(cannedResponse.scope === 'user' && { userId: cannedResponse.userId }),
105+
createdBy: cannedResponse.createdBy,
106+
});
103107
} else {
104108
const user = await Users.findOneById(userId);
105109

apps/meteor/tests/end-to-end/api/livechat/15-canned-responses.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { createAgent, createDepartment } from '../../../data/livechat/rooms';
99
import { removeTag, saveTags } from '../../../data/livechat/tags';
1010
import { createMonitor, createUnit } from '../../../data/livechat/units';
1111
import { updatePermission, updateSetting } from '../../../data/permissions.helper';
12-
import { password } from '../../../data/user';
12+
import { password, adminUsername } from '../../../data/user';
1313
import { createUser, login } from '../../../data/users.helper';
1414
import { IS_EE } from '../../../e2e/config/constants';
1515

@@ -245,6 +245,33 @@ import { IS_EE } from '../../../e2e/config/constants';
245245
expect(getResult).to.have.property('success', true);
246246
expect(getResult.cannedResponses).to.be.an('array').with.lengthOf(0);
247247
});
248+
249+
it('should persist userId when updating a canned response', async () => {
250+
const response = await createCannedResponse();
251+
252+
const {
253+
body: { cannedResponses },
254+
} = await request.get(api('canned-responses')).set(credentials).query({}).expect(200);
255+
256+
const targetCannedResponse = cannedResponses.find(
257+
(cannedResponse: IOmnichannelCannedResponse) => cannedResponse.shortcut === response.shortcut,
258+
);
259+
260+
const { body } = await request
261+
.post(api('canned-responses'))
262+
.set(credentials)
263+
.send({ _id: targetCannedResponse._id, shortcut: `${targetCannedResponse.shortcut}-edited`, text: 'edited text', scope: 'user' })
264+
.expect(200);
265+
expect(body).to.have.property('success', true);
266+
267+
const { body: getResult } = await request
268+
.get(api('canned-responses'))
269+
.set(credentials)
270+
.query({ shortcut: `${targetCannedResponse.shortcut}-edited` })
271+
.expect(200);
272+
expect(getResult).to.have.property('success', true);
273+
expect(getResult.cannedResponses[0]).to.have.property('userId', adminUsername);
274+
});
248275
});
249276

250277
describe('[DELETE] canned-responses', () => {

0 commit comments

Comments
 (0)