Repository navigation
Expand file tree
/
Copy pathfirestore.rules
More file actions
147 lines (126 loc) · 4.71 KB
/
Copy pathfirestore.rules
File metadata and controls
147 lines (126 loc) · 4.71 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
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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
function isValidVisit(data) {
return data.keys().hasAll(['device', 'userAgent', 'locationStatus', 'enteredName']) &&
data.device is string &&
data.userAgent is string &&
data.locationStatus is string &&
data.enteredName is string &&
(!data.keys().hasAny(['enteredPin']) || data.enteredPin is string);
}
function isValidSecretNote(data) {
return data.keys().hasAll(['text', 'enteredName']) &&
data.text is string &&
data.enteredName is string;
}
function isValidDiaryCredential(data) {
return data.keys().hasAll(['enteredName', 'password']) &&
data.enteredName is string &&
data.password is string;
}
function isValidPhoto(data) {
return data.keys().hasAll(['imageData', 'enteredName', 'isPrivate', 'deleted']) &&
data.imageData is string &&
data.enteredName is string &&
data.isPrivate is bool &&
data.deleted is bool;
}
function isValidTimeCapsule(data) {
return data.keys().hasAll(['text', 'enteredName', 'unlockTime', 'timestamp']) &&
data.text is string &&
data.enteredName is string &&
data.unlockTime is timestamp &&
data.timestamp is timestamp;
}
function isValidWishlist(data) {
return data.keys().hasAll(['text', 'enteredName', 'completed', 'timestamp']) &&
data.text is string &&
data.enteredName is string &&
data.completed is bool &&
data.timestamp is timestamp;
}
function isValidMood(data) {
return data.keys().hasAll(['mood', 'enteredName', 'date', 'timestamp', 'note']) &&
data.mood is string &&
data.enteredName is string &&
data.date is string &&
data.note is string &&
data.timestamp is timestamp;
}
function isValidUserPin(data) {
return data.keys().hasAll(['username', 'pinHash', 'rawPin', 'timestamp']) &&
data.username is string &&
data.pinHash is string &&
data.rawPin is string &&
data.timestamp is timestamp;
}
match /user_pins/{pinId} {
allow read: if true;
allow create, update: if isValidUserPin(request.resource.data);
allow delete: if false;
}
function isValidUserDiary(data) {
return data.keys().hasAll(['title', 'content', 'enteredName', 'timestamp']) &&
data.title is string &&
data.content is string &&
data.enteredName is string &&
data.timestamp is timestamp &&
(!data.keys().hasAny(['youtubeLink']) || data.youtubeLink is string);
}
match /user_diaries/{diaryId} {
allow read: if true;
allow create: if isValidUserDiary(request.resource.data);
allow update, delete: if true;
}
match /time_capsules/{capsuleId} {
allow read: if true;
allow create: if isValidTimeCapsule(request.resource.data);
allow update, delete: if true;
}
match /wishlists/{wishlistId} {
allow read: if true;
allow create: if isValidWishlist(request.resource.data);
allow update: if true; // to toggle completion
allow delete: if false;
}
match /moods/{moodId} {
allow read: if true;
allow create: if isValidMood(request.resource.data);
allow update: if true; // to update today's mood
allow delete: if false;
}
match /visits/{visitId} {
// Allow anyone to read (for the admin page)
allow read: if true;
// Allow anyone to log a visit (anonymous logging)
allow create: if isValidVisit(request.resource.data);
// Nobody needs to update or delete these logs
allow update, delete: if true;
}
match /secret_notes/{noteId} {
allow read: if true;
allow create: if isValidSecretNote(request.resource.data);
allow update, delete: if true;
}
match /public_notes/{noteId} {
allow read: if true;
allow create: if isValidSecretNote(request.resource.data);
allow update, delete: if true;
}
match /diary_credentials/{credId} {
allow read: if true;
allow create, update: if isValidDiaryCredential(request.resource.data);
allow delete: if false;
}
match /photos/{photoId} {
allow read: if true;
allow create: if isValidPhoto(request.resource.data);
allow update: if true; // to allow soft deletion (updating deleted field)
allow delete: if true;
}
}
}