Skip to content

Instantly share code, notes, and snippets.

@mogaming217
Created February 6, 2019 02:46
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mogaming217/5a672f2ed05ed84ef3ceeb2572fb5642 to your computer and use it in GitHub Desktop.
Save mogaming217/5a672f2ed05ed84ef3ceeb2572fb5642 to your computer and use it in GitHub Desktop.
何かおかしそうなところがあれば教えてください。
service cloud.firestore {
match /databases/{database}/documents {
match /groups/{groupID} {
allow get, update: if isAuthenticated() && isUserBelongingToThisGroup(groupID, request.auth.uid);
match /users/{userID} {
allow read: if isAuthenticated() && isUserBelongingToThisGroup(groupID, request.auth.uid);
}
match /boards/{boardID} {
allow create: if (isAuthenticated()
&& isUserBelongingToThisGroup(groupID, request.auth.uid))
&& getBoardsCount(groupID) < 5;
allow read, update: if isAuthenticated() && isUserBelongingToThisGroup(groupID, request.auth.uid);
match /tasks/{taskID} {
allow read, write: if isAuthenticated() && isUserBelongingToThisGroup(groupID, request.auth.uid);
match /comments/{commentID} {
allow read, write: if isAuthenticated() && isUserBelongingToThisGroup(groupID, request.auth.uid);
}
}
}
}
match /users/{userID} {
allow update, get: if isAuthenticated() && isUserAuthenticated(userID);
match /groups/{groupID} {
allow update, read: if isAuthenticated() && isUserAuthenticated(userID);
}
match /deviceTokens/{deviceTokenID} {
allow create: if isAuthenticated() && isUserAuthenticated(userID);
}
match /opinions/{opinionID} {
allow create: if isAuthenticated() && isUserAuthenticated(userID);
}
}
function documentPath(paths) {
return path([['databases', database, 'documents'].join('/'), paths.join('/')].join('/'));
}
function getData(path) {
return get(path).data;
}
function getBoardsCount(groupID) {
return getData(documentPath(['groups', groupID])).boardCount;
}
// firebaseの認証ユーザーかどうか
function isAuthenticated() {
return request.auth != null;
}
// Firebase認証がされているユーザーかどうか
function isUserAuthenticated(userID) {
return request.auth.uid == userID;
}
// グループに属しているユーザーかどうか
function isUserBelongingToThisGroup(groupID, userID) {
return exists(/databases/$(database)/documents/groups/$(groupID)/users/$(userID))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment