-
Notifications
You must be signed in to change notification settings - Fork 30
/
firestore.rules
173 lines (156 loc) · 5.78 KB
/
firestore.rules
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
rules_version = '2';
function isUpdateRestrictedToField(request, field) {
return request.resource.data.diff(resource.data).affectedKeys().hasOnly([field]);
}
function role(name) {
return get(/databases/$(database)/documents/roles/$(name)).data;
}
service cloud.firestore {
match /databases/{database}/documents {
function worldFromResource() {
return get(/databases/$(database)/documents/worlds/$(resource.data.worldId)).data;
}
function worldFromRequest() {
return get(/databases/$(database)/documents/worlds/$(request.resource.data.worldId)).data;
}
match /authConfigs/{authConfigId} {
allow read, write: if false;
}
match /users/{userId} {
allow get: if request.auth.uid != null;
allow list: if request.auth.uid != null;
allow write: if request.auth.uid == userId;
match /visits/{venueId} {
allow read: if true;
allow write: if request.auth.uid == userId;
}
match /onboardedWorlds/{worldId} {
allow read: if request.auth.uid == userId;
allow write: if false;
}
}
match /userprivate/{userId} {
allow read, write: if request.auth.uid == userId;
}
match /privatechats/{userId}/{restOfPath=**} {
allow create: if request.auth.uid != null && request.resource.data.fromUser.id == request.auth.uid;
allow read: if request.auth.uid != null && userId == request.auth.uid;
allow update: if request.auth.uid != null && isUpdateRestrictedToField(request, 'isRead');
}
match /experiences/{experienceId}/{restOfPath=**} {
allow read, write: if request.auth.uid != null;
}
match /retunableMediaElements/{elementId} {
allow read, write: if request.auth.uid != null;
}
match /venues/{venue} {
allow read: if true;
function venueData() {
return get(/databases/$(database)/documents/venues/$(venue)).data;
}
function world() {
return get(/databases/$(database)/documents/worlds/$(venueData().worldId)).data;
}
function checkIfWorldOwner() {
return request.auth.uid in role('admin').users || request.auth.uid in world().owners
}
match /events/{event} {
allow read: if true;
allow write: if checkIfWorldOwner();
}
match /chatMessagesCounter/{shardId} {
allow read, write: if request.auth.uid != null;
allow delete: if false;
}
match /chats/{messageId} {
allow read, create: if request.auth.uid != null && !world().isHidden;
allow delete: if checkIfWorldOwner();
allow update: if request.auth.uid != null && isUpdateRestrictedToField(request, 'repliesCount');
match /thread/{messageId} {
allow read, create: if request.auth.uid != null;
allow delete: if checkIfWorldOwner();
allow update: if false;
}
}
match /jukeboxMessages/{restOfPath=**} {
allow read, create: if request.auth.uid != null;
allow update: if checkIfWorldOwner() && isUpdateRestrictedToField(request, 'deleted');
}
match /access/{method} {
allow read, write: if false;
}
match /accessgranted/{userId} {
allow read, write: if false;
}
match /recentSeatedUsers/{userId} {
allow read: if request.auth.uid != null;
allow write: if request.auth.uid == userId;
}
match /seatedTableUsers/{userId} {
allow read: if request.auth.uid != null;
allow write: if request.auth.uid == userId;
}
match /sections/{sectionId} {
allow read: if request.auth.uid != null;
allow write: if checkIfSpaceOrWorldOwner();
match /seatedSectionUsers/{userId} {
allow read: if request.auth.uid != null;
allow write: if request.auth.uid == userId;
}
}
match /screeningRoomVideos/{screeningRoomVideoId} {
allow read: if request.auth.uid != null;
allow write: if false;
}
match /firebarrels/{firebarrelId} {
allow read: if request.auth.uid != null;
// @debt any user can set an empty arr
allow create, update: if request.auth.uid != null && (request.resource.data.diff(resource.data).affectedKeys().hasOnly(['connectedUsers']));
allow delete: if false;
}
match /artcars/{artcarId} {
allow read: if request.auth.uid != null;
allow write: if false;
}
}
match /roles/{roleId} {
allow read: if request.auth.uid != null;
allow write: if false;
}
match /settings/{settingId} {
allow read: if request.auth.uid != null;
allow write: if false;
}
match /sounds/{soundId} {
allow read: if request.auth.uid != null;
allow write: if false;
}
match /worlds/{worldId} {
allow create: if request.auth.uid in role('admin').users;
function world() {
return get(/databases/$(database)/documents/worlds/$(worldId)).data;
}
allow get: if !resource.data.isHidden;
allow list: if !resource.data.isHidden;
allow update, delete: if request.auth.uid in role('admin').users && request.auth.uid in world().owners;
match /seatedUsers/{userId} {
allow read: if request.auth.uid != null;
allow write: if request.auth.uid == userId;
}
match /recentSeatedUsers/{userId} {
allow read: if request.auth.uid != null;
allow write: if request.auth.uid == userId;
}
}
match /worldEvents/{eventId} {
allow update, delete: if request.auth.uid in worldFromResource().owners;
allow create: if request.auth.uid in worldFromRequest().owners;
allow read: if true
}
match /userPresence/{userPresence} {
allow update, delete: if resource.data.userId == request.auth.uid;
allow create: if true;
allow read: if true;
}
}
}