- delete route '/users/siret'

- delete route 'users/procedure'
- create route 'users/dossiers/new?procedure_id=:procedure_id'
- delete a part of unused code
- adapt demo page with new procedure URL
This commit is contained in:
Xavier J 2015-12-03 12:00:22 +01:00
parent 851f4e830e
commit afaa6a5ac9
19 changed files with 166 additions and 333 deletions

View file

@ -1,4 +1,3 @@
function show_dossier_id_input (){ function show_dossier_id_input (){
$("#btn_show_dossier_id_input").hide() $("#btn_show_dossier_id_input").hide()
$("#pro_dossier_id").show()
} }

View file

@ -6,6 +6,13 @@
display: none; display: none;
} }
#dossier_siret {
margin-bottom: 10px;
margin-left: auto;
margin-right: auto;
width: 200px;
}
#titre_procedure { #titre_procedure {
margin-top: 3%; margin-top: 3%;
margin-bottom: 2%; margin-bottom: 2%;

View file

@ -3,10 +3,13 @@ class RootController < ApplicationController
if user_signed_in? if user_signed_in?
redirect_to users_dossiers_path redirect_to users_dossiers_path
elsif gestionnaire_signed_in? elsif gestionnaire_signed_in?
redirect_to backoffice_dossiers_path redirect_to backoffice_dossiers_path
elsif administrateur_signed_in? elsif administrateur_signed_in?
redirect_to admin_procedures_path redirect_to admin_procedures_path
else else
redirect_to new_user_session_path redirect_to new_user_session_path
end end

View file

@ -28,6 +28,16 @@ class Users::DossiersController < UsersController
total_dossiers_per_state total_dossiers_per_state
end end
def new
procedure = Procedure.where(archived: false).find(params[:procedure_id])
@dossier = Dossier.new(procedure: procedure)
@siret = params[:siret] || current_user.siret
rescue ActiveRecord::RecordNotFound
error_procedure
end
def show def show
@dossier = current_user_dossier params[:id] @dossier = current_user_dossier params[:id]
@ -35,7 +45,7 @@ class Users::DossiersController < UsersController
@entreprise = @dossier.entreprise.decorate @entreprise = @dossier.entreprise.decorate
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found') flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(controller: :siret) redirect_to url_for users_dossiers_path
end end
def create def create
@ -52,7 +62,7 @@ class Users::DossiersController < UsersController
end end
end end
@dossier = Dossier.create(user: current_user, state: 'draft', procedure_id: params['procedure_id']) @dossier = Dossier.create(user: current_user, state: 'draft', procedure_id: create_params[:procedure_id])
@entreprise.dossier = @dossier @entreprise.dossier = @dossier
@entreprise.save @entreprise.save
@ -65,7 +75,8 @@ class Users::DossiersController < UsersController
rescue RestClient::ResourceNotFound rescue RestClient::ResourceNotFound
flash.alert = t('errors.messages.invalid_siret') flash.alert = t('errors.messages.invalid_siret')
redirect_to url_for(controller: :siret, procedure_id: params['procedure_id']) redirect_to url_for new_users_dossiers_path(procedure_id: create_params[:procedure_id])
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found') flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(controller: :siret) redirect_to url_for(controller: :siret)
@ -117,7 +128,7 @@ class Users::DossiersController < UsersController
end end
def siret def siret
params[:siret] create_params[:siret]
end end
def siren def siren
@ -129,4 +140,12 @@ class Users::DossiersController < UsersController
@dossiers_en_attente_total = !@dossiers_en_attente.nil? ? @dossiers_en_attente.size : current_user.dossiers.waiting_for_gestionnaire.size @dossiers_en_attente_total = !@dossiers_en_attente.nil? ? @dossiers_en_attente.size : current_user.dossiers.waiting_for_gestionnaire.size
@dossiers_termine_total = !@dossiers_termine.nil? ? @dossiers_termine.size : current_user.dossiers.termine.size @dossiers_termine_total = !@dossiers_termine.nil? ? @dossiers_termine.size : current_user.dossiers.termine.size
end end
def create_params
params.require(:dossier).permit(:siret, :procedure_id)
end
def error_procedure
render :file => "#{Rails.root}/public/404_procedure_not_found.html", :status => 404
end
end end

View file

@ -1,12 +0,0 @@
class Users::ProcedureController < UsersController
def index
@procedure = Procedure.where(archived: false).find(params[:procedure_id])
@siret = params[:siret] || current_user.siret
rescue ActiveRecord::RecordNotFound
error_procedure
end
def error_procedure
render :file => "#{Rails.root}/public/404_procedure_not_found.html", :status => 404
end
end

View file

@ -1,9 +0,0 @@
class Users::SiretController < UsersController
def index
@siret = params[:siret] || current_user.siret
redirect_to(users_path(procedure_id: params['procedure_id'], siret: @siret))
rescue ActionController::UrlGenerationError
redirect_to(new_user_session_path)
end
end

View file

@ -18,7 +18,7 @@ class Dossier < ActiveRecord::Base
has_many :commentaires, dependent: :destroy has_many :commentaires, dependent: :destroy
delegate :siren, to: :entreprise delegate :siren, to: :entreprise
delegate :siret, to: :etablissement delegate :siret, to: :etablissement, allow_nil: true
delegate :types_de_piece_justificative, to: :procedure delegate :types_de_piece_justificative, to: :procedure
delegate :types_de_champ, to: :procedure delegate :types_de_champ, to: :procedure

View file

@ -13,7 +13,7 @@
%td %td
= procedure.id = procedure.id
%td.col-md-4.col-lg-4 %td.col-md-4.col-lg-4
= link_to procedure.libelle, "/users/procedure/#{procedure.id}" = link_to procedure.libelle, "/users/dossiers/new?procedure_id=#{procedure.id}"
%td %td
= procedure.description = procedure.description
%td.col-md-3.col-lg-3 %td.col-md-3.col-lg-3

View file

@ -0,0 +1,19 @@
.container.center#users_siret_index
.row
%p.lead{id: 'pro_section'}
%br
= image_tag('logo-tps.png')
%br
%h2#titre_procedure.text-info
= @dossier.procedure.libelle
%p
= @dossier.procedure.description
%br
= form_for @dossier, url: {controller: 'users/dossiers', action: :create}, method: :post do |f|
.form-group.form-group-lg
= f.text_field :siret, class: "form-control", placeholder: "Entrez votre Siret", value: @siret
= f.hidden_field :procedure_id
= f.submit 'Commencer', class: %w(btn btn-lg btn-success), style: 'margin-top:20px;'

View file

@ -1,17 +0,0 @@
%p.lead{id: 'pro_section'}
%br
= image_tag('logo-tps.png')
%br
%h2#titre_procedure.text-info
= @procedure.libelle
%p
= @procedure.description
%br
= form_tag(url_for({controller: :dossiers, action: :create}), class: 'form-inline', method: 'POST') do |f|
.form-group.form-group-lg
= text_field_tag :siret, nil, :class => "form-control", :placeholder => "Entrez votre Siret", :id => "siret", :name => "siret", :maxlength => 14, :style => 'margin-bottom:10px', value: @siret
%br
= submit_tag "Commencer", class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', data: { disable_with: "Commencer", submit: true}
%input{type: 'hidden', value: "#{@procedure.id}", name: 'procedure_id', id: 'procedure_id'}

View file

@ -1,4 +0,0 @@
.container.center#users_siret_index
.row
= render partial: 'pro'

View file

@ -21,9 +21,6 @@ Rails.application.routes.draw do
get 'demo' => 'demo#index' get 'demo' => 'demo#index'
namespace :users do namespace :users do
get 'siret' => 'siret#index'
get 'procedure/:procedure_id' => 'procedure#index'
resources :dossiers do resources :dossiers do
get '/description' => 'description#show' get '/description' => 'description#show'
get '/description/error' => 'description#error' get '/description/error' => 'description#error'

View file

@ -1,124 +1,5 @@
require 'spec_helper' require 'spec_helper'
describe DossiersController, type: :controller do describe DossiersController, type: :controller do
# let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) }
# let(:procedure) { create(:procedure) }
# let(:dossier_id) { dossier.id }
# let(:siret_not_found) { 999_999_999_999 }
# let(:siren) { dossier.siren }
# let(:siret) { dossier.siret }
# let(:bad_siret) { 1 }
# describe 'GET #show' do
# it 'returns http success with dossier_id valid' do
# get :show, id: dossier_id
# expect(response).to have_http_status(:success)
# end
# it 'redirection vers siret si mauvais dossier ID' do
# get :show, id: siret_not_found
# expect(response).to redirect_to('/siret')
# end
# end
# describe 'POST #create' do
# before do
# stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret_not_found}?token=#{SIADETOKEN}")
# .to_return(status: 404, body: 'fake body')
# stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}")
# .to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
# stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
# .to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
# end
# describe 'professionnel fills form' do
# context 'when pro_dossier_id is empty' do
# context 'with valid siret ' do
# subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }
# it 'create a dossier' do
# expect { subject }.to change { Dossier.count }.by(1)
# end
# it 'creates entreprise' do
# expect { subject }.to change { Entreprise.count }.by(1)
# end
# it 'links entreprise to dossier' do
# expect(Entreprise.last.dossier).to eq(Dossier.last)
# end
# it 'creates etablissement for dossier' do
# expect { subject }.to change { Etablissement.count }.by(1)
# end
# it 'links etablissement to dossier' do
# subject
# expect(Etablissement.last.dossier).to eq(Dossier.last)
# end
# it 'links etablissement to entreprise' do
# subject
# expect(Etablissement.last.entreprise).to eq(Entreprise.last)
# end
# it 'links procedure to dossier' do
# subject
# expect(Dossier.last.procedure).to eq(Procedure.last)
# end
# it 'state of dossier is draft' do
# subject
# expect(Dossier.last.state).to eq('draft')
# end
# end
# context 'with non existant siret' do
# let(:siret_not_found) { '11111111111111' }
# subject { post :create, siret: siret_not_found, pro_dossier_id: '', procedure_id: procedure.id }
# it 'does not create new dossier' do
# expect { subject }.not_to change { Dossier.count }
# end
# it 'redirects to show' do
# expect(subject).to redirect_to(controller: :siret, procedure_id: procedure.id)
# end
# end
# end
# end
# end
# describe 'PUT #update' do
# before do
# put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees }
# end
# context 'when Checkbox is checked' do
# let(:autorisation_donnees) { '1' }
# it 'redirects to demande' do
# expect(response).to redirect_to(controller: :description, action: :show, dossier_id: dossier.id)
# end
# it 'update dossier' do
# dossier.reload
# expect(dossier.autorisation_donnees).to be_truthy
# end
# end
# context 'when Checkbox is not checked' do
# let(:autorisation_donnees) { '0' }
# it 'uses flash alert to display message' do
# expect(flash[:alert]).to have_content('Les conditions sont obligatoires.')
# end
# it "doesn't update dossier autorisation_donnees" do
# dossier.reload
# expect(dossier.autorisation_donnees).to be_falsy
# end
# end
# end
end end

View file

@ -5,6 +5,7 @@ describe Users::DossiersController, type: :controller do
let(:use_api_carto) { false } let(:use_api_carto) { false }
let(:procedure) { create(:procedure, use_api_carto: use_api_carto) } let(:procedure) { create(:procedure, use_api_carto: use_api_carto) }
let(:procedure_id) { procedure.id }
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:siret_not_found) { 999_999_999_999 } let(:siret_not_found) { 999_999_999_999 }
@ -22,9 +23,44 @@ describe Users::DossiersController, type: :controller do
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
end end
it 'redirection vers siret si mauvais dossier ID' do it 'redirection vers liste dossier si mauvais dossier ID' do
get :show, id: siret_not_found get :show, id: siret_not_found
expect(response).to redirect_to('/users/siret') expect(response).to redirect_to('/users/dossiers')
end
end
describe 'GET #new' do
subject { get :new, procedure_id: procedure_id }
context 'when params procedure_id is present' do
context 'when procedure_id is valid' do
context 'when user is logged in' do
before do
sign_in create(:user)
end
it { is_expected.to have_http_status(:success) }
context 'when procedure is archived' do
let(:procedure) { create(:procedure, archived: 'true') }
it { is_expected.to have_http_status(404) }
end
end
context 'when user is not logged' do
it { is_expected.to have_http_status(302) }
end
end
context 'when procedure_id is not valid' do
let(:procedure_id) { 0 }
before do
sign_in create(:user)
end
it { is_expected.to have_http_status(404) }
end
end end
end end
@ -45,77 +81,75 @@ describe Users::DossiersController, type: :controller do
describe 'professionnel fills form' do describe 'professionnel fills form' do
let(:user) { create(:user) } let(:user) { create(:user) }
context 'when pro_dossier_id is empty' do context 'with valid siret ' do
context 'with valid siret ' do before do
before do sign_in user
sign_in user
end
subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }
it 'create a dossier' do
expect { subject }.to change { Dossier.count }.by(1)
end
it 'creates entreprise' do
expect { subject }.to change { Entreprise.count }.by(1)
end
it 'links entreprise to dossier' do
subject
expect(Entreprise.last.dossier).to eq(Dossier.last)
end
it "links dossier to user" do
subject
expect(Dossier.last.user).to eq(user)
end
it 'creates etablissement for dossier' do
expect { subject }.to change { Etablissement.count }.by(1)
end
it 'links etablissement to dossier' do
subject
expect(Etablissement.last.dossier).to eq(Dossier.last)
end
it 'links etablissement to entreprise' do
subject
expect(Etablissement.last.entreprise).to eq(Entreprise.last)
end
it 'creates exercices for dossier' do
expect { subject }.to change { Exercice.count }.by(3)
expect(Exercice.last.etablissement).to eq(Dossier.last.etablissement)
end
it 'links procedure to dossier' do
subject
expect(Dossier.last.procedure).to eq(Procedure.last)
end
it 'state of dossier is draft' do
subject
expect(Dossier.last.state).to eq('draft')
end
end end
context 'with non existant siret' do subject { post :create, dossier: {siret: siret, procedure_id: Procedure.last} }
before do
sign_in create(:user)
end
let(:siret_not_found) { '11111111111111' }
subject { post :create, siret: siret_not_found, pro_dossier_id: '', procedure_id: procedure.id }
it 'does not create new dossier' do
expect { subject }.not_to change { Dossier.count }
end
it 'redirects to show' do it 'create a dossier' do
expect(subject).to redirect_to(controller: :siret, procedure_id: procedure.id) expect { subject }.to change { Dossier.count }.by(1)
end end
it 'creates entreprise' do
expect { subject }.to change { Entreprise.count }.by(1)
end
it 'links entreprise to dossier' do
subject
expect(Entreprise.last.dossier).to eq(Dossier.last)
end
it "links dossier to user" do
subject
expect(Dossier.last.user).to eq(user)
end
it 'creates etablissement for dossier' do
expect { subject }.to change { Etablissement.count }.by(1)
end
it 'links etablissement to dossier' do
subject
expect(Etablissement.last.dossier).to eq(Dossier.last)
end
it 'links etablissement to entreprise' do
subject
expect(Etablissement.last.entreprise).to eq(Entreprise.last)
end
it 'creates exercices for dossier' do
expect { subject }.to change { Exercice.count }.by(3)
expect(Exercice.last.etablissement).to eq(Dossier.last.etablissement)
end
it 'links procedure to dossier' do
subject
expect(Dossier.last.procedure).to eq(Procedure.last)
end
it 'state of dossier is draft' do
subject
expect(Dossier.last.state).to eq('draft')
end
end
context 'with non existant siret' do
before do
sign_in create(:user)
end
let(:siret_not_found) { '11111111111111' }
subject { post :create, dossier: {siret: siret_not_found, procedure_id: procedure.id} }
it 'does not create new dossier' do
expect { subject }.not_to change { Dossier.count }
end
it 'redirects to show' do
expect(subject).to redirect_to new_users_dossiers_path(procedure_id: procedure_id)
end end
end end
end end
@ -124,7 +158,7 @@ describe Users::DossiersController, type: :controller do
describe 'PUT #update' do describe 'PUT #update' do
before do before do
sign_in dossier.user sign_in dossier.user
put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees } put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees}
end end
context 'when Checkbox is checked' do context 'when Checkbox is checked' do
let(:autorisation_donnees) { '1' } let(:autorisation_donnees) { '1' }
@ -139,7 +173,7 @@ describe Users::DossiersController, type: :controller do
let(:use_api_carto) { true } let(:use_api_carto) { true }
before do before do
put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees } put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees}
end end
it 'redirects to carte' do it 'redirects to carte' do
expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier.id) expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier.id)

View file

@ -1,42 +0,0 @@
require 'spec_helper'
describe Users::ProcedureController, type: :controller do
let(:procedure) { create(:procedure) }
let(:procedure_id) { procedure.id }
describe 'GET #index' do
subject { get :index, procedure_id: procedure_id }
context 'when params procedure_id is present' do
context 'when procedure_id is valid' do
context 'when user is logged in' do
before do
sign_in create(:user)
end
it { is_expected.to have_http_status(:success) }
context 'when procedure is archived' do
let(:procedure) { create(:procedure, archived: 'true') }
it { is_expected.to have_http_status(404) }
end
end
context 'when user is not logged' do
it { is_expected.to have_http_status(302) }
end
end
context 'when procedure_id is not valid' do
let(:procedure_id) { 0 }
before do
sign_in create(:user)
end
it { is_expected.to have_http_status(404) }
end
end
end
end

View file

@ -1,42 +0,0 @@
require 'spec_helper'
describe Users::SiretController, type: :controller do
let!(:procedure) { create(:procedure) }
describe 'GET #index' do
before do
get :index, procedure_id: procedure
end
context 'when params procedure_id is present' do
context 'when procedure_id is valid' do
context 'when user is logged in' do
before do
sign_in create(:user)
end
subject { get :index, procedure_id: procedure }
it { expect(subject).to redirect_to(users_path(procedure_id: procedure.id)) }
context 'when params siret is present' do
subject { get :index, procedure_id: procedure, siret: '123456789' }
it { expect(subject).to redirect_to(users_path(procedure_id: procedure.id, siret: '123456789')) }
end
context 'when procedure_id is not valid' do
let(:procedure) { '' }
it { is_expected.to have_http_status(302) }
end
context 'when params procedure_id is not present' do
subject { get :index }
it { is_expected.to redirect_to new_user_session_path }
end
end
context 'when user is not logged' do
it { expect(response).to have_http_status(302) }
end
end
end
end
end

View file

@ -68,13 +68,13 @@ feature 'France Connect Connexion' do
end end
context 'when starting page is procedure' do context 'when starting page is procedure' do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:initial_path) { users_siret_path(procedure_id: procedure.id ) } let(:initial_path) { new_users_dossiers_path(procedure_id: procedure.id ) }
scenario 'he is redirected to siret page' do scenario 'he is redirected to siret page' do
expect(page).to have_css('#users_siret_index') expect(page).to have_css('#users_siret_index')
end end
scenario 'the siret is already written in form' do scenario 'the siret is already written in form' do
expect(page.find_by_id('siret').value).to have_content(siret) expect(page.find_by_id('dossier_siret').value).to have_content(siret)
end end
end end
end end

View file

@ -7,7 +7,7 @@ feature 'user path for dossier creation' do
let(:siren) { siret[0...9] } let(:siren) { siret[0...9] }
context 'user arrives on siret page' do context 'user arrives on siret page' do
before do before do
visit users_siret_path(procedure_id: procedure.id) visit new_users_dossiers_path(procedure_id: procedure.id)
end end
scenario 'he is redirected on login page' do scenario 'he is redirected on login page' do
@ -23,7 +23,7 @@ feature 'user path for dossier creation' do
end end
end end
scenario 'redirects to siret page' do scenario 'redirects to siret page' do
expect(page).to have_css('#siret') expect(page).to have_css('#dossier_siret')
end end
context 'sets siret' do context 'sets siret' do
before do before do
@ -34,7 +34,7 @@ feature 'user path for dossier creation' do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/exercices.json')) .to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
page.find_by_id('siret').set siret page.find_by_id('dossier_siret').set siret
page.click_on 'Commencer' page.click_on 'Commencer'
end end
scenario 'user is on page recap info entreprise' do scenario 'user is on page recap info entreprise' do

View file

@ -7,7 +7,7 @@ feature 'user arrive on siret page' do
let(:siren) { siret[0...9] } let(:siren) { siret[0...9] }
context 'when user is not logged in' do context 'when user is not logged in' do
before do before do
visit users_siret_path(procedure_id: procedure.id) visit new_users_dossiers_path(procedure_id: procedure.id)
end end
scenario 'he is redirected to login page' do scenario 'he is redirected to login page' do
expect(page).to have_css('#login_user') expect(page).to have_css('#login_user')
@ -31,7 +31,7 @@ feature 'user arrive on siret page' do
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) .to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/exercices.json')) .to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
page.find_by_id('siret').set siret page.find_by_id('dossier_siret').set siret
page.click_on 'Commencer' page.click_on 'Commencer'
end end
scenario 'he is redirected to recap info entreprise page' do scenario 'he is redirected to recap info entreprise page' do