DishDelish/dishdelish-app

View on GitHub
database.rules.json

Summary

Maintainability
Test Coverage
{
  "rules": {
    "recipes": {
      ".indexOn": ["recipeName", "userName", "cookTime", "prepTime", "likes", "numRatings"]
    },
    "favorites": {
      "$user_id": {
        ".indexOn": [".value"],
        ".write": "$user_id === auth.uid"
      }
    },
    "help": {
      // Allow anyone to read from this node
      ".read": true,
      // Index each location's geohash for faster querying
      ".indexOn": [
        "g"
      ],
      // Schema validation
      "$key": {
        // Allow anyone to add or update keys in the GeoFire index, but not remove them
        ".write": "$key === auth.id && newData.exists()",
        // Key validation
        ".validate": "(newData.hasChildren(['g', 'l']) || data.hasChildren(['g', 'l'])) && newData.getPriority().length <= 22 && newData.getPriority().length > 0",
        // Geohash validation
        "g": {
          ".validate": "newData.val() == newData.parent().getPriority()"
        },
        // Location coordinates validation
        "l": {
          "0": {
            ".validate": "newData.isNumber() && newData.val() >= -90 && newData.val() <= 90"
          },
          "1": {
            ".validate": "newData.isNumber() && newData.val() >= -180 && newData.val() <= 180"
          },
          "$other": {
            ".validate": false
          }
        },
        "offered": {
          ".read": true,
          ".write": "$key === auth.id"
        }
      }
    },
    ".read": true,  //Allow read and write access to anyone 
    ".write": true,  //Not recommended for release production 
  }
}