Restreindre les statuts selon le workflow
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
This commit is contained in:
parent
701a765576
commit
30ccee3a2a
2 changed files with 7 additions and 1 deletions
|
|
@ -401,8 +401,9 @@ def create_for_group():
|
||||||
def detail(id):
|
def detail(id):
|
||||||
"""Détail d'une intervention."""
|
"""Détail d'une intervention."""
|
||||||
intervention = Intervention.query.get_or_404(id)
|
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()
|
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()
|
history = intervention.status_history.order_by(StatusChange.created_at.desc()).all()
|
||||||
return render_template('interventions/detail.html',
|
return render_template('interventions/detail.html',
|
||||||
intervention=intervention,
|
intervention=intervention,
|
||||||
|
|
@ -532,6 +533,10 @@ def change_status(id):
|
||||||
comment = request.form.get('comment', '')
|
comment = request.form.get('comment', '')
|
||||||
|
|
||||||
allowed = INTERVENTION_TRANSITIONS.get(old_status, set())
|
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:
|
if new_status != old_status and new_status not in allowed:
|
||||||
flash(f'Transition interdite : {old_status} → {new_status}.', 'danger')
|
flash(f'Transition interdite : {old_status} → {new_status}.', 'danger')
|
||||||
return redirect(url_for('interventions.detail', id=intervention.id))
|
return redirect(url_for('interventions.detail', id=intervention.id))
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@
|
||||||
<option value="amelioratif" {% if (prefilled.type if prefilled is defined else (intervention.type if intervention is defined else '')) == 'amelioratif' %}selected{% endif %}>Amélioratif</option>
|
<option value="amelioratif" {% if (prefilled.type if prefilled is defined else (intervention.type if intervention is defined else '')) == 'amelioratif' %}selected{% endif %}>Amélioratif</option>
|
||||||
<option value="administratif" {% if (prefilled.type if prefilled is defined else (intervention.type if intervention is defined else '')) == 'administratif' %}selected{% endif %}>Administratif</option>
|
<option value="administratif" {% if (prefilled.type if prefilled is defined else (intervention.type if intervention is defined else '')) == 'administratif' %}selected{% endif %}>Administratif</option>
|
||||||
<option value="formation" {% if (prefilled.type if prefilled is defined else (intervention.type if intervention is defined else '')) == 'formation' %}selected{% endif %}>Formation</option>
|
<option value="formation" {% if (prefilled.type if prefilled is defined else (intervention.type if intervention is defined else '')) == 'formation' %}selected{% endif %}>Formation</option>
|
||||||
|
<option value="prevention" {% if (prefilled.type if prefilled is defined else (intervention.type if intervention is defined else '')) == 'prevention' %}selected{% endif %}>Prévention</option>
|
||||||
</select>
|
</select>
|
||||||
{% if json_suggestions and json_suggestions.type %}
|
{% if json_suggestions and json_suggestions.type %}
|
||||||
<small class="text-success"><i class="bi bi-lightbulb"></i> Suggestion: {{ json_suggestions.type }}</small>
|
<small class="text-success"><i class="bi bi-lightbulb"></i> Suggestion: {{ json_suggestions.type }}</small>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue