forked from CipherCraze/Spark-IQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.rules
More file actions
86 lines (76 loc) · 3.96 KB
/
storage.rules
File metadata and controls
86 lines (76 loc) · 3.96 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
rules_version = '2';
// Craft rules based on data in your Firestore database
// allow write: if firestore.get(
// /databases/(default)/documents/users/$(request.auth.uid)).data.isAdmin;
service firebase.storage {
match /b/{bucket}/o {
// Helper functions
function isAuthenticated() {
return request.auth != null;
}
// For now, allow any authenticated user to upload assignments
// In a production environment, you would need to implement custom claims
// or use a different approach to verify teacher status
function isTeacher() {
return isAuthenticated();
}
function isUserInChat(chatId) {
return isAuthenticated() &&
exists(/databases/$(database)/documents/chats/$(chatId)) &&
request.auth.uid in get(/databases/$(database)/documents/chats/$(chatId)).data.participants;
}
// Profile pictures - specific rules
match /profile-pictures/{userId}/{allPaths=**} {
allow read: if isAuthenticated(); // Any authenticated user can view profile pictures
allow write: if isAuthenticated() && request.auth.uid == userId; // Only user can upload their own picture
}
// Chat attachments and files
match /chat/{chatId}/{allPaths=**} {
allow read: if isUserInChat(chatId);
allow write: if isUserInChat(chatId) &&
request.resource.size < 10 * 1024 * 1024 && // 10MB file size limit
request.resource.contentType.matches('image/.*|video/.*|application/pdf'); // Restrict file types
}
// Assignment files
match /assignments/{teacherId}/{allPaths=**} {
allow read: if isAuthenticated();
allow write: if isAuthenticated() &&
request.auth.uid == teacherId && // Users can only upload to their own folder
request.resource.size < 20 * 1024 * 1024; // 20MB file size limit
allow delete: if isAuthenticated() && request.auth.uid == teacherId; // Users can delete their own files
}
// Announcement attachments
match /announcements/{teacherId}/{fileName} {
allow read: if isAuthenticated(); // Any authenticated user can read announcements
allow write: if isAuthenticated() &&
request.auth.uid == teacherId && // Users can only write to their own folder
request.resource.size < 20 * 1024 * 1024 && // 20MB file size limit
request.resource.contentType.matches('image/.*|video/.*|application/pdf|application/msword|application/vnd.openxmlformats-officedocument.wordprocessingml.document'); // Restrict file types
allow delete: if isAuthenticated() && request.auth.uid == teacherId; // Users can delete their own attachments
}
// Submission files - Updated rules
match /submissions/{assignmentId}/{studentId}/{fileName} {
allow read: if isAuthenticated() && (
request.auth.uid == studentId // Students can read their own submissions
);
allow create, update: if isAuthenticated() &&
request.auth.uid == studentId && // Students can only write to their own folder
request.resource.size < 50 * 1024 * 1024; // 50MB file size limit
allow delete: if isAuthenticated() && request.auth.uid == studentId; // Students can delete their own submissions
}
// Suggestions files
match /suggestions/{userId}/{allPaths=**} {
allow read: if isAuthenticated();
allow write: if isAuthenticated() &&
request.auth.uid == userId && // Users can only write to their own folder
request.resource.size < 10 * 1024 * 1024 && // 10MB file size limit
request.resource.contentType.matches('image/.*|video/.*|application/pdf'); // Restrict file types
allow delete: if isAuthenticated() && request.auth.uid == userId; // Users can delete their own suggestions
}
// Default rule - deny all other access
match /{allPaths=**} {
allow read: if isAuthenticated();
allow write: if false;
}
}
}