Skip to content

Commit

Permalink
fix: native policies were transform into function
Browse files Browse the repository at this point in the history
  • Loading branch information
mastilver committed Jun 21, 2015
1 parent 4785027 commit b317cf8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ function parsePolicies(input){

/*
input [Esprima Object]
fromFactory [Boolean] set to true the result will be interpreted by a factory
*/
function parseEsprima(input){
function parseEsprima(input, fromFactory){

var type = input.type;

Expand All @@ -62,7 +63,11 @@ function parseEsprima(input){

var policyName = input.name;

return require(sails.config.paths.policies + '/' + policyName);
if(fromFactory){
return require(sails.config.paths.policies + '/' + policyName);
}

return policyName;
}


Expand All @@ -71,7 +76,10 @@ function parseEsprima(input){
var factoryName = input.callee.name;

var factory = require(sails.config.paths.policiesFactories + '/' + factoryName);
var args = input.arguments.map(this.parseEsprima, this);

var args = input.arguments.map(function(arg){
return this.parseEsprima(arg, true);
}, this);

return factory.apply(this, args);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sails-hook-parametized-policies",
"version": "0.2.0",
"version": "0.2.1",
"description": "",
"main": "index.js",
"directories": {
Expand Down
3 changes: 3 additions & 0 deletions test/basicSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ describe('parametized policies hook - basic', function(){
});

it('should not modify non function policies', function(done){

sails.config.policies.MainController.ok.should.be.equal('accept');

request(sails.hooks.http.app)
.get('/ok')
.expect(200, done);
Expand Down

0 comments on commit b317cf8

Please sign in to comment.