fix erreur firebase

This commit is contained in:
2025-06-03 20:41:45 +02:00
parent 57c59c911a
commit 080fb7d077
2 changed files with 19 additions and 12 deletions

View File

@ -20,22 +20,24 @@ class EventProvider with ChangeNotifier {
print( print(
'Loading events for user: $userId (canViewAllEvents: $canViewAllEvents)'); 'Loading events for user: $userId (canViewAllEvents: $canViewAllEvents)');
QuerySnapshot eventsSnapshot; QuerySnapshot eventsSnapshot;
if (canViewAllEvents) { // On charge tous les events pour les users non-admins aussi
eventsSnapshot = await _firestore.collection('events').get(); eventsSnapshot = await _firestore.collection('events').get();
} else {
eventsSnapshot = await _firestore
.collection('events')
.where('workforce',
arrayContains: _firestore.collection('users').doc(userId))
.get();
}
print('Found ${eventsSnapshot.docs.length} events for user'); print('Found ${eventsSnapshot.docs.length} events for user');
_events = eventsSnapshot.docs.map((doc) { // On filtre côté client si l'utilisateur n'est pas admin
final allEvents = eventsSnapshot.docs.map((doc) {
print('Event data: ${doc.data()}'); print('Event data: ${doc.data()}');
return EventModel.fromMap(doc.data() as Map<String, dynamic>, doc.id); return EventModel.fromMap(doc.data() as Map<String, dynamic>, doc.id);
}).toList(); }).toList();
if (canViewAllEvents) {
_events = allEvents;
} else {
final userRef = _firestore.collection('users').doc(userId);
_events = allEvents
.where((e) => e.workforce.any((ref) => ref.id == userRef.id))
.toList();
}
print('Parsed ${_events.length} events'); print('Parsed ${_events.length} events');

View File

@ -98,6 +98,7 @@ class EventDetails extends StatelessWidget {
const SizedBox(width: 12), const SizedBox(width: 12),
_buildStatusIcon(event.status), _buildStatusIcon(event.status),
const SizedBox(width: 8), const SizedBox(width: 8),
Spacer(),
if (Provider.of<LocalUserProvider>(context, listen: false) if (Provider.of<LocalUserProvider>(context, listen: false)
.hasPermission('edit_event')) .hasPermission('edit_event'))
IconButton( IconButton(
@ -828,8 +829,12 @@ class EquipeSection extends StatelessWidget {
if (snapshot.hasError) { if (snapshot.hasError) {
return Padding( return Padding(
padding: const EdgeInsets.symmetric(vertical: 16), padding: const EdgeInsets.symmetric(vertical: 16),
child: Text('Erreur lors du chargement de l\'équipe', child: Text(
style: TextStyle(color: Colors.red)), snapshot.error.toString().contains('permission-denied')
? "Vous n'avez pas la permission de voir tous les membres de l'équipe."
: "Erreur lors du chargement de l'équipe : ${snapshot.error}",
style: const TextStyle(color: Colors.red),
),
); );
} }
final users = snapshot.data ?? []; final users = snapshot.data ?? [];