From 24c4bd7c4356e22cbab264e5af3c5b84ff2bd22d Mon Sep 17 00:00:00 2001 From: alexayan <773655223@qq.com> Date: Mon, 22 Aug 2016 16:48:55 +0800 Subject: [PATCH 1/2] middleware first argument support function --- lib/acl.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/acl.js b/lib/acl.js index 9851717..32a5432 100644 --- a/lib/acl.js +++ b/lib/acl.js @@ -683,7 +683,11 @@ Acl.prototype.middleware = function(numPathComponents, userId, actions){ if(!numPathComponents){ resource = url; }else{ - resource = url.split('/').slice(0,numPathComponents+1).join('/'); + if(typeof numPathComponents === 'function'){ + resource = numPathComponents.bind(req)(url); + }else{ + resource = url.split('/').slice(0,numPathComponents+1).join('/'); + } } if(!_actions){ From 1b2ae30c6b4ec59831e87c2683327e176c233402 Mon Sep 17 00:00:00 2001 From: alexayan <773655223@qq.com> Date: Mon, 22 Aug 2016 16:58:57 +0800 Subject: [PATCH 2/2] modify middleware arguments assets --- lib/acl.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/acl.js b/lib/acl.js index 32a5432..77f2981 100644 --- a/lib/acl.js +++ b/lib/acl.js @@ -636,9 +636,9 @@ Acl.prototype.clean = function(callback){ Acl.prototype.middleware = function(numPathComponents, userId, actions){ contract(arguments) .params() - .params('number') - .params('number','string|number|function') - .params('number','string|number|function', 'string|array') + .params('number|function') + .params('number|function','string|number|function') + .params('number|function','string|number|function', 'string|array') .end(); var acl = this;