-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
117 lines (102 loc) · 5.64 KB
/
firestore.rules
File metadata and controls
117 lines (102 loc) · 5.64 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Reglas para la colección de usuarios
match /users/{userId} {
allow create: if request.auth != null;
allow read: if true;
allow update: if request.auth != null && (
// El usuario puede actualizar su propio documento (p. ej., su lista de 'following' o su fcmToken)
(request.auth.uid == userId && request.resource.data.diff(resource.data).affectedKeys().hasOnly(['following', 'fcmToken', 'username', 'email', 'profilePictureUrl', 'alias', 'location', 'bio'])) ||
// Otro usuario puede actualizar la lista de seguidores y el contador de este usuario
(request.resource.data.diff(resource.data).affectedKeys().hasOnly(['followers', 'followersCount'])) ||
// Otro usuario puede añadir una notificación al documento de este usuario
(request.resource.data.diff(resource.data).affectedKeys().hasOnly(['notifications']))
);
allow delete: if request.auth != null && (resource.data.mentorId == request.auth.uid || request.auth.uid == 'Ee6vjE08F0ZhxkETaVuMN4buTsn2');
}
// Reglas para la colección de libros
match /books/{bookId} {
allow read: if true;
allow create: if request.auth != null;
allow update: if request.auth != null && (resource.data.ownerId == request.auth.uid || request.resource.data.diff(resource.data).affectedKeys().hasOnly(['views']));
allow delete: if request.auth != null && request.auth.uid == resource.data.ownerId;
// Subcolección para calificaciones de libros
match /ratings/{ratingId} {
allow read: if true;
allow create: if request.auth != null;
allow update, delete: if request.auth != null && resource.data.userId == request.auth.uid;
}
}
// Reglas para la colección de entradas del foro
match /forumEntries/{entryId} {
allow read: if true;
allow create: if request.auth != null;
allow delete: if request.auth != null && (request.auth.uid == resource.data.userId || request.auth.uid == resource.data.bookOwnerId || request.auth.uid == resource.data.contentOwnerId);
}
// Reglas para la nueva colección unificada de reseñas
match /reviews/{reviewId} {
allow read: if true;
allow create: if request.auth != null;
allow update, delete: if request.auth != null && (request.auth.uid == resource.data.userId || request.auth.uid == resource.data.itemOwnerId);
}
// Reglas para la colección de chats y subcolección de mensajes
match /chats/{chatId} {
allow read, write: if request.auth != null && request.auth.uid in resource.data.participants;
match /messages/{messageId} {
allow read, write: if request.auth != null && get(/databases/$(database)/documents/chats/$(chatId)).data.participants.hasAny([request.auth.uid]);
}
}
// Reglas para la colección de notificaciones
match /notifications/{notificationId} {
allow create: if request.auth != null;
allow read: if request.auth != null && request.auth.uid == resource.data.recipientId;
allow update: if request.auth != null && request.auth.uid == resource.data.recipientId && request.resource.data.diff(resource.data).affectedKeys().hasOnly(['read']);
}
// Reglas para la colección de solicitudes de agentes (Embajada)
match /agent_requests/{requestId} {
allow read: if request.auth != null;
allow create: if request.auth != null;
}
// Reglas para contenido de YouTube
match /videos/{videoId} {
allow read: if true;
allow create: if request.auth != null;
allow update: if request.auth != null && (request.resource.data.diff(resource.data).affectedKeys().hasOnly(['views']) || request.auth.uid == resource.data.ownerId);
allow delete: if request.auth.uid == resource.data.ownerId;
}
match /movies/{movieId} {
allow read: if true;
allow create: if request.auth != null;
allow update: if request.auth != null && (request.resource.data.diff(resource.data).affectedKeys().hasOnly(['views']) || request.auth.uid == resource.data.ownerId);
allow delete: if request.auth.uid == resource.data.ownerId;
}
match /music/{musicId} {
allow read: if true;
allow create: if request.auth != null;
allow update: if request.auth != null && (request.resource.data.diff(resource.data).affectedKeys().hasOnly(['views']) || request.auth.uid == resource.data.ownerId);
allow delete: if request.auth.uid == resource.data.ownerId;
}
match /videojuegos/{videojuegoId} {
allow read: if true;
allow create: if request.auth != null;
allow update: if request.auth != null && (request.resource.data.diff(resource.data).affectedKeys().hasOnly(['views']) || request.auth.uid == resource.data.ownerId);
allow delete: if request.auth.uid == resource.data.ownerId;
}
match /webs/{webId} {
allow read: if true;
allow create: if request.auth != null;
allow update: if request.auth != null && (request.resource.data.diff(resource.data).affectedKeys().hasOnly(['views']) || request.auth.uid == resource.data.ownerId);
allow delete: if request.auth.uid == resource.data.ownerId;
}
// Reglas para la Embajada de Agentes
match /embassy_keys/{keyId} {
allow read, create, update: if request.auth != null && request.auth.uid == request.resource.data.mentorId;
allow read, delete: if request.auth != null && resource.data.mentorId == request.auth.uid;
}
match /agent_logs/{logId} {
allow read: if request.auth != null; // Simplificado para visualización de mentoría
allow create: if request.auth != null;
}
}
}