diff --git a/packages/plugins/acl/src/server.ts b/packages/plugins/acl/src/server.ts index c083cb064..bce65fbc5 100644 --- a/packages/plugins/acl/src/server.ts +++ b/packages/plugins/acl/src/server.ts @@ -593,12 +593,6 @@ export class PluginACL extends Plugin { return; } - const collection = ctx.db.getCollection(resourceName); - - if (!collection) { - return; - } - if (ctx.status !== 200) { return; } @@ -607,6 +601,12 @@ export class PluginACL extends Plugin { return; } + const collection = ctx.db.getCollection(resourceName); + + if (!collection) { + return; + } + const Model = collection.model; const primaryKeyField = Model.primaryKeyField || Model.primaryKeyAttribute; @@ -667,6 +667,7 @@ export class PluginACL extends Plugin { actionCtx.permission?.can === null && !actionCtx.permission.skip ? null : actionCtx.permission?.parsedParams || {}, + actionCtx, ]); } @@ -676,7 +677,7 @@ export class PluginACL extends Plugin { const allAllowed = []; - for (const [action, params] of actionsParams) { + for (const [action, params, actionCtx] of actionsParams) { if (!params) { continue; } @@ -686,7 +687,10 @@ export class PluginACL extends Plugin { continue; } - const queryParams = collection.repository.buildQueryOptions(params); + const queryParams = collection.repository.buildQueryOptions({ + ...params, + context: actionCtx, + }); const actionSql = ctx.db.sequelize.queryInterface.queryGenerator.selectQuery( Model.getTableName(),