The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rocket.Chat/apps/meteor/app/livechat/server/methods/sendTranscript.ts

47 lines
1.3 KiB

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
import type { ServerMethods } from '@rocket.chat/ui-contexts';
import { Users } from '@rocket.chat/models';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { Livechat } from '../lib/LivechatTyped';
8 years ago
declare module '@rocket.chat/ui-contexts' {
// 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) {
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 },
});
return Livechat.sendTranscript({ token, rid, email, subject, user });
},
});
DDPRateLimiter.addRule(
{
type: 'method',
name: 'livechat:sendTranscript',
connectionId() {
return true;
},
},
1,
5000,
);