elixirlabsinc / endslaverynow

Creating the End Slavery Now project
2 stars 0 forks source link

Click views #25

Open DanCurrie15 opened 5 years ago

pedanticantic commented 5 years ago

The definition of the rules before I started (in case I lose my own backup):

{
  "rules": {
    ".read": true,
    ".write": "auth !== null",
    "users": {
      ".read": "auth !== null",
      ".write": "auth !== null"
    }
  }
}
pedanticantic commented 5 years ago

I have done this work now - see the click views PR.

I've already updated the rules (I assume only on the development database) because it won't break anything. They are:

{
  "rules": {
    "products": {
      "$product": {
        ".write": true,
        "purchaseURlClicks": {
          ".validate": true
        },
        "$other": {
          ".validate": "auth !== null || data.val() === newData.val()"
        }
      }
    },
    ".read": true,
    ".write": "auth !== null",
    "users": {
      ".read": "auth !== null",
      ".write": "auth !== null"
    }
  }
}

The new rules are slightly more complicated that I wanted, but they're not too bad. In English, the above says you can edit a field if any of these are true:

This allows a user who is not logged in, to save a product record with just the click count changed.