import { isRegisterUser } from '@rocket.chat/core-typings'; import type { ServerMethods } from '@rocket.chat/ddp-client'; import { Users, Rooms } from '@rocket.chat/models'; import { check } from 'meteor/check'; import { Meteor } from 'meteor/meteor'; import { hasPermissionAsync } from '../../lib/authorization/hasPermission'; import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger'; import { unarchiveRoom } from '../../lib/rooms/unarchiveRoom'; declare module '@rocket.chat/ddp-client' { // eslint-disable-next-line @typescript-eslint/naming-convention interface ServerMethods { unarchiveRoom(rid: string): Promise; } } export const executeUnarchiveRoom = async (userId: string, rid: string) => { check(rid, String); 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); }; Meteor.methods({ async unarchiveRoom(rid) { methodDeprecationLogger.method('unarchiveRoom', '9.0.0', '/v1/channels.unarchive'); const userId = Meteor.userId(); if (!userId) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'unarchiveRoom' }); } return executeUnarchiveRoom(userId, rid); }, });