@@ -12,21 +12,41 @@ service cloud.firestore {
1212 return isAuthenticated() &&
1313 request.auth.uid == doc.data.firebaseAnonAuthID;
1414 }
15+
16+ // Helper function to check if user has admin access
17+ function isAdmin() {
18+ return isAuthenticated() && (
19+ // Add your admin user IDs here (replace with actual UIDs from the dashboard)
20+ request.auth.uid == "62hhFmQoJwOMjnbkeNG9y7uhY8i2" ||
21+ request.auth.uid == "ANOTHER_ADMIN_UID_HERE" ||
22+ // Option for custom claims (if you implement that later)
23+ request.auth.token.admin == true ||
24+ request.auth.token.role == "admin"
25+ );
26+ }
1527
1628 // Rules for testing collection
1729 match /testing/{studyID} {
1830 allow create: if isAuthenticated() && !exists(/databases/$(database)/documents/testing/$(studyID));
19- allow read: if isAuthenticated(); // Add this line
31+ allow read: if isAuthenticated();
32+ allow list: if isAdmin(); // Admins can list all studies
33+
2034 match /data/{partID} {
2135 allow create: if isAuthenticated() &&
2236 request.resource.data.firebaseAnonAuthID == request.auth.uid;
23- allow read, update: if isOwner(resource);
37+ allow read, update: if isOwner(resource) || isAdmin(); // Admins can read/update any data
38+ allow list: if isAdmin(); // Admins can list all data documents
2439 allow delete: if false;
2540
2641 match /private/private_data {
2742 allow create: if isAuthenticated() &&
2843 request.resource.data.firebaseAnonAuthID == request.auth.uid;
29- allow read, update: if isOwner(resource);
44+ allow read, update: if isOwner(resource) || isAdmin(); // Admins can access private data
45+ allow delete: if false;
46+ }
47+
48+ match /notes/annotations {
49+ allow create, read, update: if isAdmin(); // Only admins can manage notes
3050 allow delete: if false;
3151 }
3252 }
@@ -35,17 +55,25 @@ service cloud.firestore {
3555 // Rules for real collection (identical to testing)
3656 match /real/{studyID} {
3757 allow create: if isAuthenticated() && !exists(/databases/$(database)/documents/real/$(studyID));
38- allow read: if isAuthenticated(); // Add this line
58+ allow read: if isAuthenticated();
59+ allow list: if isAdmin(); // Admins can list all studies
60+
3961 match /data/{partID} {
4062 allow create: if isAuthenticated() &&
4163 request.resource.data.firebaseAnonAuthID == request.auth.uid;
42- allow read, update: if isOwner(resource);
64+ allow read, update: if isOwner(resource) || isAdmin(); // Admins can read/update any data
65+ allow list: if isAdmin(); // Admins can list all data documents
4366 allow delete: if false;
4467
4568 match /private/private_data {
4669 allow create: if isAuthenticated() &&
4770 request.resource.data.firebaseAnonAuthID == request.auth.uid;
48- allow read, update: if isOwner(resource);
71+ allow read, update: if isOwner(resource) || isAdmin(); // Admins can access private data
72+ allow delete: if false;
73+ }
74+
75+ match /notes/annotations {
76+ allow create, read, update: if isAdmin(); // Only admins can manage notes
4977 allow delete: if false;
5078 }
5179 }
0 commit comments