Merge pull request #2157 from betagouv/fix-2145
[Fix #2145] When procedure is archived, usager should not be able to …
This commit is contained in:
commit
3b0ce63170
10 changed files with 170 additions and 34 deletions
|
@ -5,6 +5,7 @@
|
|||
padding: ($default-spacer * 3) ($default-spacer * 2);
|
||||
border: 1px solid $border-grey;
|
||||
margin-bottom: $default-spacer * 2;
|
||||
background: #FFFFFF;
|
||||
|
||||
.card-title {
|
||||
font-weight: bold;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -14,4 +14,8 @@ module DossierHelper
|
|||
"highlighted"
|
||||
end
|
||||
end
|
||||
|
||||
def dossier_submission_is_closed?(dossier)
|
||||
dossier.brouillon? && dossier.procedure.archivee?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
= h string_to_html(@dossier.procedure.description)
|
||||
|
||||
.column.identity-form
|
||||
= render partial: "shared/dossiers/submit_is_over", locals: { dossier: @dossier }
|
||||
|
||||
- if !dossier_submission_is_closed?(@dossier)
|
||||
= form_for @dossier.individual, url: update_identite_dossier_path(@dossier), html: { class: "form" } do |f|
|
||||
%h1 Données d'identité
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
.container
|
||||
= render partial: "shared/dossiers/submit_is_over", locals: { dossier: dossier }
|
||||
|
||||
- if notice_url(dossier.procedure).present?
|
||||
%p
|
||||
Pour vous aider à remplir votre dossier, vous pouvez consulter
|
||||
|
@ -58,7 +60,7 @@
|
|||
class: 'button send',
|
||||
data: { action: 'draft', disable_with: 'Envoi...' }
|
||||
|
||||
- if current_user.owns?(dossier)
|
||||
- if current_user.owns?(dossier) && dossier.can_transition_to_en_construction?
|
||||
= f.button 'Soumettre le dossier',
|
||||
class: 'button send primary',
|
||||
data: { action: 'submit', disable_with: 'Envoi...' }
|
||||
|
@ -67,3 +69,5 @@
|
|||
= f.button 'Enregistrer les modifications du dossier',
|
||||
class: 'button send primary',
|
||||
data: { action: 'submit', disable_with: 'Envoi...' }
|
||||
|
||||
= render partial: "shared/dossiers/submit_is_over", locals: { dossier: dossier }
|
||||
|
|
8
app/views/shared/dossiers/_submit_is_over.html.haml
Normal file
8
app/views/shared/dossiers/_submit_is_over.html.haml
Normal file
|
@ -0,0 +1,8 @@
|
|||
- if dossier_submission_is_closed?(dossier)
|
||||
.card.featured
|
||||
.card-title
|
||||
Le dépôt de dossier est fermé
|
||||
- if dossier.procedure.archived_at.present?
|
||||
Il n'est plus possible de déposer de dossier pour cette démarche en ligne depuis le #{dossier.procedure.archived_at.strftime("%d/%m/%Y")}.
|
||||
- else
|
||||
Il n'est plus possible de déposer de dossier pour cette démarche en ligne.
|
|
@ -233,6 +233,7 @@ describe NewUser::DossiersController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when dossier can be updated by the owner' do
|
||||
it 'updates the champs' do
|
||||
subject
|
||||
|
||||
|
@ -241,6 +242,18 @@ describe NewUser::DossiersController, type: :controller do
|
|||
expect(dossier.reload.state).to eq('en_construction')
|
||||
end
|
||||
|
||||
context "on an archived procedure" do
|
||||
before { dossier.procedure.archive }
|
||||
|
||||
it "it does not change state" do
|
||||
subject
|
||||
|
||||
expect(response).not_to redirect_to(merci_dossier_path(dossier))
|
||||
expect(dossier.reload.state).to eq('brouillon')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'sends an email only on the first #update' do
|
||||
delivery = double
|
||||
expect(delivery).to receive(:deliver_later).with(no_args)
|
||||
|
|
|
@ -25,4 +25,61 @@ RSpec.describe DossierHelper, type: :helper do
|
|||
it { is_expected.to eq nil }
|
||||
end
|
||||
end
|
||||
|
||||
describe ".dossier_submission_is_closed?" do
|
||||
let(:dossier) { create(:dossier, state: state) }
|
||||
let(:state) { "brouillon" }
|
||||
|
||||
subject { dossier_submission_is_closed?(dossier) }
|
||||
|
||||
context "when dossier state is brouillon" do
|
||||
it { is_expected.to be false }
|
||||
|
||||
context "when dossier state is brouillon and procedure is archivee" do
|
||||
before { dossier.procedure.archive }
|
||||
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for "returns false" do
|
||||
it { is_expected.to be false }
|
||||
|
||||
context "and procedure is archivee" do
|
||||
before { dossier.procedure.archive }
|
||||
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
end
|
||||
|
||||
context "when dossier state is en_construction" do
|
||||
let(:state) { "en_construction" }
|
||||
|
||||
it_behaves_like "returns false"
|
||||
end
|
||||
|
||||
context "when dossier state is en_construction" do
|
||||
let(:state) { "en_instruction" }
|
||||
|
||||
it_behaves_like "returns false"
|
||||
end
|
||||
|
||||
context "when dossier state is en_construction" do
|
||||
let(:state) { "accepte" }
|
||||
|
||||
it_behaves_like "returns false"
|
||||
end
|
||||
|
||||
context "when dossier state is en_construction" do
|
||||
let(:state) { "refuse" }
|
||||
|
||||
it_behaves_like "returns false"
|
||||
end
|
||||
|
||||
context "when dossier state is en_construction" do
|
||||
let(:state) { "sans_suite" }
|
||||
|
||||
it_behaves_like "returns false"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue