Hi,
I'm having a problem with security rules where I want to restrict `write` on a template to the owning user, but I also want to allow that `user` to "re-assign" the template to another user (change the template user from their UID to another users UID). So, the desired behavior is that once the owning user has "re-assigned" the template to another user, only the new owning user can make updates (`write`) to the template.
In the ember model, the template belongsTo a user.
So, my rules should allow `write` under the following conditions:
- IF authenticated and user is creating a new template and the template user is the currently authenticated user OR
- IF authenticated and user is updating an existing template and the existing template user is the currently authenticated user
Here is the relevant section of my `rules.json` file:
"templates": {
".read": "auth !== null",
"$template_id": {
".write": "auth !== null && ((!data.exists() && newData.child('user').val() == auth.uid) || (data.exists() && data.child('user').val() == auth.uid))",
".validate": "newData.hasChildren(['user', 'createdAt', 'updatedAt'])"
},
},
The rules above correctly allow a user to create and delete a template they have created, but it fails with "permission denied" when the user who owns the template tries to change the 'user' to a different user.
In reading the security docs, my interpretation is that `data` should be the value *before* it is changed, thus `data.child('user').val()` *should* match the current user and allow it to change.
It seems like this should work, but it doesn't :( Is what I'm trying to do possible?
Thanks for any assistance!