Merge pull request #33 from sgmap/block_dossier_initiation_if_procedure_is_archived
Block dossier initiation if procedure is archived
This commit is contained in:
commit
4de6a9595a
7 changed files with 71 additions and 33 deletions
|
@ -17,20 +17,21 @@ class Users::DescriptionController < UsersController
|
|||
acc
|
||||
end
|
||||
|
||||
unless @dossier.can_be_initiated?
|
||||
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 unless @dossier.can_be_initiated?
|
||||
|
||||
@champs = @dossier.ordered_champs
|
||||
|
||||
mandatory = true
|
||||
|
|
|
@ -304,4 +304,8 @@ class Dossier < ActiveRecord::Base
|
|||
def invite_by_user? email
|
||||
(invites_user.pluck :email).include? email
|
||||
end
|
||||
|
||||
def can_be_initiated?
|
||||
!(procedure.archived && draft?)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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,16 @@
|
|||
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 !@dossier.can_be_initiated?
|
||||
.alert.alert-danger
|
||||
= t('errors.messages.procedure_archived')
|
||||
- elsif !@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,27 @@ 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 'procedure is archived' do
|
||||
render_views
|
||||
let(:archived) { true }
|
||||
|
||||
it { expect(response).to have_http_status(:success) }
|
||||
it { expect(response.body).to_not have_content(I18n.t('errors.messages.procedure_archived')) }
|
||||
|
||||
context 'dossier is a draft' do
|
||||
let(:state) { 'draft' }
|
||||
|
||||
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
|
||||
|
@ -90,7 +105,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 +113,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 +145,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 +160,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 +169,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 +196,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 +210,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 +229,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 +269,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 +279,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 +296,22 @@ 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(302) }
|
||||
|
||||
context 'Le dossier est en brouillon' do
|
||||
let(:state) { 'draft' }
|
||||
|
||||
it { expect(response.status).to eq(403) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #pieces_justificatives', vcr: {cassette_name: 'controllers_users_description_controller_pieces_justificatives'} do
|
||||
|
|
|
@ -5,9 +5,11 @@ 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(:state) { 'initiated' }
|
||||
|
||||
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: 'initiated') }
|
||||
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: state) }
|
||||
|
||||
let(:dossier_id) { dossier.id }
|
||||
let(:bad_dossier_id) { Dossier.count + 10000 }
|
||||
|
|
Loading…
Reference in a new issue