Ari*_*rif 10 parameters acl controllers policies sails.js
Sails.js(0.9v)控制器的策略定义为:
RabbitController:{
Run Code Online (Sandbox Code Playgroud)'*': false, nurture : 'isRabbitMother', feed : ['isNiceToAnimals', 'hasRabbitFood'] }
有没有办法将params传递给这些acls,例如:
RabbitController:{
Run Code Online (Sandbox Code Playgroud)'*': false, nurture : 'isRabbitMother(myparam)', feed : ['isNiceToAnimals(myparam1, myparam2)', 'hasRabbitFood(anotherParam)'] }
这可能会导致这些函数多次用于不同的参数.谢谢Arif
sgr*_*454 13
策略是具有签名的中间件功能:
    function myPolicy (req, res, next)
无法为这些功能指定其他参数.但是,您可以创建包装函数以动态创建策略:
    function policyMaker (myArg) {
      return function (req, res, next) {
        if (req.params('someParam') == myArg) {
          return next();
        } else {
          return res.forbidden();
        }
      }
    }
    module.exports = {
      RabbitController: {
        // create a policy for the nurture action
        nurture: policyMaker('foo'),
        // use the policy at 
        // /api/policies/someOtherPolicy.js for the feed action
        feed: 'someOtherPolicy'
      }
    }
在实践中,您希望将此代码分离到另一个文件中require,但这应该让您开始.
| 归档时间: | 
 | 
| 查看次数: | 3105 次 | 
| 最近记录: |