Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 正在创建firebase规则,以向所有者授予写入权限,并向提供的电子邮件授予读取权限_Android_Firebase_Firebase Realtime Database_Firebase Security - Fatal编程技术网

Android 正在创建firebase规则,以向所有者授予写入权限,并向提供的电子邮件授予读取权限

Android 正在创建firebase规则,以向所有者授予写入权限,并向提供的电子邮件授予读取权限,android,firebase,firebase-realtime-database,firebase-security,Android,Firebase,Firebase Realtime Database,Firebase Security,我有如下的数据结构,如果需要的话,我准备重新构造,以实现我的目标。 我希望所有者能够读或写,并且在“sharedWithEmail”键中具有邮件Id的用户能够读取列表 "root_node" : { "firebaseUid1" : { "-Kb5L4zvfgscWdDC9utF" : { "data1" : 1, "data2" : "abcd", "sharedWithEmail" : "abc@gmail.com", "userM

我有如下的数据结构,如果需要的话,我准备重新构造,以实现我的目标。 我希望所有者能够读或写,并且在“sharedWithEmail”键中具有邮件Id的用户能够读取列表

"root_node" : {
  "firebaseUid1" : {
    "-Kb5L4zvfgscWdDC9utF" : {
      "data1" : 1,
      "data2" : "abcd",
      "sharedWithEmail" : "abc@gmail.com",
      "userMail" : "user1@gmail.com"
    },
    "-Kb5sddvfgscWdDC9utF" : {
      "data1" : 2,
      "data2" : "abcd",
      "sharedWithEmail" : "123@gmail.com",
      "userMail" : "user1@gmail.com"
    },
    "-Kb5sddvfgscWdDC9utF" : {
      "data1" : 3,
      "data2" : "abcd",
      "sharedWithEmail" : "blabla@gmail.com",
      "userMail" : "user1@gmail.com"
    }
  }
  {
  "firebaseUid2" : {
    "-Kb5L4zvfgscWdDC9utF" : {
      "data1" : 1,
      "data2" : "abcd",
      "sharedWithEmail" : "1@gmail.com",
      "userMail" : "user2@gmail.com"
    },
    "-Kb5sddvfgscWdDC9utF" : {
      "data1" : 2,
      "data2" : "abcd",
      "sharedWithEmail" : "1@gmail.com",
      "userMail" : "user2@gmail.com"
    },
    "-Kb5sddvfgscWdDC9utF" : {
      "data1" : 3,
      "data2" : "abcd",
      "sharedWithEmail" : "b2@gmail.com",
      "userMail" : "user2@gmail.com"
    }

在您当前的结构中,您可以测试用户是否有权访问特定帖子,因为该帖子与他们的电子邮件共享:

{
  "rules": {
    "root_node": {
      "$uid": {
        "$postid": {
          ".read": "auth.token.email === child('sharedWithEmail').val()"
        }
      }
    }
  }
}

但使用这种结构,无法测试用户是否有权访问特定用户的所有帖子,因为您无法在定义安全规则的路径下搜索节点。

谢谢Frank的回答,所以,你能建议我使用什么样的结构来实现这个功能吗?在这个功能中,只有所有者才允许写和读,而具有“sharedWithEmail”键的用户也可以读。这就是这个答案所显示的。如果不是你想要的,请用不同的词描述问题。或者更好的方法是:显示:什么写入操作应该成功,什么操作应该失败?我的应用程序具有通过提供邮件id与任何人共享项目的功能。同时,我还希望共享该项目的人能够访问该项目。现在,请建议我如何实现这种行为。非常感谢你的努力。这就是我答案中的规则所达到的目的,不是吗?你试过了吗?什么操作产生了不想要的结果?这似乎不起作用,如果您有其他解决方案,请让我知道。