Skip to content

Commit

Permalink
Update firestore.rules
Browse files Browse the repository at this point in the history
  • Loading branch information
samtstern committed Sep 30, 2020
1 parent 479cb91 commit 875956f
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions firestore.rules
@@ -1,29 +1,36 @@
rules_version = "2";
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {

// Restaurants:
// - Authenticated user can read
// - Authenticated user can create/update (for demo)
// - Validate updates
// - Deletes are not allowed
// Determine if the value of the field "key" is the same
// before and after the request.
function unchanged(key) {
return (key in resource.data)
&& (key in request.resource.data)
&& (resource.data[key] == request.resource.data[key]);
}

match /databases/{database}/documents {
// Restaurants:
// - Authenticated user can read
// - Authenticated user can create/update (for demo purposes only)
// - Updates are allowed if no fields are added and name is unchanged
// - Deletes are not allowed (default)
match /restaurants/{restaurantId} {
allow read, create: if request.auth != null;
allow read: if request.auth != null;
allow create: if request.auth != null;
allow update: if request.auth != null
&& request.resource.data.name == resource.data.name
allow delete: if false;

&& (request.resource.data.keys() == resource.data.keys())
&& unchanged("name");
// Ratings:
// - Authenticated user can read
// - Authenticated user can create if userId matches
// - Deletes and updates are not allowed
// - Deletes and updates are not allowed (default)
match /ratings/{ratingId} {
allow read: if request.auth != null;
allow create: if request.auth != null
&& request.resource.data.userId == request.auth.uid;
allow update, delete: if false;

}
}
}
}
}
}

0 comments on commit 875956f

Please sign in to comment.