Merge pull request #2391 from tchak/reset-procedure
Drop procedure dossiers when updating brouillon
This commit is contained in:
commit
bd8eec56d2
9 changed files with 69 additions and 13 deletions
|
@ -1,6 +1,7 @@
|
|||
class Admin::PiecesJustificativesController < AdminController
|
||||
before_action :retrieve_procedure
|
||||
before_action :procedure_locked?
|
||||
before_action :reset_procedure, only: [:update, :destroy, :move_up, :move_down]
|
||||
|
||||
def show
|
||||
end
|
||||
|
@ -22,12 +23,6 @@ class Admin::PiecesJustificativesController < AdminController
|
|||
render json: { message: 'Type de piece justificative not found' }, status: 404
|
||||
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
|
||||
index = params[:index].to_i - 1
|
||||
if @procedure.switch_types_de_piece_justificative index
|
||||
|
@ -44,4 +39,12 @@ class Admin::PiecesJustificativesController < AdminController
|
|||
render json: {}, status: 400
|
||||
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
|
||||
|
|
|
@ -83,11 +83,12 @@ class Admin::ProceduresController < AdminController
|
|||
@procedure = current_administrateur.procedures.find(params[:id])
|
||||
|
||||
if !@procedure.update(procedure_params)
|
||||
flash.now.alert = @procedure.errors.full_messages
|
||||
return render 'edit'
|
||||
flash.alert = @procedure.errors.full_messages
|
||||
else
|
||||
reset_procedure
|
||||
flash.notice = 'Procédure modifiée'
|
||||
end
|
||||
|
||||
flash.notice = 'Procédure modifiée'
|
||||
redirect_to edit_admin_procedure_path(id: @procedure.id)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Admin::TypesDeChampController < AdminController
|
||||
before_action :retrieve_procedure
|
||||
before_action :procedure_locked?
|
||||
before_action :reset_procedure, only: [:update, :destroy, :move_up, :move_down]
|
||||
|
||||
def destroy
|
||||
@procedure.types_de_champ.destroy(params[:id])
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Admin::TypesDeChampPrivateController < AdminController
|
||||
before_action :retrieve_procedure
|
||||
before_action :procedure_locked?
|
||||
before_action :reset_procedure, only: [:update, :destroy, :move_up, :move_down]
|
||||
|
||||
def destroy
|
||||
@procedure.types_de_champ_private.destroy(params[:id])
|
||||
|
|
|
@ -21,4 +21,10 @@ class AdminController < ApplicationController
|
|||
redirect_to admin_procedure_path(id: @procedure.id)
|
||||
end
|
||||
end
|
||||
|
||||
def reset_procedure
|
||||
if @procedure.brouillon_avec_lien?
|
||||
@procedure.reset!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -109,10 +109,23 @@ class Procedure < ApplicationRecord
|
|||
dossiers.update_all(hidden_at: now)
|
||||
end
|
||||
|
||||
def reset!
|
||||
if locked?
|
||||
raise "Can not reset a locked procedure."
|
||||
else
|
||||
dossiers.delete_all
|
||||
end
|
||||
end
|
||||
|
||||
def locked?
|
||||
publiee_ou_archivee?
|
||||
end
|
||||
|
||||
# This method is needed for transition. Eventually this will be the same as brouillon?.
|
||||
def brouillon_avec_lien?
|
||||
Flipflop.publish_draft? && brouillon? && procedure_path.present?
|
||||
end
|
||||
|
||||
def publiee_ou_archivee?
|
||||
publiee? || archivee?
|
||||
end
|
||||
|
|
|
@ -16,6 +16,7 @@ Flipflop.configure do
|
|||
end
|
||||
|
||||
feature :web_hook
|
||||
feature :publish_draft
|
||||
|
||||
feature :new_dossier_details,
|
||||
title: "Nouvelle page « Dossier »"
|
||||
|
|
|
@ -258,7 +258,7 @@ describe Admin::ProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when administrateur is connected' do
|
||||
before do
|
||||
def update_procedure
|
||||
put :update, params: { id: procedure.id, procedure: procedure_params }
|
||||
procedure.reload
|
||||
end
|
||||
|
@ -274,6 +274,8 @@ describe Admin::ProceduresController, type: :controller do
|
|||
let(:duree_conservation_dossiers_dans_ds) { 7 }
|
||||
let(:duree_conservation_dossiers_hors_ds) { 5 }
|
||||
|
||||
before { update_procedure }
|
||||
|
||||
describe 'procedure attributs in database' do
|
||||
subject { procedure }
|
||||
|
||||
|
@ -299,6 +301,7 @@ describe Admin::ProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when many attributs are not valid' do
|
||||
before { update_procedure }
|
||||
let(:libelle) { '' }
|
||||
let(:description) { '' }
|
||||
|
||||
|
@ -315,12 +318,30 @@ describe Admin::ProceduresController, type: :controller do
|
|||
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
|
||||
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
|
||||
subject { procedure }
|
||||
|
||||
it { expect(subject.libelle).to eq procedure_params[:libelle] }
|
||||
it { expect(subject.description).to eq procedure_params[:description] }
|
||||
it { expect(subject.organisation).to eq procedure_params[:organisation] }
|
||||
|
|
|
@ -29,6 +29,15 @@ FactoryBot.define do
|
|||
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
|
||||
after(:build) do |procedure, _evaluator|
|
||||
procedure.service = create(:service)
|
||||
|
|
Loading…
Reference in a new issue