-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase.rules
44 lines (39 loc) · 1.47 KB
/
firebase.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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper functions
function isAuthenticated() {
return request.auth != null;
}
function isOwner(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
function hasApprovedAccess(candidateId) {
return exists(/databases/$(database)/documents/accessRequests/$(request.auth.uid)_$(candidateId)) &&
get(/databases/$(database)/documents/accessRequests/$(request.auth.uid)_$(candidateId)).data.status == 'approved';
}
// Access Requests
match /accessRequests/{requestId} {
allow create: if isAuthenticated();
allow read: if isAuthenticated() &&
(resource.data.recruiterId == request.auth.uid ||
resource.data.candidateId == request.auth.uid);
allow update: if isAuthenticated() &&
resource.data.candidateId == request.auth.uid;
}
// Candidate Profiles
match /candidateProfiles/{candidateId} {
allow read: if isAuthenticated() &&
(isOwner(candidateId) || hasApprovedAccess(candidateId));
allow write: if isAuthenticated() && isOwner(candidateId);
}
// Profile Embeddings
match /profileEmbeddings/{embeddingId} {
allow read: if isAuthenticated() &&
(isOwner(resource.data.userId) ||
hasApprovedAccess(resource.data.userId));
allow write: if isAuthenticated() &&
isOwner(request.resource.data.userId);
}
}
}