From 30ccee3a2a3668478e23ecf7e1e0ee724eed5131 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 21 Aug 2026 10:14:07 +0000 Subject: [PATCH] Restreindre les statuts selon le workflow --- app_new/interventions/crud.py | 7 ++++++- app_new/interventions/templates/new.html | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app_new/interventions/crud.py b/app_new/interventions/crud.py index 9543aa3..b1f01a9 100644 --- a/app_new/interventions/crud.py +++ b/app_new/interventions/crud.py @@ -401,8 +401,9 @@ def create_for_group(): def detail(id): """Détail d'une intervention.""" intervention = Intervention.query.get_or_404(id) + allowed_workflow_statuses = set(WORKFLOW_STATUS_ORDERS.get(intervention.workflow_type, WORKFLOW_STATUS_ORDERS['corrective'])) | {'refusee', 'annulee', 'reportee'} transitions = [(key, value['label']) for key, value in INTERVENTION_STATUSES.items() - if key in INTERVENTION_TRANSITIONS.get(intervention.status, set())] + if key in INTERVENTION_TRANSITIONS.get(intervention.status, set()) and key in allowed_workflow_statuses] history = intervention.status_history.order_by(StatusChange.created_at.desc()).all() return render_template('interventions/detail.html', intervention=intervention, @@ -532,6 +533,10 @@ def change_status(id): comment = request.form.get('comment', '') allowed = INTERVENTION_TRANSITIONS.get(old_status, set()) + workflow_statuses = set(WORKFLOW_STATUS_ORDERS.get(intervention.workflow_type, WORKFLOW_STATUS_ORDERS['corrective'])) | {'refusee', 'annulee', 'reportee'} + if new_status not in workflow_statuses: + flash(f'Le statut « {new_status} » ne correspond pas au workflow {intervention.workflow_label}.', 'danger') + return redirect(url_for('interventions.detail', id=intervention.id)) if new_status != old_status and new_status not in allowed: flash(f'Transition interdite : {old_status} → {new_status}.', 'danger') return redirect(url_for('interventions.detail', id=intervention.id)) diff --git a/app_new/interventions/templates/new.html b/app_new/interventions/templates/new.html index 1dc5542..cf26b86 100644 --- a/app_new/interventions/templates/new.html +++ b/app_new/interventions/templates/new.html @@ -66,6 +66,7 @@ + {% if json_suggestions and json_suggestions.type %} Suggestion: {{ json_suggestions.type }}