Block dossier initiation if procedure is archived
This commit is contained in:
parent
63a7b91e60
commit
a24980145c
6 changed files with 72 additions and 32 deletions
|
@ -17,20 +17,21 @@ class Users::DescriptionController < UsersController
|
||||||
acc
|
acc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @procedure.archived?
|
||||||
|
flash[:alert] = t('errors.messages.procedure_archived')
|
||||||
|
end
|
||||||
|
|
||||||
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(root_path)
|
redirect_to url_for(root_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# def error
|
def update
|
||||||
# show
|
|
||||||
# flash.now.alert = 'Un ou plusieurs attributs obligatoires sont manquants ou incorrects.'
|
|
||||||
# render 'show'
|
|
||||||
# end
|
|
||||||
|
|
||||||
def create
|
|
||||||
@dossier = current_user_dossier
|
@dossier = current_user_dossier
|
||||||
@procedure = @dossier.procedure
|
@procedure = @dossier.procedure
|
||||||
|
|
||||||
|
return head :forbidden if @procedure.archived?
|
||||||
|
|
||||||
@champs = @dossier.ordered_champs
|
@champs = @dossier.ordered_champs
|
||||||
|
|
||||||
mandatory = true
|
mandatory = true
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
= @dossier.procedure.libelle
|
= @dossier.procedure.libelle
|
||||||
|
|
||||||
-#TODO use form_for
|
-#TODO use form_for
|
||||||
= form_tag(url_for({controller: 'users/description', action: :create, dossier_id: @dossier.id}), class: 'form', method: 'POST', multipart: true) do
|
= form_tag(url_for({controller: 'users/description', action: :update, dossier_id: @dossier.id}), class: 'form', method: 'POST', multipart: true) do
|
||||||
-unless @champs.nil?
|
-unless @champs.nil?
|
||||||
#liste_champs
|
#liste_champs
|
||||||
=render partial: 'users/description/champs', locals:{private: false}
|
=render partial: 'users/description/champs', locals:{private: false}
|
||||||
|
@ -41,16 +41,17 @@
|
||||||
Vous pourrez dans tous les cas les compléter plus tard si vous ne les possédez pas de suite.
|
Vous pourrez dans tous les cas les compléter plus tard si vous ne les possédez pas de suite.
|
||||||
|
|
||||||
|
|
||||||
-route = Rails.application.routes.recognize_path(request.referrer)
|
-route = Rails.application.routes.recognize_path(request.referrer) # WTF ?
|
||||||
- unless route[:controller].match('admin')
|
- unless route[:controller].match('admin')
|
||||||
%div{style: 'text-align:right'}
|
%div{style: 'text-align:right'}
|
||||||
%h6 Tous les champs portant un * sont obligatoires.
|
%h6 Tous les champs portant un * sont obligatoires.
|
||||||
|
|
||||||
-if !@dossier.draft?
|
- if @procedure.archived?
|
||||||
=render partial: '/layouts/modifications_terminees'
|
.alert.alert-danger
|
||||||
-else
|
= t('errors.messages.procedure_archived')
|
||||||
= submit_tag 'Soumettre mon dossier', id: 'suivant', name: 'submit[nouveaux]', class: %w(btn btn btn-success), style: 'float:right', data: { disable_with: 'Soumettre votre dossier', submit: true}
|
- else
|
||||||
= submit_tag 'Enregistrer un brouillon', id: 'brouillon', name: 'submit[brouillon]', class: %w(btn btn-xs btn-default), style: 'float:right; margin-right: 10px; margin-top: 6px', data: {disable_with: 'Enregistrer un brouillon', submit: true}
|
- if !@dossier.draft?
|
||||||
|
= render partial: '/layouts/modifications_terminees'
|
||||||
%br
|
- else
|
||||||
%br
|
= submit_tag 'Soumettre mon dossier', id: 'suivant', name: 'submit[nouveaux]', class: 'btn btn btn-success', style: 'float:right', disabled: @procedure.archived?, data: { disable_with: 'Soumettre votre dossier', submit: true}
|
||||||
|
= submit_tag 'Enregistrer un brouillon', id: 'brouillon', name: 'submit[brouillon]', class: 'btn btn-xs btn-default', style: 'float:right; margin-right: 10px; margin-top: 6px', disabled: @procedure.archived?, data: {disable_with: 'Enregistrer un brouillon', submit: true}
|
||||||
|
|
|
@ -147,6 +147,7 @@ fr:
|
||||||
france_connect:
|
france_connect:
|
||||||
connexion: "Erreur lors de la connexion à France Connect."
|
connexion: "Erreur lors de la connexion à France Connect."
|
||||||
extension_white_list_error: "Le format de fichier de la pièce jointe n'est pas valide."
|
extension_white_list_error: "Le format de fichier de la pièce jointe n'est pas valide."
|
||||||
|
procedure_archived: "Cette démarche en ligne a été fermée, il n'est plus possible de déposer de dossier."
|
||||||
|
|
||||||
datetime:
|
datetime:
|
||||||
distance_in_words:
|
distance_in_words:
|
||||||
|
|
|
@ -63,9 +63,8 @@ Rails.application.routes.draw do
|
||||||
resources :dossiers do
|
resources :dossiers do
|
||||||
get '/add_siret' => 'dossiers/add_siret#show'
|
get '/add_siret' => 'dossiers/add_siret#show'
|
||||||
|
|
||||||
get '/description' => 'description#show'
|
get 'description' => 'description#show'
|
||||||
# get '/description/error' => 'description#error'
|
post 'description' => 'description#update'
|
||||||
post 'description' => 'description#create'
|
|
||||||
|
|
||||||
patch 'pieces_justificatives' => 'description#pieces_justificatives'
|
patch 'pieces_justificatives' => 'description#pieces_justificatives'
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,20 @@ shared_examples 'description_controller_spec' do
|
||||||
context 'when all is ok' do
|
context 'when all is ok' do
|
||||||
before do
|
before do
|
||||||
dossier.entreprise = create :entreprise
|
dossier.entreprise = create :entreprise
|
||||||
|
get :show, params: {dossier_id: dossier_id}
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success' do
|
it 'returns http success' do
|
||||||
get :show, params: {dossier_id: dossier_id}
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'but procedure is archived' do
|
||||||
|
let(:archived) { true }
|
||||||
|
render_views
|
||||||
|
|
||||||
|
it { expect(response).to have_http_status(:success) }
|
||||||
|
it { expect(response.body).to have_content(I18n.t('errors.messages.procedure_archived')) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirection vers start si mauvais dossier ID' do
|
it 'redirection vers start si mauvais dossier ID' do
|
||||||
|
@ -90,7 +98,7 @@ shared_examples 'description_controller_spec' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #update' do
|
||||||
let(:timestamp) { Time.now }
|
let(:timestamp) { Time.now }
|
||||||
let(:description) { 'Description de test Coucou, je suis un saut à la ligne Je suis un double saut la ligne.' }
|
let(:description) { 'Description de test Coucou, je suis un saut à la ligne Je suis un double saut la ligne.' }
|
||||||
|
|
||||||
|
@ -98,7 +106,7 @@ shared_examples 'description_controller_spec' do
|
||||||
describe 'Premier enregistrement des données' do
|
describe 'Premier enregistrement des données' do
|
||||||
let(:submit) { {nouveaux: 'nouveaux'} }
|
let(:submit) { {nouveaux: 'nouveaux'} }
|
||||||
|
|
||||||
subject { post :create, params: {dossier_id: dossier_id, submit: submit} }
|
subject { post :update, params: {dossier_id: dossier_id, submit: submit} }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
dossier.draft!
|
dossier.draft!
|
||||||
|
@ -130,7 +138,7 @@ shared_examples 'description_controller_spec' do
|
||||||
context 'En train de manipuler un dossier non brouillon' do
|
context 'En train de manipuler un dossier non brouillon' do
|
||||||
before do
|
before do
|
||||||
dossier.initiated!
|
dossier.initiated!
|
||||||
post :create, params: {dossier_id: dossier_id}
|
post :update, params: {dossier_id: dossier_id}
|
||||||
dossier.reload
|
dossier.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -145,7 +153,7 @@ shared_examples 'description_controller_spec' do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Quand la procédure accepte les CERFA' do
|
context 'Quand la procédure accepte les CERFA' do
|
||||||
subject { post :create, params: {dossier_id: dossier_id,
|
subject { post :update, params: {dossier_id: dossier_id,
|
||||||
cerfa_pdf: cerfa_pdf} }
|
cerfa_pdf: cerfa_pdf} }
|
||||||
|
|
||||||
it 'Notification interne is create' do
|
it 'Notification interne is create' do
|
||||||
|
@ -154,7 +162,7 @@ shared_examples 'description_controller_spec' do
|
||||||
|
|
||||||
context 'Sauvegarde du CERFA PDF', vcr: {cassette_name: 'controllers_users_description_controller_save_cerfa'} do
|
context 'Sauvegarde du CERFA PDF', vcr: {cassette_name: 'controllers_users_description_controller_save_cerfa'} do
|
||||||
before do
|
before do
|
||||||
post :create, params: {dossier_id: dossier_id,
|
post :update, params: {dossier_id: dossier_id,
|
||||||
cerfa_pdf: cerfa_pdf}
|
cerfa_pdf: cerfa_pdf}
|
||||||
dossier.reload
|
dossier.reload
|
||||||
end
|
end
|
||||||
|
@ -181,7 +189,7 @@ shared_examples 'description_controller_spec' do
|
||||||
let(:cerfas) { Cerfa.where(dossier_id: dossier_id) }
|
let(:cerfas) { Cerfa.where(dossier_id: dossier_id) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
post :create, params: {dossier_id: dossier_id, cerfa_pdf: cerfa_pdf}
|
post :update, params: {dossier_id: dossier_id, cerfa_pdf: cerfa_pdf}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "il y a deux CERFA PDF pour ce dossier" do
|
it "il y a deux CERFA PDF pour ce dossier" do
|
||||||
|
@ -195,7 +203,7 @@ shared_examples 'description_controller_spec' do
|
||||||
context 'Sauvegarde du CERFA PDF' do
|
context 'Sauvegarde du CERFA PDF' do
|
||||||
let!(:procedure) { create(:procedure) }
|
let!(:procedure) { create(:procedure) }
|
||||||
before do
|
before do
|
||||||
post :create, params: {dossier_id: dossier_id,
|
post :update, params: {dossier_id: dossier_id,
|
||||||
cerfa_pdf: cerfa_pdf}
|
cerfa_pdf: cerfa_pdf}
|
||||||
dossier.reload
|
dossier.reload
|
||||||
end
|
end
|
||||||
|
@ -214,7 +222,7 @@ shared_examples 'description_controller_spec' do
|
||||||
let(:dossier_minute_value) { '00' }
|
let(:dossier_minute_value) { '00' }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
post :create, params: {dossier_id: dossier_id,
|
post :update, params: {dossier_id: dossier_id,
|
||||||
champs: {
|
champs: {
|
||||||
"'#{dossier.champs.first.id}'" => dossier_champs_first,
|
"'#{dossier.champs.first.id}'" => dossier_champs_first,
|
||||||
"'#{dossier.champs.second.id}'" => dossier_date_value
|
"'#{dossier.champs.second.id}'" => dossier_date_value
|
||||||
|
@ -254,7 +262,7 @@ shared_examples 'description_controller_spec' do
|
||||||
context 'Sauvegarde des pièces justificatives', vcr: {cassette_name: 'controllers_users_description_controller_sauvegarde_pj'} do
|
context 'Sauvegarde des pièces justificatives', vcr: {cassette_name: 'controllers_users_description_controller_sauvegarde_pj'} do
|
||||||
let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids }
|
let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids }
|
||||||
before do
|
before do
|
||||||
post :create, params: {dossier_id: dossier_id,
|
post :update, params: {dossier_id: dossier_id,
|
||||||
'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0,
|
'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0,
|
||||||
'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1}
|
'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1}
|
||||||
dossier.reload
|
dossier.reload
|
||||||
|
@ -264,7 +272,7 @@ shared_examples 'description_controller_spec' do
|
||||||
it 'ClamavService safe_file? is call' do
|
it 'ClamavService safe_file? is call' do
|
||||||
expect(ClamavService).to receive(:safe_file?).twice
|
expect(ClamavService).to receive(:safe_file?).twice
|
||||||
|
|
||||||
post :create, params: {dossier_id: dossier_id,
|
post :update, params: {dossier_id: dossier_id,
|
||||||
'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0,
|
'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0,
|
||||||
'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1}
|
'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1}
|
||||||
end
|
end
|
||||||
|
@ -281,6 +289,16 @@ shared_examples 'description_controller_spec' do
|
||||||
it { expect(subject.user).to eq user }
|
it { expect(subject.user).to eq user }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'La procédure est archivée' do
|
||||||
|
let(:archived) { true }
|
||||||
|
|
||||||
|
before do
|
||||||
|
post :update, params: { dossier_id: dossier.id }
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(response.status).to eq(403) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #pieces_justificatives', vcr: {cassette_name: 'controllers_users_description_controller_pieces_justificatives'} do
|
describe 'POST #pieces_justificatives', vcr: {cassette_name: 'controllers_users_description_controller_pieces_justificatives'} do
|
||||||
|
|
|
@ -5,8 +5,9 @@ require 'controllers/users/description_controller_shared_example'
|
||||||
describe Users::DescriptionController, type: :controller, vcr: {cassette_name: 'controllers_users_description_controller'} do
|
describe Users::DescriptionController, type: :controller, vcr: {cassette_name: 'controllers_users_description_controller'} do
|
||||||
let(:owner_user) { create(:user) }
|
let(:owner_user) { create(:user) }
|
||||||
let(:invite_by_user) { create :user, email: 'invite@plop.com' }
|
let(:invite_by_user) { create :user, email: 'invite@plop.com' }
|
||||||
|
let(:archived) { false }
|
||||||
|
|
||||||
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true) }
|
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true, archived: archived) }
|
||||||
let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: 'initiated') }
|
let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: 'initiated') }
|
||||||
|
|
||||||
let(:dossier_id) { dossier.id }
|
let(:dossier_id) { dossier.id }
|
||||||
|
@ -42,4 +43,23 @@ describe Users::DescriptionController, type: :controller, vcr: {cassette_name: '
|
||||||
|
|
||||||
it_should_behave_like "description_controller_spec"
|
it_should_behave_like "description_controller_spec"
|
||||||
end
|
end
|
||||||
|
#
|
||||||
|
# context 'POST #update' do
|
||||||
|
# let(:user) { owner_user }
|
||||||
|
#
|
||||||
|
# subject { post :update, params: { dossier_id: dossier.id } }
|
||||||
|
#
|
||||||
|
# before do
|
||||||
|
# subject
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# it { expect(response.status).to eq(302) }
|
||||||
|
#
|
||||||
|
# context 'when procedure is archived' do
|
||||||
|
# let(:archived) { true }
|
||||||
|
#
|
||||||
|
# it { expect(response.status).to eq(403) }
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue