Compare commits
No commits in common. "31857ec89130cedca9c4720d7b7d664ecda1aa57" and "358eefdab31a24fc832069ba38d40f26c050c3c1" have entirely different histories.
31857ec891
...
358eefdab3
@ -1,37 +0,0 @@
|
|||||||
# Ticket #14 – Note pour modifications backend
|
|
||||||
|
|
||||||
**Contexte :** Première connexion admin → panneau Paramètres, déblocage après clic sur « Sauvegarder ». Le front appelle `POST /api/v1/configuration/setup/complete` au clic sur Sauvegarder.
|
|
||||||
|
|
||||||
## Problème
|
|
||||||
|
|
||||||
Erreur renvoyée par le back :
|
|
||||||
`invalid input syntax for type uuid: "system"`
|
|
||||||
|
|
||||||
- Le controller fait `const userId = req.user?.id || 'system'` puis `markSetupCompleted(userId)`.
|
|
||||||
- Le service `set()` fait `config.modifiePar = { id: userId }` ; la colonne `modifie_par` est une FK UUID vers `users`.
|
|
||||||
- La chaîne `"system"` n’est pas un UUID valide → erreur PostgreSQL.
|
|
||||||
|
|
||||||
## Modifications à apporter au backend
|
|
||||||
|
|
||||||
**Option A – Accepter l’absence d’utilisateur (recommandé si la route peut être appelée sans JWT)**
|
|
||||||
|
|
||||||
1. **`config.controller.ts`** (route `completeSetup`)
|
|
||||||
- Remplacer :
|
|
||||||
`const userId = req.user?.id || 'system';`
|
|
||||||
- Par :
|
|
||||||
`const userId = req.user?.id ?? null;`
|
|
||||||
|
|
||||||
2. **`config.service.ts`** (`markSetupCompleted`)
|
|
||||||
- Changer la signature :
|
|
||||||
`async markSetupCompleted(userId: string | null): Promise<void>`
|
|
||||||
- Et appeler :
|
|
||||||
`await this.set('setup_completed', 'true', userId ?? undefined);`
|
|
||||||
- Dans `set()`, ne pas remplir `modifiePar` quand `userId` est absent (déjà le cas si `if (userId)`).
|
|
||||||
|
|
||||||
**Option B – Imposer un utilisateur authentifié**
|
|
||||||
|
|
||||||
- Activer le guard JWT (et éventuellement RolesGuard) sur `POST /configuration/setup/complete` pour que `req.user` soit toujours défini, et garder `userId = req.user.id` (plus de fallback `'system'`).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Une fois le back modifié, le flux « Sauvegarder » → déblocage des panneaux fonctionne sans erreur.
|
|
||||||
@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:p_tits_pas/services/configuration_service.dart';
|
|
||||||
import 'package:p_tits_pas/widgets/admin/assistante_maternelle_management_widget.dart';
|
import 'package:p_tits_pas/widgets/admin/assistante_maternelle_management_widget.dart';
|
||||||
import 'package:p_tits_pas/widgets/admin/gestionnaire_management_widget.dart';
|
import 'package:p_tits_pas/widgets/admin/gestionnaire_management_widget.dart';
|
||||||
import 'package:p_tits_pas/widgets/admin/parent_managmant_widget.dart';
|
import 'package:p_tits_pas/widgets/admin/parent_managmant_widget.dart';
|
||||||
@ -15,34 +14,12 @@ class AdminDashboardScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
||||||
/// null = chargement du statut setup, true/false = connu
|
|
||||||
bool? _setupCompleted;
|
|
||||||
|
|
||||||
/// 0 = Gestion des utilisateurs, 1 = Paramètres
|
/// 0 = Gestion des utilisateurs, 1 = Paramètres
|
||||||
int mainTabIndex = 0;
|
int mainTabIndex = 0;
|
||||||
|
|
||||||
/// Sous-onglet quand mainTabIndex == 0 : 0=Gestionnaires, 1=Parents, 2=AM, 3=Administrateurs
|
/// Sous-onglet quand mainTabIndex == 0 : 0=Gestionnaires, 1=Parents, 2=AM, 3=Administrateurs
|
||||||
int subIndex = 0;
|
int subIndex = 0;
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_loadSetupStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _loadSetupStatus() async {
|
|
||||||
try {
|
|
||||||
final completed = await ConfigurationService.getSetupStatus();
|
|
||||||
if (!mounted) return;
|
|
||||||
setState(() {
|
|
||||||
_setupCompleted = completed;
|
|
||||||
if (!completed) mainTabIndex = 1;
|
|
||||||
});
|
|
||||||
} catch (_) {
|
|
||||||
if (mounted) setState(() => _setupCompleted = true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void onMainTabChange(int index) {
|
void onMainTabChange(int index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
mainTabIndex = index;
|
mainTabIndex = index;
|
||||||
@ -57,11 +34,6 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (_setupCompleted == null) {
|
|
||||||
return const Scaffold(
|
|
||||||
body: Center(child: CircularProgressIndicator()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: PreferredSize(
|
appBar: PreferredSize(
|
||||||
preferredSize: const Size.fromHeight(60.0),
|
preferredSize: const Size.fromHeight(60.0),
|
||||||
@ -74,7 +46,6 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
|||||||
child: DashboardAppBarAdmin(
|
child: DashboardAppBarAdmin(
|
||||||
selectedIndex: mainTabIndex,
|
selectedIndex: mainTabIndex,
|
||||||
onTabChange: onMainTabChange,
|
onTabChange: onMainTabChange,
|
||||||
setupCompleted: _setupCompleted!,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -96,9 +67,7 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
|||||||
|
|
||||||
Widget _getBody() {
|
Widget _getBody() {
|
||||||
if (mainTabIndex == 1) {
|
if (mainTabIndex == 1) {
|
||||||
return ParametresPanel(
|
return const ParametresPanel();
|
||||||
onSetupCompleted: () => setState(() => _setupCompleted = true),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
switch (subIndex) {
|
switch (subIndex) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|||||||
@ -106,9 +106,8 @@ class ConfigurationService {
|
|||||||
body: jsonEncode(body),
|
body: jsonEncode(body),
|
||||||
);
|
);
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200) {
|
||||||
final err = jsonDecode(response.body) as Map<String, dynamic>?;
|
final err = jsonDecode(response.body) as Map;
|
||||||
final msg = err != null ? (err['message'] as String? ?? err['error'] as String?) : null;
|
throw Exception(err['message'] ?? 'Erreur lors de la sauvegarde');
|
||||||
throw Exception(msg ?? 'Erreur lors de la sauvegarde');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,12 +118,11 @@ class ConfigurationService {
|
|||||||
headers: await _headers(),
|
headers: await _headers(),
|
||||||
body: jsonEncode({'testEmail': testEmail}),
|
body: jsonEncode({'testEmail': testEmail}),
|
||||||
);
|
);
|
||||||
final data = jsonDecode(response.body) as Map<String, dynamic>?;
|
final data = jsonDecode(response.body) as Map;
|
||||||
if (response.statusCode == 200 && (data?['success'] == true)) {
|
if (response.statusCode == 200 && data['success'] == true) {
|
||||||
return data!['message'] as String? ?? 'Test SMTP réussi.';
|
return data['message'] as String? ?? 'Test SMTP réussi.';
|
||||||
}
|
}
|
||||||
final msg = data != null ? (data['error'] as String? ?? data['message'] as String?) : null;
|
throw Exception(data['error'] ?? data['message'] ?? 'Échec du test SMTP');
|
||||||
throw Exception(msg ?? 'Échec du test SMTP');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// POST /api/v1/configuration/setup/complete (après première config)
|
/// POST /api/v1/configuration/setup/complete (après première config)
|
||||||
@ -134,9 +132,8 @@ class ConfigurationService {
|
|||||||
headers: await _headers(),
|
headers: await _headers(),
|
||||||
);
|
);
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200) {
|
||||||
final err = jsonDecode(response.body) as Map<String, dynamic>?;
|
final err = jsonDecode(response.body) as Map;
|
||||||
final msg = err != null ? (err['message'] as String? ?? err['error'] as String?) : null;
|
throw Exception(err['message'] ?? 'Erreur finalisation configuration');
|
||||||
throw Exception(msg ?? 'Erreur finalisation configuration');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,14 +4,11 @@ import 'package:flutter/material.dart';
|
|||||||
class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidget {
|
class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidget {
|
||||||
final int selectedIndex;
|
final int selectedIndex;
|
||||||
final ValueChanged<int> onTabChange;
|
final ValueChanged<int> onTabChange;
|
||||||
/// Si false, l'onglet "Gestion des utilisateurs" est grisé et inaccessible.
|
|
||||||
final bool setupCompleted;
|
|
||||||
|
|
||||||
const DashboardAppBarAdmin({
|
const DashboardAppBarAdmin({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.selectedIndex,
|
required this.selectedIndex,
|
||||||
required this.onTabChange,
|
required this.onTabChange,
|
||||||
this.setupCompleted = true,
|
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -35,9 +32,9 @@ class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidge
|
|||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
_buildNavItem(context, 'Gestion des utilisateurs', 0, enabled: setupCompleted),
|
_buildNavItem(context, 'Gestion des utilisateurs', 0),
|
||||||
const SizedBox(width: 24),
|
const SizedBox(width: 24),
|
||||||
_buildNavItem(context, 'Paramètres', 1, enabled: true),
|
_buildNavItem(context, 'Paramètres', 1),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -77,26 +74,23 @@ class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidge
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildNavItem(BuildContext context, String title, int index, {bool enabled = true}) {
|
Widget _buildNavItem(BuildContext context, String title, int index) {
|
||||||
final bool isActive = index == selectedIndex;
|
final bool isActive = index == selectedIndex;
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: enabled ? () => onTabChange(index) : null,
|
onTap: () => onTabChange(index),
|
||||||
child: Opacity(
|
child: Container(
|
||||||
opacity: enabled ? 1.0 : 0.5,
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
child: Container(
|
decoration: BoxDecoration(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
color: isActive ? const Color(0xFF9CC5C0) : Colors.transparent,
|
||||||
decoration: BoxDecoration(
|
borderRadius: BorderRadius.circular(20),
|
||||||
color: isActive ? const Color(0xFF9CC5C0) : Colors.transparent,
|
border: isActive ? null : Border.all(color: Colors.black26),
|
||||||
borderRadius: BorderRadius.circular(20),
|
),
|
||||||
border: isActive ? null : Border.all(color: Colors.black26),
|
child: Text(
|
||||||
),
|
title,
|
||||||
child: Text(
|
style: TextStyle(
|
||||||
title,
|
color: isActive ? Colors.white : Colors.black,
|
||||||
style: TextStyle(
|
fontWeight: isActive ? FontWeight.w600 : FontWeight.normal,
|
||||||
color: isActive ? Colors.white : Colors.black,
|
fontSize: 14,
|
||||||
fontWeight: isActive ? FontWeight.w600 : FontWeight.normal,
|
|
||||||
fontSize: 14,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -3,10 +3,7 @@ import 'package:p_tits_pas/services/configuration_service.dart';
|
|||||||
|
|
||||||
/// Panneau Paramètres / Configuration (ticket #15) : 3 sections sur une page.
|
/// Panneau Paramètres / Configuration (ticket #15) : 3 sections sur une page.
|
||||||
class ParametresPanel extends StatefulWidget {
|
class ParametresPanel extends StatefulWidget {
|
||||||
/// Appelé après une sauvegarde réussie (pour débloquer le reste du dashboard si config initiale).
|
const ParametresPanel({super.key});
|
||||||
final VoidCallback? onSetupCompleted;
|
|
||||||
|
|
||||||
const ParametresPanel({super.key, this.onSetupCompleted});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ParametresPanel> createState() => _ParametresPanelState();
|
State<ParametresPanel> createState() => _ParametresPanelState();
|
||||||
@ -107,12 +104,6 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
|||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enregistre en base sans marquer la config initiale comme terminée (utilisé avant test SMTP).
|
|
||||||
Future<void> _saveBulkOnly() async {
|
|
||||||
await ConfigurationService.updateBulk(_buildPayload());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sauvegarde + marque la config initiale comme terminée + débloque les panneaux.
|
|
||||||
Future<void> _save() async {
|
Future<void> _save() async {
|
||||||
setState(() {
|
setState(() {
|
||||||
_message = null;
|
_message = null;
|
||||||
@ -121,9 +112,6 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
|||||||
try {
|
try {
|
||||||
await ConfigurationService.updateBulk(_buildPayload());
|
await ConfigurationService.updateBulk(_buildPayload());
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
await ConfigurationService.completeSetup();
|
|
||||||
if (!mounted) return;
|
|
||||||
widget.onSetupCompleted?.call();
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_isSaving = false;
|
_isSaving = false;
|
||||||
_message = 'Configuration enregistrée.';
|
_message = 'Configuration enregistrée.';
|
||||||
@ -172,7 +160,7 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
|||||||
if (email == null || !mounted) return;
|
if (email == null || !mounted) return;
|
||||||
setState(() => _message = null);
|
setState(() => _message = null);
|
||||||
try {
|
try {
|
||||||
await _saveBulkOnly();
|
await _save();
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
final msg = await ConfigurationService.testSmtp(email);
|
final msg = await ConfigurationService.testSmtp(email);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user