-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
90 lines (76 loc) · 3.28 KB
/
firestore.rules
File metadata and controls
90 lines (76 loc) · 3.28 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Users collection - all authenticated users can read (for leaderboard), write own only
match /users/{userId} {
allow read: if request.auth != null;
allow write: if request.auth != null && request.auth.uid == userId;
}
// Challenge sessions - read/write own sessions
match /challengeSessions/{sessionId} {
allow read, write: if request.auth != null && (
sessionId.matches('^' + request.auth.uid + '_.*') ||
resource.data.uid == request.auth.uid
);
}
// Events collection - read all, write via backend only
match /events/{eventId} {
allow read: if request.auth != null;
allow write: if false; // Backend only via Admin SDK
}
// Pending rewards - read own, write via backend only
match /pending_rewards/{rewardId} {
allow read: if request.auth != null;
allow write: if false; // Backend only
}
// System collection - read only
match /system/{doc} {
allow read: if request.auth != null;
allow write: if false; // Admin only
}
// Partners collection - read only
match /partners/{partnerId} {
allow read: if request.auth != null;
allow write: if false; // Admin only
}
// Certificates — public read for verification links, authenticated write (owner only)
match /certificates/{hash} {
allow read: if true; // Public — anyone with the link can verify
allow create: if request.auth != null &&
request.resource.data.uid == request.auth.uid;
allow update, delete: if false; // Immutable once issued
}
// Weekly SDG Tasks — public read so unauthenticated preview works;
// write is backend/admin SDK only (Student B seeds via API)
match /weekly_tasks/{taskId} {
allow read: if true;
allow write: if false; // Admin SDK only (api/seed-weekly-task.js)
}
// Weekly Completions — students create own submissions, community votes
// Community upvote/downvote replaces admin approval
match /weekly_completions/{docId} {
// Anyone authenticated can read (for community feed)
allow read: if request.auth != null;
// Students can create their own submissions
allow create: if request.auth != null &&
request.resource.data.uid == request.auth.uid;
// Any authenticated user can update (for community voting: upvoters, downvoters, netScore)
allow update: if request.auth != null;
allow delete: if false; // Never delete submissions
}
// Cheat logs — individual violation events for audit trail
// Server-only writes; students can read their own logs
match /cheatLogs/{logId} {
allow read: if request.auth != null &&
resource.data.userId == request.auth.uid;
allow write: if false; // Server-only via Admin SDK
}
// Violation summaries — per-user-per-challenge violation count (tamper-resistant)
// Students can read their own summary; writes are server-only
match /violationSummaries/{docId} {
allow read: if request.auth != null &&
docId.matches('^' + request.auth.uid + '_.*');
allow write: if false; // Server-only via Admin SDK
}
}
}