@@ -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 { 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' ;
@@ -781,8 +781,6 @@ export class APIClass<TBasePath extends string = '', TOperations extends Record<
781781
782782 const operations = endpoints ;
783783
784- const shouldVerifyPermissions = checkPermissions ( options ) ;
785-
786784 // Allow for more than one route using the same option and endpoints
787785 if ( ! Array . isArray ( subpaths ) ) {
788786 subpaths = [ subpaths ] ;
@@ -856,31 +854,6 @@ export class APIClass<TBasePath extends string = '', TOperations extends Record<
856854 throw new Meteor . Error ( 'invalid-params' , validatorFunc . errors ?. map ( ( error : any ) => error . message ) . join ( '\n ' ) ) ;
857855 }
858856 }
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-
884857 if (
885858 this . userId &&
886859 ( await api . processTwoFactor ( {
@@ -941,6 +914,7 @@ export class APIClass<TBasePath extends string = '', TOperations extends Record<
941914 userWithoutUsername : options . userWithoutUsername ,
942915 logger,
943916 } ) ,
917+ permissionsMiddleware ( _options as TypedOptions ) ,
944918 license ( _options as TypedOptions , License ) ,
945919 ( operations [ method as keyof Operations < TPathPattern , TOptions > ] as Record < string , any > ) . action ,
946920 ) ;
0 commit comments