[Fix #2145] When procedure is archived, usager should not be able to submit a dossier

This commit is contained in:
Mathieu Magnin 2018-06-25 18:07:16 +02:00
parent e33c59f9be
commit 9afbd16bbf
3 changed files with 47 additions and 1 deletions

View file

@ -72,7 +72,7 @@ module NewUser
elsif draft?
flash.now.notice = 'Votre brouillon a bien été sauvegardé.'
render :modifier
elsif @dossier.brouillon?
elsif @dossier.can_transition_to_en_construction?
@dossier.en_construction!
NotificationMailer.send_initiated_notification(@dossier).deliver_later
redirect_to merci_dossier_path(@dossier)

View file

@ -167,6 +167,10 @@ class Dossier < ApplicationRecord
!(procedure.archivee? && brouillon?)
end
def can_transition_to_en_construction?
!procedure.archivee? && brouillon?
end
def can_be_updated_by_the_user?
brouillon? || en_construction?
end

View file

@ -835,4 +835,46 @@ describe Dossier do
}.to have_enqueued_job(WebHookJob)
end
end
describe "#can_transition_to_en_construction?" do
let(:procedure) { create(:procedure, :published) }
let(:dossier) { create(:dossier, state: state, procedure: procedure) }
subject { dossier.can_transition_to_en_construction? }
context "dossier state is brouillon" do
let(:state) { "brouillon" }
it { is_expected.to be true }
context "procedure is archived" do
before { procedure.archive }
it { is_expected.to be false }
end
end
context "dossier state is en_construction" do
let(:state) { "en_construction" }
it { is_expected.to be false }
end
context "dossier state is en_instruction" do
let(:state) { "en_instruction" }
it { is_expected.to be false }
end
context "dossier state is en_instruction" do
let(:state) { "accepte" }
it { is_expected.to be false }
end
context "dossier state is en_instruction" do
let(:state) { "refuse" }
it { is_expected.to be false }
end
context "dossier state is en_instruction" do
let(:state) { "sans_suite" }
it { is_expected.to be false }
end
end
end