Merge pull request #8134 from tchak/cleanup-attestation-templates
refactor(attestation_template): remove unused code
This commit is contained in:
commit
9a16ab4112
7 changed files with 6 additions and 62 deletions
|
@ -11,8 +11,6 @@ module Administrateurs
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@procedure.move_attestation_template_to_procedure!
|
|
||||||
|
|
||||||
@attestation_template = @procedure.attestation_template
|
@attestation_template = @procedure.attestation_template
|
||||||
|
|
||||||
if @attestation_template.update(activated_attestation_params)
|
if @attestation_template.update(activated_attestation_params)
|
||||||
|
@ -27,8 +25,6 @@ module Administrateurs
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@procedure.move_attestation_template_to_procedure!
|
|
||||||
|
|
||||||
@attestation_template = build_attestation_template(activated_attestation_params)
|
@attestation_template = build_attestation_template(activated_attestation_params)
|
||||||
|
|
||||||
if @attestation_template.save
|
if @attestation_template.save
|
||||||
|
|
|
@ -16,7 +16,6 @@ class AttestationTemplate < ApplicationRecord
|
||||||
include TagsSubstitutionConcern
|
include TagsSubstitutionConcern
|
||||||
|
|
||||||
belongs_to :procedure, inverse_of: :attestation_template
|
belongs_to :procedure, inverse_of: :attestation_template
|
||||||
has_many :revisions, class_name: 'ProcedureRevision', inverse_of: :attestation_template, dependent: :nullify
|
|
||||||
|
|
||||||
has_one_attached :logo
|
has_one_attached :logo
|
||||||
has_one_attached :signature
|
has_one_attached :signature
|
||||||
|
@ -86,10 +85,6 @@ class AttestationTemplate < ApplicationRecord
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def procedure
|
|
||||||
super || revisions.last&.procedure
|
|
||||||
end
|
|
||||||
|
|
||||||
def logo_checksum
|
def logo_checksum
|
||||||
logo.attached? ? logo.checksum : nil
|
logo.attached? ? logo.checksum : nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -742,21 +742,17 @@ class Dossier < ApplicationRecord
|
||||||
{ lon: lon, lat: lat, zoom: zoom }
|
{ lon: lon, lat: lat, zoom: zoom }
|
||||||
end
|
end
|
||||||
|
|
||||||
def active_attestation_template
|
|
||||||
attestation_template || revision.attestation_template
|
|
||||||
end
|
|
||||||
|
|
||||||
def unspecified_attestation_champs
|
def unspecified_attestation_champs
|
||||||
if active_attestation_template&.activated?
|
if attestation_template&.activated?
|
||||||
active_attestation_template.unspecified_champs_for_dossier(self)
|
attestation_template.unspecified_champs_for_dossier(self)
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_attestation
|
def build_attestation
|
||||||
if active_attestation_template&.activated?
|
if attestation_template&.activated?
|
||||||
active_attestation_template.attestation_for(self)
|
attestation_template.attestation_for(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,6 @@ class Procedure < ApplicationRecord
|
||||||
has_many :published_types_de_champ_public, through: :published_revision, source: :types_de_champ_public
|
has_many :published_types_de_champ_public, through: :published_revision, source: :types_de_champ_public
|
||||||
has_many :published_types_de_champ_private, through: :published_revision, source: :types_de_champ_private
|
has_many :published_types_de_champ_private, through: :published_revision, source: :types_de_champ_private
|
||||||
|
|
||||||
has_one :draft_attestation_template, through: :draft_revision, source: :attestation_template
|
|
||||||
|
|
||||||
has_one :published_dossier_submitted_message, dependent: :destroy, through: :published_revision, source: :dossier_submitted_message
|
has_one :published_dossier_submitted_message, dependent: :destroy, through: :published_revision, source: :dossier_submitted_message
|
||||||
has_one :draft_dossier_submitted_message, dependent: :destroy, through: :draft_revision, source: :dossier_submitted_message
|
has_one :draft_dossier_submitted_message, dependent: :destroy, through: :draft_revision, source: :dossier_submitted_message
|
||||||
has_many :dossier_submitted_messages, through: :revisions, source: :dossier_submitted_message
|
has_many :dossier_submitted_messages, through: :revisions, source: :dossier_submitted_message
|
||||||
|
@ -597,13 +595,6 @@ class Procedure < ApplicationRecord
|
||||||
touch(:whitelisted_at)
|
touch(:whitelisted_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
def move_attestation_template_to_procedure!
|
|
||||||
if draft_attestation_template.present? && draft_attestation_template != attestation_template
|
|
||||||
draft_attestation_template.update_column(:procedure_id, id)
|
|
||||||
reload
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def closed_mail_template_attestation_inconsistency_state
|
def closed_mail_template_attestation_inconsistency_state
|
||||||
# As an optimization, don’t check the predefined templates (they are presumed correct)
|
# As an optimization, don’t check the predefined templates (they are presumed correct)
|
||||||
if closed_mail.present?
|
if closed_mail.present?
|
||||||
|
@ -812,7 +803,7 @@ class Procedure < ApplicationRecord
|
||||||
transaction do
|
transaction do
|
||||||
reset!
|
reset!
|
||||||
draft_revision.types_de_champ.filter(&:only_present_on_draft?).each(&:destroy)
|
draft_revision.types_de_champ.filter(&:only_present_on_draft?).each(&:destroy)
|
||||||
draft_revision.update(attestation_template: nil, dossier_submitted_message: nil)
|
draft_revision.update(dossier_submitted_message: nil)
|
||||||
draft_revision.destroy
|
draft_revision.destroy
|
||||||
update!(draft_revision: create_new_revision(published_revision))
|
update!(draft_revision: create_new_revision(published_revision))
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
class ProcedureRevision < ApplicationRecord
|
class ProcedureRevision < ApplicationRecord
|
||||||
self.implicit_order_column = :created_at
|
self.implicit_order_column = :created_at
|
||||||
belongs_to :procedure, -> { with_discarded }, inverse_of: :revisions, optional: false
|
belongs_to :procedure, -> { with_discarded }, inverse_of: :revisions, optional: false
|
||||||
belongs_to :attestation_template, inverse_of: :revisions, optional: true, dependent: :destroy
|
|
||||||
belongs_to :dossier_submitted_message, inverse_of: :revisions, optional: true, dependent: :destroy
|
belongs_to :dossier_submitted_message, inverse_of: :revisions, optional: true, dependent: :destroy
|
||||||
|
|
||||||
has_many :dossiers, inverse_of: :revision, foreign_key: :revision_id
|
has_many :dossiers, inverse_of: :revision, foreign_key: :revision_id
|
||||||
|
|
|
@ -133,7 +133,7 @@ describe Administrateurs::AttestationTemplatesController, type: :controller do
|
||||||
|
|
||||||
it do
|
it do
|
||||||
expect(flash.alert).to be_present
|
expect(flash.alert).to be_present
|
||||||
expect(procedure.draft_attestation_template).to be nil
|
expect(procedure.attestation_template).to be nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
describe '20221108114545_assign_attestation_templates_to_procedures' do
|
|
||||||
let(:rake_task) { Rake::Task['after_party:assign_attestation_templates_to_procedures'] }
|
|
||||||
let(:procedure) { create(:procedure, :published) }
|
|
||||||
let(:attestation_template) { create(:attestation_template) }
|
|
||||||
let(:attestation_template_old) { create(:attestation_template, procedure: procedure) }
|
|
||||||
let(:procedure2) { create(:procedure, :published) }
|
|
||||||
let(:attestation_template2) { create(:attestation_template) }
|
|
||||||
|
|
||||||
subject(:run_task) do
|
|
||||||
rake_task.invoke
|
|
||||||
end
|
|
||||||
|
|
||||||
before do
|
|
||||||
procedure.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'l1')
|
|
||||||
procedure.publish_revision!
|
|
||||||
procedure.draft_revision.update!(attestation_template: attestation_template)
|
|
||||||
procedure.published_revision.update!(attestation_template: attestation_template)
|
|
||||||
procedure.revisions.first.update!(attestation_template: attestation_template_old)
|
|
||||||
|
|
||||||
procedure2.draft_revision.update!(attestation_template: attestation_template2)
|
|
||||||
procedure2.published_revision.update!(attestation_template: attestation_template2)
|
|
||||||
end
|
|
||||||
after { rake_task.reenable }
|
|
||||||
|
|
||||||
it "assigns attestation template to procedure" do
|
|
||||||
expect(procedure.attestation_template).to eq(attestation_template_old)
|
|
||||||
expect(procedure2.attestation_template).to be_nil
|
|
||||||
run_task
|
|
||||||
expect(procedure.reload.attestation_template).to eq(attestation_template)
|
|
||||||
expect(attestation_template_old.reload.procedure_id).to be_nil
|
|
||||||
expect(procedure2.reload.attestation_template).to eq(attestation_template2)
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in a new issue