Created
February 6, 2019 02:46
-
-
Save mogaming217/5a672f2ed05ed84ef3ceeb2572fb5642 to your computer and use it in GitHub Desktop.
何かおかしそうなところがあれば教えてください。
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 characters
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