-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
91 lines (82 loc) · 3.22 KB
/
firestore.rules
File metadata and controls
91 lines (82 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
84
85
86
87
88
89
90
91
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper functions
function isLoggedIn() {
return request.auth != null;
}
function getUserData() {
let path = /databases/$(database)/documents/users/$(request.auth.uid);
return exists(path) ? get(path).data : {};
}
function isAdmin() {
return isLoggedIn() && (getUserData().get('role', 'user') == 'admin');
}
function isBlacklisted() {
return isLoggedIn() && (getUserData().get('isBlacklisted', false) == true);
}
function isOwner(uid) {
return request.auth.uid == uid;
}
function getUserRole() {
return getUserData().get('role', 'user');
}
// Global Admin Override
match /{document=**} {
allow read, write: if isAdmin();
}
// Users: anyone can read their own, only themselves can write (admins handled by global)
match /users/{userId} {
allow read: if isLoggedIn();
allow create: if isLoggedIn() && isOwner(userId);
allow update: if isLoggedIn() && isOwner(userId);
}
// Events: anyone can read approved events; organizers can create/edit their own
match /events/{eventId} {
allow read: if true;
allow create: if isLoggedIn() &&
(getUserRole() == 'organizer' || isAdmin()) &&
!isBlacklisted();
allow update: if isLoggedIn() && !isBlacklisted() &&
(resource.data.organizerId == request.auth.uid || isAdmin() ||
request.resource.data.diff(resource.data).affectedKeys().hasOnly(['registered']));
allow delete: if isLoggedIn() && (resource.data.organizerId == request.auth.uid || isAdmin());
}
// Registrations
match /registrations/{regId} {
allow read: if isLoggedIn() &&
(resource.data.userId == request.auth.uid || getUserRole() == 'organizer');
allow create: if isLoggedIn() && !isBlacklisted();
allow update, delete: if isLoggedIn() && resource.data.userId == request.auth.uid;
}
// Teams
match /teams/{teamId} {
allow read: if isLoggedIn();
allow create: if isLoggedIn() && !isBlacklisted();
allow update: if isLoggedIn() && !isBlacklisted() &&
(resource.data.leaderId == request.auth.uid ||
request.auth.uid in resource.data.members);
allow delete: if isLoggedIn() && resource.data.leaderId == request.auth.uid;
}
// Submissions
match /submissions/{subId} {
allow read: if isLoggedIn();
allow create: if isLoggedIn() && getUserRole() == 'participant' && !isBlacklisted();
allow update: if isLoggedIn() && !isBlacklisted() && resource.data.userId == request.auth.uid;
allow delete: if isLoggedIn() && resource.data.userId == request.auth.uid;
}
// Scores
match /scores/{scoreId} {
allow read: if true;
allow create: if isLoggedIn() && getUserRole() == 'judge';
allow update: if isLoggedIn() && resource.data.judgeId == request.auth.uid;
}
// Admin Only Collections (read/write handled by global admin override)
match /adminSettings/{docId} {
allow read, write: if false; // Only via Admin override
}
match /moderationLog/{docId} {
allow read, write: if false; // Only via Admin override
}
}
}