Sails.js (0.9v) controllers have policies defined as:
RabbitController: {
'*': false, nurture : 'isRabbitMother', feed : ['isNiceToAnimals', 'hasRabbitFood'] }
is there a way to pass params to these acls eg:
RabbitController: {
'*': false, nurture : 'isRabbitMother(myparam)', feed : ['isNiceToAnimals(myparam1, myparam2)', 'hasRabbitFood(anotherParam)'] }
This may lead to multiple use of these functions for different params. Thanks Arif
I've created a Sails hook that does the job: https://www.npmjs.com/package/sails-hook-parametized-policies
I still need to write the documentation for it, but you can checkout the test folder to see how it works.
You just need to create a file
api/policiesFactories/isNiceTo.js
:in
config/policies.json
:The policies are middleware functions with the signature:
There's no way to specify additional parameters for these functions. However, you could create wrapper functions to create the policies dynamically:
In practice you'd want to separate this code into another file and
require
it, but this should get you started.Check out sails-must.