11import { api , Authorization } from '@rocket.chat/core-services' ;
22import type { IRole } from '@rocket.chat/core-typings' ;
33import { Roles , Users } from '@rocket.chat/models' ;
4- import { ajv , isRoleAddUserToRoleProps , isRoleDeleteProps , isRoleRemoveUserFromRoleProps } from '@rocket.chat/rest-typings' ;
4+ import {
5+ ajv ,
6+ isRoleAddUserToRoleProps ,
7+ isRoleDeleteProps ,
8+ isRoleRemoveUserFromRoleProps ,
9+ validateUnauthorizedErrorResponse ,
10+ } from '@rocket.chat/rest-typings' ;
511import { check , Match } from 'meteor/check' ;
612import { Meteor } from 'meteor/meteor' ;
713
@@ -17,18 +23,6 @@ import { API } from '../api';
1723import { getPaginationItems } from '../helpers/getPaginationItems' ;
1824import { getUserFromParams } from '../helpers/getUserFromParams' ;
1925
20- API . v1 . addRoute (
21- 'roles.list' ,
22- { authRequired : true } ,
23- {
24- async get ( ) {
25- const roles = await Roles . find ( { } , { projection : { _updatedAt : 0 } } ) . toArray ( ) ;
26-
27- return API . v1 . success ( { roles } ) ;
28- } ,
29- } ,
30- ) ;
31-
3226API . v1 . addRoute (
3327 'roles.sync' ,
3428 { authRequired : true } ,
@@ -225,38 +219,82 @@ API.v1.addRoute(
225219 } ,
226220) ;
227221
228- const rolesRoutes = API . v1 . get (
229- 'roles.getUsersInPublicRoles' ,
230- {
231- authRequired : true ,
232- response : {
233- 200 : ajv . compile < {
234- users : {
235- _id : string ;
236- username : string ;
237- roles : string [ ] ;
238- } [ ] ;
239- } > ( {
240- type : 'object' ,
241- properties : {
242- users : {
243- type : 'array' ,
244- items : {
245- type : 'object' ,
246- properties : { _id : { type : 'string' } , username : { type : 'string' } , roles : { type : 'array' , items : { type : 'string' } } } ,
222+ const rolesRoutes = API . v1
223+ . get (
224+ 'roles.list' ,
225+ {
226+ authRequired : true ,
227+ response : {
228+ 200 : ajv . compile < {
229+ roles : IRole [ ] ;
230+ } > ( {
231+ type : 'object' ,
232+ properties : {
233+ roles : {
234+ type : 'array' ,
235+ items : {
236+ $ref : '#/components/schemas/IRole' ,
237+ } ,
238+ } ,
239+ success : {
240+ type : 'boolean' ,
241+ enum : [ true ] ,
247242 } ,
248243 } ,
249- } ,
250- } ) ,
244+ required : [ 'roles' , 'success' ] ,
245+ additionalProperties : false ,
246+ } ) ,
247+ 401 : validateUnauthorizedErrorResponse ,
248+ } ,
251249 } ,
252- } ,
250+ async function action ( ) {
251+ const roles = await Roles . find ( { } , { projection : { _updatedAt : 0 } } ) . toArray ( ) ;
253252
254- async ( ) => {
255- return API . v1 . success ( {
256- users : await Authorization . getUsersFromPublicRoles ( ) ,
257- } ) ;
258- } ,
259- ) ;
253+ return API . v1 . success ( { roles } ) ;
254+ } ,
255+ )
256+ . get (
257+ 'roles.getUsersInPublicRoles' ,
258+ {
259+ authRequired : true ,
260+ response : {
261+ 200 : ajv . compile < {
262+ users : {
263+ _id : string ;
264+ username : string ;
265+ roles : string [ ] ;
266+ } [ ] ;
267+ } > ( {
268+ type : 'object' ,
269+ properties : {
270+ users : {
271+ type : 'array' ,
272+ items : {
273+ type : 'object' ,
274+ properties : {
275+ _id : { type : 'string' } ,
276+ username : { type : 'string' } ,
277+ roles : { type : 'array' , items : { type : 'string' } } ,
278+ } ,
279+ } ,
280+ } ,
281+ success : {
282+ type : 'boolean' ,
283+ enum : [ true ] ,
284+ } ,
285+ } ,
286+ required : [ 'users' , 'success' ] ,
287+ additionalProperties : false ,
288+ } ) ,
289+ 401 : validateUnauthorizedErrorResponse ,
290+ } ,
291+ } ,
292+ async function action ( ) {
293+ return API . v1 . success ( {
294+ users : await Authorization . getUsersFromPublicRoles ( ) ,
295+ } ) ;
296+ } ,
297+ ) ;
260298
261299type RolesEndpoints = ExtractRoutesFromAPI < typeof rolesRoutes > ;
262300
0 commit comments