-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
75 lines (62 loc) · 2.16 KB
/
Copy pathfirestore.rules
File metadata and controls
75 lines (62 loc) · 2.16 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
function isAdmin() {
return isSignedIn() &&
exists(/databases/$(database)/documents/roles_admin/$(request.auth.uid)) &&
get(/databases/$(database)/documents/roles_admin/$(request.auth.uid)).data.role == 'admin';
}
// Allow users to check their own admin role
match /roles_admin/{userId} {
allow read: if isSignedIn() && request.auth.uid == userId;
allow write: if isAdmin(); // Only admins can modify roles
}
// Number Generator Rules
match /availableNumbers/{numberId} {
// Users can see unused stock OR their own assigned numbers
allow read: if isSignedIn() && (
resource.data.isUsed == false ||
resource.data.assignedTo == request.auth.token.email ||
isAdmin()
);
// Admin can populate/delete data
allow create, delete: if isAdmin();
// Users can only mark a number as used if it's currently free
allow update: if isSignedIn()
&& resource.data.isUsed == false
&& request.resource.data.isUsed == true
&& (request.resource.data.assignedTo == request.auth.token.email || isAdmin());
}
match /userGenerationLimits/{userId} {
allow read, write: if isSignedIn() && request.auth.uid == userId;
allow read, write: if isAdmin();
}
// Employee History Rules
match /employee_history/{docId} {
allow read: if isSignedIn();
allow create, update, delete: if isAdmin();
}
// Media Library Rules
match /media_library/{id} {
allow read: if true;
allow write, delete: if isAdmin();
}
// BIOS & Boot Menu Keys Rules
match /bios_keys/{keyId} {
allow read: if true; // Publik, siapa saja bisa cari tombol
allow create, update, delete: if isAdmin(); // Hanya bisa diisi/diubah Admin
}
// Audit logs
match /audit_logs/{logId} {
allow write: if isSignedIn();
allow read: if isAdmin();
}
// Default deny
match /{path=**} {
allow read, write: if false;
}
}
}