transition from accepte to instruction as superadmin
This commit is contained in:
parent
85378ae193
commit
38b48f4217
7 changed files with 65 additions and 3 deletions
|
@ -108,10 +108,14 @@ module Gestionnaires
|
|||
def repasser_en_instruction
|
||||
if dossier.en_instruction?
|
||||
flash.notice = 'Le dossier est déjà en instruction.'
|
||||
else
|
||||
if dossier.accepte? && !administration_signed_in?
|
||||
flash.notice = 'Il n\'est pas possible de repasser un dossier accepte en instruction.'
|
||||
else
|
||||
flash.notice = "Le dossier #{dossier.id} a été repassé en instruction."
|
||||
dossier.repasser_en_instruction!(current_gestionnaire)
|
||||
end
|
||||
end
|
||||
|
||||
render partial: 'state_button_refresh', locals: { dossier: dossier }
|
||||
end
|
||||
|
|
|
@ -30,6 +30,16 @@ module Manager
|
|||
redirect_to manager_dossier_path(dossier)
|
||||
end
|
||||
|
||||
def repasser_en_instruction
|
||||
dossier = Dossier.find(params[:id])
|
||||
dossier.repasser_en_instruction(current_administration)
|
||||
|
||||
logger.info("Le dossier #{dossier.id} est repassé en instruction par #{current_administration.email}")
|
||||
flash[:notice] = "Le dossier #{dossier.id} est repassé en instruction."
|
||||
|
||||
redirect_to manager_dossier_path(dossier)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unfiltered_list?
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class Dossier < ApplicationRecord
|
||||
include DossierFilteringConcern
|
||||
include Devise::Controllers::Helpers
|
||||
|
||||
enum state: {
|
||||
brouillon: 'brouillon',
|
||||
|
@ -86,6 +87,7 @@ class Dossier < ApplicationRecord
|
|||
event :repasser_en_instruction, after: :after_repasser_en_instruction do
|
||||
transitions from: :refuse, to: :en_instruction
|
||||
transitions from: :sans_suite, to: :en_instruction
|
||||
transitions from: :accepte, to: :en_instruction
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -228,6 +230,9 @@ class Dossier < ApplicationRecord
|
|||
!procedure.archivee? && brouillon?
|
||||
end
|
||||
|
||||
def can_retransition_to_en_instruction?
|
||||
end
|
||||
|
||||
def can_be_updated_by_user?
|
||||
brouillon? || en_construction?
|
||||
end
|
||||
|
|
|
@ -28,6 +28,9 @@ as well as a link to its edit page.
|
|||
</h1>
|
||||
|
||||
<div>
|
||||
<% if dossier.accepte? %>
|
||||
<%= link_to 'Repasser en instruction', repasser_en_instruction_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous le passage en instruction du dossier ?" } %>
|
||||
<% end %>
|
||||
<% if dossier.hidden_at.nil? %>
|
||||
<%= link_to 'Supprimer le dossier', hide_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous la suppression du dossier ?" } %>
|
||||
<% end %>
|
||||
|
|
|
@ -16,6 +16,7 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :dossiers, only: [:index, :show] do
|
||||
post 'hide', on: :member
|
||||
post 'repasser_en_instruction', on: :member
|
||||
end
|
||||
|
||||
resources :administrateurs, only: [:index, :show, :new, :create] do
|
||||
|
|
|
@ -4,6 +4,8 @@ describe Gestionnaires::DossiersController, type: :controller do
|
|||
render_views
|
||||
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
let(:administration) { create(:administration) }
|
||||
let(:gestionnaires) { [gestionnaire] }
|
||||
let(:procedure) { create(:procedure, :published, gestionnaires: gestionnaires) }
|
||||
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||
|
@ -153,9 +155,10 @@ describe Gestionnaires::DossiersController, type: :controller do
|
|||
|
||||
describe '#repasser_en_instruction' do
|
||||
let(:dossier) { create(:dossier, :refuse, procedure: procedure) }
|
||||
let(:current_user) { gestionnaire }
|
||||
|
||||
before do
|
||||
sign_in gestionnaire
|
||||
sign_in current_user
|
||||
post :repasser_en_instruction,
|
||||
params: { procedure_id: procedure.id, dossier_id: dossier.id },
|
||||
format: 'js'
|
||||
|
@ -173,6 +176,29 @@ describe Gestionnaires::DossiersController, type: :controller do
|
|||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the dossier is accepte' do
|
||||
let(:dossier) { create(:dossier, :accepte, procedure: procedure) }
|
||||
|
||||
it 'it is not possible to go back to en_instruction as gestionnaire' do
|
||||
expect(dossier.reload.state).to eq(Dossier.states.fetch(:accepte))
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
context 'as administrateur' do
|
||||
let (:current_user) { administrateur }
|
||||
it 'it is not possible to go back to en_instruction' do
|
||||
expect(dossier.reload.state).to eq(Dossier.states.fetch(:accepte))
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
end
|
||||
context 'as superadmin' do
|
||||
let (:current_user) { administration }
|
||||
it 'it is not possible to go back to en_instruction' do
|
||||
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#terminer' do
|
||||
|
|
|
@ -11,4 +11,17 @@ describe Manager::DossiersController, type: :controller do
|
|||
|
||||
it { expect(dossier.hidden_at).not_to be_nil }
|
||||
end
|
||||
|
||||
describe '#repasser_en_instruction' do
|
||||
let(:administration) { create :administration }
|
||||
let!(:dossier) { create(:dossier, :accepte) }
|
||||
|
||||
before do
|
||||
sign_in administration
|
||||
post :repasser_en_instruction, params: { id: dossier.id }
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { expect(dossier.en_instruction?).to be true }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue