When procedure is archived user can update dossier if not in brouillon
This commit is contained in:
parent
88654535ea
commit
7e4f473027
5 changed files with 30 additions and 13 deletions
|
@ -17,7 +17,7 @@ class Users::DescriptionController < UsersController
|
|||
acc
|
||||
end
|
||||
|
||||
if @procedure.archived?
|
||||
unless @dossier.can_be_initiated?
|
||||
flash[:alert] = t('errors.messages.procedure_archived')
|
||||
end
|
||||
|
||||
|
@ -30,7 +30,7 @@ class Users::DescriptionController < UsersController
|
|||
@dossier = current_user_dossier
|
||||
@procedure = @dossier.procedure
|
||||
|
||||
return head :forbidden if @procedure.archived?
|
||||
return head :forbidden unless @dossier.can_be_initiated?
|
||||
|
||||
@champs = @dossier.ordered_champs
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -46,11 +46,10 @@
|
|||
%div{style: 'text-align:right'}
|
||||
%h6 Tous les champs portant un * sont obligatoires.
|
||||
|
||||
- if @procedure.archived?
|
||||
- if !@dossier.can_be_initiated?
|
||||
.alert.alert-danger
|
||||
= t('errors.messages.procedure_archived')
|
||||
- else
|
||||
- if !@dossier.draft?
|
||||
- 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}
|
||||
|
|
|
@ -24,14 +24,21 @@ shared_examples 'description_controller_spec' do
|
|||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
context 'but procedure is archived' do
|
||||
let(:archived) { true }
|
||||
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
|
||||
get :show, params: {dossier_id: bad_dossier_id}
|
||||
|
@ -297,9 +304,15 @@ shared_examples 'description_controller_spec' 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
|
||||
let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids }
|
||||
|
|
|
@ -6,9 +6,10 @@ describe Users::DescriptionController, type: :controller, vcr: {cassette_name: '
|
|||
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, archived: archived) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: 'initiated') }
|
||||
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