Last active
July 27, 2024 00:35
-
-
Save katowulf/01d4d0792fc6a3e4fa0af465e7c5030f to your computer and use it in GitHub Desktop.
Revisions
-
Kato Richardson revised this gist
May 27, 2020 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ // docs/{docId}/users is an array of user ids allowed to access the doc match /docs/{docId} { allow read if request.auth.uid in getData('docs/$(docId)').users; } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ // docs/{docId}/groups is an array of group ids allowed to access this doc // membershipList/{userId}/groups is an array of groups this user is a member of (populated by a Function) match /docs/{docId} { allow read if getData('membershipList/' + request.auth.uid).groups.hasAny( getData('docs/$(docId)').groups ); } -
Kato Richardson revised this gist
Jun 7, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ // membershipList/{userId}/groups is an array of groups this user is a member of (populated by a Function) /match/.../{docId} { allow read if getData('membershipList/' + request.auth.uid).groups.hasAny( getData('docs/$(docId)').groups ); } /** -
Kato Richardson created this gist
Jun 7, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ // docs/{docId}/users is an array of user ids allowed to access the doc /match/docs/{docId} { allow read if request.auth.uid in getData('docs/$(docId)').users; } /** * Shortcut to simplify pathing */ function getPath(childPath) { return path('/databases/'+database+'/documents/'+childPath) } /** * Fetch data from a given Firestore document */ function getData(docPath) { return get(getPath(docPath)).data } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ // Assumes that group members are stored in a subcollection under /groups/{groupId}/members/{userId} const memberPath = '/groups/{groupId}/members/{userId}'; // Trigger updates to our generated maps if group membership changes exports.memberAdded = functions.firestore.document(memberPath).onCreate(memberAdded); exports.memberDeleted = functions.firestore.document(memberPath).onDelete(memberDeleted); function memberAdded(snap, context) { const [groupId, userId] = context.params; const data = { groups: admin.firestore.FieldValue.arrayUnion(groupId) } return admin.firestore().doc(`membershipList/${userId}`).update(data); } function memberDeleted(snap, context) { const [groupId, userId] = context.params; const data = { groups: admin.firestore.FieldValue.arrayRemove(groupId) }; return admin.firestore().doc(`membershipList/${userId}`).update(data); } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ // docs/{docId}/groups is an array of group ids allowed to access this doc // membershipList/{userId}/groups is an array of groups this user is a member of (populated by a Function) /match/.../{docId} { allow read if .hasAny( getData('docs/$(docId)').groups ); } /** * Shortcut to simplify pathing */ function getPath(childPath) { return path('/databases/'+database+'/documents/'+childPath) } /** * Fetch data from a given Firestore document */ function getData(docPath) { return get(getPath(docPath)).data }