Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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/may-be-it-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": minor
"@rocket.chat/rest-typings": minor
---

Add OpenAPI support for the Rocket.Chat rooms.hide API endpoints by migrating to a modern chained route definition syntax and utilizing shared AJV schemas for validation
76 changes: 50 additions & 26 deletions apps/meteor/app/api/server/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
isRoomsOpenProps,
isRoomsMembersOrderedByRoleProps,
isRoomsChangeArchivationStateProps,
isRoomsHideProps,
isRoomsInviteProps,
validateBadRequestErrorResponse,
validateUnauthorizedErrorResponse,
Expand Down Expand Up @@ -925,33 +924,22 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'rooms.hide',
{ authRequired: true, validateParams: isRoomsHideProps },
{
async post() {
const { roomId } = this.bodyParams;

if (!(await canAccessRoomIdAsync(roomId, this.userId))) {
return API.v1.unauthorized();
}

const user = await Users.findOneById(this.userId, { projections: { _id: 1 } });

if (!user) {
return API.v1.failure('error-invalid-user');
}

const modCount = await hideRoomMethod(this.userId, roomId);

if (!modCount) {
return API.v1.failure('error-room-already-hidden');
}
type RoomsHideProps = {
roomId: string;
};

return API.v1.success();
const roomsHideSchema = {
type: 'object',
properties: {
roomId: {
type: 'string',
minLength: 1,
},
},
);
required: ['roomId'],
additionalProperties: false,
};


type RoomsFavorite =
| {
Expand Down Expand Up @@ -1026,6 +1014,7 @@ const isRoomsLeavePropsSchema = {

const isRoomsFavoriteProps = ajv.compile<RoomsFavorite>(RoomsFavoriteSchema);
const isRoomsLeaveProps = ajv.compile<RoomsLeave>(isRoomsLeavePropsSchema);
const isRoomsHideProps = ajv.compile<RoomsHideProps>(roomsHideSchema);

export const roomEndpoints = API.v1
.get(
Expand Down Expand Up @@ -1233,7 +1222,42 @@ export const roomEndpoints = API.v1

return API.v1.success();
},
);
)
.post(
'rooms.hide',
{
authRequired: true,
body: isRoomsHideProps,
response: {
200: ajv.compile<void>({
type:'object',
properties:{
success:{type:'boolean', enum:[true]},
},
required:['success'],
additionalProperties:false,
}),
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
},
},
async function action(){
const { roomId } = this.bodyParams;

if (!(await canAccessRoomIdAsync(roomId, this.userId))) {
return API.v1.unauthorized('You do not have access to this room');
}

const modCount = await hideRoomMethod(this.userId, roomId);

if (!modCount) {
return API.v1.failure('error-room-already-hidden');
}

return API.v1.success();

}
)

type RoomEndpoints = ExtractRoutesFromAPI<typeof roomEndpoints> &
ExtractRoutesFromAPI<typeof roomEndpoints> &
Expand Down
22 changes: 0 additions & 22 deletions packages/rest-typings/src/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,24 +669,6 @@ const membersOrderedByRoleRolePropsSchema = {

export const isRoomsMembersOrderedByRoleProps = ajv.compile<RoomsMembersOrderedByRoleProps>(membersOrderedByRoleRolePropsSchema);

type RoomsHideProps = {
roomId: string;
};

const roomsHideSchema = {
type: 'object',
properties: {
roomId: {
type: 'string',
minLength: 1,
},
},
required: ['roomId'],
additionalProperties: false,
};

export const isRoomsHideProps = ajv.compile<RoomsHideProps>(roomsHideSchema);

type RoomsInviteProps = {
roomId: string;
action: 'accept' | 'reject';
Expand Down Expand Up @@ -847,10 +829,6 @@ export type RoomsEndpoints = {
}>;
};

'/v1/rooms.hide': {
POST: (params: RoomsHideProps) => void;
};

'/v1/rooms.invite': {
POST: (params: RoomsInviteProps) => void;
};
Expand Down