-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirestore.rules
More file actions
78 lines (65 loc) · 2.58 KB
/
firestore.rules
File metadata and controls
78 lines (65 loc) · 2.58 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Check if the user is authenticated
function isAuthenticated() {
return request.auth != null;
}
// Check if the user is the admin
function isAdmin() {
return isAuthenticated() && request.auth.token.email == 'vector.scalernset@gmail.com';
}
// Allow admin to read and write all documents
match /{document=**} {
allow read, write: if isAdmin();
}
// System config specifically for admin access
match /systemConfig/{configId} {
allow read: if isAuthenticated();
allow write: if isAdmin();
}
// Specific rule for appSettings document
match /systemConfig/appSettings {
allow read: if true; // Everyone can read app settings
allow write: if isAdmin(); // Only admin can write
}
// Users collection - additional specific rules
match /users/{userId} {
// Allow users to read/write their own documents
allow read, write: if isAuthenticated() && request.auth.uid == userId;
// Allow users to read/write their own purchases
match /purchases/{purchaseId} {
allow read, write: if isAuthenticated() && request.auth.uid == userId;
}
// Allow users to read/write their own completedTests
match /completedTests/{testId} {
allow read, write: if isAuthenticated() && request.auth.uid == userId;
}
}
// Allow access to testResults collection for authenticated users
match /testResults/{resultId} {
// Allow users to read/write their own test results
allow read: if isAuthenticated() && request.auth.uid == resource.data.userId;
allow create: if isAuthenticated() && request.auth.uid == request.resource.data.userId;
allow update, delete: if isAuthenticated() && request.auth.uid == resource.data.userId;
}
// Allow admin to read all purchases using collectionGroup queries
match /{path=**}/purchases/{purchaseId} {
allow read: if isAdmin();
}
// Allow admin to read all completed tests using collectionGroup queries
match /{path=**}/completedTests/{testId} {
allow read: if isAdmin();
}
// Test Series with subcollections
match /testSeries/{testId} {
allow read: if true; // Everyone can read test series
allow create, update, delete: if isAdmin();
// Allow access to questions subcollection
match /questions/{questionId} {
allow read: if true;
allow create, update, delete: if isAdmin();
}
}
}
}