Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
} |