fix erreur firebase
This commit is contained in:
@ -20,22 +20,24 @@ class EventProvider with ChangeNotifier {
|
||||
print(
|
||||
'Loading events for user: $userId (canViewAllEvents: $canViewAllEvents)');
|
||||
QuerySnapshot eventsSnapshot;
|
||||
if (canViewAllEvents) {
|
||||
// On charge tous les events pour les users non-admins aussi
|
||||
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');
|
||||
|
||||
_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()}');
|
||||
return EventModel.fromMap(doc.data() as Map<String, dynamic>, doc.id);
|
||||
}).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');
|
||||
|
||||
|
@ -98,6 +98,7 @@ class EventDetails extends StatelessWidget {
|
||||
const SizedBox(width: 12),
|
||||
_buildStatusIcon(event.status),
|
||||
const SizedBox(width: 8),
|
||||
Spacer(),
|
||||
if (Provider.of<LocalUserProvider>(context, listen: false)
|
||||
.hasPermission('edit_event'))
|
||||
IconButton(
|
||||
@ -828,8 +829,12 @@ class EquipeSection extends StatelessWidget {
|
||||
if (snapshot.hasError) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
child: Text('Erreur lors du chargement de l\'équipe',
|
||||
style: TextStyle(color: Colors.red)),
|
||||
child: Text(
|
||||
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 ?? [];
|
||||
|
Reference in New Issue
Block a user