The ruleset protects the user's entry like follows:
- only him or an admin can read his data
- only an admin can update a user's permissions
- a user can update all his data, unless he sets the permissions object
The rule looks like:
match /users/{userId} {
allow read: if isCurrentUser(userId) || isAdmin();
allow write: if (isCurrentUser(userId) && !isModifyingPermissions()) || isAdmin();
function isModifyingPermissions(){
return request.resource.data['permissions'] != null;
}
}
I'm stuck with the isModifiyingPermissions()
function. It properly refuses a write in case the request has a value for the permissions
property. However, the rule crashes if no permissions
property is provided, stating the following:
Error: simulator.rules line [19], column [15]. Property permissions is undefined on object.
How can one write "check presence of a property on request resource" ?