【问题标题】:Sails.js - protect blueprint associations using policiesSails.js - 使用策略保护蓝图关联
【发布时间】:2015-02-14 11:29:22
【问题描述】:

为了在模型之间创建多对多关联,我使用蓝图访问以下内容:

/api/item/1/tags/2


如何使用策略保护此操作?

此操作似乎不符合任何查找/创建/更新/销毁策略。

【问题讨论】:

    标签: sails.js waterline


    【解决方案1】:

    检查一下:

    module.exports.routes = {
    
      //Set blueprints
      'GET /findAllUsers': {model: 'user', blueprint: 'find'},
      'GET /user/findAll': {blueprint: 'find'}
      'GET /user/findAll': {blueprint: 'find', model: 'pet'}
      // Set policies in routes
      '/foo': {policy: 'myPolicy'}
      // Mix of blueprints and policies
      'GET /mix-of-both': [
         {policy: 'isLoggued'},
         {blueprint: 'find', model: 'tag'}
       ]
    }  
    

    查看官方文档:http://sailsjs.org/#/documentation/concepts/Routes/RouteTargetSyntax.html

    希望对你有帮助!

    【讨论】:

    • 请注意,策略配置应始终出现在 控制器配置之前。所以你的/mix-of-both 配置应该有相反的顺序,你的/foo 配置应该有一个控制器或蓝图配置链接到它。这个想法是运行策略,然后如果通过,则运行其他一些业务逻辑。
    • 起来!你说得对,现在已经修好了。谢谢:)
    【解决方案2】:

    这里不需要自定义路由;您所指的蓝图称为populate,因此可以在您的config/policies.js 中使用以下命令对其进行保护:

    ItemController: {
    
      populate: 'somePolicy'
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-01
      • 2017-07-13
      • 2015-06-07
      相关资源
      最近更新 更多