From e5c6788914174325ec8c1ef0cbb917f76e11ede2 Mon Sep 17 00:00:00 2001 From: AllanPazRibeiro Date: Thu, 20 Jun 2024 16:31:12 -0300 Subject: [PATCH] refactor: remove deprecated meteor eraseRoom method --- .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/teams.ts | 8 +++---- apps/meteor/server/methods/eraseRoom.ts | 29 ----------------------- 6 files changed, 16 insertions(+), 36 deletions(-) create mode 100644 .changeset/chilled-boats-sip.md 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..d6d168f4b64f 100644 --- a/apps/meteor/app/api/server/v1/channels.ts +++ b/apps/meteor/app/api/server/v1/channels.ts @@ -24,6 +24,7 @@ import { Meteor } from 'meteor/meteor'; import { isTruthy } from '../../../../lib/isTruthy'; import { findUsersOfRoom } from '../../../../server/lib/findUsersOfRoom'; +import { eraseRoom } from '../../../../server/methods/eraseRoom'; import { hideRoomMethod } from '../../../../server/methods/hideRoom'; import { removeUserFromRoomMethod } from '../../../../server/methods/removeUserFromRoom'; import { canAccessRoomAsync } from '../../../authorization/server'; @@ -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..90f6ccbeed85 100644 --- a/apps/meteor/app/api/server/v1/groups.ts +++ b/apps/meteor/app/api/server/v1/groups.ts @@ -6,6 +6,7 @@ import { Meteor } from 'meteor/meteor'; import type { Filter } from 'mongodb'; import { findUsersOfRoom } from '../../../../server/lib/findUsersOfRoom'; +import { eraseRoom } from '../../../../server/methods/eraseRoom'; import { hideRoomMethod } from '../../../../server/methods/hideRoom'; import { removeUserFromRoomMethod } from '../../../../server/methods/removeUserFromRoom'; import { canAccessRoomAsync, roomAccessAttributes } from '../../../authorization/server'; @@ -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 1084ac96a188..90d5ed6015f2 100644 --- a/apps/meteor/app/api/server/v1/im.ts +++ b/apps/meteor/app/api/server/v1/im.ts @@ -15,6 +15,7 @@ import { Match, check } from 'meteor/check'; import { Meteor } from 'meteor/meteor'; import { createDirectMessage } from '../../../../server/methods/createDirectMessage'; +import { eraseRoom } from '../../../../server/methods/eraseRoom'; import { hideRoomMethod } from '../../../../server/methods/hideRoom'; import { canAccessRoomIdAsync } from '../../../authorization/server/functions/canAccessRoom'; import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; @@ -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/teams.ts b/apps/meteor/app/api/server/v1/teams.ts index c111bc482360..71f114221932 100644 --- a/apps/meteor/app/api/server/v1/teams.ts +++ b/apps/meteor/app/api/server/v1/teams.ts @@ -14,8 +14,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/methods/eraseRoom'; import { canAccessRoomAsync } from '../../../authorization/server'; import { hasPermissionAsync, hasAtLeastOnePermissionAsync } from '../../../authorization/server/functions/hasPermission'; import { removeUserFromRoom } from '../../../lib/server/functions/removeUserFromRoom'; @@ -135,7 +135,7 @@ API.v1.addRoute( if (rooms.length) { for await (const room of rooms) { - await Meteor.callAsync('eraseRoom', room); + await eraseRoom(room, this.userId); } } @@ -613,7 +613,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); } } @@ -621,7 +621,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/methods/eraseRoom.ts index e11c0fe6dcfd..4d288448ea55 100644 --- a/apps/meteor/server/methods/eraseRoom.ts +++ b/apps/meteor/server/methods/eraseRoom.ts @@ -2,12 +2,10 @@ 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'; export async function eraseRoom(rid: string, uid: string): Promise { @@ -57,30 +55,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; - }, -});