问题描述
我想限制用户权限,以便普通用户只能读取/写入自己的用户文档。
I would like to restrict the user permissions so that a normal user is only able to read/write its own user document.
我设法设置了写入权限这样用户只能编辑自己的文档(通过设计文档中的validate_doc_update函数)。
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).
现在,我只需要限制用户查看用户列表,或者其他用户文档。如果我将数据库读取权限设置为'_admin'角色,则用户将无法查看自己的文档,这不是我想要的。
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?
推荐答案
不幸的是,每个文档不可能。
但是,如果使用 list函数
,可以执行后查询过滤器,该过滤器基于当前会话用户限制视图查询的结果。 (通过 userCtx
参数)
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 the userCtx
parameter)
这篇关于CouchDB对_users数据库的读/写限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!