From 5ac8117c6983d005fab22a95c5d066aa8fb77a76 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 09:09:23 +0200 Subject: [PATCH 01/24] =?UTF-8?q?DossierController#modifier=20=E2=86=92=20?= =?UTF-8?q?#brouillon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../new_user/dossiers_controller.rb | 14 ++++++------ app/controllers/users/carte_controller.rb | 2 +- .../users/dossiers/invites_controller.rb | 2 +- app/controllers/users/dossiers_controller.rb | 2 +- app/helpers/dossier_helper.rb | 2 +- app/views/dossiers/_edit_dossier.html.haml | 2 +- app/views/dossiers/_infos_dossier.html.haml | 2 +- ...modifier.html.haml => brouillon.html.haml} | 0 app/views/new_user/dossiers/demande.html.haml | 2 +- config/routes.rb | 4 ++-- spec/controllers/invites_controller_spec.rb | 4 ++-- .../new_user/dossiers_controller_spec.rb | 22 +++++++++---------- .../users/carte_controller_shared_example.rb | 2 +- .../users/dossiers/invites_controller_spec.rb | 2 +- .../users/dossiers_controller_spec.rb | 2 +- .../features/new_user/dossier_details_spec.rb | 2 +- spec/features/new_user/dossier_spec.rb | 2 +- spec/features/new_user/invite_spec.rb | 14 ++++++------ .../features/new_user/linked_dropdown_spec.rb | 2 +- spec/features/users/complete_demande_spec.rb | 2 +- spec/features/users/dossier_creation_spec.rb | 8 +++---- spec/helpers/dossier_helper_spec.rb | 2 +- ...ml_spec.rb => brouillon.html.haml_spec.rb} | 2 +- .../dossiers/demande.html.haml_spec.rb | 2 +- .../new_user/dossiers/index.html.haml_spec.rb | 2 +- .../recapitulatif/show.html.haml_spec.rb | 2 +- 26 files changed, 52 insertions(+), 52 deletions(-) rename app/views/new_user/dossiers/{modifier.html.haml => brouillon.html.haml} (100%) rename spec/views/new_user/dossiers/{modifier.html.haml_spec.rb => brouillon.html.haml_spec.rb} (94%) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 3a008190d..5eb13e001 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -4,8 +4,8 @@ module NewUser helper_method :new_demarche_url - before_action :ensure_ownership!, except: [:index, :show, :demande, :messagerie, :modifier, :update, :recherche] - before_action :ensure_ownership_or_invitation!, only: [:show, :demande, :messagerie, :modifier, :update, :create_commentaire] + before_action :ensure_ownership!, except: [:index, :show, :demande, :messagerie, :brouillon, :update, :recherche] + before_action :ensure_ownership_or_invitation!, only: [:show, :demande, :messagerie, :brouillon, :update, :create_commentaire] before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update] before_action :forbid_invite_submission!, only: [:update] @@ -25,7 +25,7 @@ module NewUser def show if dossier.brouillon? - redirect_to modifier_dossier_path(dossier) + redirect_to brouillon_dossier_path(dossier) elsif !Flipflop.new_dossier_details? redirect_to users_dossier_recapitulatif_path(dossier) @@ -64,7 +64,7 @@ module NewUser if @dossier.procedure.module_api_carto.use_api_carto redirect_to users_dossier_carte_path(@dossier.id) else - redirect_to modifier_dossier_path(@dossier) + redirect_to brouillon_dossier_path(@dossier) end else flash.now.alert = @dossier.errors.full_messages @@ -72,7 +72,7 @@ module NewUser end end - def modifier + def brouillon @dossier = dossier_with_champs # TODO: remove when the champs are unifed @@ -104,10 +104,10 @@ module NewUser if errors.present? flash.now.alert = errors - render :modifier + render :brouillon elsif draft? flash.now.notice = 'Votre brouillon a bien été sauvegardé.' - render :modifier + render :brouillon elsif @dossier.can_transition_to_en_construction? @dossier.en_construction! NotificationMailer.send_initiated_notification(@dossier).deliver_later diff --git a/app/controllers/users/carte_controller.rb b/app/controllers/users/carte_controller.rb index 032883703..89a5eab33 100644 --- a/app/controllers/users/carte_controller.rb +++ b/app/controllers/users/carte_controller.rb @@ -25,7 +25,7 @@ class Users::CarteController < UsersController dossier.update(json_latlngs: safe_json_latlngs) - redirect_to modifier_dossier_path(dossier) + redirect_to brouillon_dossier_path(dossier) end def get_position diff --git a/app/controllers/users/dossiers/invites_controller.rb b/app/controllers/users/dossiers/invites_controller.rb index 343edf98c..1d451a8ca 100644 --- a/app/controllers/users/dossiers/invites_controller.rb +++ b/app/controllers/users/dossiers/invites_controller.rb @@ -10,7 +10,7 @@ class Users::Dossiers::InvitesController < UsersController @facade = InviteDossierFacades.new params[:id].to_i, current_user.email if @facade.dossier.brouillon? - redirect_to modifier_dossier_path(@facade.dossier) + redirect_to brouillon_dossier_path(@facade.dossier) else render 'users/recapitulatif/show' end diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index aede9da0a..06d1ec4eb 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -142,7 +142,7 @@ class Users::DossiersController < UsersController if @facade.dossier.procedure.module_api_carto.use_api_carto redirect_to url_for(controller: :carte, action: :show, dossier_id: @facade.dossier.id) else - redirect_to modifier_dossier_path(@facade.dossier) + redirect_to brouillon_dossier_path(@facade.dossier) end end end diff --git a/app/helpers/dossier_helper.rb b/app/helpers/dossier_helper.rb index f6769e34c..c6b725c41 100644 --- a/app/helpers/dossier_helper.rb +++ b/app/helpers/dossier_helper.rb @@ -17,7 +17,7 @@ module DossierHelper def url_for_dossier(dossier) if dossier.brouillon? - modifier_dossier_path(dossier) + brouillon_dossier_path(dossier) else users_dossier_recapitulatif_path(dossier) end diff --git a/app/views/dossiers/_edit_dossier.html.haml b/app/views/dossiers/_edit_dossier.html.haml index 4f442527c..00b550510 100644 --- a/app/views/dossiers/_edit_dossier.html.haml +++ b/app/views/dossiers/_edit_dossier.html.haml @@ -1,5 +1,5 @@ - if !@facade.dossier.read_only? - if user_signed_in? && (current_user.owns_or_invite?(@facade.dossier)) - = link_to modifier_dossier_path(@facade.dossier), class: 'action', id: 'maj_infos' do + = link_to brouillon_dossier_path(@facade.dossier), class: 'action', id: 'maj_infos' do #edit-dossier.col-lg-2.col-md-2.col-sm-2.col-xs-2.action = "MODIFIER" diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index 00f85ffdc..6b4de117c 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -41,7 +41,7 @@ - if champ.type_champ == TypeDeChamp.type_champs.fetch(:dossier_link) - dossier = Dossier.includes(:procedure).find_by(id: champ.decorate.value) - if dossier - = link_to("Dossier #{dossier.id}", modifier_dossier_path(dossier), target: '_blank') + = link_to("Dossier #{dossier.id}", brouillon_dossier_path(dossier), target: '_blank') %br = sanitize(dossier.text_summary) - else diff --git a/app/views/new_user/dossiers/modifier.html.haml b/app/views/new_user/dossiers/brouillon.html.haml similarity index 100% rename from app/views/new_user/dossiers/modifier.html.haml rename to app/views/new_user/dossiers/brouillon.html.haml diff --git a/app/views/new_user/dossiers/demande.html.haml b/app/views/new_user/dossiers/demande.html.haml index f5be19d48..cf82b1e3b 100644 --- a/app/views/new_user/dossiers/demande.html.haml +++ b/app/views/new_user/dossiers/demande.html.haml @@ -7,4 +7,4 @@ .container - if !@dossier.read_only? - = link_to "Modifier le dossier", modifier_dossier_path(@dossier), class: 'button primary edit-form' + = link_to "Modifier le dossier", brouillon_dossier_path(@dossier), class: 'button primary edit-form' diff --git a/config/routes.rb b/config/routes.rb index fc6b800e4..05b17af1f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -275,8 +275,8 @@ Rails.application.routes.draw do member do get 'identite' patch 'update_identite' - get 'modifier' - patch 'modifier', to: 'dossiers#update' + get 'brouillon' + patch 'modifier', to: 'dossiers#update', as: 'modifier' get 'merci' get 'demande' get 'messagerie' diff --git a/spec/controllers/invites_controller_spec.rb b/spec/controllers/invites_controller_spec.rb index 63295fd8d..31035d801 100644 --- a/spec/controllers/invites_controller_spec.rb +++ b/spec/controllers/invites_controller_spec.rb @@ -69,14 +69,14 @@ describe InvitesController, type: :controller do context 'when user has access to dossier' do before do - request.env["HTTP_REFERER"] = "/dossiers/#{dossier.id}/modifier" + request.env["HTTP_REFERER"] = "/dossiers/#{dossier.id}/brouillon" dossier.update(user: signed_in_profile) end it { expect { subject }.to change(InviteUser, :count).by(1) } it "redirects to the previous URL" do - expect(subject).to redirect_to("/dossiers/#{dossier.id}/modifier") + expect(subject).to redirect_to("/dossiers/#{dossier.id}/brouillon") end context 'when email is assign to an user' do diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index 36a7b2eea..b318ff6cb 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -174,7 +174,7 @@ describe NewUser::DossiersController, type: :controller do let(:dossier_params) { { autorisation_donnees: true } } it do - expect(response).to redirect_to(modifier_dossier_path(dossier)) + expect(response).to redirect_to(brouillon_dossier_path(dossier)) end context 'on a procedure with carto' do @@ -208,14 +208,14 @@ describe NewUser::DossiersController, type: :controller do end end - describe '#modifier' do + describe '#brouillon' do before { sign_in(user) } let!(:dossier) { create(:dossier, user: user, autorisation_donnees: true) } - subject { get :modifier, params: { id: dossier.id } } + subject { get :brouillon, params: { id: dossier.id } } context 'when autorisation_donnees is checked' do - it { is_expected.to render_template(:modifier) } + it { is_expected.to render_template(:brouillon) } end context 'when autorisation_donnees is not checked' do @@ -238,7 +238,7 @@ describe NewUser::DossiersController, type: :controller do let!(:dossier) { create(:dossier, user: user) } it 'returns the edit page' do - get :modifier, params: { id: dossier.id } + get :brouillon, params: { id: dossier.id } expect(response).to have_http_status(:success) end end @@ -318,7 +318,7 @@ describe NewUser::DossiersController, type: :controller do subject end - it { expect(response).to render_template(:modifier) } + it { expect(response).to render_template(:brouillon) } it { expect(flash.alert).to eq(['nop']) } it 'does not send an email' do @@ -335,7 +335,7 @@ describe NewUser::DossiersController, type: :controller do subject end - it { expect(response).to render_template(:modifier) } + it { expect(response).to render_template(:brouillon) } it { expect(flash.alert).to eq(['nop']) } end @@ -349,13 +349,13 @@ describe NewUser::DossiersController, type: :controller do subject end - it { expect(response).to render_template(:modifier) } + it { expect(response).to render_template(:brouillon) } it { expect(flash.alert).to eq(['Le champ l doit être rempli.', 'pj']) } context 'and the user saves a draft' do let(:payload) { submit_payload.merge(save_draft: true) } - it { expect(response).to render_template(:modifier) } + it { expect(response).to render_template(:brouillon) } it { expect(flash.notice).to eq('Votre brouillon a bien été sauvegardé.') } it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:brouillon)) } end @@ -385,7 +385,7 @@ describe NewUser::DossiersController, type: :controller do subject end - it { expect(response).to render_template(:modifier) } + it { expect(response).to render_template(:brouillon) } it { expect(flash.notice).to eq('Votre brouillon a bien été sauvegardé.') } it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:brouillon)) } end @@ -490,7 +490,7 @@ describe NewUser::DossiersController, type: :controller do context 'when the dossier is a brouillon' do let(:dossier) { create(:dossier, user: user) } - it { is_expected.to redirect_to(modifier_dossier_path(dossier)) } + it { is_expected.to redirect_to(brouillon_dossier_path(dossier)) } end context 'when the dossier has been submitted' do diff --git a/spec/controllers/users/carte_controller_shared_example.rb b/spec/controllers/users/carte_controller_shared_example.rb index 06bc20a45..14be73f2c 100644 --- a/spec/controllers/users/carte_controller_shared_example.rb +++ b/spec/controllers/users/carte_controller_shared_example.rb @@ -105,7 +105,7 @@ shared_examples 'carte_controller_spec' do end it 'Redirection vers le formulaire de la procedure' do - expect(response).to redirect_to(modifier_dossier_path(dossier)) + expect(response).to redirect_to(brouillon_dossier_path(dossier)) end end diff --git a/spec/controllers/users/dossiers/invites_controller_spec.rb b/spec/controllers/users/dossiers/invites_controller_spec.rb index ee71a2af4..c9b0f5e27 100644 --- a/spec/controllers/users/dossiers/invites_controller_spec.rb +++ b/spec/controllers/users/dossiers/invites_controller_spec.rb @@ -56,7 +56,7 @@ describe Users::Dossiers::InvitesController, type: :controller do let(:dossier) { create :dossier, state: Dossier.states.fetch(:brouillon) } it { is_expected.to have_http_status(302) } - it { is_expected.to redirect_to modifier_dossier_path(dossier) } + it { is_expected.to redirect_to brouillon_dossier_path(dossier) } end context 'and dossier is not a brouillon' do diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index c5a44b8b7..8a518d099 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -355,7 +355,7 @@ describe Users::DossiersController, type: :controller do context 'procedure not use api carto' do it 'redirects to demande' do - expect(response).to redirect_to(modifier_dossier_path(dossier)) + expect(response).to redirect_to(brouillon_dossier_path(dossier)) end end diff --git a/spec/features/new_user/dossier_details_spec.rb b/spec/features/new_user/dossier_details_spec.rb index d6644e634..d416d194a 100644 --- a/spec/features/new_user/dossier_details_spec.rb +++ b/spec/features/new_user/dossier_details_spec.rb @@ -25,7 +25,7 @@ describe 'Dossier details:' do expect(page).to have_current_path(demande_dossier_path(dossier)) click_on 'Modifier le dossier' - expect(page).to have_current_path(modifier_dossier_path(dossier)) + expect(page).to have_current_path(brouillon_dossier_path(dossier)) fill_in('texte obligatoire', with: 'Nouveau texte') click_on 'Enregistrer les modifications du dossier' diff --git a/spec/features/new_user/dossier_spec.rb b/spec/features/new_user/dossier_spec.rb index 4859ed215..8e6dd4722 100644 --- a/spec/features/new_user/dossier_spec.rb +++ b/spec/features/new_user/dossier_spec.rb @@ -152,7 +152,7 @@ feature 'The user' do fill_in('individual_nom', with: 'nom') check 'dossier_autorisation_donnees' click_on 'Continuer' - expect(page).to have_current_path(modifier_dossier_path(user_dossier)) + expect(page).to have_current_path(brouillon_dossier_path(user_dossier)) end def select_date_and_time(date, field) diff --git a/spec/features/new_user/invite_spec.rb b/spec/features/new_user/invite_spec.rb index 190961871..41d5f0631 100644 --- a/spec/features/new_user/invite_spec.rb +++ b/spec/features/new_user/invite_spec.rb @@ -16,7 +16,7 @@ feature 'Invitations' do fill_in 'Libelle du champ', with: 'Some edited value' send_invite_to "user_invite@exemple.fr" - expect(page).to have_current_path(modifier_dossier_path(dossier)) + expect(page).to have_current_path(brouillon_dossier_path(dossier)) expect(page).to have_text("Une invitation a été envoyée à user_invite@exemple.fr.") expect(page).to have_text("user_invite@exemple.fr") @@ -29,7 +29,7 @@ feature 'Invitations' do expect(page).to have_current_path(new_user_session_path) submit_login_form(invited_user) - expect(page).to have_current_path(modifier_dossier_path(dossier)) + expect(page).to have_current_path(brouillon_dossier_path(dossier)) expect(page).to have_no_selector('.button.invite-user-action') fill_in 'Libelle du champ', with: 'Some edited value' @@ -43,7 +43,7 @@ feature 'Invitations' do expect(page).to have_current_path(new_user_session_path) submit_login_form(invited_user) - expect(page).to have_current_path(modifier_dossier_path(dossier)) + expect(page).to have_current_path(brouillon_dossier_path(dossier)) expect(page).to have_button('Soumettre le dossier', disabled: true) expect(page).to have_selector('.invite-cannot-submit') @@ -75,10 +75,10 @@ feature 'Invitations' do # We should be able to just click() the link, but Capybara detects that the # enclosing div would be clicked instead. - expect(page).to have_link("MODIFIER", href: modifier_dossier_path(dossier)) - visit modifier_dossier_path(dossier) + expect(page).to have_link("MODIFIER", href: brouillon_dossier_path(dossier)) + visit brouillon_dossier_path(dossier) - expect(page).to have_current_path(modifier_dossier_path(dossier)) + expect(page).to have_current_path(brouillon_dossier_path(dossier)) fill_in "Libelle du champ", with: "Some edited value" click_button "Enregistrer les modifications du dossier" @@ -105,7 +105,7 @@ feature 'Invitations' do def navigate_to_brouillon(dossier) expect(page).to have_current_path(dossiers_path) click_on(dossier.id) - expect(page).to have_current_path(modifier_dossier_path(dossier)) + expect(page).to have_current_path(brouillon_dossier_path(dossier)) end def navigate_to_recapitulatif(dossier) diff --git a/spec/features/new_user/linked_dropdown_spec.rb b/spec/features/new_user/linked_dropdown_spec.rb index 01758f0bc..d4fe7cbae 100644 --- a/spec/features/new_user/linked_dropdown_spec.rb +++ b/spec/features/new_user/linked_dropdown_spec.rb @@ -61,7 +61,7 @@ feature 'linked dropdown lists' do fill_in('individual_nom', with: 'nom') check 'dossier_autorisation_donnees' click_on 'Continuer' - expect(page).to have_current_path(modifier_dossier_path(user_dossier)) + expect(page).to have_current_path(brouillon_dossier_path(user_dossier)) end def primary_id_for(libelle) diff --git a/spec/features/users/complete_demande_spec.rb b/spec/features/users/complete_demande_spec.rb index c63202c40..07e7fdd4c 100644 --- a/spec/features/users/complete_demande_spec.rb +++ b/spec/features/users/complete_demande_spec.rb @@ -64,7 +64,7 @@ feature 'user path for dossier creation' do page.find_by_id('etape_suivante').click end scenario 'user is on edition page' do - expect(page).to have_current_path(modifier_dossier_path(Dossier.last)) + expect(page).to have_current_path(brouillon_dossier_path(Dossier.last)) end context 'user fill and validate description page' do before do diff --git a/spec/features/users/dossier_creation_spec.rb b/spec/features/users/dossier_creation_spec.rb index 504e0d007..310d43e64 100644 --- a/spec/features/users/dossier_creation_spec.rb +++ b/spec/features/users/dossier_creation_spec.rb @@ -28,7 +28,7 @@ feature 'As a User I wanna create a dossier' do expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id)) click_button('Etape suivante') - expect(page).to have_current_path(modifier_dossier_path(procedure_for_individual.dossiers.last)) + expect(page).to have_current_path(brouillon_dossier_path(procedure_for_individual.dossiers.last)) expect(user.dossiers.first.individual.birthdate).to eq(Date.new(1987, 10, 14)) end @@ -40,7 +40,7 @@ feature 'As a User I wanna create a dossier' do expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s)) click_button('Etape suivante') - expect(page).to have_current_path(modifier_dossier_path(procedure_for_individual.dossiers.last)) + expect(page).to have_current_path(brouillon_dossier_path(procedure_for_individual.dossiers.last)) expect(user.dossiers.first.individual.birthdate).to eq(Date.new(1987, 10, 14)) end @@ -55,7 +55,7 @@ feature 'As a User I wanna create a dossier' do expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last)) click_button('Etape suivante') - expect(page).to have_current_path(modifier_dossier_path(procedure_for_individual.dossiers.last)) + expect(page).to have_current_path(brouillon_dossier_path(procedure_for_individual.dossiers.last)) expect(user.dossiers.first.individual.birthdate).to eq(nil) end @@ -85,7 +85,7 @@ feature 'As a User I wanna create a dossier' do page.find_by_id('etape_suivante').click expect(page).to have_current_path(users_dossier_carte_path(procedure_with_siret.dossiers.last.id.to_s)) page.find_by_id('etape_suivante').click - expect(page).to have_current_path(modifier_dossier_path(procedure_with_siret.dossiers.last)) + expect(page).to have_current_path(brouillon_dossier_path(procedure_with_siret.dossiers.last)) end end end diff --git a/spec/helpers/dossier_helper_spec.rb b/spec/helpers/dossier_helper_spec.rb index 03fa70d43..56330c487 100644 --- a/spec/helpers/dossier_helper_spec.rb +++ b/spec/helpers/dossier_helper_spec.rb @@ -31,7 +31,7 @@ RSpec.describe DossierHelper, type: :helper do context "when the dossier is in the brouillon state" do let(:dossier) { create(:dossier, state: Dossier.states.fetch(:brouillon)) } - it { is_expected.to eq "/dossiers/#{dossier.id}/modifier" } + it { is_expected.to eq "/dossiers/#{dossier.id}/brouillon" } end context "when the dossier is any other state" do diff --git a/spec/views/new_user/dossiers/modifier.html.haml_spec.rb b/spec/views/new_user/dossiers/brouillon.html.haml_spec.rb similarity index 94% rename from spec/views/new_user/dossiers/modifier.html.haml_spec.rb rename to spec/views/new_user/dossiers/brouillon.html.haml_spec.rb index d5fb987da..d5951c8f3 100644 --- a/spec/views/new_user/dossiers/modifier.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/brouillon.html.haml_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'new_user/dossiers/modifier.html.haml', type: :view do +describe 'new_user/dossiers/brouillon.html.haml', type: :view do let(:procedure) { create(:procedure, :with_api_carto, :with_two_type_de_piece_justificative, :with_notice, for_individual: true) } let(:dossier) { create(:dossier, :with_entreprise, :with_service, state: Dossier.states.fetch(:brouillon), procedure: procedure) } let(:footer) { view.content_for(:footer) } diff --git a/spec/views/new_user/dossiers/demande.html.haml_spec.rb b/spec/views/new_user/dossiers/demande.html.haml_spec.rb index 0dff42b3d..0f0a15236 100644 --- a/spec/views/new_user/dossiers/demande.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/demande.html.haml_spec.rb @@ -21,7 +21,7 @@ describe 'new_user/dossiers/demande.html.haml', type: :view do end context 'when the dossier is editable' do - it { is_expected.to have_link('Modifier le dossier', href: modifier_dossier_path(dossier)) } + it { is_expected.to have_link('Modifier le dossier', href: brouillon_dossier_path(dossier)) } end context 'when the dossier is read-only' do diff --git a/spec/views/new_user/dossiers/index.html.haml_spec.rb b/spec/views/new_user/dossiers/index.html.haml_spec.rb index 869e70b78..f2b0bebc5 100644 --- a/spec/views/new_user/dossiers/index.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/index.html.haml_spec.rb @@ -26,7 +26,7 @@ describe 'new_user/dossiers/index.html.haml', type: :view do dossier = user_dossiers.first expect(rendered).to have_text(dossier_brouillon.id) expect(rendered).to have_text(dossier_brouillon.procedure.libelle) - expect(rendered).to have_link(dossier_brouillon.id, href: modifier_dossier_path(dossier_brouillon)) + expect(rendered).to have_link(dossier_brouillon.id, href: brouillon_dossier_path(dossier_brouillon)) expect(rendered).to have_text(dossier_en_construction.id) expect(rendered).to have_text(dossier_en_construction.procedure.libelle) diff --git a/spec/views/users/recapitulatif/show.html.haml_spec.rb b/spec/views/users/recapitulatif/show.html.haml_spec.rb index f07ff7a4d..b332127bb 100644 --- a/spec/views/users/recapitulatif/show.html.haml_spec.rb +++ b/spec/views/users/recapitulatif/show.html.haml_spec.rb @@ -31,7 +31,7 @@ describe 'users/recapitulatif/show.html.haml', type: :view do end it 'le lien vers l édition est correct' do - expect(rendered).to have_selector("a[id=maj_infos][href='/dossiers/#{dossier_id}/modifier']") + expect(rendered).to have_selector("a[id=maj_infos][href='/dossiers/#{dossier_id}/brouillon']") end end From 338ffb8b5012055b03e2798080e574a7e9dde8cd Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 10:49:26 +0200 Subject: [PATCH 02/24] =?UTF-8?q?DossierController#update=20=E2=86=92=20#u?= =?UTF-8?q?pdate=5Fbrouillon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/new_user/dossiers_controller.rb | 10 +++++----- app/views/shared/dossiers/_edit.html.haml | 2 +- config/routes.rb | 2 +- spec/controllers/new_user/dossiers_controller_spec.rb | 6 +++--- spec/features/new_user/dossier_spec.rb | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 5eb13e001..4156384bf 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -4,10 +4,10 @@ module NewUser helper_method :new_demarche_url - before_action :ensure_ownership!, except: [:index, :show, :demande, :messagerie, :brouillon, :update, :recherche] - before_action :ensure_ownership_or_invitation!, only: [:show, :demande, :messagerie, :brouillon, :update, :create_commentaire] - before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update] - before_action :forbid_invite_submission!, only: [:update] + before_action :ensure_ownership!, except: [:index, :show, :demande, :messagerie, :brouillon, :update_brouillon, :recherche] + before_action :ensure_ownership_or_invitation!, only: [:show, :demande, :messagerie, :brouillon, :update_brouillon, :create_commentaire] + before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update_brouillon] + before_action :forbid_invite_submission!, only: [:update_brouillon] def index @user_dossiers = current_user.dossiers.includes(:procedure).order_by_updated_at.page(page) @@ -87,7 +87,7 @@ module NewUser # FIXME: remove PiecesJustificativesService # delegate draft save logic to champ ? - def update + def update_brouillon @dossier = dossier_with_champs errors = PiecesJustificativesService.upload!(@dossier, current_user, params) diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index 09b93fc56..cf8444925 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -4,7 +4,7 @@ - if apercu - form_options = { url: '', method: :get, html: { class: 'form', multipart: true } } - else - - form_options = { url: modifier_dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true } } + - form_options = { url: brouillon_dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true } } = form_for dossier, form_options do |f| diff --git a/config/routes.rb b/config/routes.rb index 05b17af1f..ca1701fd0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -276,7 +276,7 @@ Rails.application.routes.draw do get 'identite' patch 'update_identite' get 'brouillon' - patch 'modifier', to: 'dossiers#update', as: 'modifier' + patch 'brouillon', to: 'dossiers#update_brouillon' get 'merci' get 'demande' get 'messagerie' diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index b318ff6cb..c86ac130d 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -243,7 +243,7 @@ describe NewUser::DossiersController, type: :controller do end end - describe '#update' do + describe '#update_brouillon' do before { sign_in(user) } let!(:dossier) { create(:dossier, user: user) } let(:first_champ) { dossier.champs.first } @@ -261,7 +261,7 @@ describe NewUser::DossiersController, type: :controller do end let(:payload) { submit_payload } - subject { patch :update, params: payload } + subject { patch :update_brouillon, params: payload } context 'when the dossier cannot be updated by the user' do let!(:dossier) { create(:dossier, :en_instruction, user: user) } @@ -295,7 +295,7 @@ describe NewUser::DossiersController, type: :controller do end end - it 'sends an email only on the first #update' do + it 'sends an email only on the first #update_brouillon' do delivery = double expect(delivery).to receive(:deliver_later).with(no_args) diff --git a/spec/features/new_user/dossier_spec.rb b/spec/features/new_user/dossier_spec.rb index 8e6dd4722..30d5ef45e 100644 --- a/spec/features/new_user/dossier_spec.rb +++ b/spec/features/new_user/dossier_spec.rb @@ -96,12 +96,12 @@ feature 'The user' do click_on 'Enregistrer le brouillon' expect(user_dossier.reload.brouillon?).to be(true) expect(page).to have_content('Votre brouillon a bien été sauvegardé') - expect(page).to have_current_path(modifier_dossier_path(user_dossier)) + expect(page).to have_current_path(brouillon_dossier_path(user_dossier)) # Check an incomplete dossier cannot be submitted when mandatory fields are missing click_on 'Soumettre le dossier' expect(user_dossier.reload.brouillon?).to be(true) - expect(page).to have_current_path(modifier_dossier_path(user_dossier)) + expect(page).to have_current_path(brouillon_dossier_path(user_dossier)) # Check a dossier can be submitted when all mandatory fields are filled fill_in('texte obligatoire', with: 'super texte') From cd46ee06e13365c93a4700f5c51e6ea2bae31ca7 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 5 Sep 2018 18:23:10 +0200 Subject: [PATCH 03/24] Add DossierController#modifier --- app/controllers/new_user/dossiers_controller.rb | 10 +++++++--- app/views/new_user/dossiers/demande.html.haml | 2 +- app/views/new_user/dossiers/modifier.html.haml | 7 +++++++ config/routes.rb | 1 + spec/features/new_user/dossier_details_spec.rb | 2 +- spec/views/new_user/dossiers/demande.html.haml_spec.rb | 2 +- 6 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 app/views/new_user/dossiers/modifier.html.haml diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 4156384bf..1499730c0 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -4,9 +4,9 @@ module NewUser helper_method :new_demarche_url - before_action :ensure_ownership!, except: [:index, :show, :demande, :messagerie, :brouillon, :update_brouillon, :recherche] - before_action :ensure_ownership_or_invitation!, only: [:show, :demande, :messagerie, :brouillon, :update_brouillon, :create_commentaire] - before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update_brouillon] + before_action :ensure_ownership!, except: [:index, :show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :recherche] + before_action :ensure_ownership_or_invitation!, only: [:show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :create_commentaire] + before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update_brouillon, :modifier] before_action :forbid_invite_submission!, only: [:update_brouillon] def index @@ -123,6 +123,10 @@ module NewUser end end + def modifier + @dossier = dossier_with_champs + end + def merci @dossier = current_user.dossiers.includes(:procedure).find(params[:id]) end diff --git a/app/views/new_user/dossiers/demande.html.haml b/app/views/new_user/dossiers/demande.html.haml index cf82b1e3b..f5be19d48 100644 --- a/app/views/new_user/dossiers/demande.html.haml +++ b/app/views/new_user/dossiers/demande.html.haml @@ -7,4 +7,4 @@ .container - if !@dossier.read_only? - = link_to "Modifier le dossier", brouillon_dossier_path(@dossier), class: 'button primary edit-form' + = link_to "Modifier le dossier", modifier_dossier_path(@dossier), class: 'button primary edit-form' diff --git a/app/views/new_user/dossiers/modifier.html.haml b/app/views/new_user/dossiers/modifier.html.haml new file mode 100644 index 000000000..624dcaa6a --- /dev/null +++ b/app/views/new_user/dossiers/modifier.html.haml @@ -0,0 +1,7 @@ +- content_for(:title, "Modifier · Dossier nº #{@dossier.id} (#{@dossier.procedure.libelle})") + +#dossier-show + = render partial: 'new_user/dossiers/show/header', locals: { dossier: @dossier } + + .container + = render partial: "shared/dossiers/edit", locals: { dossier: @dossier, apercu: false } diff --git a/config/routes.rb b/config/routes.rb index ca1701fd0..b5799685e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -277,6 +277,7 @@ Rails.application.routes.draw do patch 'update_identite' get 'brouillon' patch 'brouillon', to: 'dossiers#update_brouillon' + get 'modifier', to: 'dossiers#modifier' get 'merci' get 'demande' get 'messagerie' diff --git a/spec/features/new_user/dossier_details_spec.rb b/spec/features/new_user/dossier_details_spec.rb index d416d194a..d6644e634 100644 --- a/spec/features/new_user/dossier_details_spec.rb +++ b/spec/features/new_user/dossier_details_spec.rb @@ -25,7 +25,7 @@ describe 'Dossier details:' do expect(page).to have_current_path(demande_dossier_path(dossier)) click_on 'Modifier le dossier' - expect(page).to have_current_path(brouillon_dossier_path(dossier)) + expect(page).to have_current_path(modifier_dossier_path(dossier)) fill_in('texte obligatoire', with: 'Nouveau texte') click_on 'Enregistrer les modifications du dossier' diff --git a/spec/views/new_user/dossiers/demande.html.haml_spec.rb b/spec/views/new_user/dossiers/demande.html.haml_spec.rb index 0f0a15236..0dff42b3d 100644 --- a/spec/views/new_user/dossiers/demande.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/demande.html.haml_spec.rb @@ -21,7 +21,7 @@ describe 'new_user/dossiers/demande.html.haml', type: :view do end context 'when the dossier is editable' do - it { is_expected.to have_link('Modifier le dossier', href: brouillon_dossier_path(dossier)) } + it { is_expected.to have_link('Modifier le dossier', href: modifier_dossier_path(dossier)) } end context 'when the dossier is read-only' do From 1341074325f804c0a731847fc3a096ef5c0a52c3 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 11:39:46 +0200 Subject: [PATCH 04/24] Add DossierController#update --- .../new_user/dossiers_controller.rb | 44 ++++++- app/views/shared/dossiers/_edit.html.haml | 4 +- config/routes.rb | 1 + .../new_user/dossiers_controller_spec.rb | 110 ++++++++++++++++++ 4 files changed, 155 insertions(+), 4 deletions(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 1499730c0..641abcf68 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -4,9 +4,9 @@ module NewUser helper_method :new_demarche_url - before_action :ensure_ownership!, except: [:index, :show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :recherche] - before_action :ensure_ownership_or_invitation!, only: [:show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :create_commentaire] - before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update_brouillon, :modifier] + before_action :ensure_ownership!, except: [:index, :show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :update, :recherche] + before_action :ensure_ownership_or_invitation!, only: [:show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :update, :create_commentaire] + before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update_brouillon, :modifier, :update] before_action :forbid_invite_submission!, only: [:update_brouillon] def index @@ -127,6 +127,44 @@ module NewUser @dossier = dossier_with_champs end + # FIXME: remove PiecesJustificativesService + # delegate draft save logic to champ ? + def update + @dossier = dossier_with_champs + + errors = PiecesJustificativesService.upload!(@dossier, current_user, params) + + if champs_params[:dossier] && !@dossier.update(champs_params[:dossier]) + errors += @dossier.errors.full_messages + end + + if !draft? + errors += @dossier.champs.select(&:mandatory_and_blank?) + .map { |c| "Le champ #{c.libelle.truncate(200)} doit être rempli." } + errors += PiecesJustificativesService.missing_pj_error_messages(@dossier) + end + + if errors.present? + flash.now.alert = errors + render :modifier + elsif draft? + flash.now.notice = 'Votre brouillon a bien été sauvegardé.' + render :modifier + elsif @dossier.can_transition_to_en_construction? + @dossier.en_construction! + NotificationMailer.send_initiated_notification(@dossier).deliver_later + redirect_to merci_dossier_path(@dossier) + elsif current_user.owns?(dossier) + if Flipflop.new_dossier_details? + redirect_to demande_dossier_path(@dossier) + else + redirect_to users_dossier_recapitulatif_path(@dossier) + end + else + redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user)) + end + end + def merci @dossier = current_user.dossiers.includes(:procedure).find(params[:id]) end diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index cf8444925..03282ecfc 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -3,8 +3,10 @@ - if apercu - form_options = { url: '', method: :get, html: { class: 'form', multipart: true } } - - else + - elsif dossier.brouillon? - form_options = { url: brouillon_dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true } } + - else + - form_options = { url: dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true } } = form_for dossier, form_options do |f| diff --git a/config/routes.rb b/config/routes.rb index b5799685e..9d49f7ed8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -278,6 +278,7 @@ Rails.application.routes.draw do get 'brouillon' patch 'brouillon', to: 'dossiers#update_brouillon' get 'modifier', to: 'dossiers#modifier' + patch ':id', to: 'dossiers#update' get 'merci' get 'demande' get 'messagerie' diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index c86ac130d..e3fb37b0d 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -410,6 +410,116 @@ describe NewUser::DossiersController, type: :controller do end end + describe '#update' do + before { sign_in(user) } + let!(:dossier) { create(:dossier, :en_construction, user: user) } + let(:first_champ) { dossier.champs.first } + let(:value) { 'beautiful value' } + let(:submit_payload) do + { + id: dossier.id, + dossier: { + champs_attributes: { + id: first_champ.id, + value: value + } + } + } + end + let(:payload) { submit_payload } + + subject { patch :update, params: payload } + + context 'when the dossier cannot be updated by the user' do + let!(:dossier) { create(:dossier, :en_instruction, user: user) } + + it 'redirects to the dossiers list' do + subject + + expect(response).to redirect_to(dossiers_path) + expect(flash.alert).to eq('Votre dossier ne peut plus être modifié') + end + end + + context 'when dossier can be updated by the owner' do + it 'updates the champs' do + subject + + expect(response).to redirect_to(users_dossier_recapitulatif_path(dossier)) + expect(first_champ.reload.value).to eq('beautiful value') + expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction)) + end + end + + context 'when the update fails' do + before do + expect_any_instance_of(Dossier).to receive(:save).and_return(false) + expect_any_instance_of(Dossier).to receive(:errors) + .and_return(double(full_messages: ['nop'])) + + subject + end + + it { expect(response).to render_template(:modifier) } + it { expect(flash.alert).to eq(['nop']) } + + it 'does not send an email' do + expect(NotificationMailer).not_to receive(:send_initiated_notification) + + subject + end + end + + context 'when the pj service returns an error' do + before do + expect(PiecesJustificativesService).to receive(:upload!).and_return(['nop']) + + subject + end + + it { expect(response).to render_template(:modifier) } + it { expect(flash.alert).to eq(['nop']) } + end + + context 'when a mandatory champ is missing' do + let(:value) { nil } + + before do + first_champ.type_de_champ.update(mandatory: true, libelle: 'l') + allow(PiecesJustificativesService).to receive(:missing_pj_error_messages).and_return(['pj']) + + subject + end + + it { expect(response).to render_template(:modifier) } + it { expect(flash.alert).to eq(['Le champ l doit être rempli.', 'pj']) } + end + + context 'when dossier has no champ' do + let(:submit_payload) { { id: dossier.id } } + + it 'does not raise any errors' do + subject + + expect(response).to redirect_to(users_dossier_recapitulatif_path(dossier)) + end + end + + context 'when the user has an invitation but is not the owner' do + let(:dossier) { create(:dossier) } + let!(:invite) { create(:invite, dossier: dossier, user: user, type: 'InviteUser') } + + before do + dossier.en_construction! + subject + end + + it { expect(first_champ.reload.value).to eq('beautiful value') } + it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction)) } + it { expect(response).to redirect_to(users_dossiers_invite_path(invite)) } + end + end + describe '#index' do before { sign_in(user) } From 87e59e2bfb4705fd3e690d7925670c10c76b3070 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 5 Sep 2018 19:05:43 +0200 Subject: [PATCH 05/24] Streamline DossierController#update_brouillon and #update --- .../new_user/dossiers_controller.rb | 32 ++++++------------- .../new_user/dossiers_controller_spec.rb | 11 ------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 641abcf68..b5b3c742e 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -85,8 +85,9 @@ module NewUser end end - # FIXME: remove PiecesJustificativesService - # delegate draft save logic to champ ? + # FIXME: + # - remove PiecesJustificativesService + # - delegate draft save logic to champ ? def update_brouillon @dossier = dossier_with_champs @@ -112,12 +113,8 @@ module NewUser @dossier.en_construction! NotificationMailer.send_initiated_notification(@dossier).deliver_later redirect_to merci_dossier_path(@dossier) - elsif current_user.owns?(dossier) - if Flipflop.new_dossier_details? - redirect_to demande_dossier_path(@dossier) - else - redirect_to users_dossier_recapitulatif_path(@dossier) - end + elsif !draft? && !@dossier.can_transition_to_en_construction? + render :brouillon else redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user)) end @@ -127,8 +124,8 @@ module NewUser @dossier = dossier_with_champs end - # FIXME: remove PiecesJustificativesService - # delegate draft save logic to champ ? + # FIXME: + # - remove PiecesJustificativesService def update @dossier = dossier_with_champs @@ -138,22 +135,13 @@ module NewUser errors += @dossier.errors.full_messages end - if !draft? - errors += @dossier.champs.select(&:mandatory_and_blank?) - .map { |c| "Le champ #{c.libelle.truncate(200)} doit être rempli." } - errors += PiecesJustificativesService.missing_pj_error_messages(@dossier) - end + errors += @dossier.champs.select(&:mandatory_and_blank?) + .map { |c| "Le champ #{c.libelle.truncate(200)} doit être rempli." } + errors += PiecesJustificativesService.missing_pj_error_messages(@dossier) if errors.present? flash.now.alert = errors render :modifier - elsif draft? - flash.now.notice = 'Votre brouillon a bien été sauvegardé.' - render :modifier - elsif @dossier.can_transition_to_en_construction? - @dossier.en_construction! - NotificationMailer.send_initiated_notification(@dossier).deliver_later - redirect_to merci_dossier_path(@dossier) elsif current_user.owns?(dossier) if Flipflop.new_dossier_details? redirect_to demande_dossier_path(@dossier) diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index e3fb37b0d..de694100a 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -396,17 +396,6 @@ describe NewUser::DossiersController, type: :controller do it { expect(response).to redirect_to(root_path) } it { expect(flash.alert).to eq("Vous n'avez pas accès à ce dossier") } end - - context 'and the invite updates a dossier en constructions' do - before do - dossier.en_construction! - subject - end - - it { expect(first_champ.reload.value).to eq('beautiful value') } - it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction)) } - it { expect(response).to redirect_to(users_dossiers_invite_path(invite)) } - end end end From f5debfef466d054d6dc1d55aaec74b9568ec4417 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 5 Sep 2018 19:06:00 +0200 Subject: [PATCH 06/24] =?UTF-8?q?DossierController#draft=3F=20=E2=86=92=20?= =?UTF-8?q?#save=5Fdraft=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/new_user/dossiers_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index b5b3c742e..618f06709 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -97,7 +97,7 @@ module NewUser errors += @dossier.errors.full_messages end - if !draft? + if !save_draft? errors += @dossier.champs.select(&:mandatory_and_blank?) .map { |c| "Le champ #{c.libelle.truncate(200)} doit être rempli." } errors += PiecesJustificativesService.missing_pj_error_messages(@dossier) @@ -106,14 +106,14 @@ module NewUser if errors.present? flash.now.alert = errors render :brouillon - elsif draft? + elsif save_draft? flash.now.notice = 'Votre brouillon a bien été sauvegardé.' render :brouillon elsif @dossier.can_transition_to_en_construction? @dossier.en_construction! NotificationMailer.send_initiated_notification(@dossier).deliver_later redirect_to merci_dossier_path(@dossier) - elsif !draft? && !@dossier.can_transition_to_en_construction? + elsif !save_draft? && !@dossier.can_transition_to_en_construction? render :brouillon else redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user)) @@ -275,10 +275,10 @@ module NewUser end def passage_en_construction? - dossier.brouillon? && !draft? + dossier.brouillon? && !save_draft? end - def draft? + def save_draft? params[:save_draft] end end From 230bf22b7790e7c5b26cc0200db87418be817e08 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 13:29:56 +0200 Subject: [PATCH 07/24] Redactor DossierController#update_brouillon --- .../new_user/dossiers_controller.rb | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 618f06709..275157b33 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -8,6 +8,7 @@ module NewUser before_action :ensure_ownership_or_invitation!, only: [:show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :update, :create_commentaire] before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update_brouillon, :modifier, :update] before_action :forbid_invite_submission!, only: [:update_brouillon] + before_action :forbid_closed_submission!, only: [:update_brouillon] def index @user_dossiers = current_user.dossiers.includes(:procedure).order_by_updated_at.page(page) @@ -106,17 +107,15 @@ module NewUser if errors.present? flash.now.alert = errors render :brouillon - elsif save_draft? - flash.now.notice = 'Votre brouillon a bien été sauvegardé.' - render :brouillon - elsif @dossier.can_transition_to_en_construction? - @dossier.en_construction! - NotificationMailer.send_initiated_notification(@dossier).deliver_later - redirect_to merci_dossier_path(@dossier) - elsif !save_draft? && !@dossier.can_transition_to_en_construction? - render :brouillon else - redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user)) + if save_draft? + flash.now.notice = 'Votre brouillon a bien été sauvegardé.' + render :brouillon + else + @dossier.en_construction! + NotificationMailer.send_initiated_notification(@dossier).deliver_later + redirect_to merci_dossier_path(@dossier) + end end end @@ -257,6 +256,12 @@ module NewUser end end + def forbid_closed_submission! + if passage_en_construction? && !dossier.can_transition_to_en_construction? + forbidden! + end + end + def forbidden! flash[:alert] = "Vous n'avez pas accès à ce dossier" redirect_to root_path From 6fe1f912c82cbadced1d577b310d5e71922a7a9e Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 13:31:29 +0200 Subject: [PATCH 08/24] Refactor DossiersController#update Nested ifs are heavier but easier to understand as related conditions are visually grouped --- app/controllers/new_user/dossiers_controller.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 275157b33..568e54375 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -141,14 +141,16 @@ module NewUser if errors.present? flash.now.alert = errors render :modifier - elsif current_user.owns?(dossier) - if Flipflop.new_dossier_details? - redirect_to demande_dossier_path(@dossier) - else - redirect_to users_dossier_recapitulatif_path(@dossier) - end else - redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user)) + if current_user.owns?(dossier) + if Flipflop.new_dossier_details? + redirect_to demande_dossier_path(@dossier) + else + redirect_to users_dossier_recapitulatif_path(@dossier) + end + else + redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user)) + end end end From 23405efd3af7c80937d073b46bf0bccd0cfb0941 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 13:35:59 +0200 Subject: [PATCH 09/24] Mutualize some code in #update_dossier_and_compute_errors --- .../new_user/dossiers_controller.rb | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 568e54375..d048f15ef 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -92,17 +92,7 @@ module NewUser def update_brouillon @dossier = dossier_with_champs - errors = PiecesJustificativesService.upload!(@dossier, current_user, params) - - if champs_params[:dossier] && !@dossier.update(champs_params[:dossier]) - errors += @dossier.errors.full_messages - end - - if !save_draft? - errors += @dossier.champs.select(&:mandatory_and_blank?) - .map { |c| "Le champ #{c.libelle.truncate(200)} doit être rempli." } - errors += PiecesJustificativesService.missing_pj_error_messages(@dossier) - end + errors = update_dossier_and_compute_errors if errors.present? flash.now.alert = errors @@ -128,15 +118,7 @@ module NewUser def update @dossier = dossier_with_champs - errors = PiecesJustificativesService.upload!(@dossier, current_user, params) - - if champs_params[:dossier] && !@dossier.update(champs_params[:dossier]) - errors += @dossier.errors.full_messages - end - - errors += @dossier.champs.select(&:mandatory_and_blank?) - .map { |c| "Le champ #{c.libelle.truncate(200)} doit être rempli." } - errors += PiecesJustificativesService.missing_pj_error_messages(@dossier) + errors = update_dossier_and_compute_errors if errors.present? flash.now.alert = errors @@ -240,6 +222,22 @@ module NewUser Dossier.with_champs.find(params[:id]) end + def update_dossier_and_compute_errors + errors = PiecesJustificativesService.upload!(@dossier, current_user, params) + + if champs_params[:dossier] && !@dossier.update(champs_params[:dossier]) + errors += @dossier.errors.full_messages + end + + if !save_draft? + errors += @dossier.champs.select(&:mandatory_and_blank?) + .map { |c| "Le champ #{c.libelle.truncate(200)} doit être rempli." } + errors += PiecesJustificativesService.missing_pj_error_messages(@dossier) + end + + errors + end + def ensure_ownership! if !current_user.owns?(dossier) forbidden! From 095166e38fda0649acb58bb612debe99330a8062 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 7 Sep 2018 10:31:39 +0200 Subject: [PATCH 10/24] Add original states restoration after some tests To avoid failing tests --- spec/controllers/new_user/dossiers_controller_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index de694100a..88b0ccbe7 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -585,6 +585,10 @@ describe NewUser::DossiersController, type: :controller do sign_in(user) end + after do + Flipflop::FeatureSet.current.test!.switch!(:new_dossier_details, false) + end + subject! { get(:show, params: { id: dossier.id }) } context 'when the dossier is a brouillon' do @@ -616,6 +620,10 @@ describe NewUser::DossiersController, type: :controller do sign_in(user) end + after do + Flipflop::FeatureSet.current.test!.switch!(:new_dossier_details, false) + end + subject! { get(:demande, params: { id: dossier.id }) } it { expect(assigns(:dossier)).to eq(dossier) } From 59e809f02965651130aa6584e9b7eb230d2e1319 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 14:02:02 +0200 Subject: [PATCH 11/24] =?UTF-8?q?active=5Ftab=5Fitem=20=E2=86=92=20dynamic?= =?UTF-8?q?=5Ftab=5Fitem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/tabs_helper.rb | 2 +- app/views/new_gestionnaire/avis/_header.html.haml | 6 +++--- app/views/new_gestionnaire/dossiers/_header.html.haml | 10 +++++----- app/views/new_user/dossiers/show/_header.html.haml | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/helpers/tabs_helper.rb b/app/helpers/tabs_helper.rb index d85a5e197..de31d48c9 100644 --- a/app/helpers/tabs_helper.rb +++ b/app/helpers/tabs_helper.rb @@ -9,7 +9,7 @@ module TabsHelper } end - def active_tab_item(label, url, badge: nil, notification: false) + def dynamic_tab_item(label, url, badge: nil, notification: false) tab_item(label, url, active: current_page?(url), badge: badge, notification: notification) end end diff --git a/app/views/new_gestionnaire/avis/_header.html.haml b/app/views/new_gestionnaire/avis/_header.html.haml index fb0ed039b..a44f30158 100644 --- a/app/views/new_gestionnaire/avis/_header.html.haml +++ b/app/views/new_gestionnaire/avis/_header.html.haml @@ -5,6 +5,6 @@ %li= "#{dossier.procedure.libelle}, dossier nº #{dossier.id}" %ul.tabs - = active_tab_item('Demande', gestionnaire_avis_path(avis)) - = active_tab_item('Avis', instruction_gestionnaire_avis_path(avis), notification: avis.answer.blank?) - = active_tab_item('Messagerie', messagerie_gestionnaire_avis_path(avis)) + = dynamic_tab_item('Demande', gestionnaire_avis_path(avis)) + = dynamic_tab_item('Avis', instruction_gestionnaire_avis_path(avis), notification: avis.answer.blank?) + = dynamic_tab_item('Messagerie', messagerie_gestionnaire_avis_path(avis)) diff --git a/app/views/new_gestionnaire/dossiers/_header.html.haml b/app/views/new_gestionnaire/dossiers/_header.html.haml index 2b568b77c..8526eda4d 100644 --- a/app/views/new_gestionnaire/dossiers/_header.html.haml +++ b/app/views/new_gestionnaire/dossiers/_header.html.haml @@ -21,23 +21,23 @@ %ul.tabs - notifications_summary = current_gestionnaire.notifications_for_dossier(dossier) - = active_tab_item('Demande', + = dynamic_tab_item('Demande', gestionnaire_dossier_path(dossier.procedure, dossier), notification: notifications_summary[:demande]) - = active_tab_item('Annotations privées', + = dynamic_tab_item('Annotations privées', annotations_privees_gestionnaire_dossier_path(dossier.procedure, dossier), notification: notifications_summary[:annotations_privees]) - = active_tab_item('Avis externes', + = dynamic_tab_item('Avis externes', avis_gestionnaire_dossier_path(dossier.procedure, dossier), notification: notifications_summary[:avis]) - = active_tab_item('Messagerie', + = dynamic_tab_item('Messagerie', messagerie_gestionnaire_dossier_path(dossier.procedure, dossier), notification: notifications_summary[:messagerie]) - = active_tab_item('Personnes impliquées', + = dynamic_tab_item('Personnes impliquées', personnes_impliquees_gestionnaire_dossier_path(dossier.procedure, dossier)) .container diff --git a/app/views/new_user/dossiers/show/_header.html.haml b/app/views/new_user/dossiers/show/_header.html.haml index c5144e0be..c71437eac 100644 --- a/app/views/new_user/dossiers/show/_header.html.haml +++ b/app/views/new_user/dossiers/show/_header.html.haml @@ -8,6 +8,6 @@ %h2 Dossier nº #{dossier.id} %ul.tabs - = active_tab_item('Résumé', dossier_path(dossier)) - = active_tab_item('Demande', demande_dossier_path(dossier)) - = active_tab_item('Messagerie', messagerie_dossier_path(dossier)) + = dynamic_tab_item('Résumé', dossier_path(dossier)) + = dynamic_tab_item('Demande', demande_dossier_path(dossier)) + = dynamic_tab_item('Messagerie', messagerie_dossier_path(dossier)) From ee4d71a3f491db2697d41fc04bf3ec5de213ff0c Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 7 Sep 2018 11:28:32 +0200 Subject: [PATCH 12/24] dynamic_tab_item now handles url arrays --- app/helpers/tabs_helper.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/helpers/tabs_helper.rb b/app/helpers/tabs_helper.rb index de31d48c9..6080aa2ad 100644 --- a/app/helpers/tabs_helper.rb +++ b/app/helpers/tabs_helper.rb @@ -9,7 +9,11 @@ module TabsHelper } end - def dynamic_tab_item(label, url, badge: nil, notification: false) - tab_item(label, url, active: current_page?(url), badge: badge, notification: notification) + def dynamic_tab_item(label, url_or_urls, badge: nil, notification: false) + urls = [url_or_urls].flatten + url = urls.first + active = urls.any? { |u| current_page?(u) } + + tab_item(label, url, active: active, badge: badge, notification: notification) end end From 038cabfae39f28f7ec2cf2468a288741c5d9e046 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 15:26:14 +0200 Subject: [PATCH 13/24] =?UTF-8?q?The=20Demande=20tab=20should=20be=20activ?= =?UTF-8?q?e=20when=20we=E2=80=99re=20editing=20the=20demande?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/new_user/dossiers/show/_header.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/new_user/dossiers/show/_header.html.haml b/app/views/new_user/dossiers/show/_header.html.haml index c71437eac..6fd9cc867 100644 --- a/app/views/new_user/dossiers/show/_header.html.haml +++ b/app/views/new_user/dossiers/show/_header.html.haml @@ -9,5 +9,5 @@ %ul.tabs = dynamic_tab_item('Résumé', dossier_path(dossier)) - = dynamic_tab_item('Demande', demande_dossier_path(dossier)) + = dynamic_tab_item('Demande', [demande_dossier_path(dossier), modifier_dossier_path(dossier)]) = dynamic_tab_item('Messagerie', messagerie_dossier_path(dossier)) From 9c6a66ae75420c5ada600dea80c3f7c97825a975 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 15:36:50 +0200 Subject: [PATCH 14/24] Change the route for DossierController#modifier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we submit the form, and there’s an error, the URL would be `/dossiers/:id`, therefore `dossier_path(dossier)`, so the Résumé tab would be active, not the messagerie tab. This change prevents this behaviour. --- app/views/shared/dossiers/_edit.html.haml | 2 +- config/routes.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index 03282ecfc..f298f5d89 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -6,7 +6,7 @@ - elsif dossier.brouillon? - form_options = { url: brouillon_dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true } } - else - - form_options = { url: dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true } } + - form_options = { url: modifier_dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true } } = form_for dossier, form_options do |f| diff --git a/config/routes.rb b/config/routes.rb index 9d49f7ed8..cb8855c75 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -271,14 +271,14 @@ Rails.application.routes.draw do # scope module: 'new_user' do - resources :dossiers, only: [:index, :show, :update] do + resources :dossiers, only: [:index, :show] do member do get 'identite' patch 'update_identite' get 'brouillon' patch 'brouillon', to: 'dossiers#update_brouillon' get 'modifier', to: 'dossiers#modifier' - patch ':id', to: 'dossiers#update' + patch 'modifier', to: 'dossiers#update' get 'merci' get 'demande' get 'messagerie' From 6cd88db8537a06fc051c423a8c93197a9f6419fd Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 4 Sep 2018 18:24:15 +0200 Subject: [PATCH 15/24] messagerie: make "Send" button primary --- app/views/shared/dossiers/messages/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/dossiers/messages/_form.html.haml b/app/views/shared/dossiers/messages/_form.html.haml index aff5b4500..db9e9d27b 100644 --- a/app/views/shared/dossiers/messages/_form.html.haml +++ b/app/views/shared/dossiers/messages/_form.html.haml @@ -8,4 +8,4 @@ (taille max : 20 Mo) .send-wrapper - = f.submit 'Envoyer', class: 'button send', data: { disable: true } + = f.submit 'Envoyer', class: 'button primary send', data: { disable: true } From a6aac28b66cdd68e46290a876f3e17f0dfc12a87 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 4 Sep 2018 18:25:55 +0200 Subject: [PATCH 16/24] messagerie: move "Send" button to the right --- app/views/shared/dossiers/messages/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/dossiers/messages/_form.html.haml b/app/views/shared/dossiers/messages/_form.html.haml index db9e9d27b..6cc26c2bf 100644 --- a/app/views/shared/dossiers/messages/_form.html.haml +++ b/app/views/shared/dossiers/messages/_form.html.haml @@ -7,5 +7,5 @@ .notice (taille max : 20 Mo) - .send-wrapper + %div = f.submit 'Envoyer', class: 'button primary send', data: { disable: true } From 21dc9f810921a95f5139ed8e7bb189545ae60bea Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 4 Sep 2018 18:27:34 +0200 Subject: [PATCH 17/24] messagerie: improve success message --- app/controllers/new_user/dossiers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index d048f15ef..d602695f5 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -144,7 +144,7 @@ module NewUser @commentaire = CommentaireService.create(current_user, dossier, commentaire_params) if @commentaire.save - flash.notice = "Message envoyé" + flash.notice = "Votre message a bien été envoyé à l’instructeur en charge de votre dossier." redirect_to messagerie_dossier_path(dossier) else flash.now.alert = @commentaire.errors.full_messages From fe13871380c58652addd6c9b80a25e0d5a5c42c5 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 4 Sep 2018 18:30:31 +0200 Subject: [PATCH 18/24] messagerie: add explanation for usagers --- app/assets/stylesheets/new_design/dossier_show.scss | 4 ++++ app/views/new_user/dossiers/messagerie.html.haml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/assets/stylesheets/new_design/dossier_show.scss b/app/assets/stylesheets/new_design/dossier_show.scss index c9c92a581..def3e15d3 100644 --- a/app/assets/stylesheets/new_design/dossier_show.scss +++ b/app/assets/stylesheets/new_design/dossier_show.scss @@ -34,4 +34,8 @@ .button.edit-form { float: right; } + + .messagerie-explanation { + margin-bottom: $default-padding * 2; + } } diff --git a/app/views/new_user/dossiers/messagerie.html.haml b/app/views/new_user/dossiers/messagerie.html.haml index 26d4fb8b6..964b2f663 100644 --- a/app/views/new_user/dossiers/messagerie.html.haml +++ b/app/views/new_user/dossiers/messagerie.html.haml @@ -3,4 +3,8 @@ #dossier-show = render partial: 'new_user/dossiers/show/header', locals: { dossier: @dossier } + .container + %p.messagerie-explanation + La messagerie vous permet de contacter l’instructeur en charge de votre dossier. + = render partial: "shared/dossiers/messagerie", locals: { dossier: @dossier, user_email: current_user.email, messagerie_seen_at: nil, new_commentaire: @commentaire, form_url: commentaire_dossier_path(@dossier) } From 211674435e767df4644bd0993c85e9c35a1df3ec Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 6 Sep 2018 13:04:43 +0000 Subject: [PATCH 19/24] messagerie: better format message dates --- app/helpers/commentaire_helper.rb | 6 ++++ .../dossiers/messages/_message.html.haml | 2 +- config/locales/time_format.en.rb | 10 +++++++ config/locales/time_format.fr.rb | 10 +++++++ spec/helpers/commentaire_helper_spec.rb | 30 +++++++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 config/locales/time_format.en.rb create mode 100644 config/locales/time_format.fr.rb diff --git a/app/helpers/commentaire_helper.rb b/app/helpers/commentaire_helper.rb index 467a08fa8..a39c9e736 100644 --- a/app/helpers/commentaire_helper.rb +++ b/app/helpers/commentaire_helper.rb @@ -4,4 +4,10 @@ module CommentaireHelper "from-me" end end + + def commentaire_date(commentaire) + is_current_year = (commentaire.created_at.year == Date.current.year) + template = is_current_year ? :message_date : :message_date_with_year + I18n.l(commentaire.created_at.localtime, format: template) + end end diff --git a/app/views/shared/dossiers/messages/_message.html.haml b/app/views/shared/dossiers/messages/_message.html.haml index f4f3ceeac..218c0870b 100644 --- a/app/views/shared/dossiers/messages/_message.html.haml +++ b/app/views/shared/dossiers/messages/_message.html.haml @@ -7,7 +7,7 @@ - if ![user_email, commentaire.dossier.user.email, OLD_CONTACT_EMAIL, CONTACT_EMAIL].include?(commentaire.email) %span.guest Invité %span.date{ class: highlight_if_unseen_class(messagerie_seen_at, commentaire.created_at) } - = I18n.l(commentaire.created_at.localtime, format: '%d/%m/%Y à %H:%M ') + = commentaire_date(commentaire) .rich-text= sanitize(commentaire.body) - if commentaire.piece_justificative diff --git a/config/locales/time_format.en.rb b/config/locales/time_format.en.rb new file mode 100644 index 000000000..f2605dd56 --- /dev/null +++ b/config/locales/time_format.en.rb @@ -0,0 +1,10 @@ +{ + :en => { + :time => { + :formats => { + :message_date => lambda { |time, _| "%B #{time.day.ordinalize} at %H:%M" }, + :message_date_with_year => lambda { |time, _| "%B #{time.day.ordinalize} %Y at %H:%M" } + } + } + } +} diff --git a/config/locales/time_format.fr.rb b/config/locales/time_format.fr.rb new file mode 100644 index 000000000..708184241 --- /dev/null +++ b/config/locales/time_format.fr.rb @@ -0,0 +1,10 @@ +{ + :fr => { + :time => { + :formats => { + :message_date => lambda { |time, _| "le #{time.day == 1 ? '1er' : time.day} %B à %H h %M" }, + :message_date_with_year => lambda { |time, _| "le #{time.day == 1 ? '1er' : time.day} %B %Y à %H h %M" } + } + } + } +} diff --git a/spec/helpers/commentaire_helper_spec.rb b/spec/helpers/commentaire_helper_spec.rb index 8f9813664..f96f03d99 100644 --- a/spec/helpers/commentaire_helper_spec.rb +++ b/spec/helpers/commentaire_helper_spec.rb @@ -18,4 +18,34 @@ RSpec.describe CommentaireHelper, type: :helper do it { is_expected.to eq nil } end end + + describe '.commentaire_date' do + let(:present_date) { Time.local(2018, 9, 2, 10, 5, 0) } + let(:creation_date) { present_date } + let(:commentaire) do + Timecop.freeze(creation_date) { create(:commentaire, email: "michel@pref.fr") } + end + + subject do + Timecop.freeze(present_date) { commentaire_date(commentaire) } + end + + it 'doesn’t include the creation year' do + expect(subject).to eq 'le 2 septembre à 10 h 05' + end + + context 'when displaying a commentaire created on a previous year' do + let(:creation_date) { present_date.prev_year } + it 'includes the creation year' do + expect(subject).to eq 'le 2 septembre 2017 à 10 h 05' + end + end + + context 'when formatting the first day of the month' do + let(:present_date) { Time.local(2018, 9, 1, 10, 5, 0) } + it 'includes the ordinal' do + expect(subject).to eq 'le 1er septembre à 10 h 05' + end + end + end end From 353ab812fca0de89b45dd824f2621c11a69c7f38 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 6 Sep 2018 16:08:24 +0200 Subject: [PATCH 20/24] =?UTF-8?q?messagerie:=20fix=20'Invit=C3=A9'=20label?= =?UTF-8?q?=20in=20message=20sender?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/commentaire_helper.rb | 4 ++++ .../shared/dossiers/messages/_message.html.haml | 2 +- spec/helpers/commentaire_helper_spec.rb | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/helpers/commentaire_helper.rb b/app/helpers/commentaire_helper.rb index a39c9e736..f22163a07 100644 --- a/app/helpers/commentaire_helper.rb +++ b/app/helpers/commentaire_helper.rb @@ -5,6 +5,10 @@ module CommentaireHelper end end + def commentaire_is_from_guest(commentaire) + commentaire.dossier.invites.map(&:email).include?(commentaire.email) + end + def commentaire_date(commentaire) is_current_year = (commentaire.created_at.year == Date.current.year) template = is_current_year ? :message_date : :message_date_with_year diff --git a/app/views/shared/dossiers/messages/_message.html.haml b/app/views/shared/dossiers/messages/_message.html.haml index 218c0870b..b49e88abb 100644 --- a/app/views/shared/dossiers/messages/_message.html.haml +++ b/app/views/shared/dossiers/messages/_message.html.haml @@ -4,7 +4,7 @@ %h2 %span.mail = render partial: 'shared/dossiers/messages/message_issuer', locals: { commentaire: commentaire, user_email: user_email } - - if ![user_email, commentaire.dossier.user.email, OLD_CONTACT_EMAIL, CONTACT_EMAIL].include?(commentaire.email) + - if commentaire_is_from_guest(commentaire) %span.guest Invité %span.date{ class: highlight_if_unseen_class(messagerie_seen_at, commentaire.created_at) } = commentaire_date(commentaire) diff --git a/spec/helpers/commentaire_helper_spec.rb b/spec/helpers/commentaire_helper_spec.rb index f96f03d99..9f0bd998b 100644 --- a/spec/helpers/commentaire_helper_spec.rb +++ b/spec/helpers/commentaire_helper_spec.rb @@ -19,6 +19,23 @@ RSpec.describe CommentaireHelper, type: :helper do end end + describe '.commentaire_is_from_guest' do + let(:dossier) { create(:dossier) } + let!(:guest) { create(:invite_user, dossier: dossier) } + + subject { commentaire_is_from_guest(commentaire) } + + context 'when the commentaire sender is not a guest' do + let(:commentaire) { create(:commentaire, dossier: dossier, email: "michel@pref.fr") } + it { is_expected.to be false } + end + + context 'when the commentaire sender is a guest on this dossier' do + let(:commentaire) { create(:commentaire, dossier: dossier, email: guest.email) } + it { is_expected.to be true } + end + end + describe '.commentaire_date' do let(:present_date) { Time.local(2018, 9, 2, 10, 5, 0) } let(:creation_date) { present_date } From 1da0321c26f82596bd6b6d7d0c74873422bb5b58 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 6 Sep 2018 16:11:36 +0200 Subject: [PATCH 21/24] messagerie: never display full sender email See #2307 --- app/views/shared/dossiers/messages/_message_issuer.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/dossiers/messages/_message_issuer.html.haml b/app/views/shared/dossiers/messages/_message_issuer.html.haml index 5f4eee4f2..dc4f7bce0 100644 --- a/app/views/shared/dossiers/messages/_message_issuer.html.haml +++ b/app/views/shared/dossiers/messages/_message_issuer.html.haml @@ -5,4 +5,4 @@ - when CONTACT_EMAIL Email automatique - else - = commentaire.email + = commentaire.sender From 23170f54c09426e409c5d37cd47d7b728117ba0a Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 11:20:16 +0100 Subject: [PATCH 22/24] Instructeur should see published drafts --- app/models/gestionnaire.rb | 6 +++++- app/models/procedure.rb | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 033f3df54..97dc3c65f 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -18,7 +18,11 @@ class Gestionnaire < ApplicationRecord has_many :dossiers_from_avis, through: :avis, source: :dossier def visible_procedures - procedures.publiees_ou_archivees + if Flipflop.publish_draft? + procedures.avec_lien + else + procedures.publiees_ou_archivees + end end def can_view_dossier?(dossier_id) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index cb82b7869..d508e64fa 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -46,6 +46,7 @@ class Procedure < ApplicationRecord scope :by_libelle, -> { order(libelle: :asc) } scope :created_during, -> (range) { where(created_at: range) } scope :cloned_from_library, -> { where(cloned_from_library: true) } + scope :avec_lien, -> { joins(:procedure_path) } validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :description, presence: true, allow_blank: false, allow_nil: false From 23017f4b17a32fd893a84fd8fbc1445a5bd89a23 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 11:21:07 +0100 Subject: [PATCH 23/24] Show better lien information on procedure page --- app/views/admin/procedures/show.html.haml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index 331e65183..cb4492a9c 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -49,14 +49,27 @@ %div %h3 Lien démarche - %div{ style: 'margin-left: 3%;' } + %div{ style: 'margin-top: 30px;' } - if @procedure.archivee? - %b + .alert.alert-info Cette démarche est archivée et n’est donc pas accessible par le public. - - elsif @procedure.brouillon_avec_lien? || @procedure.publiee? + - elsif @procedure.publiee? = link_to procedure_lien(@procedure), sanitize_url(procedure_lien(@procedure)), target: :blank + - elsif @procedure.brouillon_avec_lien? + - if @procedure.gestionnaires.present? && @procedure.service.present? + = link_to procedure_lien(@procedure), sanitize_url(procedure_lien(@procedure)), target: :blank + - else + .alert.alert-info + Pour pouvoir tester cette démarche, vous devez d’abord lui affecter + - if @procedure.gestionnaires.empty? + = link_to("des instructeurs", admin_procedure_instructeurs_path(@procedure)) + - if @procedure.gestionnaires.empty? && @procedure.service.nil? + et + - if @procedure.service.nil? + = link_to("un service", services_path(procedure_id: @procedure)) + \. - else - %b + .alert.alert-info Cette démarche n’a pas encore de lien, et n’est donc pas accessible par le public. %br From 5dadaa1a8d583bca27c51e46e7fe2a6351bb4299 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 11:21:50 +0100 Subject: [PATCH 24/24] Show brouillon tag on procedure names in user and instructeur lists --- app/views/new_user/dossiers/index.html.haml | 2 +- app/views/shared/dossiers/_header.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index f824b4365..e37d78286 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -39,7 +39,7 @@ = dossier.id %td = link_to(url_for_dossier(dossier), class: 'cell-link') do - = dossier.procedure.libelle + = procedure_libelle(dossier.procedure) %td.status-col = link_to(url_for_dossier(dossier), class: 'cell-link') do = render partial: 'shared/dossiers/status_badge', locals: { dossier: dossier } diff --git a/app/views/shared/dossiers/_header.html.haml b/app/views/shared/dossiers/_header.html.haml index d73c8c377..edf4c5b92 100644 --- a/app/views/shared/dossiers/_header.html.haml +++ b/app/views/shared/dossiers/_header.html.haml @@ -1,6 +1,6 @@ %h1 %span.icon.folder - = dossier.procedure.libelle + = procedure_libelle(dossier.procedure) .dossier-form-actions - if current_user.owns?(dossier)