mirror of
https://github.com/RocketChat/Rocket.Chat.git
synced 2025-12-27 22:40:49 +00:00
chore!: remove deprecated livechat:sendTranscript method (#37396)
This commit is contained in:
parent
dda545daf8
commit
dad0746ba7
5
.changeset/strong-bats-swim.md
Normal file
5
.changeset/strong-bats-swim.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'@rocket.chat/meteor': major
|
||||
---
|
||||
|
||||
Removes deprecated `livechat:sendTranscript` method
|
||||
@ -19,7 +19,6 @@ import './methods/saveDepartment';
|
||||
import './methods/sendMessageLivechat';
|
||||
import './methods/sendFileLivechatMessage';
|
||||
import './methods/takeInquiry';
|
||||
import './methods/sendTranscript';
|
||||
import './lib/QueueManager';
|
||||
import './lib/RoutingManager';
|
||||
import './lib/routing/External';
|
||||
|
||||
@ -1,52 +0,0 @@
|
||||
import { Omnichannel } from '@rocket.chat/core-services';
|
||||
import type { ServerMethods } from '@rocket.chat/ddp-client';
|
||||
import { LivechatRooms, Users } from '@rocket.chat/models';
|
||||
import { check } from 'meteor/check';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
|
||||
import { RateLimiter } from '../../../lib/server';
|
||||
import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';
|
||||
import { sendTranscript } from '../lib/sendTranscript';
|
||||
|
||||
declare module '@rocket.chat/ddp-client' {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
interface ServerMethods {
|
||||
'livechat:sendTranscript'(token: string, rid: string, email: string, subject: string): boolean;
|
||||
}
|
||||
}
|
||||
|
||||
Meteor.methods<ServerMethods>({
|
||||
async 'livechat:sendTranscript'(token, rid, email, subject) {
|
||||
methodDeprecationLogger.method('livechat:sendTranscript', '8.0.0', '/v1/livechat/transcript');
|
||||
check(rid, String);
|
||||
check(email, String);
|
||||
|
||||
const uid = Meteor.userId();
|
||||
if (!uid || !(await hasPermissionAsync(uid, 'send-omnichannel-chat-transcript'))) {
|
||||
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
|
||||
method: 'livechat:sendTranscript',
|
||||
});
|
||||
}
|
||||
|
||||
const user = await Users.findOneById(uid, {
|
||||
projection: { _id: 1, username: 1, name: 1, utcOffset: 1 },
|
||||
});
|
||||
|
||||
const room = await LivechatRooms.findOneById(rid, { projection: { activity: 1 } });
|
||||
if (!room) {
|
||||
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'livechat:sendTranscript' });
|
||||
}
|
||||
if (!(await Omnichannel.isWithinMACLimit(room))) {
|
||||
throw new Meteor.Error('error-mac-limit-reached', 'MAC limit reached', { method: 'livechat:sendTranscript' });
|
||||
}
|
||||
|
||||
return sendTranscript({ token, rid, email, subject, user });
|
||||
},
|
||||
});
|
||||
|
||||
RateLimiter.limitMethod('livechat:sendTranscript', 1, 5000, {
|
||||
connectionId() {
|
||||
return true;
|
||||
},
|
||||
});
|
||||
@ -19,7 +19,7 @@ import { after, afterEach, before, describe, it } from 'mocha';
|
||||
import type { Response } from 'supertest';
|
||||
|
||||
import type { SuccessResult } from '../../../../app/api/server/definition';
|
||||
import { getCredentials, api, request, credentials, methodCall } from '../../../data/api-data';
|
||||
import { getCredentials, api, request, credentials } from '../../../data/api-data';
|
||||
import { apps, APP_URL } from '../../../data/apps/apps-data';
|
||||
import { createCustomField } from '../../../data/livechat/custom-fields';
|
||||
import type { OnlineAgent } from '../../../data/livechat/department';
|
||||
@ -52,7 +52,7 @@ import {
|
||||
import { saveTags } from '../../../data/livechat/tags';
|
||||
import { createMonitor, createUnit, deleteUnit } from '../../../data/livechat/units';
|
||||
import type { DummyResponse } from '../../../data/livechat/utils';
|
||||
import { parseMethodResponse, sleep } from '../../../data/livechat/utils';
|
||||
import { sleep } from '../../../data/livechat/utils';
|
||||
import {
|
||||
restorePermissionToRoles,
|
||||
addPermissions,
|
||||
@ -3630,161 +3630,4 @@ describe('LIVECHAT - rooms', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('livechat:sendTranscript', () => {
|
||||
describe('with no permission', () => {
|
||||
before(async () => {
|
||||
await updatePermission('send-omnichannel-chat-transcript', []);
|
||||
});
|
||||
after(async () => {
|
||||
await updatePermission('send-omnichannel-chat-transcript', ['admin']);
|
||||
});
|
||||
it('should fail if user doesnt have send-omnichannel-chat-transcript permission', async () => {
|
||||
const { body } = await request
|
||||
.post(methodCall('livechat:sendTranscript'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
message: JSON.stringify({
|
||||
msg: 'method',
|
||||
id: '1091',
|
||||
method: 'livechat:sendTranscript',
|
||||
params: ['test', 'test', 'test', 'test'],
|
||||
}),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const result = parseMethodResponse(body);
|
||||
expect(body.success).to.be.true;
|
||||
expect(result).to.have.property('error').that.is.an('object').that.has.property('error', 'error-not-allowed');
|
||||
});
|
||||
});
|
||||
it('should fail if not all params are provided', async () => {
|
||||
const { body } = await request
|
||||
.post(methodCall('livechat:sendTranscript'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
message: JSON.stringify({
|
||||
msg: 'method',
|
||||
id: '1091',
|
||||
method: 'livechat:sendTranscript',
|
||||
params: [],
|
||||
}),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const result = parseMethodResponse(body);
|
||||
expect(body.success).to.be.true;
|
||||
expect(result).to.have.property('error').that.is.an('object').that.has.property('errorType', 'Match.Error');
|
||||
});
|
||||
it('should fail if token is invalid', async () => {
|
||||
const { body } = await request
|
||||
.post(methodCall('livechat:sendTranscript'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
message: JSON.stringify({
|
||||
msg: 'method',
|
||||
id: '1091',
|
||||
method: 'livechat:sendTranscript',
|
||||
params: ['invalid-token', 'test', 'test', 'test'],
|
||||
}),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const result = parseMethodResponse(body);
|
||||
expect(body.success).to.be.true;
|
||||
expect(result).to.have.property('error').that.is.an('object');
|
||||
});
|
||||
it('should fail if roomId is invalid', async () => {
|
||||
const visitor = await createVisitor();
|
||||
const { body } = await request
|
||||
.post(methodCall('livechat:sendTranscript'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
message: JSON.stringify({
|
||||
msg: 'method',
|
||||
id: '1091',
|
||||
method: 'livechat:sendTranscript',
|
||||
params: [visitor.token, 'invalid-room-id', 'test', 'test'],
|
||||
}),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const result = parseMethodResponse(body);
|
||||
expect(body.success).to.be.true;
|
||||
expect(result).to.have.property('error').that.is.an('object');
|
||||
await deleteVisitor(visitor.token);
|
||||
});
|
||||
describe('with rooms', () => {
|
||||
let visitor1: ILivechatVisitor;
|
||||
let visitor2: ILivechatVisitor;
|
||||
let room: IOmnichannelRoom;
|
||||
before(async () => {
|
||||
visitor1 = await createVisitor();
|
||||
visitor2 = await createVisitor();
|
||||
room = await createLivechatRoom(visitor1.token);
|
||||
});
|
||||
after(async () => {
|
||||
await deleteVisitor(visitor1.token);
|
||||
await deleteVisitor(visitor2.token);
|
||||
await closeOmnichannelRoom(room._id);
|
||||
});
|
||||
|
||||
it('should fail if token is from another conversation', async () => {
|
||||
const { body } = await request
|
||||
.post(methodCall('livechat:sendTranscript'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
message: JSON.stringify({
|
||||
msg: 'method',
|
||||
id: '1091',
|
||||
method: 'livechat:sendTranscript',
|
||||
params: [visitor2.token, room._id, 'test', 'test'],
|
||||
}),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const result = parseMethodResponse(body);
|
||||
expect(body.success).to.be.true;
|
||||
expect(result).to.have.property('error').that.is.an('object');
|
||||
});
|
||||
|
||||
it('should fail if email provided is invalid', async () => {
|
||||
const { body } = await request
|
||||
.post(methodCall('livechat:sendTranscript'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
message: JSON.stringify({
|
||||
msg: 'method',
|
||||
id: '1091',
|
||||
method: 'livechat:sendTranscript',
|
||||
params: [visitor1.token, room._id, 'invalid-email', 'test'],
|
||||
}),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const result = parseMethodResponse(body);
|
||||
expect(body.success).to.be.true;
|
||||
expect(result).to.have.property('error').that.is.an('object');
|
||||
});
|
||||
|
||||
it('should work if all params are good', async () => {
|
||||
const { body } = await request
|
||||
.post(methodCall('livechat:sendTranscript'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
message: JSON.stringify({
|
||||
msg: 'method',
|
||||
id: '1091',
|
||||
method: 'livechat:sendTranscript',
|
||||
params: [visitor1.token, room._id, 'test@test', 'test'],
|
||||
}),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const result = parseMethodResponse(body);
|
||||
expect(body.success).to.be.true;
|
||||
expect(result).to.have.property('result', true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user