fix(mobile): URL changement mdp corrigée + v3.0 — multi-org, AppAuth, sécurité prod

Auth:
- profile_repository.dart: /api/auth/change-password → /api/membres/auth/change-password

Multi-org (Phase 3):
- OrgSelectorPage, OrgSwitcherBloc, OrgSwitcherEntry
- org_context_service.dart: headers X-Active-Organisation-Id + X-Active-Role

Navigation:
- MorePage: navigation conditionnelle par typeOrganisation
- Suppression adaptive_navigation (remplacé par main_navigation_layout)

Auth AppAuth:
- keycloak_webview_auth_service: fixes AppAuth Android
- AuthBloc: gestion REAUTH_REQUIS + premierLoginComplet

Onboarding:
- Nouveaux états: payment_method_page, onboarding_shared_widgets
- SouscriptionStatusModel mis à jour StatutValidationSouscription

Android:
- build.gradle: ProGuard/R8, network_security_config
- Gradle wrapper mis à jour
This commit is contained in:
dahoud
2026-04-07 20:56:03 +00:00
parent 22f9c7e9a1
commit 70cbd1c873
63 changed files with 9316 additions and 6122 deletions

View File

@@ -0,0 +1,144 @@
/// BLoC pour le sélecteur d'organisation multi-org.
///
/// Charge GET /api/membres/mes-organisations et maintient
/// l'organisation active via [OrgContextService].
library org_switcher_bloc;
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:injectable/injectable.dart';
import 'package:dio/dio.dart';
import '../../../core/network/api_client.dart';
import '../../../core/network/org_context_service.dart';
import '../../../core/utils/logger.dart';
import '../data/models/org_switcher_entry.dart';
// ─── ÉVÉNEMENTS ─────────────────────────────────────────────────────────────
abstract class OrgSwitcherEvent extends Equatable {
const OrgSwitcherEvent();
@override
List<Object?> get props => [];
}
/// Charge la liste des organisations du membre connecté.
class OrgSwitcherLoadRequested extends OrgSwitcherEvent {
const OrgSwitcherLoadRequested();
}
/// Sélectionne une organisation comme active.
class OrgSwitcherSelectRequested extends OrgSwitcherEvent {
final OrgSwitcherEntry organisation;
const OrgSwitcherSelectRequested(this.organisation);
@override
List<Object?> get props => [organisation];
}
// ─── ÉTATS ──────────────────────────────────────────────────────────────────
abstract class OrgSwitcherState extends Equatable {
const OrgSwitcherState();
@override
List<Object?> get props => [];
}
class OrgSwitcherInitial extends OrgSwitcherState {}
class OrgSwitcherLoading extends OrgSwitcherState {}
class OrgSwitcherLoaded extends OrgSwitcherState {
final List<OrgSwitcherEntry> organisations;
final OrgSwitcherEntry? active;
const OrgSwitcherLoaded({required this.organisations, this.active});
OrgSwitcherLoaded copyWith({
List<OrgSwitcherEntry>? organisations,
OrgSwitcherEntry? active,
}) {
return OrgSwitcherLoaded(
organisations: organisations ?? this.organisations,
active: active ?? this.active,
);
}
@override
List<Object?> get props => [organisations, active];
}
class OrgSwitcherError extends OrgSwitcherState {
final String message;
const OrgSwitcherError(this.message);
@override
List<Object?> get props => [message];
}
// ─── BLOC ────────────────────────────────────────────────────────────────────
@injectable
class OrgSwitcherBloc extends Bloc<OrgSwitcherEvent, OrgSwitcherState> {
final ApiClient _apiClient;
final OrgContextService _orgContextService;
static const String _endpoint = '/api/membres/mes-organisations';
OrgSwitcherBloc(this._apiClient, this._orgContextService)
: super(OrgSwitcherInitial()) {
on<OrgSwitcherLoadRequested>(_onLoad);
on<OrgSwitcherSelectRequested>(_onSelect);
}
Future<void> _onLoad(
OrgSwitcherLoadRequested event,
Emitter<OrgSwitcherState> emit,
) async {
emit(OrgSwitcherLoading());
try {
final response = await _apiClient.get<List<dynamic>>(_endpoint);
final rawList = response.data as List<dynamic>? ?? [];
final orgs = rawList
.map((e) => OrgSwitcherEntry.fromJson(e as Map<String, dynamic>))
.toList();
// Auto-select si une seule organisation ou si une org est déjà active
OrgSwitcherEntry? active;
if (_orgContextService.hasContext) {
active = orgs.where((o) => o.organisationId == _orgContextService.activeOrganisationId).firstOrNull;
}
active ??= orgs.isNotEmpty ? orgs.first : null;
if (active != null && !_orgContextService.hasContext) {
_applyActiveOrg(active);
}
emit(OrgSwitcherLoaded(organisations: orgs, active: active));
} on DioException catch (e) {
AppLogger.warning('OrgSwitcherBloc: erreur réseau: ${e.message}');
emit(OrgSwitcherError('Impossible de charger vos organisations: ${e.message}'));
} catch (e) {
AppLogger.error('OrgSwitcherBloc: erreur inattendue: $e');
emit(OrgSwitcherError('Erreur inattendue: $e'));
}
}
Future<void> _onSelect(
OrgSwitcherSelectRequested event,
Emitter<OrgSwitcherState> emit,
) async {
final current = state;
if (current is! OrgSwitcherLoaded) return;
_applyActiveOrg(event.organisation);
emit(current.copyWith(active: event.organisation));
AppLogger.info('OrgSwitcherBloc: sélection → ${event.organisation.nom}');
}
void _applyActiveOrg(OrgSwitcherEntry org) {
_orgContextService.setActiveOrganisation(
organisationId: org.organisationId,
nom: org.nom,
type: org.typeOrganisation,
modulesActifsCsv: org.modulesActifs,
);
}
}

View File

@@ -0,0 +1,73 @@
/// Modèle pour un item du sélecteur d'organisation.
/// Mappé depuis GET /api/membres/mes-organisations.
library org_switcher_entry;
import 'package:equatable/equatable.dart';
class OrgSwitcherEntry extends Equatable {
final String organisationId;
final String nom;
final String? nomCourt;
final String typeOrganisation;
final String? categorieType;
final String? modulesActifs;
final String? statut;
final String? statutMembre;
final String? roleOrg;
final String? dateAdhesion;
const OrgSwitcherEntry({
required this.organisationId,
required this.nom,
this.nomCourt,
required this.typeOrganisation,
this.categorieType,
this.modulesActifs,
this.statut,
this.statutMembre,
this.roleOrg,
this.dateAdhesion,
});
/// Libellé court pour le switcher (nomCourt ou nom tronqué).
String get libelleCourt {
if (nomCourt != null && nomCourt!.isNotEmpty) return nomCourt!;
if (nom.length > 25) return '${nom.substring(0, 22)}';
return nom;
}
/// Modules actifs parsés en Set<String>.
Set<String> get modulesActifsSet {
if (modulesActifs == null || modulesActifs!.isEmpty) return {};
return modulesActifs!.split(',').map((m) => m.trim()).toSet();
}
factory OrgSwitcherEntry.fromJson(Map<String, dynamic> json) {
return OrgSwitcherEntry(
organisationId: json['organisationId']?.toString() ?? '',
nom: json['nom']?.toString() ?? '',
nomCourt: json['nomCourt']?.toString(),
typeOrganisation: json['typeOrganisation']?.toString() ?? '',
categorieType: json['categorieType']?.toString(),
modulesActifs: json['modulesActifs']?.toString(),
statut: json['statut']?.toString(),
statutMembre: json['statutMembre']?.toString(),
roleOrg: json['roleOrg']?.toString(),
dateAdhesion: json['dateAdhesion']?.toString(),
);
}
@override
List<Object?> get props => [
organisationId,
nom,
nomCourt,
typeOrganisation,
categorieType,
modulesActifs,
statut,
statutMembre,
roleOrg,
dateAdhesion,
];
}

View File

@@ -0,0 +1,384 @@
/// Page de sélection d'organisation pour les membres multi-org.
///
/// S'affiche après la connexion si le membre appartient à plusieurs organisations,
/// ou accessible depuis le profil pour changer d'organisation active.
library org_selector_page;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../bloc/org_switcher_bloc.dart';
import '../../data/models/org_switcher_entry.dart';
class OrgSelectorPage extends StatefulWidget {
/// Si true, la page ne peut pas être ignorée (premier choix obligatoire).
final bool required;
const OrgSelectorPage({super.key, this.required = false});
@override
State<OrgSelectorPage> createState() => _OrgSelectorPageState();
}
class _OrgSelectorPageState extends State<OrgSelectorPage> {
@override
void initState() {
super.initState();
context.read<OrgSwitcherBloc>().add(const OrgSwitcherLoadRequested());
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(
title: const Text('Choisir une organisation'),
automaticallyImplyLeading: !widget.required,
elevation: 0,
),
body: BlocConsumer<OrgSwitcherBloc, OrgSwitcherState>(
listener: (context, state) {
if (state is OrgSwitcherLoaded && widget.required && state.active != null) {
// Une org a été auto-sélectionnée, on peut continuer
}
},
builder: (context, state) {
if (state is OrgSwitcherLoading) {
return const Center(child: CircularProgressIndicator());
}
if (state is OrgSwitcherError) {
return _ErrorView(
message: state.message,
onRetry: () => context
.read<OrgSwitcherBloc>()
.add(const OrgSwitcherLoadRequested()),
);
}
if (state is OrgSwitcherLoaded) {
if (state.organisations.isEmpty) {
return const _EmptyView();
}
return _OrgList(
organisations: state.organisations,
active: state.active,
onSelect: (org) {
context
.read<OrgSwitcherBloc>()
.add(OrgSwitcherSelectRequested(org));
Navigator.of(context).pop(org);
},
);
}
return const SizedBox.shrink();
},
),
);
}
}
// ─── Widgets privés ──────────────────────────────────────────────────────────
class _OrgList extends StatelessWidget {
final List<OrgSwitcherEntry> organisations;
final OrgSwitcherEntry? active;
final ValueChanged<OrgSwitcherEntry> onSelect;
const _OrgList({
required this.organisations,
required this.active,
required this.onSelect,
});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
child: Text(
'Sélectionnez l\'organisation dans laquelle vous souhaitez travailler.',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
),
Expanded(
child: ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
itemCount: organisations.length,
separatorBuilder: (_, __) => const SizedBox(height: 8),
itemBuilder: (context, index) {
final org = organisations[index];
final isActive = active?.organisationId == org.organisationId;
return _OrgCard(
org: org,
isActive: isActive,
onTap: () => onSelect(org),
);
},
),
),
],
);
}
}
class _OrgCard extends StatelessWidget {
final OrgSwitcherEntry org;
final bool isActive;
final VoidCallback onTap;
const _OrgCard({
required this.org,
required this.isActive,
required this.onTap,
});
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return Card(
elevation: isActive ? 3 : 1,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: isActive
? BorderSide(color: colorScheme.primary, width: 2)
: BorderSide.none,
),
color: isActive
? colorScheme.primaryContainer.withValues(alpha: 0.3)
: colorScheme.surface,
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
// Icône / avatar
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: isActive
? colorScheme.primary
: colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(12),
),
alignment: Alignment.center,
child: Text(
org.nom.isNotEmpty ? org.nom[0].toUpperCase() : '?',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: isActive ? colorScheme.onPrimary : colorScheme.onSurfaceVariant,
),
),
),
const SizedBox(width: 12),
// Informations
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
org.libelleCourt,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
color: isActive ? colorScheme.primary : null,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Row(
children: [
_Chip(org.typeOrganisation),
if (org.statutMembre != null) ...[
const SizedBox(width: 6),
_Chip(
org.statutMembre!,
color: org.statutMembre == 'ACTIF'
? Colors.green.shade700
: Colors.orange.shade700,
),
],
],
),
if (org.roleOrg != null) ...[
const SizedBox(height: 2),
Text(
org.roleOrg!,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: colorScheme.onSurfaceVariant,
),
),
],
],
),
),
if (isActive)
Icon(Icons.check_circle, color: colorScheme.primary, size: 24),
],
),
),
),
);
}
}
class _Chip extends StatelessWidget {
final String label;
final Color? color;
const _Chip(this.label, {this.color});
@override
Widget build(BuildContext context) {
final effectiveColor = color ?? Theme.of(context).colorScheme.onSurfaceVariant;
return Container(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: effectiveColor.withValues(alpha: 0.12),
borderRadius: BorderRadius.circular(4),
),
child: Text(
label,
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w500,
color: effectiveColor,
),
),
);
}
}
class _ErrorView extends StatelessWidget {
final String message;
final VoidCallback onRetry;
const _ErrorView({required this.message, required this.onRetry});
@override
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.cloud_off, size: 56, color: Colors.grey),
const SizedBox(height: 16),
Text(message, textAlign: TextAlign.center),
const SizedBox(height: 16),
ElevatedButton.icon(
onPressed: onRetry,
icon: const Icon(Icons.refresh),
label: const Text('Réessayer'),
),
],
),
),
);
}
}
class _EmptyView extends StatelessWidget {
const _EmptyView();
@override
Widget build(BuildContext context) {
return const Center(
child: Padding(
padding: EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.business_outlined, size: 56, color: Colors.grey),
SizedBox(height: 16),
Text(
'Vous n\'êtes membre d\'aucune organisation active.',
textAlign: TextAlign.center,
),
],
),
),
);
}
}
/// Widget compact pour afficher/changer l'org active dans une AppBar ou drawer.
///
/// Usage:
/// ```dart
/// OrgSwitcherBadge(onTap: () => _openOrgSelector(context))
/// ```
class OrgSwitcherBadge extends StatelessWidget {
final OrgSwitcherEntry? activeOrg;
final VoidCallback onTap;
const OrgSwitcherBadge({
super.key,
required this.activeOrg,
required this.onTap,
});
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
final label = activeOrg?.libelleCourt ?? 'Choisir organisation';
return GestureDetector(
onTap: onTap,
child: Container(
constraints: const BoxConstraints(maxWidth: 200),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: colorScheme.primaryContainer.withValues(alpha: 0.4),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: colorScheme.primary.withValues(alpha: 0.4),
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.business, size: 16, color: colorScheme.primary),
const SizedBox(width: 6),
Flexible(
child: Text(
label,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: colorScheme.primary,
),
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 4),
Icon(Icons.arrow_drop_down, size: 18, color: colorScheme.primary),
],
),
),
);
}
}
/// Ouvre [OrgSelectorPage] comme bottom sheet modal.
///
/// Retourne l'[OrgSwitcherEntry] sélectionnée ou null si annulé.
Future<OrgSwitcherEntry?> showOrgSelector(
BuildContext context, {
bool required = false,
}) {
return Navigator.of(context).push<OrgSwitcherEntry>(
MaterialPageRoute(
builder: (_) => BlocProvider.value(
value: context.read<OrgSwitcherBloc>(),
child: OrgSelectorPage(required: required),
),
),
);
}

View File

@@ -605,6 +605,12 @@ class _OrganizationsPageState extends State<OrganizationsPage> with TickerProvid
return _buildEmptyState();
}
// Vérifier le rôle une seule fois pour toute la liste (UI-02)
final authState = context.read<AuthBloc>().state;
final canManageOrgs = authState is AuthAuthenticated &&
(authState.effectiveRole == UserRole.superAdmin ||
authState.effectiveRole == UserRole.orgAdmin);
return ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
@@ -617,9 +623,9 @@ class _OrganizationsPageState extends State<OrganizationsPage> with TickerProvid
child: OrganizationCard(
organization: org,
onTap: () => _showOrganizationDetails(org),
onEdit: () => _showEditOrganizationDialog(org),
onDelete: () => _confirmDeleteOrganization(org),
showActions: true,
onEdit: canManageOrgs ? () => _showEditOrganizationDialog(org) : null,
onDelete: canManageOrgs ? () => _confirmDeleteOrganization(org) : null,
showActions: canManageOrgs,
),
);
},