-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore.rules
103 lines (83 loc) · 1.94 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
rules_version = '2'
service cloud.firestore {
match /databases/{database}/documents {
match /users/{uid} {
allow read
allow create: if
isSignedInWith(uid)
allow update: if
isSignedInWith(uid) ||
onlyUpdatedFields(['allowContact']) ||
onlyUpdatedFields(['unsubscribed', 'unsubscribed.due-cards'])
match /blocked/{otherUid} {
allow read, create, update
}
match /tokens/{token} {
allow read, create, update: if
isSignedInWith(uid)
}
match /activity/{day} {
allow read
}
match /decks/{deckId} {
allow read, write: if
isSignedInWith(uid)
match /drafts/{draftId} {
allow read, write: if
isSignedInWith(uid)
}
match /cards/{cardId} {
allow read: if
isSignedInWith(uid)
}
}
}
match /topics/{topicId} {
allow read
}
match /decks/{deckId} {
allow read
allow create: if
isSignedInAsDeckCreator(getNewData())
allow write: if
isSignedInAsDeckCreator(getOldData())
match /sections/{sectionId} {
allow read
allow write: if
isSignedInAsDeckCreator(getDeck(deckId))
}
match /cards/{cardId} {
allow read
allow write: if
isSignedInAsDeckCreator(getDeck(deckId))
}
}
match /counters/{counter} {
allow read
}
match /previewDeckScores/{scoreId} {
allow read, create
}
function isSignedIn() {
return request.auth != null
}
function isSignedInWith(uid) {
return isSignedIn() && request.auth.uid == uid
}
function getNewData() {
return request.resource.data
}
function getOldData() {
return resource.data
}
function onlyUpdatedFields(fields) {
return getNewData().diff(getOldData()).affectedKeys().hasOnly(fields)
}
function getDeck(deckId) {
return get(/databases/$(database)/documents/decks/$(deckId)).data
}
function isSignedInAsDeckCreator(deck) {
return isSignedInWith(deck.creator)
}
}
}