From 16031df55d344e033cd78055b96f23fa5808585e Mon Sep 17 00:00:00 2001 From: Chia Yu Pai Date: Thu, 2 Apr 2015 16:18:08 +0800 Subject: [PATCH 1/6] support room router --- lib/acl.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/acl.js b/lib/acl.js index cfd06ff..6864ef8 100644 --- a/lib/acl.js +++ b/lib/acl.js @@ -584,7 +584,7 @@ Acl.prototype.middleware = function(numPathComponents, userId, actions){ return; } - url = req.url.split('?')[0]; + url = req.originalUrl.split('?')[0]; if(!numPathComponents){ resource = url; }else{ @@ -789,5 +789,3 @@ function allowsBucket(role){ exports = module.exports = Acl; - - From 740136cd96a8de9f54cedb9f28a1cbabf8fdffdf Mon Sep 17 00:00:00 2001 From: Chia Yu Pai Date: Mon, 6 Apr 2015 04:44:05 +0800 Subject: [PATCH 2/6] Hotfix: support params on memory --- lib/memory-backend.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/memory-backend.js b/lib/memory-backend.js index c539c48..703f2f5 100644 --- a/lib/memory-backend.js +++ b/lib/memory-backend.js @@ -96,6 +96,7 @@ MemoryBackend.prototype = { var self = this; values = makeArray(values); + bucket = bucket.replace(/(:[^\/]*)/g, '[^\\/]'); // Hotfix: support params transaction.push(function(){ if(!self._buckets[bucket]){ From ac4e5c9e7eb3b068caeac23675bcc069c4dc73c7 Mon Sep 17 00:00:00 2001 From: Chia Yu Pai Date: Fri, 10 Apr 2015 05:50:39 +0800 Subject: [PATCH 3/6] add asterisk to correct match parameters in url --- lib/memory-backend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/memory-backend.js b/lib/memory-backend.js index 703f2f5..b076013 100644 --- a/lib/memory-backend.js +++ b/lib/memory-backend.js @@ -96,7 +96,7 @@ MemoryBackend.prototype = { var self = this; values = makeArray(values); - bucket = bucket.replace(/(:[^\/]*)/g, '[^\\/]'); // Hotfix: support params + bucket = bucket.replace(/(:[^\/]*)/g, '[^\\/\*]'); // Hotfix: support params transaction.push(function(){ if(!self._buckets[bucket]){ From f7ed1e21fa3dacc4a8a1024759bb13a2582c35be Mon Sep 17 00:00:00 2001 From: Chia Yu Pai Date: Fri, 10 Apr 2015 06:02:07 +0800 Subject: [PATCH 4/6] add asterisk to correct match parameters in url --- lib/memory-backend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/memory-backend.js b/lib/memory-backend.js index 703f2f5..b076013 100644 --- a/lib/memory-backend.js +++ b/lib/memory-backend.js @@ -96,7 +96,7 @@ MemoryBackend.prototype = { var self = this; values = makeArray(values); - bucket = bucket.replace(/(:[^\/]*)/g, '[^\\/]'); // Hotfix: support params + bucket = bucket.replace(/(:[^\/]*)/g, '[^\\/\*]'); // Hotfix: support params transaction.push(function(){ if(!self._buckets[bucket]){ From 29fe34407bf3a79e61dac597b19d16879ceadfbf Mon Sep 17 00:00:00 2001 From: Chia Yu Pai Date: Fri, 10 Apr 2015 06:02:41 +0800 Subject: [PATCH 5/6] fixed regexp --- lib/memory-backend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/memory-backend.js b/lib/memory-backend.js index b076013..bbec9c2 100644 --- a/lib/memory-backend.js +++ b/lib/memory-backend.js @@ -96,7 +96,7 @@ MemoryBackend.prototype = { var self = this; values = makeArray(values); - bucket = bucket.replace(/(:[^\/]*)/g, '[^\\/\*]'); // Hotfix: support params + bucket = bucket.replace(/(:[^\/]*)/g, '[^\\/]\*'); // Hotfix: support params transaction.push(function(){ if(!self._buckets[bucket]){ From 6b45596239030efa860646fa591834882a06a0c2 Mon Sep 17 00:00:00 2001 From: Chia Yu Pai Date: Wed, 15 Apr 2015 05:05:41 +0800 Subject: [PATCH 6/6] remove custom action to avoiding bugs --- lib/acl.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/acl.js b/lib/acl.js index 6864ef8..8f3b6bc 100644 --- a/lib/acl.js +++ b/lib/acl.js @@ -542,12 +542,11 @@ Acl.prototype.clean = function(callback){ Express Middleware */ -Acl.prototype.middleware = function(numPathComponents, userId, actions){ +Acl.prototype.middleware = function(numPathComponents, userId){ contract(arguments) .params() .params('number') .params('number','string|number|function') - .params('number','string|number|function', 'string|array') .end(); var acl = this; @@ -565,6 +564,8 @@ Acl.prototype.middleware = function(numPathComponents, userId, actions){ resource, url; + var actions = req.method.toLowerCase(); + // call function to fetch userId if(typeof userId === 'function'){ _userId = userId(req, res); @@ -591,10 +592,6 @@ Acl.prototype.middleware = function(numPathComponents, userId, actions){ resource = url.split('/').slice(0,numPathComponents+1).join('/'); } - if(!actions){ - actions = req.method.toLowerCase(); - } - acl.logger?acl.logger.debug('Requesting '+actions+' on '+resource+' by user '+_userId):null; acl.isAllowed(_userId, resource, actions, function(err, allowed){