-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
99 lines (84 loc) · 3.69 KB
/
Copy pathfirestore.rules
File metadata and controls
99 lines (84 loc) · 3.69 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Users can only read/write their own user document
match /users/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
// Additional validation for user data
allow create: if request.resource.data.keys().hasAll(['name', 'email', 'createdAt', 'progress']);
allow update: if request.resource.data.diff(resource.data).affectedKeys().hasOnly(['name', 'progress', 'lastLogin', 'lastActive', 'lastModuleId', 'moduleScores', 'updatedAt']);
}
// Progress data - users can only access their own progress
match /user_progress/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
match /modules/{moduleId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
// Allow access to quiz results subcollection
match /quizResults/{resultId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
}
match /videos/{videoId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
}
// Module content - readable by all authenticated users
match /modules/{moduleId} {
allow read: if request.auth != null;
allow write: if false;
}
// Case studies - readable by all authenticated users
match /case_studies/{caseId} {
allow read: if request.auth != null;
allow write: if false;
}
// Case Study Quizzes - users can read/write their own quiz results
match /caseStudyQuizzes/{quizId} {
allow read: if request.auth != null && resource.data.userId == request.auth.uid;
allow create: if request.auth != null && request.resource.data.userId == request.auth.uid;
allow update: if false; // Quiz results should not be modified after creation
allow delete: if false; // Quiz results cannot be deleted by users
}
// Quiz Results - users can read/write their own quiz results
match /quizResults/{quizId} {
allow read: if request.auth != null && (
resource == null ||
resource.data.userId == request.auth.uid
);
allow create: if request.auth != null && request.resource.data.userId == request.auth.uid;
allow update: if false; // Quiz results should not be modified after creation
allow delete: if false; // Quiz results cannot be deleted by users
}
// User Certifications
match /userCertifications/{certId} {
allow read: if request.auth != null && (
resource == null ||
resource.data.userId == request.auth.uid
);
allow create: if request.auth != null && request.resource.data.userId == request.auth.uid;
allow update: if false;
allow delete: if false;
}
// Badges and achievements
match /user_badges/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
match /badges/{badgeId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
}
// Analytics collection - allow authenticated users to write their own data
match /analytics/quizzes/attempts/{attemptId} {
allow read: if false; // Only admin access
allow create: if request.auth != null
&& request.resource.data.userId == request.auth.uid;
}
// Function to check if user is authenticated
function isAuthenticated() {
return request.auth != null;
}
// Function to check if user is accessing their own data
function isUserOwned(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
}
}