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/lib/server/methods/unarchiveRoom.ts

44 lines
1.4 KiB

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { Users, Rooms } from '@rocket.chat/models';
import { isRegisterUser } from '@rocket.chat/core-typings';
import type { ServerMethods } from '@rocket.chat/ui-contexts';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { unarchiveRoom } from '../functions';
declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
unarchiveRoom(rid: string): Promise<void>;
}
}
Meteor.methods<ServerMethods>({
async unarchiveRoom(rid) {
check(rid, String);
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'unarchiveRoom' });
}
const user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });
if (!user || !isRegisterUser(user)) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'archiveRoom' });
}
const room = await Rooms.findOneById(rid);
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'unarchiveRoom' });
}
if (!(await hasPermissionAsync(userId, 'unarchive-room', room._id))) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'unarchiveRoom' });
}
return unarchiveRoom(rid, user);
},
});