Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/thirty-deers-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/rest-typings': patch
'@rocket.chat/meteor': patch
---

Migrate groups.delete endpoint to the new REST API architecture
87 changes: 72 additions & 15 deletions apps/meteor/app/api/server/v1/groups.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Team, isMeteorError } from '@rocket.chat/core-services';
import type { IIntegration, IUser, IRoom, RoomType, UserStatus } from '@rocket.chat/core-typings';
import { Integrations, Messages, Rooms, Subscriptions, Uploads, Users } from '@rocket.chat/models';
import { isGroupsOnlineProps, isGroupsMessagesProps, isGroupsFilesProps } from '@rocket.chat/rest-typings';
import {
ajv,
isGroupsOnlineProps,
isGroupsMessagesProps,
isGroupsFilesProps,
validateBadRequestErrorResponse,
validateUnauthorizedErrorResponse,
} from '@rocket.chat/rest-typings';
import { isTruthy } from '@rocket.chat/tools';
import { check, Match } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
Expand Down Expand Up @@ -31,6 +38,7 @@ import { executeGetRoomRoles } from '../../../lib/server/methods/getRoomRoles';
import { leaveRoomMethod } from '../../../lib/server/methods/leaveRoom';
import { executeUnarchiveRoom } from '../../../lib/server/methods/unarchiveRoom';
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser';
import type { ExtractRoutesFromAPI } from '../ApiClass';
import { API } from '../api';
import { addUserToFileObj } from '../helpers/addUserToFileObj';
import { composeRoomWithLastMessage } from '../helpers/composeRoomWithLastMessage';
Expand Down Expand Up @@ -67,7 +75,7 @@ async function getRoomFromParams(params: { roomId?: string } | { roomName?: stri
}
})();

if (!room || room.t !== 'p') {
if (room?.t !== 'p') {
throw new Meteor.Error('error-room-not-found', 'The required "roomId" or "roomName" param provided does not match any group');
}

Expand Down Expand Up @@ -273,7 +281,7 @@ API.v1.addRoute(
room = await Rooms.findOneByName(params.roomName || '');
}

if (!room || room.t !== 'p') {
if (room?.t !== 'p') {
throw new Meteor.Error('error-room-not-found', 'The required "roomId" or "roomName" param provided does not match any group');
}

Expand Down Expand Up @@ -368,21 +376,63 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
const groupDeleteEndpoint = API.v1.post(
'groups.delete',
{ authRequired: true },
{
async post() {
const findResult = await findPrivateGroupByIdOrName({
params: this.bodyParams,
userId: this.userId,
checkedArchived: false,
});
authRequired: true,
body: ajv.compile<{ roomId?: string | undefined } | { roomName?: string | undefined }>({
oneOf: [
{
type: 'object',
properties: {
roomId: {
type: 'string',
description: 'Enter the room ID. This parameter is required if no roomName is provided.',
},
},
required: ['roomId'],
additionalProperties: false,
},
{
type: 'object',
properties: {
roomName: {
type: 'string',
description: 'Enter the room name. This parameter is required if no roomId is provided.',
},
},
required: ['roomName'],
additionalProperties: false,
},
],
}),
response: {
200: ajv.compile<void>({
type: 'object',
properties: {
success: {
type: 'boolean',
enum: [true],
description: 'Indicates if the request was successful.',
},
},
required: ['success'],
additionalProperties: false,
}),
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
},
},
async function action() {
const findResult = await findPrivateGroupByIdOrName({
params: this.bodyParams,
userId: this.userId,
checkedArchived: false,
});

await eraseRoom(findResult.rid, this.user);
await eraseRoom(findResult.rid, this.user);

return API.v1.success();
},
return API.v1.success();
},
);

Expand Down Expand Up @@ -791,7 +841,7 @@ API.v1.addRoute(
rid: findResult.rid,
...parseIds(mentionIds, 'mentions._id'),
...parseIds(starredIds, 'starred._id'),
...(pinned && pinned.toLowerCase() === 'true' ? { pinned: true } : {}),
...(pinned?.toLowerCase() === 'true' ? { pinned: true } : {}),
_hidden: { $ne: true },
};

Expand Down Expand Up @@ -1300,3 +1350,10 @@ API.v1.addRoute(
},
},
);

type GroupEndpoints = ExtractRoutesFromAPI<typeof groupDeleteEndpoint>;

declare module '@rocket.chat/rest-typings' {
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
interface Endpoints extends GroupEndpoints {}
}
9 changes: 0 additions & 9 deletions packages/rest-typings/src/v1/groups/GroupsDeleteProps.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/rest-typings/src/v1/groups/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type { GroupsCloseProps } from './GroupsCloseProps';
import type { GroupsConvertToTeamProps } from './GroupsConvertToTeamProps';
import type { GroupsCountersProps } from './GroupsCountersProps';
import type { GroupsCreateProps } from './GroupsCreateProps';
import type { GroupsDeleteProps } from './GroupsDeleteProps';
import type { GroupsFilesProps } from './GroupsFilesProps';
import type { GroupsGetIntegrationsProps } from './GroupsGetIntegrationsProps';
import type { GroupsHistoryProps } from './GroupsHistoryProps';
Expand Down Expand Up @@ -90,9 +89,6 @@ export type GroupsEndpoints = {
'/v1/groups.kick': {
POST: (params: GroupsKickProps) => void;
};
'/v1/groups.delete': {
POST: (params: GroupsDeleteProps) => void;
};
'/v1/groups.leave': {
POST: (params: GroupsLeaveProps) => void;
};
Expand Down
1 change: 0 additions & 1 deletion packages/rest-typings/src/v1/groups/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export * from './GroupsCloseProps';
export * from './GroupsConvertToTeamProps';
export * from './GroupsCreateProps';
export * from './GroupsCountersProps';
export * from './GroupsDeleteProps';
export * from './GroupsFilesProps';
export * from './GroupsKickProps';
export * from './GroupsLeaveProps';
Expand Down