Drop procedure dossiers when updating brouillon
This commit is contained in:
parent
3be678dbe5
commit
7237ff80cc
8 changed files with 63 additions and 13 deletions
|
@ -1,6 +1,7 @@
|
||||||
class Admin::PiecesJustificativesController < AdminController
|
class Admin::PiecesJustificativesController < AdminController
|
||||||
before_action :retrieve_procedure
|
before_action :retrieve_procedure
|
||||||
before_action :procedure_locked?
|
before_action :procedure_locked?
|
||||||
|
before_action :reset_procedure, only: [:update, :destroy, :move_up, :move_down]
|
||||||
|
|
||||||
def show
|
def show
|
||||||
end
|
end
|
||||||
|
@ -22,12 +23,6 @@ class Admin::PiecesJustificativesController < AdminController
|
||||||
render json: { message: 'Type de piece justificative not found' }, status: 404
|
render json: { message: 'Type de piece justificative not found' }, status: 404
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_params
|
|
||||||
params
|
|
||||||
.require(:procedure)
|
|
||||||
.permit(types_de_piece_justificative_attributes: [:libelle, :description, :id, :order_place, :mandatory, :lien_demarche])
|
|
||||||
end
|
|
||||||
|
|
||||||
def move_up
|
def move_up
|
||||||
index = params[:index].to_i - 1
|
index = params[:index].to_i - 1
|
||||||
if @procedure.switch_types_de_piece_justificative index
|
if @procedure.switch_types_de_piece_justificative index
|
||||||
|
@ -44,4 +39,12 @@ class Admin::PiecesJustificativesController < AdminController
|
||||||
render json: {}, status: 400
|
render json: {}, status: 400
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def update_params
|
||||||
|
params
|
||||||
|
.require(:procedure)
|
||||||
|
.permit(types_de_piece_justificative_attributes: [:libelle, :description, :id, :order_place, :mandatory, :lien_demarche])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -83,11 +83,12 @@ class Admin::ProceduresController < AdminController
|
||||||
@procedure = current_administrateur.procedures.find(params[:id])
|
@procedure = current_administrateur.procedures.find(params[:id])
|
||||||
|
|
||||||
if !@procedure.update(procedure_params)
|
if !@procedure.update(procedure_params)
|
||||||
flash.now.alert = @procedure.errors.full_messages
|
flash.alert = @procedure.errors.full_messages
|
||||||
return render 'edit'
|
else
|
||||||
|
reset_procedure
|
||||||
|
flash.notice = 'Procédure modifiée'
|
||||||
end
|
end
|
||||||
|
|
||||||
flash.notice = 'Procédure modifiée'
|
|
||||||
redirect_to edit_admin_procedure_path(id: @procedure.id)
|
redirect_to edit_admin_procedure_path(id: @procedure.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class Admin::TypesDeChampController < AdminController
|
class Admin::TypesDeChampController < AdminController
|
||||||
before_action :retrieve_procedure
|
before_action :retrieve_procedure
|
||||||
before_action :procedure_locked?
|
before_action :procedure_locked?
|
||||||
|
before_action :reset_procedure, only: [:update, :destroy, :move_up, :move_down]
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@procedure.types_de_champ.destroy(params[:id])
|
@procedure.types_de_champ.destroy(params[:id])
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class Admin::TypesDeChampPrivateController < AdminController
|
class Admin::TypesDeChampPrivateController < AdminController
|
||||||
before_action :retrieve_procedure
|
before_action :retrieve_procedure
|
||||||
before_action :procedure_locked?
|
before_action :procedure_locked?
|
||||||
|
before_action :reset_procedure, only: [:update, :destroy, :move_up, :move_down]
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@procedure.types_de_champ_private.destroy(params[:id])
|
@procedure.types_de_champ_private.destroy(params[:id])
|
||||||
|
|
|
@ -21,4 +21,10 @@ class AdminController < ApplicationController
|
||||||
redirect_to admin_procedure_path(id: @procedure.id)
|
redirect_to admin_procedure_path(id: @procedure.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reset_procedure
|
||||||
|
if @procedure.brouillon_avec_lien?
|
||||||
|
@procedure.reset!
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -109,6 +109,14 @@ class Procedure < ApplicationRecord
|
||||||
dossiers.update_all(hidden_at: now)
|
dossiers.update_all(hidden_at: now)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reset!
|
||||||
|
if locked?
|
||||||
|
raise "Can not reset a locked procedure."
|
||||||
|
else
|
||||||
|
dossiers.delete_all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def locked?
|
def locked?
|
||||||
publiee_ou_archivee?
|
publiee_ou_archivee?
|
||||||
end
|
end
|
||||||
|
|
|
@ -258,7 +258,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when administrateur is connected' do
|
context 'when administrateur is connected' do
|
||||||
before do
|
def update_procedure
|
||||||
put :update, params: { id: procedure.id, procedure: procedure_params }
|
put :update, params: { id: procedure.id, procedure: procedure_params }
|
||||||
procedure.reload
|
procedure.reload
|
||||||
end
|
end
|
||||||
|
@ -274,6 +274,8 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
let(:duree_conservation_dossiers_dans_ds) { 7 }
|
let(:duree_conservation_dossiers_dans_ds) { 7 }
|
||||||
let(:duree_conservation_dossiers_hors_ds) { 5 }
|
let(:duree_conservation_dossiers_hors_ds) { 5 }
|
||||||
|
|
||||||
|
before { update_procedure }
|
||||||
|
|
||||||
describe 'procedure attributs in database' do
|
describe 'procedure attributs in database' do
|
||||||
subject { procedure }
|
subject { procedure }
|
||||||
|
|
||||||
|
@ -299,6 +301,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when many attributs are not valid' do
|
context 'when many attributs are not valid' do
|
||||||
|
before { update_procedure }
|
||||||
let(:libelle) { '' }
|
let(:libelle) { '' }
|
||||||
let(:description) { '' }
|
let(:description) { '' }
|
||||||
|
|
||||||
|
@ -315,12 +318,30 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when procedure is brouillon' do
|
||||||
|
let(:procedure) { create(:procedure_with_dossiers, :with_path, :with_type_de_champ, :with_two_type_de_piece_justificative, administrateur: admin) }
|
||||||
|
let!(:dossiers_count) { procedure.dossiers.count }
|
||||||
|
|
||||||
|
describe 'dossiers are dropped' do
|
||||||
|
before do
|
||||||
|
Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { update_procedure }
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(dossiers_count).to eq(1)
|
||||||
|
expect(subject.dossiers.count).to eq(0)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when procedure is published' do
|
context 'when procedure is published' do
|
||||||
let!(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, :published, administrateur: admin) }
|
let(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, :published, administrateur: admin) }
|
||||||
|
|
||||||
|
subject { update_procedure }
|
||||||
|
|
||||||
describe 'only some properties can be updated' do
|
describe 'only some properties can be updated' do
|
||||||
subject { procedure }
|
|
||||||
|
|
||||||
it { expect(subject.libelle).to eq procedure_params[:libelle] }
|
it { expect(subject.libelle).to eq procedure_params[:libelle] }
|
||||||
it { expect(subject.description).to eq procedure_params[:description] }
|
it { expect(subject.description).to eq procedure_params[:description] }
|
||||||
it { expect(subject.organisation).to eq procedure_params[:organisation] }
|
it { expect(subject.organisation).to eq procedure_params[:organisation] }
|
||||||
|
|
|
@ -29,6 +29,15 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :with_path do
|
||||||
|
after(:create) do |procedure|
|
||||||
|
create(:procedure_path,
|
||||||
|
procedure: procedure,
|
||||||
|
administrateur: procedure.administrateur,
|
||||||
|
path: generate(:published_path))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
trait :with_service do
|
trait :with_service do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
procedure.service = create(:service)
|
procedure.service = create(:service)
|
||||||
|
|
Loading…
Reference in a new issue