具有arrays/list属性的Firebase安全规则语法

具有arrays/list属性的Firebase安全规则语法,firebase,google-cloud-firestore,firebase-security,Firebase,Google Cloud Firestore,Firebase Security,在路径为“organizations”的Firebase Firestore集合中,每个文档都包含可以更新或删除该文档的用户的字符串userID列表 export interface Organization{ name?: string, owners: string[] } 我想创建一个Firebase安全规则,确保只有具有此列表中uid的登录用户才能编辑或删除该对象。不确定合适的语法 service cloud.firestore { match /databases/{da

在路径为“organizations”的Firebase Firestore集合中,每个文档都包含可以更新或删除该文档的用户的字符串userID列表

export interface Organization{
  name?: string,
  owners: string[]
}
我想创建一个Firebase安全规则,确保只有具有此列表中uid的登录用户才能编辑或删除该对象。不确定合适的语法

service cloud.firestore {
  match /databases/{database}/documents {
    match /organizations/{organization} {
      allow read: if true;
      allow create: if request.auth != null;

      /// What should be the syntax here?
      allow update, delete: if request.auth != null && (request.auth.uid in resource.data.owners); // <--------- What should be the syntax for this line?

    }
service cloud.firestore{
匹配/databases/{database}/documents{
匹配/组织/{organization}{
允许读取:如果为真;
允许创建:if request.auth!=null;
///这里的语法应该是什么?

允许更新,删除:if request.auth!=null&&(resource.data.owners中的request.auth.uid);//好的,在这里回答我自己的问题,以防对其他人有用

看起来上面的“in”语法确实有效,尽管这是一个完全的猜测,而且我在firebase安全角色文档中找不到任何关于它的文档

最终代码:

service cloud.firestore {
  match /databases/{database}/documents {
    match /organizations/{organization} {
      allow read: if true;
      allow create: if request.auth != null;
      allow update, delete: if (request.auth != null) && (request.auth.uid in resource.data.owners); 
    }

为什么要在resource.data.owner中添加
request.auth.uid
?它似乎已经通过了
request.auth!=null
条件,对吧?必须确保用户对该特定文档有编辑权限!:-)而不是使用
&
而不是
|
。现在任何用户都可以编辑:oLike@ThomasvanBroekhoven said、 但它似乎已经修复了。否则,您可以用编程语言以编程方式执行此操作,以确保您了解正确的规则。祝您好运!