-
Notifications
You must be signed in to change notification settings - Fork 1
/
firestore-rules.txt
75 lines (75 loc) · 2.89 KB
/
firestore-rules.txt
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
service cloud.firestore {
match /databases/{database}/documents {
match /rooms/{roomID} {
allow get;
allow list: if resource.data.public ||
resource.data.owner == request.auth.uid;
allow create: if request.auth != null &&
request.resource.data.owner == request.auth.uid &&
request.resource.data.title is string &&
request.resource.data.title.size() > 1 &&
request.resource.data.title.size() < 64 &&
request.resource.data.public is bool &&
request.resource.data.usersOnline is number &&
!exists(/databases/$(database)/documents/rooms/$(roomID));
allow update: if request.auth != null &&
request.resource.data.title is string &&
request.resource.data.title.size() > 1 &&
request.resource.data.title.size() < 64 &&
request.resource.data.public is bool &&
resource.data.owner == request.auth.uid &&
request.resource.data.owner == resource.data.owner; // Can't change owner
allow delete: if request.auth != null &&
resource.data.owner == request.auth.uid;
}
match /user_settings/{userID} {
function isValidRoomId(index) {
return request.resource.data.roomHistory[index].id is string &&
request.resource.data.roomHistory[index].id.size() < 33 &&
request.resource.data.roomHistory[index].title is string &&
request.resource.data.roomHistory[index].title.size() < 65;
}
function isValidHistory() {
return request.resource.data.roomHistory is list &&
request.resource.data.roomHistory.size() < 5 &&
request.resource.data.roomHistory.size() < 1 ||
(
request.resource.data.roomHistory.size() == 1 &&
isValidRoomId(0)
) ||
(
request.resource.data.roomHistory.size() == 2 &&
isValidRoomId(0) &&
isValidRoomId(1)
) ||
(
request.resource.data.roomHistory.size() == 3 &&
isValidRoomId(0) &&
isValidRoomId(1) &&
isValidRoomId(2)
) ||
(
request.resource.data.roomHistory.size() == 4 &&
isValidRoomId(0) &&
isValidRoomId(1) &&
isValidRoomId(2) &&
isValidRoomId(3)
);
}
allow create: if request.auth != null &&
request.auth.uid == userID &&
request.resource.data.darkMode is bool &&
isValidHistory() &&
request.resource.data.version is string &&
request.resource.data.version.size() < 6;
allow update: if request.auth != null &&
request.auth.uid == userID &&
request.resource.data.darkMode is bool &&
isValidHistory() &&
request.resource.data.version is string &&
request.resource.data.version.size() < 6;
allow read: if request.auth != null &&
request.auth.uid == userID;
}
}
}