-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
78 lines (64 loc) · 3.11 KB
/
firestore.rules
File metadata and controls
78 lines (64 loc) · 3.11 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper function to check if user is authenticated
function isAuthenticated() {
return request.auth != null;
}
// Helper function to check if user owns the document
function isOwner(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
// Users collection
match /users/{userId} {
// Users can read their own profile and other users' profiles (for public info)
allow read: if isAuthenticated();
// Users can create their own profile during signup
allow create: if isAuthenticated() && request.auth.uid == userId;
// Users can update their own profile
allow update: if isOwner(userId);
}
// Bounties collection
match /bounties/{bountyId} {
// Anyone authenticated can read bounties
allow read: if isAuthenticated();
// Only companies can create bounties
allow create: if isAuthenticated()
&& exists(/databases/$(database)/documents/users/$(request.auth.uid))
&& get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'COMPANY';
// Only the creator can update their own bounties
allow update: if isAuthenticated()
&& resource.data.companyUid == request.auth.uid;
// Only the creator can delete their own bounties
allow delete: if isAuthenticated()
&& resource.data.companyUid == request.auth.uid;
}
// Submissions collection
match /submissions/{submissionId} {
// Developers can read their own submissions
allow read: if isAuthenticated()
&& (resource.data.developerUid == request.auth.uid
|| exists(/databases/$(database)/documents/bounties/$(resource.data.bountyId))
&& get(/databases/$(database)/documents/bounties/$(resource.data.bountyId)).data.companyUid == request.auth.uid);
// Only developers can create submissions
allow create: if isAuthenticated()
&& exists(/databases/$(database)/documents/users/$(request.auth.uid))
&& get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'DEVELOPER';
// Companies can update submissions for their bounties
allow update: if isAuthenticated()
&& exists(/databases/$(database)/documents/bounties/$(resource.data.bountyId))
&& get(/databases/$(database)/documents/bounties/$(resource.data.bountyId)).data.companyUid == request.auth.uid;
}
// Transactions collection
match /transactions/{transactionId} {
// Users can read transactions they're involved in
allow read: if isAuthenticated()
&& (resource.data.fromUserId == request.auth.uid
|| resource.data.toUserId == request.auth.uid);
// Only system/companies can create transactions
allow create: if isAuthenticated()
&& exists(/databases/$(database)/documents/users/$(request.auth.uid))
&& get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'COMPANY';
}
}
}