Skip to content

Commit

Permalink
Simplify rules a bit using hasChild() (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
eltoder authored Dec 1, 2024
1 parent adea1f8 commit 2b0bd24
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions database.rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
".validate": "newData.isNumber() && newData.val() == now"
},
"status": {
".write": "auth != null && data.parent().child('users/' + auth.uid).exists() && data.exists() && newData.exists()",
".write": "auth != null && data.parent().hasChild('users/' + auth.uid) && data.exists() && newData.exists()",
".validate": "newData.isString() && (data.val() == 'waiting' && newData.val() == 'ingame' && auth.uid == data.parent().child('host').val())"
},
"users": {
"$userId": {
".write": "auth != null && auth.uid == $userId && data.parent().parent().child('status').val() == 'waiting' && !(root.child('users/' + auth.uid + '/banned').exists() && now < root.child('users/' + auth.uid + '/banned').val())",
".write": "auth != null && auth.uid == $userId && data.parent().parent().child('status').val() == 'waiting' && !(root.hasChild('users/' + auth.uid + '/banned') && now < root.child('users/' + auth.uid + '/banned').val())",
".validate": "!newData.exists() || (newData.isNumber() && newData.val() == now)"
}
},
Expand All @@ -32,8 +32,8 @@
".read": "auth != null",
"events": {
"$eventId": {
".write": "!data.exists() && newData.exists() && auth != null && root.child('games/' + $gameId + '/users/' + auth.uid).exists() && root.child('games/' + $gameId + '/status').val() == 'ingame'",
".validate": "newData.hasChildren(['user', 'time', 'c1', 'c2', 'c3']) && (newData.child('c4').exists() == (root.child('games/' + $gameId + '/mode').val() == 'ultraset'))",
".write": "!data.exists() && newData.exists() && auth != null && root.hasChild('games/' + $gameId + '/users/' + auth.uid) && root.child('games/' + $gameId + '/status').val() == 'ingame'",
".validate": "newData.hasChildren(['user', 'time', 'c1', 'c2', 'c3']) && (newData.hasChild('c4') == (root.child('games/' + $gameId + '/mode').val() == 'ultraset'))",
"user": {
".validate": "newData.isString() && newData.val() == auth.uid"
},
Expand Down Expand Up @@ -61,7 +61,7 @@
"$userId": {
".read": "auth != null",
".write": "auth != null && (auth.uid == $userId || root.child('users/' + auth.uid + '/admin').val() == true)",
".validate": "newData.hasChildren(['color', 'name']) && (newData.child('banned').exists() || !data.child('banned').exists() || root.child('users/' + auth.uid + '/admin').val() == true)",
".validate": "newData.hasChildren(['color', 'name']) && (newData.hasChild('banned') || !data.hasChild('banned') || root.child('users/' + auth.uid + '/admin').val() == true)",
"color": {
".validate": "newData.isString()"
},
Expand Down Expand Up @@ -108,7 +108,7 @@
".read": "auth != null",
".indexOn": ["time", "user"],
"$messageId": {
".write": "auth != null && (!data.exists() || root.child('users/' + auth.uid + '/admin').val() == true) && !(root.child('users/' + auth.uid + '/banned').exists() && now < root.child('users/' + auth.uid + '/banned').val())",
".write": "auth != null && (!data.exists() || root.child('users/' + auth.uid + '/admin').val() == true) && !(root.hasChild('users/' + auth.uid + '/banned') && now < root.child('users/' + auth.uid + '/banned').val())",
".validate": "newData.hasChildren(['user', 'message', 'time'])",
"user": {
".validate": "newData.isString() && newData.val() == auth.uid"
Expand All @@ -129,7 +129,7 @@
".read": "auth != null",
".indexOn": ["time", "user"],
"$messageId": {
".write": "auth != null && (!data.exists() || root.child('users/' + auth.uid + '/admin').val() == true) && !(root.child('users/' + auth.uid + '/banned').exists() && now < root.child('users/' + auth.uid + '/banned').val())",
".write": "auth != null && (!data.exists() || root.child('users/' + auth.uid + '/admin').val() == true) && !(root.hasChild('users/' + auth.uid + '/banned') && now < root.child('users/' + auth.uid + '/banned').val())",
".validate": "newData.hasChildren(['user', 'message', 'time'])",
"user": {
".validate": "newData.isString() && newData.val() == auth.uid"
Expand Down

0 comments on commit 2b0bd24

Please sign in to comment.