【问题标题】:Is there a way to differentiate between query and data conditions有没有办法区分查询和数据条件
【发布时间】:2020-05-11 13:01:03
【问题描述】:

我有一个名为documentations 的feathersjs 服务。修补documentation 时,用户只能将editing 字段设置为他自己的user._idnull。另外用户只能修补自己公司的documenations

我已将我的权限存储在 MongoDB 数据库中:

...
{
  "action": "patch",
  "subject": "documentation",
  "fields": ["editing", "sections", "title", "published"],
  "conditions": {
    "company": "${user.belongsTo}"
  }
}
...

有没有办法用 CASL 实现 editing 字段逻辑?

有什么方法可以区分查询条件和数据条件吗?

【问题讨论】:

    标签: casl


    【解决方案1】:

    坦率地说,这种逻辑在我看来是 BL 关注而不是权限关注。但是你也可以用 CASL 做类似的事情,为editing 字段创建一个单独的规则:

    can(“update”, “documentation”, { company: ..., editing: { $in: [null, user.id] } }, [“editing”])
    

    所以,每次更新 editing 时只需检查权限

    【讨论】:

      猜你喜欢
      • 2020-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-15
      • 1970-01-01
      • 2018-12-20
      • 1970-01-01
      相关资源
      最近更新 更多