-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirestore.rules
More file actions
96 lines (84 loc) · 3.56 KB
/
Copy pathfirestore.rules
File metadata and controls
96 lines (84 loc) · 3.56 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
92
93
94
95
96
rules_version = '2';
// =====================================================
// Firestore security rules for WorkoutTracker & FoodTracker
// =====================================================
service cloud.firestore {
match /databases/{database}/documents {
// =====================================================
// WORKOUT TRACKER RULES (Do not touch)
// =====================================================
// === Curated content (read-only) ===
match /legendary_routines/{routineId} {
allow read: if true;
allow write: if false;
}
match /explore_programs/{programId} {
allow read: if true;
allow write: if false;
}
// === User-generated shared workouts ===
match /shared_workouts/{workoutId} {
// Read: only approved workouts, OR your own doc (any status)
allow read: if (resource.data.status == "approved")
|| (request.auth != null
&& resource.data.creatorUid == request.auth.uid);
// Create: must be authed; creatorUid must equal own UID;
// must start as pending with zero reports; size limits on text.
allow create: if request.auth != null
&& request.resource.data.creatorUid == request.auth.uid
&& request.resource.data.status == "pending"
&& request.resource.data.reportCount == 0
&& request.resource.data.title is string
&& request.resource.data.title.size() > 0
&& request.resource.data.title.size() <= 200
&& (!("description" in request.resource.data)
|| (request.resource.data.description is string
&& request.resource.data.description.size() <= 2000));
// Update: server-only (no client updates — moderation function uses admin)
allow update: if false;
// Delete: only owner can delete their own document
allow delete: if request.auth != null
&& resource.data.creatorUid == request.auth.uid;
}
// === Reports ===
match /reports/{reportId} {
allow create: if request.auth != null
&& request.resource.data.reporterUid == request.auth.uid
&& request.resource.data.workoutId is string
&& request.resource.data.reason in
["spam", "hate", "harassment", "sexual", "violence", "dangerous", "other"]
&& (!("details" in request.resource.data)
|| (request.resource.data.details is string
&& request.resource.data.details.size() <= 500));
allow read, update, delete: if false;
}
// === Per-user blocked list ===
match /users/{userId}/blocked/{blockedUid} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
// =====================================================
// FOOD TRACKER RULES
// =====================================================
// === Curated content (read-only for clients, managed by admin) ===
match /premium_recipes/{recipeId} {
allow read: if true;
allow write: if false;
}
match /academy_categories/{categoryId} {
allow read: if true;
allow write: if false;
}
match /diets/{dietId} {
allow read: if true;
allow write: if false;
}
match /fasting_plans/{planId} {
allow read: if true;
allow write: if false;
}
// === Default deny for everything else ===
match /{document=**} {
allow read, write: if false;
}
}
}