I\'m trying to create an application which allows users to collaborate on lists. Every user needs to be invited in order to be able to work on the list.
I structured
I was able to figure it out.
I changed the data structure to this:
list
list_1
owner: owner@company.com
writeAccess: [user1@company.com, user2@company.com]
id
name
items:
item_1:
id:
name:
...
Then the database rules like this are working:
service cloud.firestore {
match /databases/{database}/documents {
match /lists/{listId} {
// Allow RW on lists for owner, shared user or for everyone if it's a new list
allow read, write: if resource.data.owner == request.auth.token.email ||
request.auth.token.email in resource.data.writeAccess ||
!exists(/databases/$(database)/documents/lists/$(listId))
}
match /lists/{listId}/items/{itemId} {
// Allow RW on item for owner or shared user of parent list
allow read, write: if get(/databases/$(database)/documents/lists/$(listId)).data.owner == request.auth.token.email ||
request.auth.token.email in get(/databases/$(database)/documents/lists/$(listId)).data.writeAccess ||
!exists(/databases/$(database)/documents/lists/$(listId)) // Needed for new lists. Because lists and items are created in a batch
}
}
}