Merge pull request #8272 from tchak/feat-procedure-change-brouillon-rebase
feat(revision): allow more dossiers to rebase
This commit is contained in:
commit
f970347c93
10 changed files with 145 additions and 54 deletions
|
@ -4,20 +4,4 @@ class AdminController < ApplicationController
|
||||||
def index
|
def index
|
||||||
redirect_to(admin_procedures_path)
|
redirect_to(admin_procedures_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def retrieve_procedure
|
|
||||||
id = params[:procedure_id] || params[:id]
|
|
||||||
|
|
||||||
@procedure = current_administrateur.procedures.find(id)
|
|
||||||
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
|
||||||
flash.alert = 'Démarche inexistante'
|
|
||||||
redirect_to admin_procedures_path, status: 404
|
|
||||||
end
|
|
||||||
|
|
||||||
def reset_procedure
|
|
||||||
if @procedure.brouillon?
|
|
||||||
@procedure.reset!
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,9 +13,7 @@ module Administrateurs
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_procedure
|
def reset_procedure
|
||||||
if @procedure.brouillon? || @procedure.draft_changed?
|
@procedure.reset!
|
||||||
@procedure.reset!
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_not_super_admin!
|
def ensure_not_super_admin!
|
||||||
|
|
|
@ -3,6 +3,7 @@ module Administrateurs
|
||||||
include Logic
|
include Logic
|
||||||
|
|
||||||
before_action :retrieve_procedure, :retrieve_coordinate_and_uppers
|
before_action :retrieve_procedure, :retrieve_coordinate_and_uppers
|
||||||
|
after_action :reset_procedure
|
||||||
|
|
||||||
def update
|
def update
|
||||||
condition = condition_form.to_condition
|
condition = condition_form.to_condition
|
||||||
|
|
|
@ -4,6 +4,7 @@ module Administrateurs
|
||||||
|
|
||||||
before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :zones, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :close, :allow_expert_review, :experts_require_administrateur_invitation, :reset_draft]
|
before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :zones, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :close, :allow_expert_review, :experts_require_administrateur_invitation, :reset_draft]
|
||||||
before_action :draft_valid?, only: [:apercu]
|
before_action :draft_valid?, only: [:apercu]
|
||||||
|
after_action :reset_procedure, only: [:update]
|
||||||
|
|
||||||
ITEMS_PER_PAGE = 25
|
ITEMS_PER_PAGE = 25
|
||||||
|
|
||||||
|
@ -139,7 +140,6 @@ module Administrateurs
|
||||||
render 'edit'
|
render 'edit'
|
||||||
end
|
end
|
||||||
elsif @procedure.brouillon?
|
elsif @procedure.brouillon?
|
||||||
reset_procedure
|
|
||||||
flash.notice = 'Démarche modifiée. Tous les dossiers de cette démarche ont été supprimés.'
|
flash.notice = 'Démarche modifiée. Tous les dossiers de cette démarche ont été supprimés.'
|
||||||
redirect_to admin_procedure_path(id: @procedure.id)
|
redirect_to admin_procedure_path(id: @procedure.id)
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
module Administrateurs
|
module Administrateurs
|
||||||
class TypesDeChampController < AdministrateurController
|
class TypesDeChampController < AdministrateurController
|
||||||
before_action :retrieve_procedure
|
before_action :retrieve_procedure
|
||||||
|
after_action :reset_procedure, only: [:create, :update, :destroy]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
type_de_champ = draft.add_type_de_champ(type_de_champ_create_params)
|
type_de_champ = draft.add_type_de_champ(type_de_champ_create_params)
|
||||||
|
@ -10,7 +11,6 @@ module Administrateurs
|
||||||
@created = champ_component_from(@coordinate, focused: true)
|
@created = champ_component_from(@coordinate, focused: true)
|
||||||
@morphed = champ_components_starting_at(@coordinate, 1)
|
@morphed = champ_components_starting_at(@coordinate, 1)
|
||||||
|
|
||||||
reset_procedure
|
|
||||||
flash.notice = "Formulaire enregistré"
|
flash.notice = "Formulaire enregistré"
|
||||||
else
|
else
|
||||||
flash.alert = type_de_champ.errors.full_messages
|
flash.alert = type_de_champ.errors.full_messages
|
||||||
|
@ -24,7 +24,6 @@ module Administrateurs
|
||||||
@coordinate = draft.coordinate_for(type_de_champ)
|
@coordinate = draft.coordinate_for(type_de_champ)
|
||||||
@morphed = champ_components_starting_at(@coordinate)
|
@morphed = champ_components_starting_at(@coordinate)
|
||||||
|
|
||||||
reset_procedure
|
|
||||||
flash.notice = "Formulaire enregistré"
|
flash.notice = "Formulaire enregistré"
|
||||||
else
|
else
|
||||||
flash.alert = type_de_champ.errors.full_messages
|
flash.alert = type_de_champ.errors.full_messages
|
||||||
|
@ -69,7 +68,6 @@ module Administrateurs
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@coordinate = draft.remove_type_de_champ(params[:stable_id])
|
@coordinate = draft.remove_type_de_champ(params[:stable_id])
|
||||||
reset_procedure
|
|
||||||
flash.notice = "Formulaire enregistré"
|
flash.notice = "Formulaire enregistré"
|
||||||
|
|
||||||
if @coordinate.present?
|
if @coordinate.present?
|
||||||
|
|
|
@ -9,6 +9,10 @@ module DossierRebaseConcern
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rebase_later
|
||||||
|
DossierRebaseJob.perform_later(self)
|
||||||
|
end
|
||||||
|
|
||||||
def can_rebase?
|
def can_rebase?
|
||||||
revision != procedure.published_revision &&
|
revision != procedure.published_revision &&
|
||||||
(brouillon? || accepted_en_construction_changes? || accepted_en_instruction_changes?)
|
(brouillon? || accepted_en_construction_changes? || accepted_en_instruction_changes?)
|
||||||
|
@ -21,34 +25,32 @@ module DossierRebaseConcern
|
||||||
private
|
private
|
||||||
|
|
||||||
def accepted_en_construction_changes?
|
def accepted_en_construction_changes?
|
||||||
en_construction? && pending_changes.all? { |change| accepted_en_construction_change?(change) }
|
en_construction? && pending_changes.all? { |change| accepted_change?(change) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def accepted_en_instruction_changes?
|
def accepted_en_instruction_changes?
|
||||||
en_instruction? && pending_changes.all? { |change| accepted_en_instruction_change?(change) }
|
en_instruction? && pending_changes.all? { |change| accepted_change?(change) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def accepted_en_construction_change?(change)
|
def accepted_change?(change)
|
||||||
if change[:op] == :move || change[:op] == :remove
|
return true if change[:private]
|
||||||
true
|
return true if change[:op].in?([:remove, :move])
|
||||||
elsif change[:op] == :update
|
return !change[:mandatory] if change[:op] == :add
|
||||||
case change[:attribute]
|
|
||||||
when :carte_layers
|
case change[:attribute]
|
||||||
true
|
when :drop_down_options
|
||||||
when :mandatory
|
(change[:from] - change[:to]).empty?
|
||||||
change[:from] && !change[:to]
|
when :drop_down_other
|
||||||
else
|
!change[:from] && change[:to]
|
||||||
false
|
when :mandatory
|
||||||
end
|
change[:from] && !change[:to]
|
||||||
else
|
when :type_champ, :condition
|
||||||
false
|
false
|
||||||
|
else
|
||||||
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def accepted_en_instruction_change?(change)
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
def rebase
|
def rebase
|
||||||
# revision we are rebasing to
|
# revision we are rebasing to
|
||||||
target_revision = procedure.published_revision
|
target_revision = procedure.published_revision
|
||||||
|
@ -93,12 +95,14 @@ module DossierRebaseConcern
|
||||||
def apply(change, champs)
|
def apply(change, champs)
|
||||||
case change[:attribute]
|
case change[:attribute]
|
||||||
when :type_champ
|
when :type_champ
|
||||||
champs.each { |champ| champ.piece_justificative_file.purge_later } # FIX ME: change updated_at
|
champs.each { |champ| purge_piece_justificative_file(champ) }
|
||||||
GeoArea.where(champ: champs).destroy_all
|
GeoArea.where(champ: champs).destroy_all
|
||||||
|
Etablissement.where(champ: champs).destroy_all
|
||||||
|
|
||||||
{
|
{
|
||||||
type: "Champs::#{change[:to].classify}Champ",
|
type: "Champs::#{change[:to].classify}Champ",
|
||||||
value: nil,
|
value: nil,
|
||||||
|
value_json: nil,
|
||||||
external_id: nil,
|
external_id: nil,
|
||||||
data: nil
|
data: nil
|
||||||
}
|
}
|
||||||
|
@ -152,4 +156,8 @@ module DossierRebaseConcern
|
||||||
.where(dossier: self, types_de_champ: { stable_id: stable_id })
|
.where(dossier: self, types_de_champ: { stable_id: stable_id })
|
||||||
.destroy_all
|
.destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def purge_piece_justificative_file(champ)
|
||||||
|
ActiveStorage::Attachment.where(id: champ.piece_justificative_file.ids).delete_all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -783,7 +783,7 @@ class Procedure < ApplicationRecord
|
||||||
end
|
end
|
||||||
dossiers
|
dossiers
|
||||||
.state_not_termine
|
.state_not_termine
|
||||||
.find_each { |dossier| DossierRebaseJob.perform_later(dossier) }
|
.find_each(&:rebase_later)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_draft_revision!
|
def reset_draft_revision!
|
||||||
|
|
|
@ -252,7 +252,7 @@ class ProcedureRevision < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
added = (to_sids - from_sids).map do |sid|
|
added = (to_sids - from_sids).map do |sid|
|
||||||
{ model: :type_de_champ, op: :add, label: to_h[sid].libelle, private: to_h[sid].private?, _position: to_sids.index(sid), stable_id: sid }
|
{ model: :type_de_champ, op: :add, label: to_h[sid].libelle, private: to_h[sid].private?, mandatory: to_h[sid].mandatory?, _position: to_sids.index(sid), stable_id: sid }
|
||||||
end
|
end
|
||||||
|
|
||||||
kept = from_sids.intersection(to_sids)
|
kept = from_sids.intersection(to_sids)
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
describe Dossier do
|
describe Dossier do
|
||||||
describe '#can_rebase?' do
|
describe '#can_rebase?' do
|
||||||
let(:procedure) { create(:procedure, :with_type_de_champ_mandatory, :with_yes_no, attestation_template: build(:attestation_template)) }
|
let(:procedure) { create(:procedure, :with_type_de_champ_mandatory, :with_type_de_champ_private, :with_yes_no) }
|
||||||
let(:attestation_template) { procedure.draft_revision.attestation_template.find_or_revise! }
|
let(:attestation_template) { procedure.draft_revision.attestation_template.find_or_revise! }
|
||||||
let(:type_de_champ) { procedure.active_revision.types_de_champ_public.find { |tdc| !tdc.mandatory? } }
|
let(:type_de_champ) { procedure.active_revision.types_de_champ_public.find { |tdc| !tdc.mandatory? } }
|
||||||
|
let(:private_type_de_champ) { procedure.active_revision.types_de_champ_private.first }
|
||||||
let(:mandatory_type_de_champ) { procedure.active_revision.types_de_champ_public.find(&:mandatory?) }
|
let(:mandatory_type_de_champ) { procedure.active_revision.types_de_champ_public.find(&:mandatory?) }
|
||||||
|
|
||||||
before { Flipper.enable(:procedure_revisions, procedure) }
|
|
||||||
|
|
||||||
context 'en_construction' do
|
context 'en_construction' do
|
||||||
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||||
|
|
||||||
|
@ -26,6 +25,23 @@ describe Dossier do
|
||||||
dossier.reload
|
dossier.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should be true' do
|
||||||
|
expect(dossier.pending_changes).not_to be_empty
|
||||||
|
expect(dossier.can_rebase?).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with added mandatory type de champ' do
|
||||||
|
before do
|
||||||
|
procedure.draft_revision.add_type_de_champ({
|
||||||
|
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
||||||
|
libelle: "Un champ text",
|
||||||
|
mandatory: true
|
||||||
|
})
|
||||||
|
procedure.publish_revision!
|
||||||
|
dossier.reload
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be false' do
|
it 'should be false' do
|
||||||
expect(dossier.pending_changes).not_to be_empty
|
expect(dossier.pending_changes).not_to be_empty
|
||||||
expect(dossier.can_rebase?).to be_falsey
|
expect(dossier.can_rebase?).to be_falsey
|
||||||
|
@ -58,6 +74,34 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with type de champ change type' do
|
||||||
|
context 'type de champ public' do
|
||||||
|
before do
|
||||||
|
procedure.draft_revision.find_and_ensure_exclusive_use(type_de_champ.stable_id).update(type_champ: :checkbox)
|
||||||
|
procedure.publish_revision!
|
||||||
|
dossier.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be false' do
|
||||||
|
expect(dossier.pending_changes).not_to be_empty
|
||||||
|
expect(dossier.can_rebase?).to be_falsey
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'type de champ private' do
|
||||||
|
before do
|
||||||
|
procedure.draft_revision.find_and_ensure_exclusive_use(private_type_de_champ.stable_id).update(type_champ: :checkbox)
|
||||||
|
procedure.publish_revision!
|
||||||
|
dossier.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be true' do
|
||||||
|
expect(dossier.pending_changes).not_to be_empty
|
||||||
|
expect(dossier.can_rebase?).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'with removed type de champ' do
|
context 'with removed type de champ' do
|
||||||
before do
|
before do
|
||||||
procedure.draft_revision.remove_type_de_champ(type_de_champ.stable_id)
|
procedure.draft_revision.remove_type_de_champ(type_de_champ.stable_id)
|
||||||
|
@ -91,15 +135,19 @@ describe Dossier do
|
||||||
dossier.reload
|
dossier.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be false' do
|
it 'should be true' do
|
||||||
expect(dossier.pending_changes).not_to be_empty
|
expect(dossier.pending_changes).not_to be_empty
|
||||||
expect(dossier.can_rebase?).to be_falsey
|
expect(dossier.can_rebase?).to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with removed type de champ' do
|
context 'with added mandatory type de champ' do
|
||||||
before do
|
before do
|
||||||
procedure.draft_revision.remove_type_de_champ(type_de_champ.stable_id)
|
procedure.draft_revision.add_type_de_champ({
|
||||||
|
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
||||||
|
libelle: "Un champ text",
|
||||||
|
mandatory: true
|
||||||
|
})
|
||||||
procedure.publish_revision!
|
procedure.publish_revision!
|
||||||
dossier.reload
|
dossier.reload
|
||||||
end
|
end
|
||||||
|
@ -117,11 +165,65 @@ describe Dossier do
|
||||||
dossier.reload
|
dossier.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should be true' do
|
||||||
|
expect(dossier.pending_changes).not_to be_empty
|
||||||
|
expect(dossier.can_rebase?).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with type de champ made mandatory' do
|
||||||
|
before do
|
||||||
|
procedure.draft_revision.find_and_ensure_exclusive_use(type_de_champ.stable_id).update(mandatory: true)
|
||||||
|
procedure.publish_revision!
|
||||||
|
dossier.reload
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be false' do
|
it 'should be false' do
|
||||||
expect(dossier.pending_changes).not_to be_empty
|
expect(dossier.pending_changes).not_to be_empty
|
||||||
expect(dossier.can_rebase?).to be_falsey
|
expect(dossier.can_rebase?).to be_falsey
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with type de champ change type' do
|
||||||
|
context 'type de champ public' do
|
||||||
|
before do
|
||||||
|
procedure.draft_revision.find_and_ensure_exclusive_use(type_de_champ.stable_id).update(type_champ: :checkbox)
|
||||||
|
procedure.publish_revision!
|
||||||
|
dossier.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be false' do
|
||||||
|
expect(dossier.pending_changes).not_to be_empty
|
||||||
|
expect(dossier.can_rebase?).to be_falsey
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'type de champ private' do
|
||||||
|
before do
|
||||||
|
procedure.draft_revision.find_and_ensure_exclusive_use(private_type_de_champ.stable_id).update(type_champ: :checkbox)
|
||||||
|
procedure.publish_revision!
|
||||||
|
dossier.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be true' do
|
||||||
|
expect(dossier.pending_changes).not_to be_empty
|
||||||
|
expect(dossier.can_rebase?).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with removed type de champ' do
|
||||||
|
before do
|
||||||
|
procedure.draft_revision.remove_type_de_champ(type_de_champ.stable_id)
|
||||||
|
procedure.publish_revision!
|
||||||
|
dossier.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be true' do
|
||||||
|
expect(dossier.pending_changes).not_to be_empty
|
||||||
|
expect(dossier.can_rebase?).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -330,8 +432,7 @@ describe Dossier do
|
||||||
it { expect { subject }.to change { first_champ.data }.from({ 'a' => 1 }).to(nil) }
|
it { expect { subject }.to change { first_champ.data }.from({ 'a' => 1 }).to(nil) }
|
||||||
it { expect { subject }.to change { first_champ.geo_areas.count }.from(1).to(0) }
|
it { expect { subject }.to change { first_champ.geo_areas.count }.from(1).to(0) }
|
||||||
it { expect { subject }.to change { first_champ.piece_justificative_file.attached? }.from(true).to(false) }
|
it { expect { subject }.to change { first_champ.piece_justificative_file.attached? }.from(true).to(false) }
|
||||||
# pb with pj.purge_later
|
it { expect { subject }.not_to change { first_champ.updated_at }.from(Time.zone.parse('01/01/1901')) }
|
||||||
xit { expect { subject }.not_to change { first_champ.updated_at }.from(Time.zone.parse('01/01/1901')) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -433,6 +433,7 @@ describe ProcedureRevision do
|
||||||
op: :add,
|
op: :add,
|
||||||
label: "Un champ text",
|
label: "Un champ text",
|
||||||
private: false,
|
private: false,
|
||||||
|
mandatory: false,
|
||||||
stable_id: new_tdc.stable_id
|
stable_id: new_tdc.stable_id
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
Loading…
Reference in a new issue