Merge pull request #7642 from tchak/fix-should-not-be-able-to-remove-mandatory-files
This commit is contained in:
commit
440ceddfd1
6 changed files with 37 additions and 6 deletions
|
@ -75,6 +75,12 @@ class RootController < ApplicationController
|
|||
end
|
||||
|
||||
@dossier = Dossier.new(champs: all_champs)
|
||||
all_champs.each do |champ|
|
||||
champ.association(:dossier).target = @dossier
|
||||
champ.champs.each do |champ|
|
||||
champ.association(:dossier).target = @dossier
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def suivi
|
||||
|
|
|
@ -28,7 +28,7 @@ module ChampHelper
|
|||
|
||||
def autosave_available?(champ)
|
||||
# FIXME: enable autosave on champs private? once we figured out how to batch audit events
|
||||
champ.dossier&.brouillon? && !champ.repetition?
|
||||
champ.dossier.brouillon? && !champ.repetition?
|
||||
end
|
||||
|
||||
def editable_champ_controller(champ)
|
||||
|
@ -39,10 +39,10 @@ module ChampHelper
|
|||
# This is a public champ – it can have an autosave controller.
|
||||
if champ.public?
|
||||
# This is a champ on dossier in draft state. Activate autosave.
|
||||
if champ.dossier&.brouillon?
|
||||
if champ.dossier.brouillon?
|
||||
controllers << 'autosave'
|
||||
# This is a champ on a dossier in en_construction state. Enable conditions checker.
|
||||
elsif champ.public? && champ.dossier&.en_construction?
|
||||
elsif champ.public? && champ.dossier.en_construction?
|
||||
controllers << 'check-conditions'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -89,7 +89,7 @@ class Champ < ApplicationRecord
|
|||
end
|
||||
|
||||
def sections
|
||||
@sections ||= dossier&.sections_for(self)
|
||||
@sections ||= dossier.sections_for(self)
|
||||
end
|
||||
|
||||
def mandatory_blank_and_visible?
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
= render Attachment::EditComponent.new(form: form, attached_file: champ.piece_justificative_file, template: champ.type_de_champ.piece_justificative_template, user_can_destroy: true)
|
||||
- user_can_destroy = !champ.mandatory? || champ.dossier.brouillon?
|
||||
= render Attachment::EditComponent.new(form: form, attached_file: champ.piece_justificative_file, template: champ.type_de_champ.piece_justificative_template, user_can_destroy: user_can_destroy)
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
= render Attachment::EditComponent.new(form: form, attached_file: champ.piece_justificative_file, user_can_destroy: true)
|
||||
- user_can_destroy = !champ.mandatory? || champ.dossier.brouillon?
|
||||
= render Attachment::EditComponent.new(form: form, attached_file: champ.piece_justificative_file, user_can_destroy: user_can_destroy)
|
||||
|
|
|
@ -103,6 +103,29 @@ describe 'shared/dossiers/edit.html.haml', type: :view do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with a mandatory piece justificative' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:type_de_champ) { create(:type_de_champ_piece_justificative, procedure: dossier.procedure, mandatory: true) }
|
||||
let(:champ) { create(:champ_piece_justificative, dossier: dossier, type_de_champ: type_de_champ) }
|
||||
|
||||
context 'when dossier is en construction' do
|
||||
let(:dossier) { create(:dossier, :en_construction) }
|
||||
before { dossier.champs << champ }
|
||||
|
||||
it 'cannot delete a piece justificative' do
|
||||
expect(subject).not_to have_text('Supprimer')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when dossier is brouillon' do
|
||||
before { dossier.champs << champ }
|
||||
|
||||
it 'can delete a piece justificative' do
|
||||
expect(subject).to have_text('Supprimer')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a routed procedure' do
|
||||
let(:procedure) do
|
||||
create(:procedure,
|
||||
|
|
Loading…
Add table
Reference in a new issue