Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click views #25

Open
DanCurrie15 opened this issue Jul 27, 2019 · 2 comments
Open

Click views #25

DanCurrie15 opened this issue Jul 27, 2019 · 2 comments
Assignees

Comments

@DanCurrie15
Copy link

No description provided.

@pedanticantic
Copy link
Contributor

pedanticantic commented Aug 6, 2019

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
Copy link
Contributor

pedanticantic commented Aug 6, 2019

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:

  • you are logged in
  • you are setting the value of the purchaseURlClicks field in a product
  • you are setting another field in products (not purchaseURlClicks) and are not changing its value

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants