Repository navigation
Expand file tree
/
Copy pathstorage.rules
More file actions
71 lines (59 loc) · 3.65 KB
/
Copy pathstorage.rules
File metadata and controls
71 lines (59 loc) · 3.65 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
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
// Function to validate file size (e.g., 10MB)
function isValidSize() {
return request.resource.size <= 10 * 1024 * 1024;
}
// Function to validate file type
function isValidContentType() {
return request.resource.contentType.matches('application/pdf') ||
request.resource.contentType.matches('application/vnd.openxmlformats-officedocument.wordprocessingml.document') || // .docx
request.resource.contentType.matches('application/msword') || // .doc
request.resource.contentType.matches('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') || // .xlsx
request.resource.contentType.matches('application/vnd.ms-excel') || // .xls
request.resource.contentType.matches('image/jpeg') ||
request.resource.contentType.matches('image/png');
}
// Only allow reads and writes from Firebase Admin SDK (Backend) or Custom Auth Tokens
// The frontend will get a custom auth token from our API to upload securely
match /documents/{allPaths=**} {
allow read: if request.auth != null && request.auth.token.role == 'super_admin';
// Allow coordinators to upload securely, enforcing size and types
allow write: if request.auth != null && request.auth.token.role == 'coordinator'
&& request.resource.size < 10 * 1024 * 1024 // 10MB limit
&& request.resource.contentType.matches('application/pdf|application/vnd.openxmlformats-officedocument.*|image/jpeg|image/png');
allow delete: if request.auth != null && request.auth.token.role == 'super_admin';
}
// ── Club Logos ─────────────────────────────────────────────────────────
// Public read — club logos are visible to all students.
// Write: any authenticated user (admin panel enforces login before reaching this).
match /club-images/{allPaths=**} {
allow read: if true;
// Any authenticated user can upload — the admin panel enforces role-based
// access at the UI level. Storage rules cannot do Firestore lookups for roles.
allow write: if request.auth != null
&& request.resource.size <= 5 * 1024 * 1024
&& (request.resource.contentType == 'image/png'
|| request.resource.contentType == 'image/jpeg'
|| request.resource.contentType == 'image/webp');
allow delete: if request.auth != null;
}
// ── Datasets (Orientation) ──────────────────────────────────────────────
match /datasets/{allPaths=**} {
// Any authenticated user can upload/read datasets (UI enforces auth before upload)
allow read, write, delete: if request.auth != null;
}
// ── Media Library ─────────────────────────────────────────────────────────
match /media-library/{allPaths=**} {
// Public read — images are used on the homepage.
allow read: if true;
// Authenticated users can upload (admin panel enforces roles)
// Size limit: 10MB, Type: Images only.
allow write: if request.auth != null
&& request.resource.size <= 10 * 1024 * 1024
&& request.resource.contentType.matches('image/.*');
allow delete: if request.auth != null;
}
}
}