@@ -18,8 +18,7 @@ import type { RateLimiterOptionsToCheck } from 'meteor/rate-limit';
1818import { RateLimiter } from 'meteor/rate-limit' ;
1919import _ from 'underscore' ;
2020
21- import type { PermissionsPayload } from './api.helpers' ;
22- import { checkPermissionsForInvocation , checkPermissions , parseDeprecation } from './api.helpers' ;
21+ import { checkPermissions , parseDeprecation } from './api.helpers' ;
2322import type {
2423 FailureResult ,
2524 ForbiddenResult ,
@@ -42,6 +41,7 @@ import type {
4241import { getUserInfo } from './helpers/getUserInfo' ;
4342import { parseJsonQuery } from './helpers/parseJsonQuery' ;
4443import { authenticationMiddlewareForHono } from './middlewares/authenticationHono' ;
44+ import { permissionsMiddleware } from './middlewares/permissions' ;
4545import type { APIActionContext } from './router' ;
4646import { RocketChatAPIRouter } from './router' ;
4747import { license } from '../../../ee/app/api-enterprise/server/middlewares/license' ;
@@ -856,31 +856,6 @@ export class APIClass<TBasePath extends string = '', TOperations extends Record<
856856 throw new Meteor . Error ( 'invalid-params' , validatorFunc . errors ?. map ( ( error : any ) => error . message ) . join ( '\n ' ) ) ;
857857 }
858858 }
859- if ( shouldVerifyPermissions ) {
860- if ( ! this . userId ) {
861- if ( applyBreakingChanges ) {
862- throw new Meteor . Error ( 'error-unauthorized' , 'You must be logged in to do this' ) ;
863- }
864- throw new Meteor . Error ( 'error-unauthorized' , 'User does not have the permissions required for this action' ) ;
865- }
866- if (
867- ! ( await checkPermissionsForInvocation (
868- this . userId ,
869- _options . permissionsRequired as PermissionsPayload ,
870- this . request . method as Method ,
871- ) )
872- ) {
873- if ( applyBreakingChanges ) {
874- throw new Meteor . Error ( 'error-forbidden' , 'User does not have the permissions required for this action' , {
875- permissions : _options . permissionsRequired ,
876- } ) ;
877- }
878- throw new Meteor . Error ( 'error-unauthorized' , 'User does not have the permissions required for this action' , {
879- permissions : _options . permissionsRequired ,
880- } ) ;
881- }
882- }
883-
884859 if (
885860 this . userId &&
886861 ( await api . processTwoFactor ( {
@@ -935,14 +910,17 @@ export class APIClass<TBasePath extends string = '', TOperations extends Record<
935910 this . router [ method . toLowerCase ( ) as 'get' | 'post' | 'put' | 'delete' ] (
936911 `/${ route } ` . replaceAll ( '//' , '/' ) ,
937912 { ..._options , tags } as TypedOptions ,
938- authenticationMiddlewareForHono ( this , {
939- authRequired : options . authRequired ,
940- authOrAnonRequired : options . authOrAnonRequired ,
941- userWithoutUsername : options . userWithoutUsername ,
942- logger,
943- } ) ,
944- license ( _options as TypedOptions , License ) ,
945- ( operations [ method as keyof Operations < TPathPattern , TOptions > ] as Record < string , any > ) . action ,
913+ [
914+ authenticationMiddlewareForHono ( this , {
915+ authRequired : options . authRequired ,
916+ authOrAnonRequired : options . authOrAnonRequired ,
917+ userWithoutUsername : options . userWithoutUsername ,
918+ logger,
919+ } ) ,
920+ shouldVerifyPermissions && permissionsMiddleware ( _options as TypedOptions ) ,
921+ license ( _options as TypedOptions , License ) ,
922+ ( operations [ method as keyof Operations < TPathPattern , TOptions > ] as Record < string , any > ) . action ,
923+ ] . filter ( Boolean ) ,
946924 ) ;
947925 this . _routes . push ( {
948926 path : route ,
0 commit comments