-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
139 lines (120 loc) · 4.83 KB
/
Copy pathfirestore.rules
File metadata and controls
139 lines (120 loc) · 4.83 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// ============================================
// HELPERS — Funciones de rol reutilizables
// ============================================
function isAuth() {
return request.auth != null;
}
function isAdmin() {
return isAuth() && request.auth.token.role == 'admin';
}
function isVolunteer() {
return isAuth() && request.auth.token.role == 'volunteer';
}
function isDonor() {
return isAuth() && request.auth.token.role == 'donor';
}
function isOwner(userId) {
return isAuth() && request.auth.uid == userId;
}
// ============================================
// DONACIONES — Lectura autenticada / Escritura autenticada
// ============================================
match /donaciones/{donacionId} {
allow read: if isAuth(); // Transparencia solo para usuarios autenticados
allow create: if isAuth(); // Solo usuarios registrados donan
allow update, delete: if isAdmin(); // Solo admin puede modificar
}
// ============================================
// VOLUNTARIOS — Perfil propio + lectura admin
// ============================================
match /voluntarios/{userId} {
allow read: if isAdmin() || isOwner(userId);
allow create: if isAuth();
allow update: if isOwner(userId) || isAdmin();
allow delete: if isAdmin();
}
// ============================================
// BENEFICIARIOS — Solo admin (datos sensibles)
// ============================================
match /beneficiarios/{beneficiarioId} {
allow read, write: if isAdmin();
}
// ============================================
// REPORTES CONTRALORÍA SOCIAL — Escritura pública / Lectura admin
// ============================================
match /reportes/{reporteId} {
allow read: if isAdmin();
allow create: if true; // Reporte anónimo permitido
allow update, delete: if isAdmin();
}
// ============================================
// CENSO — Solo admin fiduciario (máxima restricción)
// ============================================
match /censo/{zonaId} {
allow read, write: if isAdmin();
}
// ============================================
// NFTs / CERTIFICADOS — Lectura autenticada / Escritura admin
// ============================================
match /certificados/{nftId} {
allow read: if isAuth();
allow write: if isAdmin();
}
// ============================================
// LOGS SOC (Ciberseguridad) — Solo admin
// ============================================
match /security_logs/{logId} {
allow read, write: if isAdmin();
}
// ============================================
// MÉDICO ALIADO — Consultas y expedientes
// ============================================
match /consultas_medicas/{consultaId} {
allow read: if isAuth() && (request.auth.token.role == 'medico' || isAdmin());
allow create: if isAuth() && request.auth.token.role == 'medico';
allow update: if isAuth() && (isOwner(resource.data.medicoId) || isAdmin());
allow delete: if isAdmin();
}
// ============================================
// HOGAR DE ACOGIDA — Registros de acogida
// ============================================
match /hogares_acogida/{hogarId} {
allow read: if isAuth() && (isOwner(hogarId) || isAdmin());
allow write: if isAuth() && (isOwner(hogarId) || isAdmin());
}
// ============================================
// RESCATISTA ANIMAL — Alertas y operaciones
// ============================================
match /rescates/{rescateId} {
allow read: if isAuth();
allow create: if isAuth();
allow update: if isAuth() && (isOwner(resource.data.rescatistaId) || isAdmin());
allow delete: if isAdmin();
}
// ============================================
// PROVEEDOR LOCAL — Catálogo y gestión
// ============================================
match /proveedores/{proveedorId} {
allow read: if isAuth();
allow write: if isAuth() && (isOwner(proveedorId) || isAdmin());
}
// ============================================
// PEDIDOS — Órdenes inter-roles
// ============================================
match /pedidos/{pedidoId} {
allow read: if isAuth() && (
resource.data.proveedorId == request.auth.uid ||
resource.data.solicitanteId == request.auth.uid ||
isAdmin()
);
allow create: if isAuth();
allow update: if isAuth() && (
resource.data.proveedorId == request.auth.uid || isAdmin()
);
allow delete: if isAdmin();
}
}
}