gpt4 book ai didi

reference - CouchDB ACL 交叉引用文档

转载 作者:行者123 更新时间:2023-12-02 22:56:46 24 4
gpt4 key购买 nike

假设我有两种类型的文档,其中一种引用另一种,例如“orders”和“order_replies”,后者具有字段“ref”,其中包含订单文档的 ID。

对于我的 validate_doc_update 函数,我希望用户只有在是原始订单的作者时才能够更改 order_reply 文档。

如何在函数中从 ID 为 newDoc.ref 的订单中获取“作者”字段?

这是迄今为止我的验证函数的一部分:

if(userCtx.roles.indexOf('employee') >= 0) {
// [...] other doc types
if (newDoc.type == 'order_reply') {
//newDoc.ref.author is not the proper approach
require((userCtx.name == newDoc.ref.author), "this is not your order reply!");
}
}

最佳答案

将作者 ID 放入订单 ID 中。例如:

  • 订单:{ "_id": "order/jack/1", ... }
  • 订单回复:{ "ref": "order/jack/1", ... }

所以你可以检查:

if (userCtx.roles.indexOf('employee') !== -1) {
if (newDoc.type === 'order_reply') {
require(userCtx.name === newDoc.ref.split('/', 3)[1], "this is not your order reply!");
}
}

如果您有多个作者,请使用“order/author1/author2/.../authorN/ordernum”作为订单的_id并检查:

var parts = newDoc.ref.split('/'),
authors = parts.slice(1, -1);
require(authors.indexOf(userCtx.name) !== -1, "this is not your order reply!");

更新:由于错误 COUCHDB-1229 ,在 doc._id 中使用“/”可能会导致问题。根据您的用例,最好使用其他分隔符,例如“:”。

关于reference - CouchDB ACL 交叉引用文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6737285/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com