11import { Team , isMeteorError } from '@rocket.chat/core-services' ;
22import type { IIntegration , IUser , IRoom , RoomType , UserStatus } from '@rocket.chat/core-typings' ;
33import { Integrations , Messages , Rooms , Subscriptions , Uploads , Users } from '@rocket.chat/models' ;
4- import { isGroupsOnlineProps
5- , isGroupsMessagesProps ,
6- isGroupsFilesProps ,
7- ajv ,
4+ import {
5+ isGroupsOnlineProps ,
6+ isGroupsMessagesProps ,
7+ isGroupsFilesProps ,
8+ ajv ,
89 validateBadRequestErrorResponse ,
910 validateUnauthorizedErrorResponse ,
1011 validateForbiddenErrorResponse ,
11- withGroupBaseProperties , } from '@rocket.chat/rest-typings' ;
12+ withGroupBaseProperties ,
13+ } from '@rocket.chat/rest-typings' ;
14+ import type { PaginatedRequest , GroupsBaseProps } from '@rocket.chat/rest-typings' ;
1215import { isTruthy } from '@rocket.chat/tools' ;
1316import { check , Match } from 'meteor/check' ;
1417import { Meteor } from 'meteor/meteor' ;
1518import type { Filter } from 'mongodb' ;
1619
17-
18- import type { ExtractRoutesFromAPI } from '../ApiClass' ;
1920import { eraseRoom } from '../../../../server/lib/eraseRoom' ;
2021import { findUsersOfRoom } from '../../../../server/lib/findUsersOfRoom' ;
2122import { openRoom } from '../../../../server/lib/openRoom' ;
@@ -40,13 +41,12 @@ import { executeGetRoomRoles } from '../../../lib/server/methods/getRoomRoles';
4041import { leaveRoomMethod } from '../../../lib/server/methods/leaveRoom' ;
4142import { executeUnarchiveRoom } from '../../../lib/server/methods/unarchiveRoom' ;
4243import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser' ;
44+ import type { ExtractRoutesFromAPI } from '../ApiClass' ;
4345import { API } from '../api' ;
4446import { addUserToFileObj } from '../helpers/addUserToFileObj' ;
4547import { composeRoomWithLastMessage } from '../helpers/composeRoomWithLastMessage' ;
4648import { getPaginationItems } from '../helpers/getPaginationItems' ;
4749import { getUserFromParams , getUserListFromParams } from '../helpers/getUserFromParams' ;
48- import type { PaginatedRequest , GroupsBaseProps } from '@rocket.chat/rest-typings' ;
49- import { nullable } from 'zod' ;
5050
5151type GroupsMembersProps = PaginatedRequest < GroupsBaseProps & { filter ?: string ; status ?: string [ ] } > ;
5252
@@ -61,12 +61,12 @@ const GroupsMembersPropsSchema = withGroupBaseProperties({
6161 type : 'string' ,
6262 } ,
6363 query : {
64- type : 'string' ,
65- nullable : true
64+ type : 'string' ,
65+ nullable : true ,
6666 } ,
6767 sort : {
6868 type : 'string' ,
69- nullable : true
69+ nullable : true ,
7070 } ,
7171 status : {
7272 type : 'array' ,
@@ -76,80 +76,76 @@ const GroupsMembersPropsSchema = withGroupBaseProperties({
7676
7777const isGroupsMembersProps = ajv . compile < GroupsMembersProps > ( GroupsMembersPropsSchema ) ;
7878
79-
8079const isGroupsMembersResponse = ajv . compile ( {
81- type : 'object' ,
82- properties : {
83- members : {
84- type : 'array' ,
85- items : { $ref : '#/components/schemas/IUser' } ,
86- } ,
87- count : { type : 'integer' } ,
88- offset : { type : 'integer' } ,
89- total : { type : 'integer' } ,
90- success : { type : 'boolean' , enum : [ true ] } ,
91- } ,
92- required : [ 'members' , 'success' ] ,
93- additionalProperties : false ,
80+ type : 'object' ,
81+ properties : {
82+ members : {
83+ type : 'array' ,
84+ items : { $ref : '#/components/schemas/IUser' } ,
85+ } ,
86+ count : { type : 'integer' } ,
87+ offset : { type : 'integer' } ,
88+ total : { type : 'integer' } ,
89+ success : { type : 'boolean' , enum : [ true ] } ,
90+ } ,
91+ required : [ 'members' , 'success' ] ,
92+ additionalProperties : false ,
9493} ) ;
9594
96- const groupsEndPoints = API . v1
97- . get (
98- 'groups.members' ,
95+ const groupsEndPoints = API . v1 . get (
96+ 'groups.members' ,
9997 {
100- authRequired : true ,
101- query : isGroupsMembersProps ,
98+ authRequired : true ,
99+ query : isGroupsMembersProps ,
102100 response : {
103101 200 : isGroupsMembersResponse ,
104- 400 : validateBadRequestErrorResponse ,
105- 401 : validateUnauthorizedErrorResponse ,
106- 403 : validateForbiddenErrorResponse
102+ 400 : validateBadRequestErrorResponse ,
103+ 401 : validateUnauthorizedErrorResponse ,
104+ 403 : validateForbiddenErrorResponse ,
105+ } ,
106+ } ,
107+ async function action ( ) {
108+ const findResult = await findPrivateGroupByIdOrName ( {
109+ params : this . queryParams ,
110+ userId : this . userId ,
111+ } ) ;
112+
113+ if ( findResult . broadcast && ! ( await hasPermissionAsync ( this . userId , 'view-broadcast-member-list' , findResult . rid ) ) ) {
114+ return API . v1 . forbidden ( 'User does not have the permissions required for this action' ) ;
107115 }
108- } ,
109- async function action ( ) {
110- const findResult = await findPrivateGroupByIdOrName ( {
111- params : this . queryParams ,
112- userId : this . userId ,
113- } ) ;
114-
115- if ( findResult . broadcast && ! ( await hasPermissionAsync ( this . userId , 'view-broadcast-member-list' , findResult . rid ) ) ) {
116- return API . v1 . forbidden ( 'User does not have the permissions required for this action' ) ;
117- }
118-
119- const { offset : skip , count : limit } = await getPaginationItems ( this . queryParams ) ;
120- const { sort = { } } = await this . parseJsonQuery ( ) ;
121-
122- check (
123- this . queryParams ,
124- Match . ObjectIncluding ( {
125- status : Match . Maybe ( [ String ] ) ,
126- filter : Match . Maybe ( String ) ,
127- } ) ,
128- ) ;
129-
130- const { status, filter } = this . queryParams ;
131-
132- const { cursor, totalCount } = await findUsersOfRoom ( {
133- rid : findResult . rid ,
134- ...( status && { status : { $in : status as UserStatus [ ] } } ) ,
135- skip,
136- limit,
137- filter,
138- ...( sort ?. username && { sort : { username : sort . username } } ) ,
139- } ) ;
140-
141- const [ members , total ] = await Promise . all ( [ cursor . toArray ( ) , totalCount ] ) ;
142-
143- return API . v1 . success ( {
144- members,
145- count : members . length ,
146- offset : skip ,
147- total,
148- } ) ;
149- }
150- )
151-
152116
117+ const { offset : skip , count : limit } = await getPaginationItems ( this . queryParams ) ;
118+ const { sort = { } } = await this . parseJsonQuery ( ) ;
119+
120+ check (
121+ this . queryParams ,
122+ Match . ObjectIncluding ( {
123+ status : Match . Maybe ( [ String ] ) ,
124+ filter : Match . Maybe ( String ) ,
125+ } ) ,
126+ ) ;
127+
128+ const { status, filter } = this . queryParams ;
129+
130+ const { cursor, totalCount } = await findUsersOfRoom ( {
131+ rid : findResult . rid ,
132+ ...( status && { status : { $in : status as UserStatus [ ] } } ) ,
133+ skip,
134+ limit,
135+ filter,
136+ ...( sort ?. username && { sort : { username : sort . username } } ) ,
137+ } ) ;
138+
139+ const [ members , total ] = await Promise . all ( [ cursor . toArray ( ) , totalCount ] ) ;
140+
141+ return API . v1 . success ( {
142+ members,
143+ count : members . length ,
144+ offset : skip ,
145+ total,
146+ } ) ;
147+ } ,
148+ ) ;
153149
154150async function getRoomFromParams ( params : { roomId ?: string } | { roomName ?: string } ) : Promise < IRoom > {
155151 if (
@@ -1367,10 +1363,9 @@ API.v1.addRoute(
13671363 } ,
13681364) ;
13691365
1370-
13711366export type GroupsHistoryEndpoints = ExtractRoutesFromAPI < typeof groupsEndPoints > ;
13721367
13731368declare module '@rocket.chat/rest-typings' {
13741369 // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
13751370 interface Endpoints extends GroupsHistoryEndpoints { }
1376- }
1371+ }
0 commit comments