ETQ Administrateur, je voudrais que les dossiers non terminés soient toujours sur la dernière révision

This commit is contained in:
Paul Chavard 2024-12-09 14:17:23 +01:00
parent 7ed76c0bfb
commit 5e7585daea
No known key found for this signature in database
13 changed files with 35 additions and 293 deletions

View file

@ -25,8 +25,8 @@ class Dossiers::ChampsRowsShowComponent < ApplicationComponent
end end
def blank_key(champ) def blank_key(champ)
key = ".blank_optional" key = champ.mandatory? ? ".blank" : ".blank_optional"
key += "_attachment" if champ.type_de_champ.piece_justificative_or_titre_identite? key += "_attachment" if champ.piece_justificative_or_titre_identite?
key key
end end

View file

@ -1,4 +1,6 @@
--- ---
en: en:
blank_optional: "empty (optional)" blank: 'empty'
blank_optional_attachment: "document not supplied (optional)" blank_attachment: 'document not supplied'
blank_optional: 'empty (optional)'
blank_optional_attachment: 'document not supplied (optional)'

View file

@ -1,4 +1,6 @@
--- ---
fr: fr:
blank_optional: "non saisi (facultatif)" blank: 'non saisi'
blank_optional_attachment: "pièce justificative non saisie (facultative)" blank_attachment: 'pièce justificative non saisie'
blank_optional: 'non saisi (facultatif)'
blank_optional_attachment: 'pièce justificative non saisie (facultative)'

View file

@ -8,7 +8,6 @@ class Procedure::RevisionChangesComponent < ApplicationComponent
@tdc_changes = previous_revision.compare_types_de_champ(new_revision) @tdc_changes = previous_revision.compare_types_de_champ(new_revision)
@public_move_changes, @private_move_changes = @tdc_changes.filter { _1.op == :move }.partition { !_1.private? } @public_move_changes, @private_move_changes = @tdc_changes.filter { _1.op == :move }.partition { !_1.private? }
@delete_champ_warning = !total_dossiers.zero? && !@tdc_changes.all?(&:can_rebase?)
@ineligibilite_rules_changes = previous_revision.compare_ineligibilite_rules(new_revision) @ineligibilite_rules_changes = previous_revision.compare_ineligibilite_rules(new_revision)
end end
@ -18,11 +17,4 @@ class Procedure::RevisionChangesComponent < ApplicationComponent
def used_by_routing_rules?(type_de_champ) def used_by_routing_rules?(type_de_champ)
@procedure.used_by_routing_rules?(type_de_champ) @procedure.used_by_routing_rules?(type_de_champ)
end end
def total_dossiers
@total_dossiers ||= @previous_revision.dossiers
.visible_by_administration
.state_en_construction_ou_instruction
.size
end
end end

View file

@ -11,15 +11,9 @@
= t('.public.add_mandatory', label: change.label) = t('.public.add_mandatory', label: change.label)
- else - else
= t(".#{prefix}.add", label: change.label) = t(".#{prefix}.add", label: change.label)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- when :remove - when :remove
- list.with_item do - list.with_item do
= t(".#{prefix}.remove", label: change.label) = t(".#{prefix}.remove", label: change.label)
- if @delete_champ_warning
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.delete_champ_html', count: total_dossiers)
- when :update - when :update
- case change.attribute - case change.attribute
- when :libelle - when :libelle
@ -28,9 +22,6 @@
- when :type_champ - when :type_champ
- list.with_item do - list.with_item do
= t(".#{prefix}.update_type_champ", label: change.label, to: t("activerecord.attributes.type_de_champ.type_champs.#{change.to}")) = t(".#{prefix}.update_type_champ", label: change.label, to: t("activerecord.attributes.type_de_champ.type_champs.#{change.to}"))
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- when :description - when :description
- list.with_item do - list.with_item do
- if change.to.blank? - if change.to.blank?
@ -47,15 +38,9 @@
- if change.from == false - if change.from == false
- list.with_item do - list.with_item do
= t(".public.enable_mandatory", label: change.label) = t(".public.enable_mandatory", label: change.label)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- else - else
- list.with_item do - list.with_item do
= t(".public.disable_mandatory", label: change.label) = t(".public.disable_mandatory", label: change.label)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- when :piece_justificative_template - when :piece_justificative_template
- list.with_item do - list.with_item do
= t(".#{prefix}.update_piece_justificative_template", label: change.label) = t(".#{prefix}.update_piece_justificative_template", label: change.label)
@ -74,9 +59,6 @@
- if removed.present? - if removed.present?
- list.with_item do - list.with_item do
= t('.remove_option', items: removed.map{ |term| "« #{term.strip} »" }.join(", ")) = t('.remove_option', items: removed.map{ |term| "« #{term.strip} »" }.join(", "))
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- if (removed.present? || added.present? ) && used_by_routing_rules?(change.type_de_champ) - if (removed.present? || added.present? ) && used_by_routing_rules?(change.type_de_champ)
.fr-alert.fr-alert--warning.fr-mt-1v .fr-alert.fr-alert--warning.fr-mt-1v
= t(".#{prefix}.update_drop_down_options_alert", label: change.label) = t(".#{prefix}.update_drop_down_options_alert", label: change.label)
@ -84,15 +66,9 @@
- if change.from == false - if change.from == false
- list.with_item do - list.with_item do
= t(".#{prefix}.enable_drop_down_other", label: change.label) = t(".#{prefix}.enable_drop_down_other", label: change.label)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- else - else
- list.with_item do - list.with_item do
= t(".#{prefix}.disable_drop_down_other", label: change.label) = t(".#{prefix}.disable_drop_down_other", label: change.label)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- when :carte_layers - when :carte_layers
- added = change.to.sort - change.from.sort - added = change.to.sort - change.from.sort
- removed = change.from.sort - change.to.sort - removed = change.from.sort - change.to.sort
@ -122,21 +98,12 @@
- if change.from.nil? - if change.from.nil?
- list.with_item do - list.with_item do
= t(".#{prefix}.add_condition", label: change.label, to: change.to) = t(".#{prefix}.add_condition", label: change.label, to: change.to)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- elsif change.to.nil? - elsif change.to.nil?
- list.with_item do - list.with_item do
= t(".#{prefix}.remove_condition", label: change.label) = t(".#{prefix}.remove_condition", label: change.label)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- else - else
- list.with_item do - list.with_item do
= t(".#{prefix}.update_condition", label: change.label, to: change.to) = t(".#{prefix}.update_condition", label: change.label, to: change.to)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- when :character_limit - when :character_limit
- if change.to.blank? - if change.to.blank?
- list.with_item do - list.with_item do

View file

@ -52,10 +52,6 @@ class Champs::DropDownListChamp < Champ
other? ? value : "" other? ? value : ""
end end
def in?(options)
options.include?(value)
end
private private
def value_is_in_options def value_is_in_options

View file

@ -43,10 +43,6 @@ class Champs::LinkedDropDownListChamp < Champ
primary_value.present? && secondary_options[primary_value]&.any?(&:present?) primary_value.present? && secondary_options[primary_value]&.any?(&:present?)
end end
def in?(options)
options.include?(primary_value) || options.include?(secondary_value)
end
private private
def pack_value(primary, secondary) def pack_value(primary, secondary)

View file

@ -29,10 +29,6 @@ class Champs::MultipleDropDownListChamp < Champ
render_as_checkboxes? render_as_checkboxes?
end end
def in?(options)
(selected_options - options).size != selected_options.size
end
def focusable_input_id def focusable_input_id
render_as_checkboxes? ? checkbox_id(drop_down_options.first) : input_id render_as_checkboxes? ? checkbox_id(drop_down_options.first) : input_id
end end

View file

@ -73,7 +73,7 @@ module DossierCloneConcern
return false if revision_id > editing_fork.revision_id return false if revision_id > editing_fork.revision_id
transaction do transaction do
rebase!(force: true) rebase!
diff = make_diff(editing_fork) diff = make_diff(editing_fork)
apply_diff(diff) apply_diff(diff)
touch(:last_champ_updated_at) touch(:last_champ_updated_at)

View file

@ -3,15 +3,12 @@
module DossierRebaseConcern module DossierRebaseConcern
extend ActiveSupport::Concern extend ActiveSupport::Concern
def rebase!(force: false) def rebase!
ProcedureRevisionPreloader.new([procedure.published_revision, revision].compact).all ProcedureRevisionPreloader.new([procedure.published_revision, revision].compact).all
return if procedure.published_revision.blank? return if procedure.published_revision.blank?
return if !can_rebase?
if force || can_rebase? transaction { rebase }
transaction do
rebase
end
end
end end
def rebase_later def rebase_later
@ -19,32 +16,15 @@ module DossierRebaseConcern
end end
def can_rebase? def can_rebase?
procedure.published_revision.present? && revision != procedure.published_revision && procedure.published_revision.present? && revision != procedure.published_revision && !termine?
(brouillon? || accepted_en_construction_changes? || accepted_en_instruction_changes?)
end end
def pending_changes def pending_changes
procedure.published_revision.present? ? revision.compare_types_de_champ(procedure.published_revision) : [] procedure.published_revision.present? ? revision.compare_types_de_champ(procedure.published_revision) : []
end end
def can_rebase_mandatory_change?(stable_id)
!champs.filter { _1.stable_id == stable_id }.any?(&:blank?)
end
def can_rebase_drop_down_options_change?(stable_id, options)
!champs.filter { _1.stable_id == stable_id }.any? { _1.in?(options) }
end
private private
def accepted_en_construction_changes?
en_construction? && pending_changes.all? { _1.can_rebase?(self) }
end
def accepted_en_instruction_changes?
en_instruction? && pending_changes.all? { _1.can_rebase?(self) }
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

View file

@ -22,7 +22,6 @@ class ProcedureRevisionChange
def op = :add def op = :add
def mandatory? = @type_de_champ.mandatory? def mandatory? = @type_de_champ.mandatory?
def can_rebase?(dossier = nil) = !mandatory?
def to_h = super.merge(mandatory: mandatory?) def to_h = super.merge(mandatory: mandatory?)
end end
@ -33,7 +32,6 @@ class ProcedureRevisionChange
end end
def op = :remove def op = :remove
def can_rebase?(dossier = nil) = true
end end
class MoveChamp < TypeDeChange class MoveChamp < TypeDeChange
@ -46,7 +44,6 @@ class ProcedureRevisionChange
end end
def op = :move def op = :move
def can_rebase?(dossier = nil) = true
def to_h = super.merge(from:, to:) def to_h = super.merge(from:, to:)
end end
@ -62,22 +59,6 @@ class ProcedureRevisionChange
def op = :update def op = :update
def to_h = super.merge(attribute:, from:, to:) def to_h = super.merge(attribute:, from:, to:)
def can_rebase?(dossier = nil)
return true if private?
case attribute
when :drop_down_options
(from - to).empty? || dossier&.can_rebase_drop_down_options_change?(stable_id, from - to)
when :drop_down_other
!from && to
when :mandatory
(from && !to) || dossier&.can_rebase_mandatory_change?(stable_id)
when :type_champ, :condition, :expression_reguliere
false
else
true
end
end
end end
class EligibiliteRulesChange class EligibiliteRulesChange

View file

@ -28,12 +28,11 @@ describe DossierRebaseConcern do
dossier dossier
end end
context 'with added non mandatory type de champ' do context 'with added type de champ' do
before do before do
procedure.draft_revision.add_type_de_champ({ procedure.draft_revision.add_type_de_champ({
type_champ: TypeDeChamp.type_champs.fetch(:text), type_champ: TypeDeChamp.type_champs.fetch(:text),
libelle: "Un champ text", libelle: "Un champ text"
mandatory: false
}) })
procedure.publish_revision! procedure.publish_revision!
dossier.reload dossier.reload
@ -44,116 +43,6 @@ describe DossierRebaseConcern do
expect(dossier.can_rebase?).to be_truthy expect(dossier.can_rebase?).to be_truthy
end end
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
expect(dossier.pending_changes).not_to be_empty
expect(dossier.can_rebase?).to be_falsey
end
end
context 'with type de champ made optional' do
before do
procedure.draft_revision.find_and_ensure_exclusive_use(mandatory_type_de_champ.stable_id).update(mandatory: false)
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
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
expect(dossier.pending_changes).not_to be_empty
expect(dossier.can_rebase?).to be_falsey
end
context 'with a value' do
before do
dossier.champs.find_by(stable_id: type_de_champ.stable_id).update(value: 'a value')
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 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 type de champ regexp and regexp change' do
let(:procedure) { create(:procedure, types_de_champ_public: [{ mandatory: true }, { type: :expression_reguliere, mandatory: false }], types_de_champ_private: [{}]) }
before do
procedure.draft_revision.find_and_ensure_exclusive_use(type_de_champ.stable_id).update(expression_reguliere: /\d+/)
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 '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
context 'en_instruction' do context 'en_instruction' do
@ -165,12 +54,11 @@ describe DossierRebaseConcern do
dossier dossier
end end
context 'with added non mandatory type de champ' do context 'with added type de champ' do
before do before do
procedure.draft_revision.add_type_de_champ({ procedure.draft_revision.add_type_de_champ({
type_champ: TypeDeChamp.type_champs.fetch(:text), type_champ: TypeDeChamp.type_champs.fetch(:text),
libelle: "Un champ text", libelle: "Un champ text"
mandatory: false
}) })
procedure.publish_revision! procedure.publish_revision!
dossier.reload dossier.reload
@ -181,90 +69,32 @@ describe DossierRebaseConcern do
expect(dossier.can_rebase?).to be_truthy expect(dossier.can_rebase?).to be_truthy
end end
end end
end
context 'with added mandatory type de champ' do context 'accepte' do
let(:dossier) { create(:dossier, :accepte, procedure: procedure) }
before do
procedure.publish!
procedure.reload
dossier
end
context 'with added type de champ' do
before do before do
procedure.draft_revision.add_type_de_champ({ procedure.draft_revision.add_type_de_champ({
type_champ: TypeDeChamp.type_champs.fetch(:text), type_champ: TypeDeChamp.type_champs.fetch(:text),
libelle: "Un champ text", libelle: "Un champ text"
mandatory: true
}) })
procedure.publish_revision! procedure.publish_revision!
dossier.reload dossier.reload
end end
it 'should be false' do
expect(dossier.pending_changes).not_to be_empty
expect(dossier.can_rebase?).to be_falsey
end
end
context 'with type de champ made optional' do
before do
procedure.draft_revision.find_and_ensure_exclusive_use(mandatory_type_de_champ.stable_id).update(mandatory: false)
procedure.publish_revision!
dossier.reload
end
it 'should be true' do 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
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
@ -396,8 +226,8 @@ describe DossierRebaseConcern do
end end
end end
context 'force rebase en construction' do context 'rebase en construction' do
subject { dossier.rebase!(force: true) } subject { dossier.rebase! }
context 'procedure not published' do context 'procedure not published' do
let(:procedure) { create(:procedure, :draft, types_de_champ_public:, types_de_champ_private:) } let(:procedure) { create(:procedure, :draft, types_de_champ_public:, types_de_champ_private:) }

View file

@ -87,7 +87,7 @@ describe 'shared/dossiers/champs', type: :view do
end end
context "with a dossier_link champ but without value" do context "with a dossier_link champ but without value" do
let(:types_de_champ_public) { [{ type: :dossier_link }] } let(:types_de_champ_public) { [{ type: :dossier_link, mandatory: false }] }
before do before do
dossier.champs.first.update(value: nil) dossier.champs.first.update(value: nil)
@ -102,7 +102,7 @@ describe 'shared/dossiers/champs', type: :view do
end end
context "with a piece justificative without value" do context "with a piece justificative without value" do
let(:types_de_champ_public) { [{ type: :piece_justificative }] } let(:types_de_champ_public) { [{ type: :piece_justificative, mandatory: false }] }
before do before do
dossier.champs.first.piece_justificative_file.purge dossier.champs.first.piece_justificative_file.purge