-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirestore.rules
More file actions
67 lines (57 loc) 路 2.48 KB
/
Copy pathfirestore.rules
File metadata and controls
67 lines (57 loc) 路 2.48 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
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() {
return isAuthenticated() &&
( (exists(/databases/$(database)/documents/users/$(request.auth.uid)) && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'admin') ||
(request.auth.token.email == "quadcosmos@gmail.com" && request.auth.token.email_verified == true));
}
function isValidUser(data) {
return data.keys().hasAll(['uid', 'email', 'role']) &&
data.uid is string &&
data.email is string &&
data.role in ['admin', 'user'];
}
// User Profiles
match /users/{userId} {
allow read: if isOwner(userId) || isAdmin();
allow create: if isAuthenticated() && isOwner(userId) &&
(request.resource.data.role == 'user' ||
(request.resource.data.role == 'admin' && request.auth.token.email == "quadcosmos@gmail.com"));
allow update: if isOwner(userId) && (request.resource.data.role == resource.data.role || isAdmin());
}
// Chats
match /chats/{chatId} {
allow read: if isAuthenticated() && (resource.data.userId == request.auth.uid || isAdmin());
allow create: if isAuthenticated() && request.resource.data.userId == request.auth.uid;
allow update, delete: if isAuthenticated() && resource.data.userId == request.auth.uid;
match /messages/{messageId} {
allow read: if isAuthenticated() && (get(/databases/$(database)/documents/chats/$(chatId)).data.userId == request.auth.uid || isAdmin());
allow create: if isAuthenticated() && get(/databases/$(database)/documents/chats/$(chatId)).data.userId == request.auth.uid;
}
}
// Logs
match /logs/{logId} {
allow read, list: if isAdmin();
allow create: if isAuthenticated(); // Allow users to log their actions
}
// TODOs
match /todo/{todoId} {
allow read: if isAuthenticated();
allow write: if isAdmin();
}
// Meeting Table (Group Chat)
match /meeting_table/{messageId} {
allow read: if isAuthenticated();
allow create: if isAuthenticated() && (request.resource.data.uid == request.auth.uid || isAdmin());
allow update, delete: if isAdmin();
}
}
}