-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
115 lines (97 loc) · 4.13 KB
/
firestore.rules
File metadata and controls
115 lines (97 loc) · 4.13 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// =======================================
// Helper Functions
// =======================================
function isAuthenticated() {
return request.auth != null;
}
function getUserData() {
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data;
}
function isSuperAdmin() {
return isAuthenticated() && getUserData().role == 'super_admin';
}
function isAdminOrAbove() {
return isAuthenticated() && getUserData().role in ['admin', 'super_admin'];
}
function isTeacherOrAbove() {
return isAuthenticated() && getUserData().role in ['teacher', 'admin', 'super_admin'];
}
// =======================================
// Users Collection
// =======================================
match /users/{userId} {
allow read: if isAuthenticated() && (request.auth.uid == userId || isAdminOrAbove());
allow create: if isSuperAdmin();
allow update: if isSuperAdmin() || request.auth.uid == userId;
allow delete: if isSuperAdmin();
}
// =======================================
// Exam Data Collection (UPDATED FOR PUBLIC READ)
// =======================================
match /exams/{examId} {
// যে কেউ লগইন ছাড়াই এক্সাম কার্ড ও রেজাল্ট দেখতে পারবে
allow read: if true;
allow create, update: if isTeacherOrAbove();
allow delete: if isAdminOrAbove();
}
// =======================================
// Exam Configs & Academic Structure
// =======================================
match /examConfigs/{configId} {
allow read: if true; // রেজাল্ট রেন্ডার করার জন্য এটিও পাবলিক রাখা হয়েছে
allow create, update: if isTeacherOrAbove();
allow delete: if isAdminOrAbove();
}
match /academicStructure/{docId} {
allow read: if true; // ড্রপডাউন মেনুগুলোর জন্য এটি পাবলিক রাখা হয়েছে
allow write: if isAdminOrAbove();
}
// =======================================
// Students Collection
// =======================================
match /students/{studentId} {
// ব্যক্তিগত প্রোফাইল সুরক্ষার জন্য এটি শুধু অথেনটিকেটেড ইউজারদের জন্য
allow read: if isAuthenticated();
allow create, update: if isTeacherOrAbove();
allow delete: if isAdminOrAbove();
}
// =======================================
// Teacher Assignments & Access Control
// =======================================
match /teacher_assignments/{assignmentId} {
allow read: if isAuthenticated();
allow create, update, delete: if isSuperAdmin();
}
match /accessControl/{docId} {
allow read: if isAuthenticated();
allow write: if isSuperAdmin();
}
// =======================================
// Settings & Notices
// =======================================
match /settings/{settingId} {
allow read: if true; // ওয়েবসাইট থিম বা লোগোর জন্য এটি পাবলিক থাকা প্রয়োজন
allow write: if isAdminOrAbove();
}
match /notices/{noticeId} {
allow read: if true; // নোটিশ বোর্ড সবার জন্য উন্মুক্ত
allow create, update, delete: if isAdminOrAbove();
}
// =======================================
// Access Requests
// =======================================
match /access_requests/{requestId} {
allow create: if true;
allow read, update, delete: if isAdminOrAbove();
}
// =======================================
// Catch-All: Deny everything else
// =======================================
match /{document=**} {
allow read, write: if false;
}
}
}