From 8c0ef3ed54981b7ef4cf9e965bb5faf77df03d68 Mon Sep 17 00:00:00 2001 From: Allan RIbeiro <35040806+AllanPazRibeiro@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:32:19 -0300 Subject: [PATCH] chore!: remove deprecated meteor eraseRoom method (#32648) Co-authored-by: Guilherme Gazzo --- .changeset/chilled-boats-sip.md | 5 +++ apps/meteor/app/api/server/v1/channels.ts | 3 +- apps/meteor/app/api/server/v1/groups.ts | 3 +- apps/meteor/app/api/server/v1/im.ts | 4 ++- apps/meteor/app/api/server/v1/rooms.ts | 2 +- apps/meteor/app/api/server/v1/teams.ts | 8 ++--- .../server/{methods => lib}/eraseRoom.ts | 32 +------------------ apps/meteor/server/methods/index.ts | 1 - 8 files changed, 18 insertions(+), 40 deletions(-) create mode 100644 .changeset/chilled-boats-sip.md rename apps/meteor/server/{methods => lib}/eraseRoom.ts (68%) diff --git a/.changeset/chilled-boats-sip.md b/.changeset/chilled-boats-sip.md new file mode 100644 index 000000000000..8488cb69a442 --- /dev/null +++ b/.changeset/chilled-boats-sip.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +This adjustment removes the deprecated `eraseRoom` method. Moving forward, use the `room.delete` endpoint to delete rooms. diff --git a/apps/meteor/app/api/server/v1/channels.ts b/apps/meteor/app/api/server/v1/channels.ts index a713bfd29ac6..b69487bdd22b 100644 --- a/apps/meteor/app/api/server/v1/channels.ts +++ b/apps/meteor/app/api/server/v1/channels.ts @@ -23,6 +23,7 @@ import { import { Meteor } from 'meteor/meteor'; import { isTruthy } from '../../../../lib/isTruthy'; +import { eraseRoom } from '../../../../server/lib/eraseRoom'; import { findUsersOfRoom } from '../../../../server/lib/findUsersOfRoom'; import { hideRoomMethod } from '../../../../server/methods/hideRoom'; import { removeUserFromRoomMethod } from '../../../../server/methods/removeUserFromRoom'; @@ -463,7 +464,7 @@ API.v1.addRoute( checkedArchived: false, }); - await Meteor.callAsync('eraseRoom', room._id); + await eraseRoom(room._id, this.userId); return API.v1.success(); }, diff --git a/apps/meteor/app/api/server/v1/groups.ts b/apps/meteor/app/api/server/v1/groups.ts index df03e38dc147..f2339b0a79c3 100644 --- a/apps/meteor/app/api/server/v1/groups.ts +++ b/apps/meteor/app/api/server/v1/groups.ts @@ -5,6 +5,7 @@ import { check, Match } from 'meteor/check'; import { Meteor } from 'meteor/meteor'; import type { Filter } from 'mongodb'; +import { eraseRoom } from '../../../../server/lib/eraseRoom'; import { findUsersOfRoom } from '../../../../server/lib/findUsersOfRoom'; import { hideRoomMethod } from '../../../../server/methods/hideRoom'; import { removeUserFromRoomMethod } from '../../../../server/methods/removeUserFromRoom'; @@ -364,7 +365,7 @@ API.v1.addRoute( checkedArchived: false, }); - await Meteor.callAsync('eraseRoom', findResult.rid); + await eraseRoom(findResult.rid, this.userId); return API.v1.success(); }, diff --git a/apps/meteor/app/api/server/v1/im.ts b/apps/meteor/app/api/server/v1/im.ts index 1ee1ac4ca400..713d0206e4c8 100644 --- a/apps/meteor/app/api/server/v1/im.ts +++ b/apps/meteor/app/api/server/v1/im.ts @@ -14,6 +14,7 @@ import { import { Match, check } from 'meteor/check'; import { Meteor } from 'meteor/meteor'; +import { eraseRoom } from '../../../../server/lib/eraseRoom'; import { createDirectMessage } from '../../../../server/methods/createDirectMessage'; import { hideRoomMethod } from '../../../../server/methods/hideRoom'; import { canAccessRoomIdAsync } from '../../../authorization/server/functions/canAccessRoom'; @@ -26,6 +27,7 @@ import { API } from '../api'; import { addUserToFileObj } from '../helpers/addUserToFileObj'; import { composeRoomWithLastMessage } from '../helpers/composeRoomWithLastMessage'; import { getPaginationItems } from '../helpers/getPaginationItems'; + // TODO: Refact or remove type findDirectMessageRoomProps = @@ -107,7 +109,7 @@ API.v1.addRoute( throw new Meteor.Error('error-not-allowed', 'Not allowed'); } - await Meteor.callAsync('eraseRoom', room._id); + await eraseRoom(room._id, this.userId); return API.v1.success(); }, diff --git a/apps/meteor/app/api/server/v1/rooms.ts b/apps/meteor/app/api/server/v1/rooms.ts index 117ae3851c43..eaf350c0f188 100644 --- a/apps/meteor/app/api/server/v1/rooms.ts +++ b/apps/meteor/app/api/server/v1/rooms.ts @@ -15,7 +15,7 @@ import { Meteor } from 'meteor/meteor'; import { isTruthy } from '../../../../lib/isTruthy'; import { omit } from '../../../../lib/utils/omit'; import * as dataExport from '../../../../server/lib/dataExport'; -import { eraseRoom } from '../../../../server/methods/eraseRoom'; +import { eraseRoom } from '../../../../server/lib/eraseRoom'; import { muteUserInRoom } from '../../../../server/methods/muteUserInRoom'; import { unmuteUserInRoom } from '../../../../server/methods/unmuteUserInRoom'; import { canAccessRoomAsync, canAccessRoomIdAsync } from '../../../authorization/server/functions/canAccessRoom'; diff --git a/apps/meteor/app/api/server/v1/teams.ts b/apps/meteor/app/api/server/v1/teams.ts index 0b534e599ac9..63132d811b1c 100644 --- a/apps/meteor/app/api/server/v1/teams.ts +++ b/apps/meteor/app/api/server/v1/teams.ts @@ -15,8 +15,8 @@ import { } from '@rocket.chat/rest-typings'; import { escapeRegExp } from '@rocket.chat/string-helpers'; import { Match, check } from 'meteor/check'; -import { Meteor } from 'meteor/meteor'; +import { eraseRoom } from '../../../../server/lib/eraseRoom'; import { canAccessRoomAsync } from '../../../authorization/server'; import { hasPermissionAsync, hasAtLeastOnePermissionAsync } from '../../../authorization/server/functions/hasPermission'; import { removeUserFromRoom } from '../../../lib/server/functions/removeUserFromRoom'; @@ -136,7 +136,7 @@ API.v1.addRoute( if (rooms.length) { for await (const room of rooms) { - await Meteor.callAsync('eraseRoom', room); + await eraseRoom(room, this.userId); } } @@ -652,7 +652,7 @@ API.v1.addRoute( // If we got a list of rooms to delete along with the team, remove them first if (rooms.length) { for await (const room of rooms) { - await Meteor.callAsync('eraseRoom', room); + await eraseRoom(room, this.userId); } } @@ -660,7 +660,7 @@ API.v1.addRoute( await Team.unsetTeamIdOfRooms(this.userId, team._id); // Remove the team's main room - await Meteor.callAsync('eraseRoom', team.roomId); + await eraseRoom(team.roomId, this.userId); // Delete all team memberships await Team.removeAllMembersFromTeam(team._id); diff --git a/apps/meteor/server/methods/eraseRoom.ts b/apps/meteor/server/lib/eraseRoom.ts similarity index 68% rename from apps/meteor/server/methods/eraseRoom.ts rename to apps/meteor/server/lib/eraseRoom.ts index e11c0fe6dcfd..d67de3325eea 100644 --- a/apps/meteor/server/methods/eraseRoom.ts +++ b/apps/meteor/server/lib/eraseRoom.ts @@ -1,14 +1,11 @@ import { AppEvents, Apps } from '@rocket.chat/apps'; import { Message, Team } from '@rocket.chat/core-services'; -import type { ServerMethods } from '@rocket.chat/ddp-client'; import { Rooms } from '@rocket.chat/models'; -import { check } from 'meteor/check'; import { Meteor } from 'meteor/meteor'; import { hasPermissionAsync } from '../../app/authorization/server/functions/hasPermission'; import { deleteRoom } from '../../app/lib/server/functions/deleteRoom'; -import { methodDeprecationLogger } from '../../app/lib/server/lib/deprecationWarningLogger'; -import { roomCoordinator } from '../lib/rooms/roomCoordinator'; +import { roomCoordinator } from './rooms/roomCoordinator'; export async function eraseRoom(rid: string, uid: string): Promise { const room = await Rooms.findOneById(rid); @@ -57,30 +54,3 @@ export async function eraseRoom(rid: string, uid: string): Promise { void Apps.getBridges()?.getListenerBridge().roomEvent(AppEvents.IPostRoomDeleted, room); } } - -declare module '@rocket.chat/ddp-client' { - // eslint-disable-next-line @typescript-eslint/naming-convention - interface ServerMethods { - eraseRoom(rid: string): Promise; - } -} - -Meteor.methods({ - async eraseRoom(rid: string) { - methodDeprecationLogger.method('eraseRoom', '7.0.0'); - - check(rid, String); - - const uid = Meteor.userId(); - - if (!uid) { - throw new Meteor.Error('error-invalid-user', 'Invalid user', { - method: 'eraseRoom', - }); - } - - await eraseRoom(rid, uid); - - return true; - }, -}); diff --git a/apps/meteor/server/methods/index.ts b/apps/meteor/server/methods/index.ts index 27c345964637..a3b4b747f715 100644 --- a/apps/meteor/server/methods/index.ts +++ b/apps/meteor/server/methods/index.ts @@ -12,7 +12,6 @@ import './channelsList'; import './createDirectMessage'; import './deleteFileMessage'; import './deleteUser'; -import './eraseRoom'; import './getAvatarSuggestion'; import './getPasswordPolicy'; import './getRoomById';