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
|
||||
end
|
||||
|
||||
if @procedure.archived?
|
||||
flash[:alert] = t('errors.messages.procedure_archived')
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
flash.alert = t('errors.messages.dossier_not_found')
|
||||
redirect_to url_for(root_path)
|
||||
end
|
||||
|
||||
# def error
|
||||
# show
|
||||
# flash.now.alert = 'Un ou plusieurs attributs obligatoires sont manquants ou incorrects.'
|
||||
# render 'show'
|
||||
# end
|
||||
|
||||
def create
|
||||
def update
|
||||
@dossier = current_user_dossier
|
||||
@procedure = @dossier.procedure
|
||||
|
||||
return head :forbidden if @procedure.archived?
|
||||
|
||||
@champs = @dossier.ordered_champs
|
||||
|
||||
mandatory = true
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
= @dossier.procedure.libelle
|
||||
|
||||
-#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?
|
||||
#liste_champs
|
||||
=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.
|
||||
|
||||
|
||||
-route = Rails.application.routes.recognize_path(request.referrer)
|
||||
-route = Rails.application.routes.recognize_path(request.referrer) # WTF ?
|
||||
- unless route[:controller].match('admin')
|
||||
%div{style: 'text-align:right'}
|
||||
%h6 Tous les champs portant un * sont obligatoires.
|
||||
|
||||
-if !@dossier.draft?
|
||||
=render partial: '/layouts/modifications_terminees'
|
||||
-else
|
||||
= 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}
|
||||
= 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}
|
||||
|
||||
%br
|
||||
%br
|
||||
- if @procedure.archived?
|
||||
.alert.alert-danger
|
||||
= t('errors.messages.procedure_archived')
|
||||
- else
|
||||
- if !@dossier.draft?
|
||||
= render partial: '/layouts/modifications_terminees'
|
||||
- else
|
||||
= 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:
|
||||
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."
|
||||
procedure_archived: "Cette démarche en ligne a été fermée, il n'est plus possible de déposer de dossier."
|
||||
|
||||
datetime:
|
||||
distance_in_words:
|
||||
|
|
|
@ -63,9 +63,8 @@ Rails.application.routes.draw do
|
|||
resources :dossiers do
|
||||
get '/add_siret' => 'dossiers/add_siret#show'
|
||||
|
||||
get '/description' => 'description#show'
|
||||
# get '/description/error' => 'description#error'
|
||||
post 'description' => 'description#create'
|
||||
get 'description' => 'description#show'
|
||||
post 'description' => 'description#update'
|
||||
|
||||
patch 'pieces_justificatives' => 'description#pieces_justificatives'
|
||||
|
||||
|
|
|
@ -17,12 +17,20 @@ shared_examples 'description_controller_spec' do
|
|||
context 'when all is ok' do
|
||||
before do
|
||||
dossier.entreprise = create :entreprise
|
||||
get :show, params: {dossier_id: dossier_id}
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get :show, params: {dossier_id: dossier_id}
|
||||
expect(response).to have_http_status(:success)
|
||||
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
|
||||
|
||||
it 'redirection vers start si mauvais dossier ID' do
|
||||
|
@ -90,7 +98,7 @@ shared_examples 'description_controller_spec' do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
describe 'POST #update' do
|
||||
let(:timestamp) { Time.now }
|
||||
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
|
||||
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
|
||||
dossier.draft!
|
||||
|
@ -130,7 +138,7 @@ shared_examples 'description_controller_spec' do
|
|||
context 'En train de manipuler un dossier non brouillon' do
|
||||
before do
|
||||
dossier.initiated!
|
||||
post :create, params: {dossier_id: dossier_id}
|
||||
post :update, params: {dossier_id: dossier_id}
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
|
@ -145,7 +153,7 @@ shared_examples 'description_controller_spec' do
|
|||
end
|
||||
|
||||
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} }
|
||||
|
||||
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
|
||||
before do
|
||||
post :create, params: {dossier_id: dossier_id,
|
||||
post :update, params: {dossier_id: dossier_id,
|
||||
cerfa_pdf: cerfa_pdf}
|
||||
dossier.reload
|
||||
end
|
||||
|
@ -181,7 +189,7 @@ shared_examples 'description_controller_spec' do
|
|||
let(:cerfas) { Cerfa.where(dossier_id: dossier_id) }
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
let!(:procedure) { create(:procedure) }
|
||||
before do
|
||||
post :create, params: {dossier_id: dossier_id,
|
||||
post :update, params: {dossier_id: dossier_id,
|
||||
cerfa_pdf: cerfa_pdf}
|
||||
dossier.reload
|
||||
end
|
||||
|
@ -214,7 +222,7 @@ shared_examples 'description_controller_spec' do
|
|||
let(:dossier_minute_value) { '00' }
|
||||
|
||||
before do
|
||||
post :create, params: {dossier_id: dossier_id,
|
||||
post :update, params: {dossier_id: dossier_id,
|
||||
champs: {
|
||||
"'#{dossier.champs.first.id}'" => dossier_champs_first,
|
||||
"'#{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
|
||||
let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids }
|
||||
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[1].to_s => piece_justificative_1}
|
||||
dossier.reload
|
||||
|
@ -264,7 +272,7 @@ shared_examples 'description_controller_spec' do
|
|||
it 'ClamavService safe_file? is call' do
|
||||
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[1].to_s => piece_justificative_1}
|
||||
end
|
||||
|
@ -281,6 +289,16 @@ shared_examples 'description_controller_spec' do
|
|||
it { expect(subject.user).to eq user }
|
||||
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
|
||||
|
||||
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
|
||||
let(:owner_user) { create(:user) }
|
||||
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_id) { dossier.id }
|
||||
|
@ -42,4 +43,23 @@ describe Users::DescriptionController, type: :controller, vcr: {cassette_name: '
|
|||
|
||||
it_should_behave_like "description_controller_spec"
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue