我可以使用FireBase规则通配符作为根

时间:2016-11-03 16:15:38

标签: android wildcard android-database android-security

好的,我一直在尝试了解Firebase规则中的Wild Card行为,并且必须询问,这个Firebase规则json在以root身份登陆Wilde卡时是否有效(下面是Firebase数据json作为ref)< / p>

    {
      "rules": {
        "$countries": {
          "admins": {
            // only admins can access this and must have is_admin=true TODO: must add super-admin 
            ".read": "root.child($countries+'/admins').child(auth.uid).child('is_admin').val() === true",
            ".write":"root.child($countries+'/admins').child(auth.uid).child('is_admin').val() === true"
          },
          "STREETS_ID": {
            ".read": "auth != null",
            "$PathKey": {
              // Allow write if the STREET_ADDRESS exit and !data.exists()
              ".write": "root.child($countries+'/STREET_ADDRESS').hasChild(newData.val()) && !data.exists()",
              ".indexOn": ".key",
              ".validate": "newData.isString()"
            }
          },
          "STREET_ADDRESS": {
            // anybody can create new street, but not overwrite existing ones.
            ".read": "auth != null",
            ".write": "!data.exists() && auth != null"
          },
          "USER_LIST": {
            ".read": "auth != null",
            ".write": "auth != null"
          },
          "CHAT_LIST": {
            ".read": "auth != null",
            ".write": "auth != null"
          },
          "CHAT_MEMBERS": {
            ".read": "auth != null",
            ".write": "auth != null"
          },
          "CHAT_MESSAGES": {
            ".read": "auth != null",
            ".write": "auth != null"
          }
        }
      }
    }

Firebase Data json :( 240个国家的快照点头)

 "UA": {
    "name": "Ukraine"
  },
  "AE": {
    "name": "United Arab Emirates"
  },
  "GB": {
    "name": "United Kingdom",
      "STREET_ID": {......    
  },
  "US": {
    "name": "United States",
      "ADMINS": {
        "34324324324-2343243ee24-23432dffdd3-3442ff342": {
         "name" : "Bob Doe",
         "is-admin": "true"
       },
        "232131232323-2322rr3-3231233rre54-343434erer3": {
         "name" : "Erik Nilsson",
         "is_admin": "true"
         }
      },
      "STREET_ID": {
         "US/California/Orange County/Orange/3138 E Maple Ave": "-K1234567",
         "US/California/Orange County/Orange/3139 E Maple Ave": "-K12334rt"
        },
        "STREET_ADDRESS": {
          "-K1234567": {
              "path": "US/California/Orange County/Orange/3138 E Maple Ave",
              "values": {
                "call": false,
                "id": "",
                "start_date": "",
                "end_date": "",
                "type": "",
                "name": ""
              }
          }, 
            .............
        },

我想要实现的目标是不必编写240个规则,每个国家一个,并且像这样为所有人创建一个规则,因为它们是相同的。请特别注意,我使用$countries规则中的"admins""STREETS_ID",我可以这样做吗?可能这里有很多错误..mmm :)

0 个答案:

没有答案