diff --git a/app/assets/stylesheets/new_design/card.scss b/app/assets/stylesheets/new_design/card.scss index 01866755d..61128cb72 100644 --- a/app/assets/stylesheets/new_design/card.scss +++ b/app/assets/stylesheets/new_design/card.scss @@ -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; diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 361eb3765..8ed830055 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -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) diff --git a/app/helpers/dossier_helper.rb b/app/helpers/dossier_helper.rb index 8e2bc2b35..46cc9e454 100644 --- a/app/helpers/dossier_helper.rb +++ b/app/helpers/dossier_helper.rb @@ -14,4 +14,8 @@ module DossierHelper "highlighted" end end + + def dossier_submission_is_closed?(dossier) + dossier.brouillon? && dossier.procedure.archivee? + end end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index a6452b395..1cf543a63 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -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 diff --git a/app/views/new_user/dossiers/identite.html.haml b/app/views/new_user/dossiers/identite.html.haml index de65aefb1..cef41586f 100644 --- a/app/views/new_user/dossiers/identite.html.haml +++ b/app/views/new_user/dossiers/identite.html.haml @@ -15,35 +15,38 @@ = h string_to_html(@dossier.procedure.description) .column.identity-form - = form_for @dossier.individual, url: update_identite_dossier_path(@dossier), html: { class: "form" } do |f| - %h1 Données d'identité + = render partial: "shared/dossiers/submit_is_over", locals: { dossier: @dossier } - %p.mb-1 Merci de remplir vos informations personnelles pour accéder à la démarche. + - 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é - %label - %span.mandatory * - champs requis + %p.mb-1 Merci de remplir vos informations personnelles pour accéder à la démarche. - = f.label :gender, class: "required" - = f.select :gender, ['M.', 'Mme'], {}, class: "small" - - .flex - .inline-champ - = f.label :prenom, class: "required" - = f.text_field :prenom, class: "small", required: true - .inline-champ - = f.label :nom, class: "required" - = f.text_field :nom, class: "small", required: true - - - if @dossier.procedure.ask_birthday? - = f.label :birthdate, class: "required" - = f.date_field :birthdate, value: @dossier.individual.birthdate, placeholder: 'format : AAAA-MM-JJ', required: true, class: "small" - - = fields_for :dossier, @dossier do |df| - = label_tag do - = df.check_box :autorisation_donnees, required: true - J'accepte - = link_to "les CGU", CGU_URL, target: :blank + %label %span.mandatory * + champs requis - = f.submit "Continuer", class: "button large primary expand" + = f.label :gender, class: "required" + = f.select :gender, ['M.', 'Mme'], {}, class: "small" + + .flex + .inline-champ + = f.label :prenom, class: "required" + = f.text_field :prenom, class: "small", required: true + .inline-champ + = f.label :nom, class: "required" + = f.text_field :nom, class: "small", required: true + + - if @dossier.procedure.ask_birthday? + = f.label :birthdate, class: "required" + = f.date_field :birthdate, value: @dossier.individual.birthdate, placeholder: 'format : AAAA-MM-JJ', required: true, class: "small" + + = fields_for :dossier, @dossier do |df| + = label_tag do + = df.check_box :autorisation_donnees, required: true + J'accepte + = link_to "les CGU", CGU_URL, target: :blank + %span.mandatory * + + = f.submit "Continuer", class: "button large primary expand" diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index 73b41af2a..d19daa799 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -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 } diff --git a/app/views/shared/dossiers/_submit_is_over.html.haml b/app/views/shared/dossiers/_submit_is_over.html.haml new file mode 100644 index 000000000..9d81a8a96 --- /dev/null +++ b/app/views/shared/dossiers/_submit_is_over.html.haml @@ -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. diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index 5be0295da..b701968e1 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -233,12 +233,25 @@ describe NewUser::DossiersController, type: :controller do end end - it 'updates the champs' do - subject + context 'when dossier can be updated by the owner' do + it 'updates the champs' do + subject - expect(response).to redirect_to(merci_dossier_path(dossier)) - expect(first_champ.reload.value).to eq('beautiful value') - expect(dossier.reload.state).to eq('en_construction') + expect(response).to redirect_to(merci_dossier_path(dossier)) + expect(first_champ.reload.value).to eq('beautiful value') + 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 diff --git a/spec/helpers/dossier_helper_spec.rb b/spec/helpers/dossier_helper_spec.rb index 0ceec6d96..5c9479589 100644 --- a/spec/helpers/dossier_helper_spec.rb +++ b/spec/helpers/dossier_helper_spec.rb @@ -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 diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index cebaea315..829009f61 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -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