Merge pull request #3293 from betagouv/page-de-garde

Ajout d'une page de garde pour les démarches
This commit is contained in:
Pierre de La Morinerie 2019-01-21 14:57:52 +01:00 committed by GitHub
commit 3cc423283c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 312 additions and 67 deletions

View file

@ -0,0 +1,11 @@
@import "constants";
.commencer {
.button:first-of-type {
margin-top: 4 * $default-spacer;
}
.button {
margin-bottom: 2 * $default-spacer;
}
}

View file

@ -5,6 +5,10 @@
h1 { h1 {
text-align: center; text-align: center;
margin-bottom: 20px; margin-bottom: 20px;
@media (max-width: $two-columns-breakpoint) {
font-size: 28px;
}
} }
hr { hr {

View file

@ -5,8 +5,8 @@ module ProcedureContextConcern
include Devise::StoreLocationExtension include Devise::StoreLocationExtension
def restore_procedure_context def restore_procedure_context
if stored_procedure_id.present? if has_stored_procedure_path?
@procedure = Procedure.publiees.find_by(id: stored_procedure_id) @procedure = find_procedure_in_context
if @procedure.blank? if @procedure.blank?
invalid_procedure_context invalid_procedure_context
@ -16,11 +16,18 @@ module ProcedureContextConcern
private private
def stored_procedure_id def has_stored_procedure_path?
stored_location = get_stored_location_for(:user) get_stored_location_for(:user)&.start_with?('/commencer/')
end
if stored_location.present? && stored_location.include?('procedure_id=') def find_procedure_in_context
stored_location.split('procedure_id=').second uri = URI(get_stored_location_for(:user))
path_components = uri.path.split('/')
if uri.path.start_with?('/commencer/test/')
Procedure.brouillon.find_by(path: path_components[3])
elsif uri.path.start_with?('/commencer/')
Procedure.publiee.find_by(path: path_components[2])
else else
nil nil
end end

View file

@ -1,25 +1,44 @@
module NewUser module NewUser
class CommencerController < ApplicationController class CommencerController < ApplicationController
def commencer_test layout 'procedure_context'
procedure = Procedure.brouillons.find_by(path: params[:path])
if procedure.present?
redirect_to new_dossier_path(procedure_id: procedure.id, brouillon: true)
else
flash.alert = "La démarche est inconnue."
redirect_to root_path
end
end
def commencer def commencer
procedure = Procedure.publiees.find_by(path: params[:path]) @procedure = Procedure.publiees.find_by(path: params[:path])
if procedure.present? if @procedure.blank?
redirect_to new_dossier_path(procedure_id: procedure.id)
else
flash.alert = "La démarche est inconnue, ou la création de nouveaux dossiers pour cette démarche est terminée." flash.alert = "La démarche est inconnue, ou la création de nouveaux dossiers pour cette démarche est terminée."
redirect_to root_path return redirect_to root_path
end end
render 'commencer/show'
end
def commencer_test
@procedure = Procedure.brouillons.find_by(path: params[:path])
if @procedure.blank?
flash.alert = "La démarche est inconnue, ou cette démarche nest maintenant plus en test."
return redirect_to root_path
end
render 'commencer/show'
end
def sign_in
store_user_location!
redirect_to new_user_session_path
end
def sign_up
store_user_location!
redirect_to new_user_registration_path
end
private
def store_user_location!
procedure = Procedure.find_by(path: params[:path])
store_location_for(:user, commencer_path(path: procedure.path))
end end
end end
end end

View file

@ -23,6 +23,14 @@ module DossierHelper
end end
end end
def url_for_new_dossier(procedure)
if procedure.brouillon?
new_dossier_url(procedure_id: procedure.id, brouillon: true)
else
new_dossier_url(procedure_id: procedure.id)
end
end
def dossier_submission_is_closed?(dossier) def dossier_submission_is_closed?(dossier)
dossier.brouillon? && dossier.procedure.archivee? dossier.brouillon? && dossier.procedure.archivee?
end end

View file

@ -0,0 +1,30 @@
- content_for(:title, @procedure.libelle)
.commencer.form
- if !user_signed_in?
%h1 Commencer la démarche
= link_to 'Créer un compte demarches-simplifiees.fr', commencer_sign_up_path(path: @procedure.path), class: ['button large expand primary']
= link_to 'Jai déjà un compte', commencer_sign_in_path(path: @procedure.path), class: ['button large expand']
- else
- dossiers = current_user.dossiers.where(procedure: @procedure)
- drafts = dossiers.merge(Dossier.state_brouillon)
- not_drafts = dossiers.merge(Dossier.state_not_brouillon)
- if dossiers.count == 0
= link_to 'Commencer la démarche', url_for_new_dossier(@procedure), class: ['button large expand primary']
- elsif drafts.count == 1 && not_drafts.count == 0
%h1 Vous avez déjà commencé à remplir un dossier
= link_to 'Continuer à remplir mon dossier', brouillon_dossier_path(drafts.first), class: ['button large expand primary']
= link_to 'Commencer un nouveau dossier', url_for_new_dossier(@procedure), class: ['button large expand']
- elsif not_drafts.count == 1
%h1 Vous avez déjà déposé un dossier
= link_to 'Voir mon dossier', dossier_path(not_drafts.first), class: ['button large expand primary']
= link_to 'Commencer un nouveau dossier', url_for_new_dossier(@procedure), class: ['button large expand']
- else
%h1 Vous avez déjà des dossiers pour cette démarche
= link_to 'Voir mes dossiers en cours', dossiers_path, class: ['button large expand primary']
= link_to 'Commencer un nouveau dossier', url_for_new_dossier(@procedure), class: ['button large expand']

View file

@ -265,6 +265,8 @@ Rails.application.routes.draw do
namespace :commencer do namespace :commencer do
get '/test/:path', action: 'commencer_test', as: :test get '/test/:path', action: 'commencer_test', as: :test
get '/:path', action: 'commencer' get '/:path', action: 'commencer'
get '/:path/sign_in', action: 'sign_in', as: :sign_in
get '/:path/sign_up', action: 'sign_up', as: :sign_up
end end
resources :dossiers, only: [:index, :show, :new] do resources :dossiers, only: [:index, :show, :new] do

View file

@ -24,7 +24,7 @@ RSpec.describe ProcedureContextConcern, type: :controller do
end end
end end
context 'when no procedure_id is present in the stored return location' do context 'when the stored return location is not a procedure URL' do
before do before do
controller.store_location_for(:user, dossiers_path) controller.store_location_for(:user, dossiers_path)
end end
@ -36,9 +36,9 @@ RSpec.describe ProcedureContextConcern, type: :controller do
end end
context 'when a procedure location has been stored' do context 'when a procedure location has been stored' do
context 'when the stored procedure does not exist' do context 'when the procedure path does not exist' do
before do before do
controller.store_location_for(:user, new_dossier_path(procedure_id: '0')) controller.store_location_for(:user, commencer_path(path: 'non-existent-path'))
end end
it 'redirects with an error' do it 'redirects with an error' do
@ -47,11 +47,11 @@ RSpec.describe ProcedureContextConcern, type: :controller do
end end
end end
context 'when the stored procedure is not published' do context 'when the procedure path exists, but not with the same publication status' do
let(:procedure) { create :procedure } let(:published_procedure) { create :procedure, :published }
before do before do
controller.store_location_for(:user, new_dossier_path(procedure_id: procedure.id)) controller.store_location_for(:user, commencer_test_path(path: published_procedure.path))
end end
it 'redirects with an error' do it 'redirects with an error' do
@ -60,16 +60,29 @@ RSpec.describe ProcedureContextConcern, type: :controller do
end end
end end
context 'when the stored procedure exists' do context 'when the stored procedure is in test' do
let(:procedure) { create :procedure, :published } let(:test_procedure) { create :procedure, :with_path }
before do before do
controller.store_location_for(:user, new_dossier_path(procedure_id: procedure.id)) controller.store_location_for(:user, commencer_test_path(path: test_procedure.path))
end end
it 'succeeds, and assigns the procedure on the controller' do it 'succeeds, and assigns the procedure on the controller' do
expect(subject.status).to eq 200 expect(subject.status).to eq 200
expect(assigns(:procedure)).to eq procedure expect(assigns(:procedure)).to eq test_procedure
end
end
context 'when the stored procedure is published' do
let(:published_procedure) { create :procedure, :published }
before do
controller.store_location_for(:user, commencer_path(path: published_procedure.path))
end
it 'succeeds, and assigns the procedure on the controller' do
expect(subject.status).to eq 200
expect(assigns(:procedure)).to eq published_procedure
end end
end end
end end

View file

@ -2,39 +2,88 @@ require 'spec_helper'
describe NewUser::CommencerController, type: :controller do describe NewUser::CommencerController, type: :controller do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published) } let(:published_procedure) { create(:procedure, :published) }
let(:procedure_id) { procedure.id } let(:draft_procedure) { create(:procedure, :with_path) }
describe 'GET #commencer' do describe '#commencer' do
subject { get :commencer, params: { path: path } } subject { get :commencer, params: { path: path } }
let(:path) { procedure.path }
it { expect(subject.status).to eq 302 } context 'when the path is for a published procedure' do
it { expect(subject).to redirect_to new_dossier_path(procedure_id: procedure.id) } let(:path) { published_procedure.path }
context 'when procedure path does not exist' do it 'renders the view' do
expect(subject.status).to eq(200)
expect(subject).to render_template('show')
expect(assigns(:procedure)).to eq published_procedure
end
end
context 'when the path is for a non-published procedure' do
let(:path) { draft_procedure.path }
it 'redirects with an error message' do
expect(subject).to redirect_to(root_path)
end
end
context 'when the path does not exist' do
let(:path) { 'hello' } let(:path) { 'hello' }
it { expect(subject).to redirect_to(root_path) } it 'redirects with an error message' do
expect(subject).to redirect_to(root_path)
end
end end
end end
describe 'GET #commencer_test' do describe '#commencer_test' do
before do subject { get :commencer_test, params: { path: path } }
Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true)
context 'when the path is for a draft procedure' do
let(:path) { draft_procedure.path }
it 'renders the view' do
expect(subject.status).to eq(200)
expect(subject).to render_template('show')
expect(assigns(:procedure)).to eq draft_procedure
end
end end
subject { get :commencer_test, params: { path: path } } context 'when the path is for a published procedure' do
let(:procedure) { create(:procedure, :with_path) } let(:path) { published_procedure.path }
let(:path) { procedure.path }
it { expect(subject.status).to eq 302 } it 'redirects with an error message' do
it { expect(subject).to redirect_to new_dossier_path(procedure_id: procedure.id, brouillon: true) } expect(subject).to redirect_to(root_path)
end
end
context 'when procedure path does not exist' do context 'when the path does not exist' do
let(:path) { 'hello' } let(:path) { 'hello' }
it { expect(subject).to redirect_to(root_path) } it 'redirects with an error message' do
expect(subject).to redirect_to(root_path)
end
end end
end end
describe '#sign_in' do
subject { get :sign_in, params: { path: published_procedure.path } }
it 'set the path to return after sign-in to the dossier creation path' do
subject
expect(controller.stored_location_for(:user)).to eq(commencer_path(path: published_procedure.path))
end
it { expect(subject).to redirect_to(new_user_session_path) }
end
describe '#sign_up' do
subject { get :sign_up, params: { path: published_procedure.path } }
it 'set the path to return after sign-up to the dossier creation path' do
subject
expect(controller.stored_location_for(:user)).to eq(commencer_path(path: published_procedure.path))
end
it { expect(subject).to redirect_to(new_user_registration_path) }
end
end end

View file

@ -27,7 +27,7 @@ describe Users::RegistrationsController, type: :controller do
let(:procedure) { create :procedure, :published } let(:procedure) { create :procedure, :published }
before do before do
controller.store_location_for(:user, new_dossier_path(procedure_id: procedure.id)) controller.store_location_for(:user, commencer_path(path: procedure.path))
end end
it 'makes the saved procedure available' do it 'makes the saved procedure available' do

View file

@ -179,7 +179,7 @@ describe Users::SessionsController, type: :controller do
let(:procedure) { create :procedure, :published } let(:procedure) { create :procedure, :published }
before do before do
controller.store_location_for(:user, new_dossier_path(procedure_id: procedure.id)) controller.store_location_for(:user, commencer_path(path: procedure.path))
end end
it 'makes the saved procedure available' do it 'makes the saved procedure available' do

View file

@ -14,10 +14,16 @@ feature 'The gestionnaire part' do
scenario 'a gestionnaire can fill a dossier' do scenario 'a gestionnaire can fill a dossier' do
visit commencer_path(path: procedure.path) visit commencer_path(path: procedure.path)
click_on 'Jai déjà un compte'
expect(page).to have_current_path new_user_session_path expect(page).to have_current_path new_user_session_path
sign_in_with(gestionnaire.email, password, true) sign_in_with(gestionnaire.email, password, true)
expect(page).to have_current_path(commencer_path(path: procedure.path))
click_on 'Commencer la démarche'
expect(page).to have_content('Identifier votre établissement')
expect(page).to have_current_path(siret_dossier_path(procedure.reload.dossiers.last))
expect(page).to have_content(procedure.libelle) expect(page).to have_content(procedure.libelle)
end end
end end

View file

@ -130,11 +130,15 @@ feature 'The user' do
def log_in(email, password, procedure) def log_in(email, password, procedure)
visit "/commencer/#{procedure.path}" visit "/commencer/#{procedure.path}"
expect(page).to have_current_path(new_user_session_path) click_on 'Jai déjà un compte'
fill_in 'user_email', with: email expect(page).to have_current_path(new_user_session_path)
fill_in 'user_password', with: password sign_in_with(email, password)
click_on 'Se connecter'
expect(page).to have_current_path("/commencer/#{procedure.path}")
click_on 'Commencer la démarche'
expect(page).to have_content("Données d'identité")
expect(page).to have_current_path(identite_dossier_path(user_dossier)) expect(page).to have_current_path(identite_dossier_path(user_dossier))
end end

View file

@ -17,10 +17,10 @@ feature 'Creating a new dossier:' do
before do before do
visit commencer_path(path: procedure.path) visit commencer_path(path: procedure.path)
click_on 'Commencer la démarche'
expect(page).to have_content(procedure.libelle) expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last)
expect(page).to have_content(procedure.description) expect_page_to_have_procedure_description(procedure)
expect(page).to have_content(procedure.service.email)
fill_in 'individual_nom', with: 'Nom' fill_in 'individual_nom', with: 'Nom'
fill_in 'individual_prenom', with: 'Prenom' fill_in 'individual_prenom', with: 'Prenom'
@ -77,13 +77,12 @@ feature 'Creating a new dossier:' do
.to_return(status: 404, body: '') .to_return(status: 404, body: '')
end end
scenario 'the user can enter the SIRET of its etablissement and create a new draft', vcr: { cassette_name: 'api_adresse_search_paris_3' }, js: true do scenario 'the user can enter the SIRET of its etablissement and create a new draft', vcr: { cassette_name: 'api_adresse_search_paris_3' } do
visit commencer_path(path: procedure.path) visit commencer_path(path: procedure.path)
click_on 'Commencer la démarche'
expect(page).to have_current_path(siret_dossier_path(dossier)) expect(page).to have_current_path siret_dossier_path(dossier)
expect(page).to have_content(procedure.libelle) expect_page_to_have_procedure_description(procedure)
expect(page).to have_content(procedure.description)
expect(page).to have_content(procedure.service.email)
fill_in 'Numéro SIRET', with: siret fill_in 'Numéro SIRET', with: siret
click_on 'Valider' click_on 'Valider'
@ -97,7 +96,10 @@ feature 'Creating a new dossier:' do
scenario 'the user is notified when its SIRET is invalid' do scenario 'the user is notified when its SIRET is invalid' do
visit commencer_path(path: procedure.path) visit commencer_path(path: procedure.path)
click_on 'Commencer la démarche'
expect(page).to have_current_path(siret_dossier_path(dossier)) expect(page).to have_current_path(siret_dossier_path(dossier))
expect_page_to_have_procedure_description(procedure)
fill_in 'Numéro SIRET', with: '0000' fill_in 'Numéro SIRET', with: '0000'
click_on 'Valider' click_on 'Valider'

View file

@ -48,11 +48,16 @@ feature 'linked dropdown lists' do
def log_in(email, password, procedure) def log_in(email, password, procedure)
visit "/commencer/#{procedure.path}" visit "/commencer/#{procedure.path}"
click_on 'Jai déjà un compte'
expect(page).to have_current_path(new_user_session_path) expect(page).to have_current_path(new_user_session_path)
fill_in 'user_email', with: email sign_in_with(email, password)
fill_in 'user_password', with: password
click_on 'Se connecter' expect(page).to have_current_path(commencer_path(path: procedure.path))
click_on 'Commencer la démarche'
expect(page).to have_content("Données d'identité")
expect(page).to have_current_path(identite_dossier_path(user_dossier)) expect(page).to have_current_path(identite_dossier_path(user_dossier))
end end

View file

@ -41,15 +41,20 @@ feature 'Signing up:' do
end end
scenario 'a new user can sign-up and fill the procedure' do scenario 'a new user can sign-up and fill the procedure' do
expect(page).to have_current_path new_user_session_path
click_on 'Créer un compte' click_on 'Créer un compte'
expect(page).to have_current_path new_user_registration_path
expect_page_to_have_procedure_description(procedure) expect_page_to_have_procedure_description(procedure)
sign_up_with user_email, user_password sign_up_with user_email, user_password
expect(page).to have_content "nous avons besoin de vérifier votre adresse #{user_email}" expect(page).to have_content "nous avons besoin de vérifier votre adresse #{user_email}"
click_confirmation_link_for user_email click_confirmation_link_for user_email
expect(page).to have_current_path(commencer_path(path: procedure.path))
expect(page).to have_content 'Votre compte a été activé' expect(page).to have_content 'Votre compte a été activé'
click_on 'Commencer la démarche'
expect(page).to have_current_path identite_dossier_path(procedure.reload.dossiers.last)
expect_page_to_have_procedure_description(procedure) expect_page_to_have_procedure_description(procedure)
end end
end end

View file

@ -21,11 +21,15 @@ feature 'Signin in:' do
end end
scenario 'an existing user can sign-in and fill the procedure' do scenario 'an existing user can sign-in and fill the procedure' do
click_on 'Jai déjà un compte'
expect(page).to have_current_path new_user_session_path expect(page).to have_current_path new_user_session_path
expect_page_to_have_procedure_description(procedure) expect_page_to_have_procedure_description(procedure)
sign_in_with user.email, password sign_in_with user.email, password
expect(page).to have_current_path(commencer_path(path: procedure.path))
click_on 'Commencer la démarche'
expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last) expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last)
expect_page_to_have_procedure_description(procedure) expect_page_to_have_procedure_description(procedure)
expect(page).to have_content "Données d'identité" expect(page).to have_content "Données d'identité"

View file

@ -0,0 +1,76 @@
require 'rails_helper'
RSpec.describe 'commencer/show.html.haml', type: :view do
include Rails.application.routes.url_helpers
let(:procedure) { create(:procedure, :with_service, :published) }
before do
assign(:procedure, procedure)
if user
sign_in user
end
end
subject { render }
context 'when no user is signed in' do
let(:user) { nil }
it 'renders sign-in and sign-up links' do
subject
expect(rendered).to have_link('Créer un compte')
expect(rendered).to have_link('Jai déjà un compte')
end
end
context 'when the user is already signed in' do
let(:user) { create :user }
shared_examples_for 'it renders a link to create a new dossier' do |button_label|
it 'renders a link to create a new dossier' do
subject
expect(rendered).to have_link(button_label, href: new_dossier_url(procedure_id: procedure.id))
end
end
context 'and they dont have any dossier on this procedure' do
it_behaves_like 'it renders a link to create a new dossier', 'Commencer la démarche'
end
context 'and they have a pending draft' do
let!(:brouillon) { create(:dossier, user: user, procedure: procedure) }
it_behaves_like 'it renders a link to create a new dossier', 'Commencer un nouveau dossier'
it 'renders a link to resume the pending draft' do
subject
expect(rendered).to have_link('Continuer à remplir mon dossier', href: brouillon_dossier_path(brouillon))
end
end
context 'and they have a submitted dossier' do
let!(:brouillon) { create(:dossier, user: user, procedure: procedure) }
let!(:dossier) { create(:dossier, :en_construction, :for_individual, user: user, procedure: procedure) }
it_behaves_like 'it renders a link to create a new dossier', 'Commencer un nouveau dossier'
it 'renders a link to the submitted dossier' do
subject
expect(rendered).to have_link('Voir mon dossier', href: dossier_path(dossier))
end
end
context 'and they have several submitted dossiers' do
let!(:brouillon) { create(:dossier, user: user, procedure: procedure) }
let!(:dossiers) { create_list(:dossier, 2, :en_construction, :for_individual, user: user, procedure: procedure) }
it_behaves_like 'it renders a link to create a new dossier', 'Commencer un nouveau dossier'
it 'renders a link to the dossiers list' do
subject
expect(rendered).to have_link('Voir mes dossiers en cours', href: dossiers_path)
end
end
end
end