Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions .changeset/groups.removeModerator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"@rocket.chat/meteor": minor
"@rocket.chat/rest-typings": minor
---

Add OpenAPI support for the Rocket.Chat groups.removeModerator API endpoints by migrating to a modern chained route definition syntax and utilizing shared AJV schemas for validation
53 changes: 41 additions & 12 deletions apps/meteor/app/api/server/v1/groups.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
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 {
isGroupsOnlineProps,
isGroupsMessagesProps,
isGroupsFilesProps,
ajv,
validateBadRequestErrorResponse,
validateUnauthorizedErrorResponse,
} from '@rocket.chat/rest-typings';
import { withUserIdProps } from '@rocket.chat/rest-typings/dist/v1/groups/BaseProps';
import { isTruthy } from '@rocket.chat/tools';
import { check, Match } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
Expand Down Expand Up @@ -31,6 +39,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 @@ -891,22 +900,35 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
const groupsEndpoints = API.v1.post(
'groups.removeModerator',
{ authRequired: true },
{
async post() {
const findResult = await findPrivateGroupByIdOrName({
params: this.bodyParams,
userId: this.userId,
});
authRequired: true,
body: withUserIdProps,
response: {
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
200: ajv.compile<void>({
type: 'object',
properties: {
success: { type: 'boolean', enum: [true] },
},
required: ['success'],
additionalProperties: false,
}),
},
},
async function action() {
const findResult = await findPrivateGroupByIdOrName({
params: this.bodyParams,
userId: this.userId,
});

const user = await getUserFromParams(this.bodyParams);
const user = await getUserFromParams(this.bodyParams);

await removeRoomModerator(this.userId, findResult.rid, user._id);
await removeRoomModerator(this.userId, findResult.rid, user._id);

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

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

export type GroupEndpoints = ExtractRoutesFromAPI<typeof groupsEndpoints>;

declare module '@rocket.chat/rest-typings' {
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
interface Endpoints extends GroupEndpoints {}
}

This file was deleted.

5 changes: 1 addition & 4 deletions packages/rest-typings/src/v1/groups/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import type { GroupsModeratorsProps } from './GroupsModeratorsProps';
import type { GroupsOnlineProps } from './GroupsOnlineProps';
import type { GroupsOpenProps } from './GroupsOpenProps';
import type { GroupsRemoveLeaderProps } from './GroupsRemoveLeaderProps';
import type { GroupsRemoveModeratorProps } from './GroupsRemoveModeratorProps';
import type { GroupsRemoveOwnerProps } from './GroupsRemoveOwnerProps';
import type { GroupsRenameProps } from './GroupsRenameProps';
import type { GroupsRolesProps } from './GroupsRolesProps';
Expand Down Expand Up @@ -107,9 +106,7 @@ export type GroupsEndpoints = {
'/v1/groups.addModerator': {
POST: (params: GroupsAddModeratorProps) => void;
};
'/v1/groups.removeModerator': {
POST: (params: GroupsRemoveModeratorProps) => void;
};

'/v1/groups.addOwner': {
POST: (params: GroupsAddOwnerProps) => 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 @@ -25,7 +25,6 @@ export * from './GroupsOnlineProps';
export * from './GroupsOpenProps';
export * from './GroupsRenameProps';
export * from './GroupsRemoveLeaderProps';
export * from './GroupsRemoveModeratorProps';
export * from './GroupsRemoveOwnerProps';
export * from './GroupsSetAnnouncementProps';
export * from './GroupsSetCustomFieldsProps';
Expand Down