-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
147 lines (125 loc) · 5.17 KB
/
Copy pathfirestore.rules
File metadata and controls
147 lines (125 loc) · 5.17 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper functions
function isAuthenticated() {
return request.auth != null;
}
function isOwner(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
function isAdmin() {
// Global Admin Hardcoded + Database Role Check
// Use efficient short-circuiting and safety checks
return isAuthenticated() && (
request.auth.token.email == 'folarin.gbenga@gmail.com' ||
(exists(/databases/$(database)/documents/users/$(request.auth.uid)) &&
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'admin')
);
}
// Public read for software catalog (AI Knowledge Base)
match /software_catalog/{docId} {
allow read: if true;
allow write: if isAuthenticated(); // Temporary fix for seeding
}
match /users/{userId} {
allow read: if isAuthenticated();
allow create: if isOwner(userId);
allow update: if isOwner(userId);
allow delete: if false;
match /download_history/{itemId} {
allow read, write: if isOwner(userId);
}
match /devices/{deviceId} {
allow read, write: if isOwner(userId);
}
// Add missing chat_history subcollection
match /chat_history/{chatId} {
// Temp Public for debug, or isOwner
allow read, write: if isOwner(userId);
}
}
// --- User Devices (Top Level used by aiService) ---
match /user_devices/{deviceId} {
allow read, write: if isAuthenticated() && (resource.data.user_id == request.auth.uid || request.resource.data.user_id == request.auth.uid);
}
// --- Forum ---
match /forum_posts/{postId} {
allow read: if true; // Publicly readable
allow create: if isAuthenticated();
allow update: if isAuthenticated() && (resource.data.user_id == request.auth.uid || isAdmin());
allow delete: if isAuthenticated() && (resource.data.user_id == request.auth.uid || isAdmin());
}
match /forum_comments/{commentId} {
allow read: if true;
allow create: if isAuthenticated();
allow update: if isAuthenticated() && (resource.data.user_id == request.auth.uid || isAdmin());
allow delete: if isAuthenticated() && (resource.data.user_id == request.auth.uid || isAdmin());
}
match /forum_likes/{likeId} {
allow read: if true;
allow create: if isAuthenticated() && request.resource.data.user_id == request.auth.uid;
allow delete: if isAuthenticated() && resource.data.user_id == request.auth.uid;
}
// --- Notifications ---
// Notifications are protected. User can see their own, OR if it is a broadcast message.
match /notifications/{notificationId} {
allow read: if isAuthenticated() && (
resource.data.recipient_user_id == request.auth.uid ||
resource.data.is_broadcast == true
);
allow create: if isAuthenticated(); // allow creation mainly for system or background triggers
allow update: if isAuthenticated() && resource.data.recipient_user_id == request.auth.uid; // verify read status update
allow delete: if isAuthenticated() && resource.data.recipient_user_id == request.auth.uid;
}
// --- Blogs ---
match /blog_posts/{blogId} {
allow read: if true;
allow write: if isAuthenticated(); // Temp fix
}
match /blog_comments/{commentId} {
allow read: if true;
allow create: if isAuthenticated();
// Allow author or generic auth user (temp admin)
allow update: if isAuthenticated() && (resource.data.user_id == request.auth.uid || isAuthenticated());
allow delete: if isAuthenticated() && (resource.data.user_id == request.auth.uid || isAuthenticated());
}
match /blog_likes/{likeId} {
allow read: if true;
allow create: if isAuthenticated() && request.resource.data.user_id == request.auth.uid;
allow delete: if isAuthenticated() && resource.data.user_id == request.auth.uid;
}
// --- Banners ---
match /banners/{bannerId} {
allow read: if true;
allow write: if isAuthenticated(); // Temp fix
}
// --- Testimonials ---
match /testimonials/{testimonialId} {
allow read: if true;
allow create: if isAuthenticated();
allow update, delete: if isAuthenticated(); // Temp fix
}
// --- Feedback ---
match /feedbacks/{feedbackId} {
allow create: if true;
allow read, update, delete: if isAuthenticated(); // Temp fix
}
// --- Vendor Map ---
match /vendor_map_markers/{markerId} {
allow read: if true;
allow create: if isAuthenticated();
// Allow update/delete if owner or admin
allow update, delete: if isAuthenticated() && (resource.data.user_id == request.auth.uid || isAuthenticated());
}
// --- Verified Software (Public Read) ---
match /verified_software/{softwareId} {
allow read: if true;
allow write: if isAuthenticated(); // Temp fix
}
// --- Global Chat History (Temp Debug: Public) ---
match /chat_history/{chatId} {
allow read, write: if true;
}
}
}