feat(routing): server side: prevent tdc deletion if used for routing
This commit is contained in:
parent
3f55fddcef
commit
c1f67499aa
3 changed files with 59 additions and 36 deletions
|
@ -67,6 +67,13 @@ module Administrateurs
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
coordinate, type_de_champ = draft.coordinate_and_tdc(params[:stable_id])
|
||||||
|
|
||||||
|
if coordinate.used_by_routing_rules?
|
||||||
|
errors = "« #{type_de_champ.libelle} » est utilisé pour le routage, vous ne pouvez pas le supprimer."
|
||||||
|
@morphed = [champ_component_from(coordinate, focused: false, errors:)]
|
||||||
|
flash.alert = errors
|
||||||
|
else
|
||||||
@coordinate = draft.remove_type_de_champ(params[:stable_id])
|
@coordinate = draft.remove_type_de_champ(params[:stable_id])
|
||||||
flash.notice = "Formulaire enregistré"
|
flash.notice = "Formulaire enregistré"
|
||||||
|
|
||||||
|
@ -75,6 +82,7 @@ module Administrateurs
|
||||||
@morphed = champ_components_starting_at(@coordinate)
|
@morphed = champ_components_starting_at(@coordinate)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
|
@ -225,6 +225,16 @@ class ProcedureRevision < ApplicationRecord
|
||||||
types_de_champ_public.any?(&:carte?)
|
types_de_champ_public.any?(&:carte?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def coordinate_and_tdc(stable_id)
|
||||||
|
return [nil, nil] if stable_id.blank?
|
||||||
|
|
||||||
|
coordinate = revision_types_de_champ
|
||||||
|
.joins(:type_de_champ)
|
||||||
|
.find_by(type_de_champ: { stable_id: stable_id })
|
||||||
|
|
||||||
|
[coordinate, coordinate&.type_de_champ]
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def compute_estimated_fill_duration
|
def compute_estimated_fill_duration
|
||||||
|
@ -245,16 +255,6 @@ class ProcedureRevision < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def coordinate_and_tdc(stable_id)
|
|
||||||
return [nil, nil] if stable_id.blank?
|
|
||||||
|
|
||||||
coordinate = revision_types_de_champ
|
|
||||||
.joins(:type_de_champ)
|
|
||||||
.find_by(type_de_champ: { stable_id: stable_id })
|
|
||||||
|
|
||||||
[coordinate, coordinate&.type_de_champ]
|
|
||||||
end
|
|
||||||
|
|
||||||
def renumber(siblings)
|
def renumber(siblings)
|
||||||
siblings.to_a.compact.each.with_index do |sibling, position|
|
siblings.to_a.compact.each.with_index do |sibling, position|
|
||||||
sibling.update_column(:position, position)
|
sibling.update_column(:position, position)
|
||||||
|
|
|
@ -157,5 +157,20 @@ describe Administrateurs::TypesDeChampController, type: :controller do
|
||||||
expect(assigns(:destroyed).libelle).to eq('l2')
|
expect(assigns(:destroyed).libelle).to eq('l2')
|
||||||
expect(morpheds).to eq([['l3', ['l1']]])
|
expect(morpheds).to eq([['l3', ['l1']]])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'rejected if type changed and routing involved' do
|
||||||
|
let(:params) do
|
||||||
|
{ procedure_id: procedure.id, stable_id: third_coordinate.stable_id }
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow_any_instance_of(ProcedureRevisionTypeDeChamp).to receive(:used_by_routing_rules?).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it do
|
||||||
|
is_expected.to have_http_status(:ok)
|
||||||
|
expect(flash.alert).to include("utilisé pour le routage")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue