我正在编写自定义云功能(官方文档)根据官方文档。
我将自定义函数应用于正确的路径/collection/{document}/subcollection/{subcollectionDocuments}
其中每个 subcollectionDocument
都有 userId
不是零的字段。这些文档没有 uid
字段,但是我在下面的2和4中尝试过。
下面的自定义函数的所有版本(AlterStoreQuestor 1,2,3和4)在云Firestore规则Playground Simulator中生成“在对象上未定义的属性资源”。
我需要将某些内容传递到自定义功能中,还是我犯了其他错误?
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function belongsToRequestor1() {
return
request.auth.uid == resource.data.userId;
}
function belongsToRequestor2() {
return
request.auth.uid == resource.data.uid;
}
function belongsToRequestor3() {
return
request.auth.uid == request.resource.data.userId;
}
function belongsToRequestor4() {
return
request.auth.uid == request.resource.data.uid;
}
…
match /collection/{documents}/subcollection/{subcollectiondocuments} {
allow update: if
belongsToRequestor1();
// or belongsToRequestor2(); or belongsToRequestor3(); or belongsToRequestor4();
…
} }
我不确定如何实现此答案对另一个问题的问题”您想测试使用其字段值的规则。” subcollectionDocuments
中的每个文档都有一个由Firebase自动生成的ID。
更新:按要求添加数据库屏幕截图(带有虚假数据)(properties = collection and评论== subcollection):
感谢您的任何帮助!
I'm writing a custom cloud function (official documentation) in Firestore security rules that checks to make sure the submitting user is the content owner, per the official documentation.
I'm applying the custom function to the correct path /collection/{documents}/subcollection/{subcollectiondocuments}
where every subcollectiondocument
has a userId
field that's not null. These documents do not have a uid
field, but I tried it anyway in 2 and 4 below.
All versions of the custom function below (belongsToRequestor 1,2,3 and 4) generate a "Property resource is undefined on object" error in the Cloud Firestore rules playground simulator.
Do I need to pass something into the custom function, or am I making some other mistake?
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function belongsToRequestor1() {
return
request.auth.uid == resource.data.userId;
}
function belongsToRequestor2() {
return
request.auth.uid == resource.data.uid;
}
function belongsToRequestor3() {
return
request.auth.uid == request.resource.data.userId;
}
function belongsToRequestor4() {
return
request.auth.uid == request.resource.data.uid;
}
…
match /collection/{documents}/subcollection/{subcollectiondocuments} {
allow update: if
belongsToRequestor1();
// or belongsToRequestor2(); or belongsToRequestor3(); or belongsToRequestor4();
…
} }
I'm not sure how to implement this answer to another question to "…enter the path to an actual document that exists if you want to test your rule that uses its field values." Each document in subcollectiondocuments
has an id auto-generated by firebase.
Update: adding database screenshot (with fake data), as requested (properties = collection and reviews == subcollection):

Thanks for any help!
发布评论