-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirestore.rules
More file actions
executable file
·77 lines (62 loc) · 2.51 KB
/
firestore.rules
File metadata and controls
executable file
·77 lines (62 loc) · 2.51 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
match /Spacemoon/appinfo {
allow read: if true;
allow write: if false;
}
match /users/{userId} {
allow read: if request.auth.uid != null;
allow write: if request.auth.uid != null && request.auth.uid == userId;
}
match /fcmTokens/{userId} {
allow read, write: if request.auth.uid != null && request.auth.uid == userId;
}
match /roomusers/{roomuserId} {
allow read: if request.auth.uid != null;
allow write: if request.auth.uid != null && request.auth.uid == resource.data.user ;
}
match /rooms/{roomId} {
allow read: if true;
allow write: if roomUserIsAdmin(roomId);
}
// function roomUserExist(roomId) {
// let roomuserId = request.auth.uid + '_' + roomId;
// return request.auth.uid != null && exists(/databases/$(database)/documents/roomusers/$(roomuserId));
// }
function roomUserIsAdmin(roomId) {
let roomuserId = request.auth.uid + '_' + roomId;
let role = get(/databases/$(database)/documents/roomusers/$(roomuserId)).data.role;
return role == 'ADMIN';
}
function roomUserIsAdminOrMod(roomId) {
let roomuserId = request.auth.uid + '_' + roomId;
let role = get(/databases/$(database)/documents/roomusers/$(roomuserId)).data.role;
return role == 'ADMIN' || role == 'MODERATOR';
}
function roomUserIsAuthenticated(roomId) {
let roomuserId = request.auth.uid + '_' + roomId;
let role = get(/databases/$(database)/documents/roomusers/$(roomuserId)).data.role;
return role == 'ADMIN' || role == 'MODERATOR' || role == 'USER' || role == 'INVITE';
}
// function roomUserUMA(roomId) {
// let roomuserId = request.auth.uid + '_' + roomId;
// let role = get(/databases/$(database)/documents/roomusers/$(roomuserId)).data.role;
// return role == 'ADMIN' || role == 'MODERATOR' || role == 'USER';
// }
match /rooms/{roomId}/tweets {
allow read, write: if false;
}
match /rooms/{roomId}/tweets/{tweetId} {
allow read: if roomUserIsAuthenticated(roomId);
allow write: if resource.data.user == request.auth.uid;
allow delete: if resource.data.user == request.auth.uid || roomUserIsAdminOrMod(roomId);
}
match /userusers/{uid}{
allow read, write: if (uid.split('_')[0] == request.auth.uid || uid.split('_')[1] == request.auth.uid);
}
}
}