【问题标题】:Firebase: allow all users to create but only owners to edit while allowing users to "join" roomsFirebase:允许所有用户创建但只有所有者可以编辑,同时允许用户“加入”房间
【发布时间】:2017-12-13 10:49:06
【问题描述】:

在我的应用中,我有任何人都可以创建的公共群组,但只能由创建者/所有者编辑(编辑群组元数据)。 此外,任何经过身份验证的用户都可以加入群组(并由已加入的用户离开)。

我有以下测试数据:

"public_groups" : {
    "group1" : {
      "metadata" : {
        "name" : "swag2017",
        "numUsers" : 2,
        "owner" : "user1",
        "price" : 500
      },
      "users" : {
        "user1" : "",
        "user2" : ""
      }
    }
  }

我有以下规则:

"public_groups": {
    ".read": "auth !== null",
    //Either group id is new or writer is the owner of the group
    "$groupId": {
      ".write": "auth !== null && (!data.exists() || data.child('metadata').child('owner').val() === auth.uid)",
      "metadata": {
        ".validate": "data.child('owner').val() == auth.uid"
      },
      "users": {
        "$userId": {
          ".validate": "auth !== null && (!data.exists() || $userId == auth.uid)"
        }
      }
    }
},

一切正常,除了不允许新用户加入群组(因为它只能由所有者编辑)。

被规则屏蔽了

".write": "auth !== null && (!data.exists() || data.child('metadata').child('owner').val() === auth.uid)"

是否可以在允许新用户加入群组的同时放弃所有限制?或者我应该重组我的数据吗?

【问题讨论】:

    标签: firebase firebase-realtime-database


    【解决方案1】:

    可能会重组。 IMO,您应该从 public_groups 节点中提取您的组成员资格记录,并为每个包含该组成员资格的组创建一个顶级 group_membership 节点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-23
      • 1970-01-01
      • 2021-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多