1. Not edited, but deleted by the author
".write": "!data.exists() || (!newData.exists() && data.child('author') === auth.id)"
2. Sympathy / Upvoting
On the client, use a transaction that allows you to safely increase the value:
ref.transaction(function(currentValue) {
return (currentValue||0)+1;
}, function(error) {
if( error )
else
});
Security is also simple:
".validate": "newData.isNumber() && newData.val() === data.val()+1"
2.5 Securing Unique Votes
, ; , , ; "" : " ? ?"
, , . , .
, , - (, /), , .
:
"votes": {
"$spark_id": {
"$vote": {
".read": "$vote === auth.id",
".write": "$vote === auth.id",
// to allow downvoting in addition to up or delete, just add -1 here
".validate": "newData.val() === 1 || newData.val() === null"
}
}
}
:
".validate": "!root.child('votes').child($spark_id).child(auth.id).exists() && newData.isNumber() && newData.val() === data.val()+1"