我很难找到一种方法来隐藏所有人的用户电子邮件,除了所有者(用户只能访问他的电子邮件)。有没有办法为某些角色隐藏某个文档字段?
这是我发现的一个示例,它创建了一个可以动态访问整个User
集合的角色:
CreateRole({
name: "tier1_role",
membership: {
resource: Collection("User"),
predicate: Query(
Lambda("userRef",
// User attribute based rule:
// It grants access only if the User has TIER1 role.
// If so, further rules specified in the privileges
// section are applied next.
Equals(Select(["data", "role"], Get(Var("userRef"))), "TIER1")
)
)
},
privileges: [
{
// Note: 'allUsers' Index is used to retrieve the
// documents from the File collection. Therefore,
// read access to the Index is required here as well.
resource: Index("allUsers"),
actions: { read: true }
}
]
})
我尝试对其进行一些更改,但无法设置字段级访问。
假设我在下面使用 GraphQL 模式设置了 FaunaDB。
enum UserRole {
TIER1
}
type User {
email: String! @unique
username: String! @unique
role: UserRole!
}
type Query {
allUsers: [User!]
}
type Mutation {
addUsers(new_users: [UserInput]): [User]
@resolver(name: "add_users", paginated: false)
}
如何创建一个 FaunaDB 角色,以使查询结果数组中的所有用户(当前用户除外allUsers
)都没有email
字段?
我可以将User
集合分为两种:一种是公开的,另一种可供文档所有者访问,但这听起来是错误的。
我是 noSQL 概念的新手,所以也许我从错误的角度看待这个问题?