Skip to content

Commit

Permalink
chore!: remove deprecated meteor eraseRoom method (#32648)
Browse files Browse the repository at this point in the history
Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>
  • Loading branch information
AllanPazRibeiro and ggazzo committed Oct 11, 2024
1 parent 98a17b5 commit 23ec389
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-boats-sip.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion apps/meteor/app/api/server/v1/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
},
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/api/server/v1/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
},
Expand Down
4 changes: 3 additions & 1 deletion apps/meteor/app/api/server/v1/im.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 =
Expand Down Expand Up @@ -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();
},
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/app/api/server/v1/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -652,15 +652,15 @@ 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);
}
}

// Move every other room back to the workspace
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<void> {
const room = await Rooms.findOneById(rid);
Expand Down Expand Up @@ -57,30 +54,3 @@ export async function eraseRoom(rid: string, uid: string): Promise<void> {
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<boolean>;
}
}

Meteor.methods<ServerMethods>({
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;
},
});
1 change: 0 additions & 1 deletion apps/meteor/server/methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import './channelsList';
import './createDirectMessage';
import './deleteFileMessage';
import './deleteUser';
import './eraseRoom';
import './getAvatarSuggestion';
import './getPasswordPolicy';
import './getRoomById';
Expand Down

0 comments on commit 23ec389

Please sign in to comment.