Repository navigation
Expand file tree
/
Copy pathstorage.rules
More file actions
83 lines (63 loc) · 3.22 KB
/
Copy pathstorage.rules
File metadata and controls
83 lines (63 loc) · 3.22 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
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
// ──────────────────────────────────────────────
// Helper Functions
// ──────────────────────────────────────────────
function isAuthenticated() {
return request.auth != null;
}
function getUserRole() {
let userDoc = firestore.get(/databases/(default)/documents/users/$(request.auth.uid));
return userDoc != null ? userDoc.data.role : null;
}
function isTeamMember() {
return isAuthenticated() && getUserRole() in ['owner', 'admin', 'author'];
}
function isAdmin() {
return isAuthenticated() && getUserRole() in ['owner', 'admin'];
}
function isValidImage() {
return request.resource.contentType.matches('image/.*')
&& request.resource.size < 5 * 1024 * 1024; // 5MB max
}
// ──────────────────────────────────────────────
// Cover Images (posts & projects)
// ──────────────────────────────────────────────
match /covers/{imageId} {
// Anyone can read (public images)
allow read: if true;
// Team members can upload valid images
allow create: if isTeamMember() && isValidImage();
// Team members can update their own uploads, admins can update any
allow update: if isAdmin() && isValidImage();
// Only admins can delete
allow delete: if isAdmin();
}
// ──────────────────────────────────────────────
// User Avatars
// ──────────────────────────────────────────────
match /avatars/{userId} {
allow read: if true;
// Users can only upload their own avatar
allow create, update: if isAuthenticated()
&& request.auth.uid == userId
&& isValidImage();
allow delete: if isAuthenticated() && request.auth.uid == userId;
}
// ──────────────────────────────────────────────
// Post Content Images (inline images in articles)
// ──────────────────────────────────────────────
match /posts/{postId}/{imageFile} {
allow read: if true;
allow create: if isTeamMember() && isValidImage();
allow delete: if isAdmin();
}
// ──────────────────────────────────────────────
// Catch-all: deny everything else
// ──────────────────────────────────────────────
match /{allPaths=**} {
allow read, write: if false;
}
}
}