-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
120 lines (105 loc) · 3.76 KB
/
Copy pathfirestore.rules
File metadata and controls
120 lines (105 loc) · 3.76 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
rules_version = '2';
// ============================================================
// ROL / YETKI GUVENLIK KURALLARI
// Bu kurallar SUNUCUDA calisir; tarayicidan kandirilamaz.
//
// Roller:
// admin (Yonetici) -> her sey
// manager (Mudur-Editor) -> okuma + ekleme/duzenleme + SILME
// staff (Personel-Editor) -> okuma + ekleme/duzenleme (SILEMEZ)
// viewer (Izleyici) -> sadece okuma
// ============================================================
service cloud.firestore {
match /databases/{database}/documents {
// --- yardimci fonksiyonlar ---
function signedIn() {
return request.auth != null;
}
function profilePath() {
return /databases/$(database)/documents/users/$(request.auth.uid);
}
function hasProfile() {
return signedIn() && exists(profilePath());
}
function profile() {
return get(profilePath()).data;
}
function isActive() {
return hasProfile() && profile().active == true;
}
function role() {
return isActive() ? profile().role : 'none';
}
function isAdmin() { return role() == 'admin'; }
function isManager() { return role() == 'manager'; }
function isStaff() { return role() == 'staff'; }
// herkes (aktif kullanici): okuyabilir
function canRead() { return isActive(); }
// admin + mudur + personel: ekleyebilir / duzenleyebilir
function canWrite() { return isAdmin() || isManager() || isStaff(); }
// admin + mudur: silebilir (personel SILEMEZ)
function canDelete() { return isAdmin() || isManager(); }
// --- kullanicilar / roller koleksiyonu ---
match /users/{userId} {
// kullanici kendi profilini okur; aktif herkes diger profilleri gorebilir
allow read: if signedIn() && (request.auth.uid == userId || isActive());
// SADECE yonetici kullanici/rol olusturur, gunceller, siler
allow create, update, delete: if isAdmin();
}
// --- esnek icerik kayitlari ---
match /content/{docId} {
allow read: if canRead();
allow create, update: if canWrite();
allow delete: if canDelete();
}
// --- raporlar (surum gecmisi dahil) ---
match /reports/{docId} {
allow read: if canRead();
allow create, update: if canWrite();
allow delete: if canDelete();
}
// --- borsa: hisseler ve skorlar ---
match /borsa_stocks/{docId} {
allow read: if canRead();
allow create, update: if canWrite();
allow delete: if canDelete();
}
// --- borsa: strateji agirliklari + makro (mudur/yonetici yazar) ---
match /borsa_config/{docId} {
allow read: if canRead();
allow write: if canDelete();
}
// --- borsa: haberler ---
match /borsa_news/{docId} {
allow read: if canRead();
allow create, update: if canWrite();
allow delete: if canDelete();
}
// --- belgeler (yuklenen dosya kayitlari) ---
match /documents/{docId} {
allow read: if canRead();
allow create, update: if canWrite();
allow delete: if canDelete();
}
// --- borsa veri onbellegi (yalniz Cloud Functions yazar) ---
match /borsa_cache/{docId} {
allow read: if canRead();
allow write: if false;
}
// --- site ayarlari (sadece yonetici yazar) ---
match /settings/{docId} {
allow read: if canRead();
allow write: if isAdmin();
}
// --- islem gunlugu / denetim kaydi (ileride) ---
match /audit/{docId} {
allow read: if isAdmin();
allow create: if isActive();
allow update, delete: if false;
}
// geri kalan her sey YASAK (varsayilan guvenli)
match /{document=**} {
allow read, write: if false;
}
}
}