-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirestore.rules
More file actions
171 lines (160 loc) · 6.42 KB
/
firestore.rules
File metadata and controls
171 lines (160 loc) · 6.42 KB
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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isValidPhoneId(phoneId) {
return phoneId.matches('^[0-9]{10,11}$');
}
function hasApplyPayloadShape(phoneId) {
return request.resource.data.keys().hasOnly([
'name',
'phone',
'email',
'gender',
'height',
'weight',
'agreePrivacy',
'agreeService',
'agreePhotoProcessing',
'agreeMarketing',
'paymentMethod',
'requestId',
'consentSnapshot',
'retentionPolicy',
'rightsRequestChannel',
'thirdPartyNotice',
'createdAt',
'updatedAt',
])
&& request.resource.data.phone == phoneId
&& request.resource.data.name is string
&& request.resource.data.email is string
&& request.resource.data.gender is string
&& request.resource.data.height is string
&& request.resource.data.weight is string
&& request.resource.data.paymentMethod is string
&& request.resource.data.agreePrivacy == true
&& request.resource.data.agreeService == true
&& request.resource.data.agreePhotoProcessing is bool
&& request.resource.data.agreeMarketing is bool
&& request.resource.data.requestId is string
&& request.resource.data.retentionPolicy is string
&& request.resource.data.rightsRequestChannel is string
&& request.resource.data.thirdPartyNotice is string
&& request.resource.data.createdAt is timestamp
&& request.resource.data.updatedAt is timestamp;
}
function hasConsentSnapshotShape() {
return request.resource.data.consentSnapshot.agreePrivacy == true
&& request.resource.data.consentSnapshot.agreeService == true
&& request.resource.data.consentSnapshot.agreePhotoProcessing is bool
&& request.resource.data.consentSnapshot.agreeMarketing is bool
&& request.resource.data.consentSnapshot.policyVersion is string
&& request.resource.data.consentSnapshot.termsVersion is string
&& request.resource.data.consentSnapshot.consentNoticeVersion is string
&& request.resource.data.consentSnapshot.agreedAtISO is string
&& request.resource.data.consentSnapshot.requestId is string
&& request.resource.data.consentSnapshot.requestId == request.resource.data.requestId;
}
function hasConsentLogShape(phoneId) {
return request.resource.data.keys().hasOnly([
'agreePrivacy',
'agreeService',
'agreePhotoProcessing',
'agreeMarketing',
'policyVersion',
'termsVersion',
'consentNoticeVersion',
'agreedAtISO',
'requestId',
'createdAt',
])
&& request.resource.data.agreePrivacy == true
&& request.resource.data.agreeService == true
&& request.resource.data.agreePhotoProcessing is bool
&& request.resource.data.agreeMarketing is bool
&& request.resource.data.policyVersion is string
&& request.resource.data.termsVersion is string
&& request.resource.data.consentNoticeVersion is string
&& request.resource.data.agreedAtISO is string
&& request.resource.data.requestId is string
&& request.resource.data.createdAt is timestamp
&& request.resource.data.requestId ==
getAfter(/databases/$(database)/documents/apply/$(phoneId)).data.requestId;
}
match /apply/{phoneId} {
allow get: if false;
allow list: if false;
allow create: if isValidPhoneId(phoneId)
&& !exists(/databases/$(database)/documents/apply/$(phoneId))
&& hasApplyPayloadShape(phoneId)
&& hasConsentSnapshotShape();
allow update, delete: if false;
match /consent_logs/{logId} {
allow create: if isValidPhoneId(phoneId)
&& existsAfter(/databases/$(database)/documents/apply/$(phoneId))
&& hasConsentLogShape(phoneId);
allow read, update, delete: if false;
}
}
match /apply_index/{phoneId} {
allow get: if isValidPhoneId(phoneId);
allow list: if false;
allow create: if isValidPhoneId(phoneId)
&& !exists(/databases/$(database)/documents/apply_index/$(phoneId))
&& request.resource.data.keys().hasOnly(['requestId', 'createdAt'])
&& request.resource.data.requestId is string
&& request.resource.data.createdAt is timestamp
&& existsAfter(/databases/$(database)/documents/apply/$(phoneId))
&& getAfter(/databases/$(database)/documents/apply/$(phoneId)).data.requestId ==
request.resource.data.requestId;
allow update, delete: if false;
}
match /surveys/{phoneId} {
allow create, update: if isValidPhoneId(phoneId)
&& request.resource.data.keys().hasOnly(['phone', 'answers', 'completedAt'])
&& request.resource.data.phone == phoneId
&& request.resource.data.answers is list
&& request.resource.data.completedAt is timestamp;
allow read, delete: if false;
}
match /contact_inquiries/{inquiryId} {
allow create: if request.resource.data.keys().hasOnly([
'name',
'email',
'topic',
'message',
'source',
'status',
'createdAt',
])
&& request.resource.data.name is string
&& request.resource.data.email is string
&& request.resource.data.topic is string
&& request.resource.data.message is string
&& request.resource.data.source in ['floating-button', 'footer']
&& request.resource.data.status == 'new'
&& request.resource.data.createdAt is timestamp;
allow read, update, delete: if false;
}
match /reviews/{reviewId} {
allow create: if request.resource.data.keys().hasOnly([
'rating',
'comment',
'source',
'status',
'createdAt',
])
&& request.resource.data.rating is int
&& request.resource.data.rating >= 1
&& request.resource.data.rating <= 5
&& request.resource.data.comment is string
&& request.resource.data.source in ['result-page', 'pdf-download']
&& request.resource.data.status == 'pending'
&& request.resource.data.createdAt is timestamp;
allow read, update, delete: if false;
}
match /{document=**} {
allow read, write: if false;
}
}
}