merge: squash develop into master
Intègre en un seul commit les évolutions récentes de develop vers master, incluant la modale admin/gestionnaire, les protections super admin, les ajustements API associés et la mise à jour documentaire des tickets/spec. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:p_tits_pas/models/user.dart';
|
||||
import 'package:p_tits_pas/screens/administrateurs/creation/gestionnaires_create.dart';
|
||||
import 'package:p_tits_pas/services/auth_service.dart';
|
||||
import 'package:p_tits_pas/services/user_service.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/admin_user_card.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/user_list.dart';
|
||||
@@ -20,10 +22,12 @@ class _AdminManagementWidgetState extends State<AdminManagementWidget> {
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
List<AppUser> _admins = [];
|
||||
String? _currentUserRole;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadCurrentUserRole();
|
||||
_loadAdmins();
|
||||
}
|
||||
|
||||
@@ -51,6 +55,48 @@ class _AdminManagementWidgetState extends State<AdminManagementWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadCurrentUserRole() async {
|
||||
final cached = await AuthService.getCurrentUser();
|
||||
if (!mounted) return;
|
||||
if (cached != null) {
|
||||
setState(() {
|
||||
_currentUserRole = cached.role.toLowerCase();
|
||||
});
|
||||
return;
|
||||
}
|
||||
final refreshed = await AuthService.refreshCurrentUser();
|
||||
if (!mounted || refreshed == null) return;
|
||||
setState(() {
|
||||
_currentUserRole = refreshed.role.toLowerCase();
|
||||
});
|
||||
}
|
||||
|
||||
bool _isSuperAdmin(AppUser user) => user.role.toLowerCase() == 'super_admin';
|
||||
|
||||
bool _canEditAdmin(AppUser target) {
|
||||
if (!_isSuperAdmin(target)) return true;
|
||||
return _currentUserRole == 'super_admin';
|
||||
}
|
||||
|
||||
Future<void> _openAdminEditDialog(AppUser user) async {
|
||||
final canEdit = _canEditAdmin(user);
|
||||
final changed = await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (dialogContext) {
|
||||
return AdminUserFormDialog(
|
||||
initialUser: user,
|
||||
adminMode: true,
|
||||
withRelais: false,
|
||||
readOnly: !canEdit,
|
||||
);
|
||||
},
|
||||
);
|
||||
if (changed == true && canEdit) {
|
||||
await _loadAdmins();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final query = widget.searchQuery.toLowerCase();
|
||||
@@ -68,19 +114,36 @@ class _AdminManagementWidgetState extends State<AdminManagementWidget> {
|
||||
itemCount: filteredAdmins.length,
|
||||
itemBuilder: (context, index) {
|
||||
final user = filteredAdmins[index];
|
||||
final isSuperAdmin = _isSuperAdmin(user);
|
||||
final canEdit = _canEditAdmin(user);
|
||||
return AdminUserCard(
|
||||
title: user.fullName,
|
||||
fallbackIcon: isSuperAdmin
|
||||
? Icons.verified_user_outlined
|
||||
: Icons.manage_accounts_outlined,
|
||||
subtitleLines: [
|
||||
user.email,
|
||||
'Rôle : ${user.role}',
|
||||
'Téléphone : ${user.telephone?.trim().isNotEmpty == true ? user.telephone : 'Non renseigné'}',
|
||||
],
|
||||
avatarUrl: user.photoUrl,
|
||||
borderColor: isSuperAdmin
|
||||
? const Color(0xFF8E6AC8)
|
||||
: Colors.grey.shade300,
|
||||
backgroundColor: isSuperAdmin
|
||||
? const Color(0xFFF4EEFF)
|
||||
: Colors.white,
|
||||
titleColor: isSuperAdmin ? const Color(0xFF5D2F99) : null,
|
||||
infoColor: isSuperAdmin
|
||||
? const Color(0xFF6D4EA1)
|
||||
: Colors.black54,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
tooltip: 'Modifier',
|
||||
icon: Icon(
|
||||
canEdit ? Icons.edit_outlined : Icons.visibility_outlined,
|
||||
),
|
||||
tooltip: canEdit ? 'Modifier' : 'Consulter',
|
||||
onPressed: () {
|
||||
// TODO: Modifier admin
|
||||
_openAdminEditDialog(user);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
@@ -6,6 +6,10 @@ class AdminUserCard extends StatefulWidget {
|
||||
final String? avatarUrl;
|
||||
final IconData fallbackIcon;
|
||||
final List<Widget> actions;
|
||||
final Color? borderColor;
|
||||
final Color? backgroundColor;
|
||||
final Color? titleColor;
|
||||
final Color? infoColor;
|
||||
|
||||
const AdminUserCard({
|
||||
super.key,
|
||||
@@ -14,6 +18,10 @@ class AdminUserCard extends StatefulWidget {
|
||||
this.avatarUrl,
|
||||
this.fallbackIcon = Icons.person,
|
||||
this.actions = const [],
|
||||
this.borderColor,
|
||||
this.backgroundColor,
|
||||
this.titleColor,
|
||||
this.infoColor,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -43,9 +51,10 @@ class _AdminUserCardState extends State<AdminUserCard> {
|
||||
child: Card(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
elevation: 0,
|
||||
color: widget.backgroundColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
side: BorderSide(color: Colors.grey.shade300),
|
||||
side: BorderSide(color: widget.borderColor ?? Colors.grey.shade300),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 9),
|
||||
@@ -76,7 +85,7 @@ class _AdminUserCardState extends State<AdminUserCard> {
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 14,
|
||||
),
|
||||
).copyWith(color: widget.titleColor),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
@@ -88,7 +97,7 @@ class _AdminUserCardState extends State<AdminUserCard> {
|
||||
style: const TextStyle(
|
||||
color: Colors.black54,
|
||||
fontSize: 12,
|
||||
),
|
||||
).copyWith(color: widget.infoColor),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
|
||||
@@ -59,7 +59,7 @@ class _GestionnaireManagementWidgetState
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (dialogContext) {
|
||||
return GestionnaireCreateDialog(initialUser: user);
|
||||
return AdminUserFormDialog(initialUser: user);
|
||||
},
|
||||
);
|
||||
if (changed == true) {
|
||||
@@ -86,6 +86,7 @@ class _GestionnaireManagementWidgetState
|
||||
final user = filteredGestionnaires[index];
|
||||
return AdminUserCard(
|
||||
title: user.fullName,
|
||||
fallbackIcon: Icons.assignment_ind_outlined,
|
||||
avatarUrl: user.photoUrl,
|
||||
subtitleLines: [
|
||||
user.email,
|
||||
|
||||
@@ -75,6 +75,7 @@ class _ParentManagementWidgetState extends State<ParentManagementWidget> {
|
||||
final parent = filteredParents[index];
|
||||
return AdminUserCard(
|
||||
title: parent.user.fullName,
|
||||
fallbackIcon: Icons.supervisor_account_outlined,
|
||||
avatarUrl: parent.user.photoUrl,
|
||||
subtitleLines: [
|
||||
parent.user.email,
|
||||
|
||||
@@ -17,6 +17,7 @@ class AdminUserManagementPanel extends StatefulWidget {
|
||||
class _AdminUserManagementPanelState extends State<AdminUserManagementPanel> {
|
||||
int _subIndex = 0;
|
||||
int _gestionnaireRefreshTick = 0;
|
||||
int _adminRefreshTick = 0;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final TextEditingController _amCapacityController = TextEditingController();
|
||||
String? _parentStatus;
|
||||
@@ -150,6 +151,7 @@ class _AdminUserManagementPanelState extends State<AdminUserManagementPanel> {
|
||||
);
|
||||
case 3:
|
||||
return AdminManagementWidget(
|
||||
key: ValueKey('admins-$_adminRefreshTick'),
|
||||
searchQuery: _searchController.text,
|
||||
);
|
||||
default:
|
||||
@@ -176,31 +178,52 @@ class _AdminUserManagementPanelState extends State<AdminUserManagementPanel> {
|
||||
}
|
||||
|
||||
Future<void> _handleAddPressed() async {
|
||||
if (_subIndex != 0) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'La création est disponible uniquement pour les gestionnaires.',
|
||||
),
|
||||
),
|
||||
if (_subIndex == 0) {
|
||||
final created = await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (dialogContext) {
|
||||
return const AdminUserFormDialog();
|
||||
},
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
if (created == true) {
|
||||
setState(() {
|
||||
_gestionnaireRefreshTick++;
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final created = await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (dialogContext) {
|
||||
return const GestionnaireCreateDialog();
|
||||
},
|
||||
);
|
||||
if (_subIndex == 3) {
|
||||
final created = await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (dialogContext) {
|
||||
return const AdminUserFormDialog(
|
||||
adminMode: true,
|
||||
withRelais: false,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
if (created == true) {
|
||||
setState(() {
|
||||
_adminRefreshTick++;
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
if (created == true) {
|
||||
setState(() {
|
||||
_gestionnaireRefreshTick++;
|
||||
});
|
||||
}
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'La création est disponible pour les gestionnaires et administrateurs.',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user