Repository navigation
Expand file tree
/
Copy pathfirestore.rules
More file actions
183 lines (161 loc) · 4.94 KB
/
Copy pathfirestore.rules
File metadata and controls
183 lines (161 loc) · 4.94 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
172
173
174
175
176
177
178
179
180
181
182
183
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function signedIn() {
return request.auth != null;
}
function currentUser() {
return get(/databases/$(database)/documents/users/$(request.auth.uid));
}
function isSuperAdmin() {
return signedIn() &&
currentUser().data.accessLevel == 0;
}
function roleFor(study) {
return signedIn() &&
study.studyRoleMap is map &&
request.auth.uid in study.studyRoleMap
? study.studyRoleMap[request.auth.uid]
: null;
}
function isOwner(study) {
return signedIn() &&
study.testAdmin.userDocId == request.auth.uid;
}
function isAdmin(study) {
return isSuperAdmin() || isOwner(study) || roleFor(study) == 0;
}
function isManager(study) {
return roleFor(study) == 4;
}
function canViewLogs(study) {
return isAdmin(study);
}
function managerChangedOnlyStudyContent() {
return request.resource.data.diff(resource.data).affectedKeys().hasOnly([
'testTitle',
'testDescription',
'testStructure',
'testOptions',
'studyConclusion',
'evaluatorInfo',
'updateDate'
]);
}
match /users/{userId} {
allow create: if signedIn() &&
request.auth.uid == userId &&
request.resource.data.accessLevel == 1;
allow read: if signedIn();
allow update: if isSuperAdmin() || (
signedIn() &&
request.resource.data.accessLevel == resource.data.accessLevel
);
allow delete: if isSuperAdmin() ||
(signedIn() && request.auth.uid == userId);
match /notifications/{notificationId} {
allow read, write, delete: if signedIn()
}
}
match /tests/{studyId} {
allow create: if signedIn() &&
request.resource.data.testAdmin.userDocId == request.auth.uid &&
request.resource.data.studyRoleMap is map;
allow read: if true;
allow update: if isAdmin(resource.data) ||
(isManager(resource.data) && managerChangedOnlyStudyContent());
allow delete: if isAdmin(resource.data);
match /sessions/{sessionId} {
allow write: if signedIn();
allow read: if true;
}
match /participants/{participantId} {
allow read, write: if signedIn();
}
match /auditTrail/{eventId} {
allow read: if signedIn() &&
get(/databases/$(database)/documents/tests/$(studyId))
.data.testAdmin.userDocId == request.auth.uid;
allow write: if false;
}
match /logs/{logId} {
allow read: if canViewLogs(
get(/databases/$(database)/documents/tests/$(studyId)).data
);
allow write: if false;
}
match /logBatches/{batchId} {
allow read, write: if false;
}
match /loggingMeta/{metadataId} {
allow read, write: if false;
}
match /studySessions/{sessionId} {
allow read: if canViewLogs(
get(/databases/$(database)/documents/tests/$(studyId)).data
);
allow write: if false;
}
}
match /answers/{answerId} {
function answerStudy() {
return get(
/databases/$(database)/documents/tests/$(resource.data.studyId)
).data;
}
allow create: if signedIn() &&
request.resource.data.createdBy == request.auth.uid &&
request.resource.data.studyId == null;
allow read: if true;
allow update: if request.resource.data.diff(resource.data).affectedKeys()
.hasOnly([
'taskAnswers',
'heuristicAnswers',
'cardSortingAnswers',
'studyId'
]);
allow delete: if (
signedIn() &&
resource.data.studyId == null &&
resource.data.createdBy == request.auth.uid
) || isAdmin(answerStudy());
match /analytics/{analyticsId} {
allow read: if true;
}
}
// Existing non-study modules retain authenticated access. Their
// collection-specific authorization is outside the study RBAC policy.
match /templates/{document=**} {
allow read, write: if signedIn();
}
match /assessments/{document=**} {
allow read, write: if signedIn();
}
match /report/{document=**} {
allow read, write: if signedIn();
}
match /audioSentiment/{document=**} {
allow read, write: if signedIn();
}
match /transcriptions/{document=**} {
allow read, write: if signedIn();
}
match /calibrations/{document=**} {
allow read, write: if signedIn();
}
match /invites/{inviteId} {
allow write: if signedIn();
allow read: if true;
}
match /agents/{agentId} {
allow read, write: if signedIn();
}
match /settings/{settingId} {
allow read: if signedIn();
}
match /{path=**}/sessions/{sessionId} {
allow write: if signedIn();
allow read: if true;
}
}
}