Refactor procedure locked and retrieve management
This commit is contained in:
parent
de0acc0a22
commit
9fb575ef8c
9 changed files with 32 additions and 37 deletions
|
@ -1,5 +1,6 @@
|
|||
class Admin::PiecesJustificativesController < AdminController
|
||||
before_action :retrieve_procedure
|
||||
before_action :procedure_locked?
|
||||
|
||||
def show
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Admin::ProceduresController < AdminController
|
||||
|
||||
before_action :retrieve_procedure, only: :edit
|
||||
before_action :retrieve_procedure, only: [:show, :edit]
|
||||
before_action :procedure_locked?, only: [:edit]
|
||||
|
||||
def index
|
||||
@procedures = current_administrateur.procedures.where(archived: false)
|
||||
|
@ -15,13 +16,10 @@ class Admin::ProceduresController < AdminController
|
|||
end
|
||||
|
||||
def show
|
||||
informations
|
||||
|
||||
@facade = AdminProceduresShowFacades.new @procedure
|
||||
@facade = AdminProceduresShowFacades.new @procedure.decorate
|
||||
end
|
||||
|
||||
def edit
|
||||
informations
|
||||
end
|
||||
|
||||
def new
|
||||
|
@ -83,12 +81,4 @@ class Admin::ProceduresController < AdminController
|
|||
def create_module_api_carto_params
|
||||
params.require(:procedure).require(:module_api_carto_attributes).permit(:id, :use_api_carto, :quartiers_prioritaires, :cadastre)
|
||||
end
|
||||
|
||||
def informations
|
||||
@procedure = current_administrateur.procedures.find(params[:id]).decorate
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
flash.alert = 'Procédure inéxistante'
|
||||
redirect_to admin_procedures_path
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Admin::TypesDeChampController < AdminController
|
||||
before_action :retrieve_procedure
|
||||
|
||||
before_action :procedure_locked?
|
||||
|
||||
def destroy
|
||||
@procedure.types_de_champ.destroy(params[:id])
|
||||
render 'show', format: :js
|
||||
|
|
|
@ -6,15 +6,19 @@ class AdminController < ApplicationController
|
|||
end
|
||||
|
||||
def retrieve_procedure
|
||||
id = params[:procedure_id] || params[:id ]
|
||||
id = params[:procedure_id] || params[:id]
|
||||
|
||||
@procedure = current_administrateur.procedures.find(id)
|
||||
|
||||
if @procedure.locked?
|
||||
render json: {message: 'Procedure locked'}, status: 403
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render json: {message: 'Procedure not found'}, status: 404
|
||||
flash.alert = 'Procédure inéxistante'
|
||||
redirect_to admin_procedures_path, status: 404
|
||||
end
|
||||
|
||||
def procedure_locked?
|
||||
if @procedure.locked?
|
||||
flash.alert = 'Procédure verrouillée'
|
||||
redirect_to admin_procedure_path(id: @procedure.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
#procedure_show
|
||||
%h2.text-info
|
||||
=@procedure.libelle
|
||||
=@facade.procedure.libelle
|
||||
%br
|
||||
|
||||
%ul.nav.nav-tabs
|
||||
%li.active
|
||||
= link_to('Informations', admin_procedure_path(@procedure))
|
||||
= link_to('Informations', admin_procedure_path(@facade.procedure))
|
||||
|
||||
%li{ class: ('disabled' if @procedure.locked?) }
|
||||
= link_to_unless(@procedure.locked?, 'Description', edit_admin_procedure_path(@procedure)) do
|
||||
%li{ class: ('disabled' if @facade.procedure.locked?) }
|
||||
= link_to_unless(@facade.procedure.locked?, 'Description', edit_admin_procedure_path(@facade.procedure)) do
|
||||
= link_to('Description', '#')
|
||||
|
||||
%li{ class: ('disabled' if @procedure.locked?) }
|
||||
= link_to_unless(@procedure.locked?, 'Champs', admin_procedure_types_de_champ_path(@procedure)) do
|
||||
%li{ class: ('disabled' if @facade.procedure.locked?) }
|
||||
= link_to_unless(@facade.procedure.locked?, 'Champs', admin_procedure_types_de_champ_path(@facade.procedure)) do
|
||||
= link_to('Champs', '#')
|
||||
|
||||
%li{ class: ('disabled' if @procedure.locked?) }
|
||||
= link_to_unless(@procedure.locked?, 'Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) do
|
||||
%li{ class: ('disabled' if @facade.procedure.locked?) }
|
||||
= link_to_unless(@facade.procedure.locked?, 'Pièces justificatives', admin_procedure_pieces_justificatives_path(@facade.procedure)) do
|
||||
= link_to('Pièces justificatives', '#')
|
||||
|
||||
|
||||
%li{style:'float:right'}
|
||||
= form_tag admin_procedure_archive_path(procedure_id: @procedure.id, archive: !@procedure.archived?), method: :put do
|
||||
= form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archived?), method: :put do
|
||||
%button#archive.btn.btn-nav.text-info{type: :button}
|
||||
%i.fa.fa-eraser
|
||||
- if @procedure.archived
|
||||
- if @facade.procedure.archived
|
||||
= 'Réactiver'
|
||||
- else
|
||||
= 'Archiver'
|
||||
|
@ -36,7 +36,7 @@
|
|||
%i.fa.fa-remove
|
||||
Annuler
|
||||
|
||||
- if @procedure.locked?
|
||||
- if @facade.procedure.locked?
|
||||
#procedure_locked.center
|
||||
%h5
|
||||
.label.label-info La procédure ne peut plus être modifiée car un usagé a déjà déposé un dossier
|
||||
|
@ -44,7 +44,7 @@
|
|||
%div
|
||||
%h3 Lien procédure
|
||||
%div{style:'margin-left:3%'}
|
||||
= @procedure.lien
|
||||
= @facade.procedure.lien
|
||||
|
||||
%br
|
||||
%h3 Dossiers
|
||||
|
|
|
@ -19,7 +19,7 @@ describe Admin::PiecesJustificativesController, type: :controller do
|
|||
|
||||
context 'when procedure have at least a file' do
|
||||
let!(:dossier) { create(:dossier, :with_user, procedure: procedure, state: :initiated) }
|
||||
it { expect(subject.status).to eq(403) }
|
||||
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
|
||||
end
|
||||
|
||||
context 'when procedure does not belong to admin' do
|
||||
|
|
|
@ -68,7 +68,7 @@ describe Admin::ProceduresController, type: :controller do
|
|||
|
||||
context 'when procedure have at least a file' do
|
||||
let!(:dossier) { create(:dossier, :with_user, procedure: procedure, state: :initiated) }
|
||||
it { expect(subject.status).to eq(403) }
|
||||
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
|
||||
end
|
||||
|
||||
context "when procedure doesn't exist" do
|
||||
|
|
|
@ -21,7 +21,7 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
|
||||
context 'when procedure have at least a file' do
|
||||
let!(:dossier) { create(:dossier, :with_user, procedure: procedure, state: :initiated) }
|
||||
it { expect(subject.status).to eq(403) }
|
||||
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
|
||||
end
|
||||
|
||||
context 'when procedure does not belong to admin' do
|
||||
|
|
|
@ -4,8 +4,7 @@ describe 'admin/procedures/show.html.haml', type: :view do
|
|||
let(:procedure) { create(:procedure) }
|
||||
|
||||
before do
|
||||
assign(:procedure, procedure.decorate)
|
||||
assign(:facade, AdminProceduresShowFacades.new(procedure))
|
||||
assign(:facade, AdminProceduresShowFacades.new(procedure.decorate))
|
||||
|
||||
render
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue