forked from milansar/rwa-trivia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore-rules.txt
177 lines (145 loc) · 5.34 KB
/
firestore-rules.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
service cloud.firestore {
function isAuthenticated() {
return request.auth != null;
}
// Add uid of admin user
// This is temp solution for time being till fetching role from user document does not work
function isAdmin() {
return isAuthenticated() &&
(request.auth.uid == '');
}
function isUserAuthenticated(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if isAdmin();
}
match /users/{userId} {
// get stat of played game with other user
match /game_played_with/{otherUserId} {
allow read: if isUserAuthenticated(userId);
}
// only allow creating user document when no roles specified
// only allow updating user document when roles are not altered
// updating of user happen via API and rules have no effect on API
allow read: if isUserAuthenticated(userId);
allow create: if isUserAuthenticated(userId) && !request.resource.data.keys().hasAny(['roles']);
allow update: if isUserAuthenticated(userId) &&
(!request.resource.data.keys().hasAny(['roles']) || (resource.data.roles == request.resource.data.roles));
}
match /categories {
match /{document=**} {
allow read;
}
}
match /lists {
match /{document=**} {
allow read;
}
}
match /questions {
match /{document=**} {
allow read: if isUserAuthenticated(resource.data.created_uid);
}
match /{questionId} {
allow get: if isUserAuthenticated(request.auth.uid);
match /reactions {
match /{userId} {
allow get, create, update, delete: if isUserAuthenticated(userId);
}
}
}
}
match /unpublished_questions {
match /{document=**} {
allow read, update: if isUserAuthenticated(resource.data.created_uid);
allow create: if isUserAuthenticated(request.resource.data.created_uid);
}
}
match /bulk_uploads {
match /{document=**} {
allow read, update: if isUserAuthenticated(resource.data.created_uid);
allow create: if isUserAuthenticated(request.resource.data.created_uid);
}
}
match /games {
match /{document=**} {
allow read: if isUserAuthenticated(request.user.uid) || isUserAuthenticated(resource.data.playerId_0) || isUserAuthenticated(resource.data.playerId_1) || isUserAuthenticated(resource.data.nextTurnPlayerId);
}
}
match /subscription/{email} {
// create rule with data size ensure that there only two keys allowed
// keys().hasAny ensure that only email, and userId are allowed as field
// resource == null ensure when document does not exist it returns
// does not throw permission denied error
allow create: if request.resource.data.size() < 3 && request.resource.data.keys().hasAny(['email', 'userId']);
allow get: if resource.data.email.lower() == email.lower() || resource == null;
}
match /invitations {
match /{document=**} {
allow create: if isUserAuthenticated(request.resource.data.created_uid);
// allow read, update: if request.auth.token.phone_number;
allow read, update: if (resource.data.email == request.auth.token.phone_number)
|| (resource.data.email == request.auth.token.email);
allow read: if (resource.data.created_uid == request.auth.uid)
|| (resource.data.email == request.auth.token.email);
}
}
match /leader_board_stats {
match /{document=**} {
allow read: if true;
}
}
match /friends/{userId} {
allow get: if isUserAuthenticated(userId);
}
match /report_questions {
match /{document=**} {
allow read, update: if isUserAuthenticated(resource.data.created_uid);
allow create: if isUserAuthenticated(request.resource.data.created_uid);
}
}
match /stats/system {
allow get: if true;
}
match /social_share {
match /{document=**} {
allow read,update : if isUserAuthenticated(request.resource.data.created_uid);
allow create: if isUserAuthenticated(request.resource.data.created_uid);
}
}
match /blogs {
match /{document=**} {
allow read: if true;
}
}
match /application_settings {
match /{document=**} {
allow read: if true;
}
}
match /accounts/{userId} {
//only allow login user to read and get it
// logged in user does not have rights to modify this document
// document can only be modified by API , triggers
allow read: if isUserAuthenticated(userId);
}
match /feedback {
match /{document=**} {
allow create: if true;
}
}
match /countries {
match /{document=**} {
allow read;
}
}
match /user_status/{userId} {
// only allow login user to read and get it
// logged in user does not have rights to modify this document
// document can only be modified by API , triggers
allow get: if isUserAuthenticated(userId);
}
}
}