Repository navigation
Expand file tree
/
Copy pathfirestore.rules.example
More file actions
53 lines (46 loc) · 2.14 KB
/
Copy pathfirestore.rules.example
File metadata and controls
53 lines (46 loc) · 2.14 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
rules_version = '2';
// Template. Copy to firestore.rules (gitignored) and replace example[.]edu with your college domain.
service cloud.firestore {
match /databases/{database}/documents {
function member() {
return request.auth != null
&& request.auth.token.email_verified == true
&& request.auth.token.email.lower().matches('.*@example[.]edu$');
}
// End of 31 Oct 2026 IST (lib/pr.ts DEADLINE)
function open() {
return request.time < timestamp.value(1793471400000);
}
function owns(data) {
return data.uid == request.auth.uid;
}
function valid(id) {
let d = request.resource.data;
return d.keys().hasAll(['uid', 'email', 'prUrl', 'owner', 'repo', 'number', 'type', 'createdAt', 'updatedAt'])
&& d.keys().hasOnly(['uid', 'email', 'prUrl', 'owner', 'repo', 'number', 'type', 'createdAt', 'updatedAt'])
&& owns(d)
&& d.email == request.auth.token.email
&& d.owner is string && d.owner.matches('^[A-Za-z0-9_.-]+$')
&& d.repo is string && d.repo.matches('^[A-Za-z0-9_.-]+$')
&& d.number is int && d.number > 0
&& d.prUrl == 'https://github.com/' + d.owner + '/' + d.repo + '/pull/' + string(d.number)
&& id == (d.owner + '__' + d.repo + '__' + string(d.number)).lower()
&& d.type in ['sosc', 'external']
&& d.updatedAt == request.time;
}
match /submissions/{id} {
// `resource == null` lets the client check whether a PR id is free before writing
allow get: if member() && (resource == null || owns(resource.data));
allow list: if member() && owns(resource.data);
allow create: if member() && open() && valid(id)
&& request.resource.data.createdAt == request.time;
allow update: if member() && open() && owns(resource.data) && valid(id)
&& request.resource.data.createdAt == resource.data.createdAt;
allow delete: if member() && open() && owns(resource.data);
}
// written only by badges/sync.mjs (admin); each member can read just their own
match /badges/{email} {
allow get: if member() && email == request.auth.token.email.lower();
}
}
}