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,12 +46,11 @@
|
|||
%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')
|
||||
- elsif !@dossier.draft?
|
||||
= render partial: '/layouts/modifications_terminees'
|
||||
- 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}
|
||||
= 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}
|
||||
|
|
|
@ -24,12 +24,19 @@ 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 have_content(I18n.t('errors.messages.procedure_archived')) }
|
||||
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
|
||||
|
||||
|
@ -297,7 +304,13 @@ shared_examples 'description_controller_spec' do
|
|||
post :update, params: { dossier_id: dossier.id }
|
||||
end
|
||||
|
||||
it { expect(response.status).to eq(403) }
|
||||
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
|
||||
|
||||
|
|
|
@ -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