2022-01-05 17:42:43 +00:00
|
|
|
rules_version = '2';
|
|
|
|
|
2022-04-29 23:35:56 +00:00
|
|
|
// To pick the right project: `firebase projects:list`, then `firebase use <project-name>`
|
2022-01-24 06:45:46 +00:00
|
|
|
// To deploy: `firebase deploy --only firestore:rules`
|
2022-01-05 17:42:43 +00:00
|
|
|
service cloud.firestore {
|
|
|
|
match /databases/{database}/documents {
|
|
|
|
|
2022-01-24 06:45:46 +00:00
|
|
|
function isAdmin() {
|
|
|
|
return request.auth.uid == 'igi2zGXsfxYPgB0DJTXVJVmwCOr2' // Austin
|
|
|
|
|| request.auth.uid == '5LZ4LgYuySdL1huCWe7bti02ghx2' // James
|
|
|
|
|| request.auth.uid == 'tlmGNz9kjXc2EteizMORes4qvWl2' // Stephen
|
|
|
|
|| request.auth.uid == 'IPTOzEqrpkWmEzh6hwvAyY9PqFb2' // Manifold
|
|
|
|
}
|
|
|
|
|
2022-01-05 17:42:43 +00:00
|
|
|
match /users/{userId} {
|
|
|
|
allow read;
|
2022-04-27 07:34:23 +00:00
|
|
|
allow update: if resource.data.id == request.auth.uid
|
2022-02-18 01:16:58 +00:00
|
|
|
&& request.resource.data.diff(resource.data).affectedKeys()
|
2022-05-12 15:07:10 +00:00
|
|
|
.hasOnly(['bio', 'bannerUrl', 'website', 'twitterHandle', 'discordHandle', 'followedCategories']);
|
2022-01-19 03:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
match /private-users/{userId} {
|
2022-01-26 21:03:45 +00:00
|
|
|
allow read: if resource.data.id == request.auth.uid || isAdmin();
|
2022-05-16 03:41:07 +00:00
|
|
|
allow update: if (resource.data.id == request.auth.uid || isAdmin())
|
|
|
|
&& request.resource.data.diff(resource.data).affectedKeys()
|
|
|
|
.hasOnly(['apiKey']);
|
2022-01-05 17:42:43 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:28:38 +00:00
|
|
|
match /private-users/{userId}/views/{viewId} {
|
|
|
|
allow create: if userId == request.auth.uid;
|
|
|
|
}
|
|
|
|
|
2022-04-19 05:16:08 +00:00
|
|
|
match /private-users/{userId}/events/{eventId} {
|
|
|
|
allow create: if userId == request.auth.uid;
|
|
|
|
}
|
|
|
|
|
2022-04-21 06:00:08 +00:00
|
|
|
match /private-users/{userId}/latency/{loadTimeId} {
|
|
|
|
allow create: if userId == request.auth.uid;
|
|
|
|
}
|
|
|
|
|
2022-05-12 15:07:10 +00:00
|
|
|
match /private-users/{userId}/cache/{docId} {
|
2022-05-01 16:36:54 +00:00
|
|
|
allow read: if userId == request.auth.uid || isAdmin();
|
|
|
|
}
|
|
|
|
|
2022-01-05 17:42:43 +00:00
|
|
|
match /contracts/{contractId} {
|
|
|
|
allow read;
|
2022-01-26 23:45:05 +00:00
|
|
|
allow update: if request.resource.data.diff(resource.data).affectedKeys()
|
2022-02-21 04:04:00 +00:00
|
|
|
.hasOnly(['description', 'closeTime', 'tags', 'lowercaseTags']);
|
2022-02-09 18:58:33 +00:00
|
|
|
allow update: if isAdmin();
|
2022-01-05 17:42:43 +00:00
|
|
|
}
|
|
|
|
|
2022-01-05 17:47:39 +00:00
|
|
|
match /{somePath=**}/bets/{betId} {
|
|
|
|
allow read;
|
|
|
|
}
|
|
|
|
|
2022-04-27 08:17:29 +00:00
|
|
|
function commentMatchesUser(userId, comment) {
|
|
|
|
// it's a bad look if someone can impersonate other ids/names/avatars so check everything
|
|
|
|
let user = get(/databases/$(database)/documents/users/$(userId));
|
|
|
|
return comment.userId == userId
|
|
|
|
&& comment.userName == user.data.name
|
|
|
|
&& comment.userUsername == user.data.username
|
|
|
|
&& comment.userAvatarUrl == user.data.avatarUrl;
|
|
|
|
}
|
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
match /{somePath=**}/comments/{commentId} {
|
2022-01-05 17:42:43 +00:00
|
|
|
allow read;
|
2022-04-27 08:17:29 +00:00
|
|
|
allow create: if request.auth != null && commentMatchesUser(request.auth.uid, request.resource.data);
|
2022-01-05 17:42:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
match /{somePath=**}/answers/{answerId} {
|
2022-01-05 22:52:54 +00:00
|
|
|
allow read;
|
|
|
|
}
|
|
|
|
|
2022-01-21 23:21:46 +00:00
|
|
|
match /folds/{foldId} {
|
|
|
|
allow read;
|
2022-04-27 08:17:29 +00:00
|
|
|
allow update: if request.auth.uid == resource.data.curatorId
|
|
|
|
&& request.resource.data.diff(resource.data).affectedKeys()
|
|
|
|
.hasOnly(['name', 'about', 'tags', 'lowercaseTags']);
|
|
|
|
allow delete: if request.auth.uid == resource.data.curatorId;
|
2022-01-21 23:21:46 +00:00
|
|
|
}
|
2022-01-26 20:03:32 +00:00
|
|
|
|
2022-02-04 00:13:04 +00:00
|
|
|
match /{somePath=**}/followers/{userId} {
|
|
|
|
allow read;
|
2022-04-27 08:17:29 +00:00
|
|
|
allow create, update: if request.auth.uid == userId && request.resource.data.userId == userId;
|
|
|
|
allow delete: if request.auth.uid == userId;
|
2022-02-04 00:13:04 +00:00
|
|
|
}
|
2022-04-29 23:35:56 +00:00
|
|
|
|
|
|
|
match /txns/{txnId} {
|
|
|
|
allow read;
|
|
|
|
}
|
2022-01-05 17:42:43 +00:00
|
|
|
}
|
2022-04-27 07:34:23 +00:00
|
|
|
}
|