CouchDB 对 _users 数据库的读/写限制
我想限制用户权限,以便普通用户只能读/写自己的用户文档。
我设法设置写入权限,以便用户只能编辑自己的文档(通过设计文档中的 validate_doc_update 函数)。
现在我只需限制用户查看用户列表或其他用户文档即可。如果我将数据库读取权限设置为“_admin”角色,那么用户将无法查看自己的文档,这不是我的意图。
这可以以更通用的方式完成吗?即设置读取权限,使用户只能读取数据库中的某些特定文档?
I would like to restrict the user permissions so that a normal user is only able to read/write its own user document.
I managed to set the write permissions such that a user can only edit their own document (via the validate_doc_update function in the design document).
Now I only have to limit a user from viewing the user list or other user documents. If I set the database read permissions to the '_admin' role, then the user will not be able to view their own document, which it's not what I intend.
Can this be done in a more general way? I.e. to set read permissions such that a user is able to read only some specific documents in the database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,每个文档的读取控制不可能。
但是,如果您使用
列表函数
,您可以执行“查询后过滤器”,根据当前会话用户限制视图查询的结果。 (通过userCtx
参数)Unfortunately, per-document read control is not possible.
However, if you use a
list function
you can perform a "post-query filter" that limits the results of a view query based on the current session user. (via theuserCtx
parameter)在 CouchDB 中,创建一个新数据库的成本很低,而且它的设计目的是使数据尽可能接近需要它的用户。
因此,建议的方法是为每个用户建立一个数据库。
In CouchDB creating a new database is cheap and it was designed to keep the data as close as possible to the user who needs it.
So the suggested approach is to have one database for each user.