【发布时间】:2019-12-24 19:16:03
【问题描述】:
我有一个 NSFW 系统,它会检查文档是否为 NSFW,如果是,则将文档字段 isNSFW 更新为 true。这很好用,但现在我不想通过设置规则向所有用户显示这些文档,而不是查询出来。
这是我拥有的,但它不起作用...... javascript
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
match /users/{user} {
allow read: if true;
}
match /docs/{doc} { // THIS HERE
allow read: if resource.data.isNSFW == false;
}
}
我尝试在resource 之前添加request.,但还是不行。
更新: javascript
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// match /{document=**} {
// allow read, write: if request.auth.uid != null;
// }
match /users/{user} {
allow read: if currentUser().uid != null;
}
match /docs {
allow read: if existingData().users[currentUser().uid] == false;
}
match /docs/{doc} {
allow write: if currentUser().uid != null;
}
}
// MARK - Funcs ---------------
function existingData() {
return resource.data
}
function incomingData() {
return request.resource.data
}
function currentUser() {
return request.auth
}
function isSignedIn() {
return request.auth != null;
}
}
得到错误:
Listen for Query(docs where users.`40S88coPQObEWSeiYMZIJlIKJkI2` == false order by __name__) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
【问题讨论】:
-
如果没有看到您的代码,就不可能确定它为什么不起作用。但请记住:规则本身并不是过滤器。您的代码还需要显式查询
isNSFW为false的文档。
标签: google-cloud-firestore firebase-security