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/e2e/server/methods/setRoomKeyID.ts

48 lines
1.5 KiB

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import type { ServerMethods } from '@rocket.chat/ui-contexts';
import { Rooms } from '@rocket.chat/models';
import type { IRoom } from '@rocket.chat/core-typings';
import { canAccessRoomIdAsync } from '../../../authorization/server/functions/canAccessRoom';
declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
'e2e.setRoomKeyID'(rid: IRoom['_id'], keyID: string): void;
}
}
Meteor.methods<ServerMethods>({
async 'e2e.setRoomKeyID'(rid, keyID) {
check(rid, String);
check(keyID, String);
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'e2e.setRoomKeyID' });
}
if (!rid) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'e2e.setRoomKeyID' });
}
if (!(await canAccessRoomIdAsync(rid, userId))) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'e2e.setRoomKeyID' });
}
const room = await Rooms.findOneById(rid, { fields: { e2eKeyId: 1 } });
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'e2e.setRoomKeyID' });
}
if (room.e2eKeyId) {
throw new Meteor.Error('error-room-e2e-key-already-exists', 'E2E Key ID already exists', {
method: 'e2e.setRoomKeyID',
});
}
await Rooms.setE2eKeyId(room._id, keyID);
},
});