-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
101 lines (83 loc) · 2.86 KB
/
Copy pathfirestore.rules
File metadata and controls
101 lines (83 loc) · 2.86 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper functions
function isSignedIn() {
return request.auth != null;
}
function getUserData() {
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data;
}
function hasRole(role) {
return isSignedIn() && getUserData().role == role;
}
function isAdmin() {
return hasRole('admin');
}
function isPastor() {
return hasRole('pastor');
}
function isFinance() {
return hasRole('finance');
}
function isUsher() {
return hasRole('usher');
}
function isLeader() {
return hasRole('leader');
}
// Users Collection
match /users/{userId} {
allow read: if isSignedIn() && (request.auth.uid == userId || isAdmin() || isPastor() || isFinance() || isLeader());
allow write: if isAdmin();
allow update: if isSignedIn() && request.auth.uid == userId && !request.resource.data.diff(resource.data).affectedKeys().hasAny(['role', 'active']);
}
// Members Collection
match /members/{memberId} {
allow read: if isSignedIn();
allow write: if isAdmin() || isPastor();
}
// Attendance & Sessions
match /attendance/{recordId} {
allow read: if isSignedIn() && (isAdmin() || isPastor() || isUsher() || isLeader() || resource.data.userId == request.auth.uid);
allow write: if isAdmin() || isPastor() || isUsher() || isLeader();
}
match /attendance_sessions/{sessionId} {
allow read: if isSignedIn();
allow write: if isAdmin() || isPastor() || isUsher() || isLeader();
}
// Finance Transactions
match /finance_transactions/{txId} {
allow read, write: if isAdmin() || isFinance();
}
// Announcements
match /announcements/{announcementId} {
allow read: if isSignedIn();
allow write: if isAdmin() || isPastor();
}
// Ministries
match /ministries/{ministryId} {
allow read: if isSignedIn();
allow create: if isAdmin() || isPastor();
allow update: if isAdmin() || isPastor() ||
(isLeader() && resource.data.leaderId == request.auth.uid);
allow delete: if isAdmin() || isPastor();
}
// Prayers
match /prayers/{prayerId} {
allow read: if isSignedIn() && (isAdmin() || isPastor() || isLeader() || resource.data.userId == request.auth.uid);
allow create: if isSignedIn();
allow update, delete: if isAdmin() || isPastor() || isLeader() || (isSignedIn() && resource.data.userId == request.auth.uid);
}
// System Config
match /system_config/{configId} {
allow read: if isSignedIn();
allow write: if isAdmin();
}
// Events
match /events/{eventId} {
allow read: if isSignedIn();
allow write: if isAdmin() || isPastor();
}
}
}