【问题标题】:How can I allow the "owners" of an Org Object in a Firebase RTB schema .read access to all "Users" that are part of the group?如何允许 Firebase RTB 架构中的组织对象的“所有者”对属于该组的所有“用户”进行 .read 访问?
【发布时间】:2020-12-21 06:48:16
【问题描述】:

鉴于以下 Firebase 实时数据库架构:

{
  "Organizations": {
    "A": {
      "name": "org a",
      "users": {
        "1": true,
        "2": true,
        "3": true
      },
      "owners": {
        "1": true,
      }
    },
    "B": {
      "name": "org B",
      "users": {
        "2": true,
        "3": true
      },
      "owners": {
        "2": true,
      }
    },
    "C": {
      "name": "org C",
      "users": {
        "1": true,
        "3": true
      },
      "owners": {
        "3": true
      }
    }
  },
  "Users": {
    "1": {
      "name": "sean",
      "organizations": {
        "A": true,
        "C": true
      }
    },
    "2": {
      "name": "sean",
      "organizations": {
        "A": true,
        "B": true,
      }
    },
    "3": {
      "name": "sean",
      "avatar": "some image url",
      "email": "example@com.com"
      "organizations": {
        "A": true,
        "B": true,
        "C": true
      }
    }
  }
}

使用实时数据库规则,如何允许组织的所有所有者查看组织的用户对象中所有用户的所有用户数据。

换句话说,目标是:通过 RTB 连接将组织的每个用户的所有数据(姓名、电子邮件、头像......)列出给所有者。

我似乎无法辨别如何格式化孩子、数据、孩子等 .write 或 .read 规则来构建一个规则集来完成此操作。感谢您的帮助。

【问题讨论】:

    标签: firebase firebase-realtime-database firebase-security rules


    【解决方案1】:

    要允许该组织的所有者阅读/Organizations/$orgId/users,您需要制定一条规则:

    {
      "rules": {
        "Organizations": {
          "$orgId": {
            "users": {
              ".read": "data.parent().child('owners').child(auth.uid).exists()"
            }
          }
        }
      }
    }
    

    【讨论】:

    • 感谢弗兰克的建议。但是,如果我没记错的话,您的解决方案只允许经过身份验证的用户读取组织对象中用户的 ID。我还需要查看保存在不同“用户”根对象中的所有用户数据(电子邮件、姓名等)。
    • 啊,这不能用你现在的结构来完成。一旦您在安全规则中出现“处于任何”状态,您就会看不出来。为了使规则保持良好运行,此类搜索是不可能的。通常的方法是对数据进行非规范化:因此(在写入时)创建每个用户可以看到的所有用户的列表,基于他们的组织成员资格。
    猜你喜欢
    • 1970-01-01
    • 2011-06-07
    • 2019-12-29
    • 1970-01-01
    • 2015-10-08
    • 2020-09-09
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多