Skip to content

Commit

Permalink
refactor: remove deprecated meteor eraseRoom method
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanPazRibeiro authored and ggazzo committed Aug 16, 2024
1 parent 8c447cf commit e5c6788
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 36 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 @@ -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';
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 @@ -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';
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 @@ -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';
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
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 @@ -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';
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -613,15 +613,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
29 changes: 0 additions & 29 deletions apps/meteor/server/methods/eraseRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 3 in apps/meteor/server/methods/eraseRoom.ts

View workflow job for this annotation

GitHub Actions / 🔎 Code Check / Code Lint

'ServerMethods' is defined but never used
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<void> {
Expand Down Expand Up @@ -57,30 +55,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;
},
});

0 comments on commit e5c6788

Please sign in to comment.