Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
80 changes: 74 additions & 6 deletions apps/meteor/app/api/server/v1/groups.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 } 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 @@ -36,6 +36,9 @@ import { addUserToFileObj } from '../helpers/addUserToFileObj';
import { composeRoomWithLastMessage } from '../helpers/composeRoomWithLastMessage';
import { getPaginationItems } from '../helpers/getPaginationItems';
import { getUserFromParams, getUserListFromParams } from '../helpers/getUserFromParams';
import { ExtractRoutesFromAPI } from '../ApiClass';
import { validateBadRequestErrorResponse } from '@rocket.chat/rest-typings';
import { validateUnauthorizedErrorResponse } from '@rocket.chat/rest-typings';

async function getRoomFromParams(params: { roomId?: string } | { roomName?: string }): Promise<IRoom> {
if (
Expand Down Expand Up @@ -891,11 +894,68 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'groups.removeModerator',
{ authRequired: true },



type GroupsBaseProps = { roomId: string; roomName?: string } | { roomId?: string; roomName: string };
const withGroupBaseProperties = (properties: Record<string, any> = {}, required: string[] = []) => ({
oneOf: [
{
type: 'object',
properties: {
roomId: {
type: 'string',
},
...properties,
},
required: ['roomId'].concat(required),
additionalProperties: false,
},
{
type: 'object',
properties: {
roomName: {
type: 'string',
},
...properties,
},
required: ['roomName'].concat(required),
additionalProperties: false,
},
],
});

type WithUserId = GroupsBaseProps & { userId: string };
const withUserIdSchema = withGroupBaseProperties(
{
async post() {
userId: {
type: 'string',
},
},
['userId'],
);
export const GroupsRemoveModeratorProps = ajv.compile<WithUserId>(withUserIdSchema);


const groupsEndpoints = API.v1.post(
"groups.removeModerator",
{
authRequired:true,
body: GroupsRemoveModeratorProps,
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,
Expand All @@ -906,8 +966,8 @@ API.v1.addRoute(
await removeRoomModerator(this.userId, findResult.rid, user._id);

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

);

API.v1.addRoute(
Expand Down Expand Up @@ -1300,3 +1360,11 @@ 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