1

Ok I keep trying to understand the Wild Card behavior in the Firebase Rules and must ask, Will this Firebase Rules json work when it comes to the Wilde card as root, (down below is the Firebase data json as a ref)

    {
      "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: (a snapshot of the 240 country nods)

 "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": ""
              }
          }, 
            .............
        },

what I want to achieve with this is to not have to write 240 rules, one for each country, and like this create one rule for all, since they are the same. Take special notice in that I use the $countries in the "admins" Rule and "STREETS_ID", can I do that? Probable a hole lot of errors here ..mmm :)

Tord Larsen
  • 2,670
  • 8
  • 33
  • 76

0 Answers0