Modifications des permissions, ajout Presta OK, vue calendrier ok
This commit is contained in:
		| @@ -3,10 +3,12 @@ import 'package:firebase_auth/firebase_auth.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:image_picker/image_picker.dart'; | ||||
| import '../models/user_model.dart'; | ||||
| import '../models/role_model.dart'; | ||||
| import '../utils/firebase_storage_manager.dart'; | ||||
|  | ||||
| class LocalUserProvider with ChangeNotifier { | ||||
|   UserModel? _currentUser; | ||||
|   RoleModel? _currentRole; | ||||
|   final FirebaseAuth _auth = FirebaseAuth.instance; | ||||
|   final FirebaseFirestore _firestore = FirebaseFirestore.instance; | ||||
|   final FirebaseStorageManager _storageManager = FirebaseStorageManager(); | ||||
| @@ -19,6 +21,8 @@ class LocalUserProvider with ChangeNotifier { | ||||
|   String? get profilePhotoUrl => _currentUser?.profilePhotoUrl; | ||||
|   String? get email => _currentUser?.email; | ||||
|   String? get phoneNumber => _currentUser?.phoneNumber; | ||||
|   RoleModel? get currentRole => _currentRole; | ||||
|   List<String> get permissions => _currentRole?.permissions ?? []; | ||||
|  | ||||
|   /// Charge les données de l'utilisateur actuel | ||||
|   Future<void> loadUserData() async { | ||||
| @@ -47,6 +51,7 @@ class LocalUserProvider with ChangeNotifier { | ||||
|  | ||||
|         setUser(UserModel.fromMap(userData, userDoc.id)); | ||||
|         print('User data loaded successfully'); | ||||
|         await loadRole(); | ||||
|       } else { | ||||
|         print('No user document found in Firestore'); | ||||
|         // Créer un document utilisateur par défaut | ||||
| @@ -73,6 +78,7 @@ class LocalUserProvider with ChangeNotifier { | ||||
|  | ||||
|         setUser(defaultUser); | ||||
|         print('Default user document created'); | ||||
|         await loadRole(); | ||||
|       } | ||||
|     } catch (e) { | ||||
|       print('Error loading user data: $e'); | ||||
| @@ -154,4 +160,24 @@ class LocalUserProvider with ChangeNotifier { | ||||
|     await _auth.signOut(); | ||||
|     clearUser(); | ||||
|   } | ||||
|  | ||||
|   Future<void> loadRole() async { | ||||
|     if (_currentUser == null) return; | ||||
|     final roleId = _currentUser!.role; | ||||
|     if (roleId.isEmpty) return; | ||||
|     try { | ||||
|       final doc = await _firestore.collection('roles').doc(roleId).get(); | ||||
|       if (doc.exists) { | ||||
|         _currentRole = | ||||
|             RoleModel.fromMap(doc.data() as Map<String, dynamic>, doc.id); | ||||
|         notifyListeners(); | ||||
|       } | ||||
|     } catch (e) { | ||||
|       print('Error loading role: $e'); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   bool hasPermission(String permission) { | ||||
|     return _currentRole?.permissions.contains(permission) ?? false; | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user