-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfirestore.rules
186 lines (147 loc) · 6.53 KB
/
firestore.rules
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
178
179
180
181
182
183
184
185
186
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isPremiumSubscriber(request) {
return 'stripeRole' in request.auth.token ? request.auth.token.stripeRole == 'premium' : false;
}
function getOrganization(organizationId) {
return exists(/databases/$(database)/documents/organizations/$(organizationId)) ? get(/databases/$(database)/documents/organizations/$(organizationId)) : null;
}
function getRecurringMeeting(recurringMeetingId) {
return get(/databases/$(database)/documents/recurringMeetingLinks/$(recurringMeetingId));
}
match /rooms/{roomId} {
allow get: if isAccessAllowed(request);
allow list: if request.auth.uid in resource.data.memberIds;
allow update: if isAccessAllowed(request) && !isUpdatingSubscriptionMetadata(request, resource);
allow delete: if false;
allow create: if false;
function isUpdatingSubscriptionMetadata(request, resource) {
return request.resource.data.diff(resource.data).affectedKeys().hasAny(['subscriptionMetadata'])
}
function isAccessAllowed(request) {
let meta = hasMetadataSet() ? getAuthorizationMetadata().data : {};
let isPasswordProtected = meta.get('passwordProtectionEnabled', false);
let organizationOnlyProtectedId = meta.get('organizationProtection', false);
let roomAccessValue = isPasswordProtected ? hasSavedPasswordAccessForUserId(request) ? getPasswordAccessForUserId(request) : {} : {};
let isExpired = 'expiresAt' in roomAccessValue ? roomAccessValue.expiresAt < request.time : false;
let isHashMatching = 'hash' in roomAccessValue ? roomAccessValue.hash == getPasswordHash() : false;
return request.auth != null && (
!isPasswordProtected ||
(
!isExpired &&
isHashMatching
)
) && (
(organizationOnlyProtectedId == '' || organizationOnlyProtectedId == false || organizationOnlyProtectedId == null) || (
request.auth.uid in getOrganization(organizationOnlyProtectedId).data.memberIds
)
);
}
function hasMetadataSet() {
return exists(/databases/$(database)/documents/rooms/$(roomId)/metadata/authorization);
}
function getAuthorizationMetadata() {
return get(/databases/$(database)/documents/rooms/$(roomId)/metadata/authorization);
}
function getRoom() {
return get(/databases/$(database)/documents/rooms/$(roomId));
}
function getPasswordHash() {
return exists(/databases/$(database)/documents/rooms/$(roomId)/metadata/passwordProtection) ?
get(/databases/$(database)/documents/rooms/$(roomId)/metadata/passwordProtection).data.value : '';
}
function hasSavedPasswordAccessForUserId(request) {
return exists(/databases/$(database)/documents/rooms/$(roomId)/metadata/passwordProtection/accessList/$(request.auth.uid));
}
function getPasswordAccessForUserId(request) {
return get(/databases/$(database)/documents/rooms/$(roomId)/metadata/passwordProtection/accessList/$(request.auth.uid)).data;
}
match /metadata/authorization {
allow write: if request.auth.uid == getRoom().data.createdById;
allow read: if true;
}
match /metadata/passwordProtection {
allow write: if false;
allow read: if isAccessAllowed(request);
}
match /metadata/memberStatus {
allow write, read: if isAccessAllowed(request);
}
match /summaries/{summaryId} {
allow write: if false;
allow read: if isAccessAllowed(request);
}
match /reactions/{reactionId} {
allow read, write: if isAccessAllowed(request);
}
}
match /userDetails/{userId} {
allow read, write: if request.auth.uid == userId;
match /integrations/{integrationName} {
allow read, write: if request.auth.uid == userId;
}
match /cardSets/{cardSetId} {
allow read, write: if request.auth.uid == userId;
}
match /meteredUsage/{usageId} {
allow read: if request.auth.uid == userId;
allow write: if false;
}
}
match /userPreferences/{userId} {
allow read, write: if request.auth.uid == userId;
}
match /userProfiles/{userId} {
allow get: if true;
allow list, update, create, delete: if false;
}
match /organizations/{organizationId} {
allow read: if request.auth.uid in resource.data.memberIds;
allow write: if request.auth.uid == request.resource.data.createdById;
allow update: if request.auth.uid == resource.data.createdById;
match /memberInvitations/{invitationId} {
allow read, write: if request.auth.uid in getOrganization(organizationId).data.memberIds;
}
}
match /recurringMeetingLinks/{linkId} {
allow get: if !('organizationId' in resource.data) || request.auth.uid in getOrganization(resource.data.organizationId).data.memberIds;
allow list: if request.auth.uid == resource.data.createdById;
allow write: if request.auth.uid == request.resource.data.createdById;
allow update: if request.auth.uid == resource.data.createdById;
match /createdRooms/{roomId} {
allow read: if !('organizationId' in resource.data) || request.auth.uid in getOrganization(getRecurringMeeting(linkId).data.organizationId).data.memberIds;
allow write: if false;
}
}
match /invitations/{invitationId} {
allow write: if request.auth.uid == request.resource.data.invitedBy;
allow read: if false;
}
match /authSessions/{sessionId} {
allow list, update, delete, create, get: if false;
}
match /feedbacks/{feedbackId} {
allow write, read: if request.auth.uid == request.resource.data.userId;
}
match /customers/{uid} {
allow read, write: if request.auth.uid == uid;
match /checkout_sessions/{id} {
allow read: if request.auth.uid == uid;
allow write: if request.auth.uid == uid && (!('creditCount' in request.resource.data.metadata) || request.resource.data.metadata.creditCount > 100)
}
match /subscriptions/{id} {
allow read: if request.auth.uid == uid;
}
}
match /products/{id} {
allow read: if true;
match /prices/{id} {
allow read: if true;
}
match /tax_rates/{id} {
allow read: if true;
}
}
}
}