Skip to content

Commit

Permalink
TypeDeChamp: purge notice explicative lors d'un changement de type_champ
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoit-MINT committed Oct 15, 2024
1 parent b588b77 commit 3c5749e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions app/models/type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,10 @@ def self.dump(options)
before_validation :check_mandatory
before_validation :normalize_libelle

before_save :remove_piece_justificative_template, if: -> { type_champ_changed? }
before_save :remove_attachment, if: -> { type_champ_changed? }
before_validation :set_drop_down_list_options, if: -> { type_champ_changed? }
before_save :remove_block, if: -> { type_champ_changed? }

after_save if: -> { @remove_piece_justificative_template } do
piece_justificative_template.purge_later
end

def valid?(context = nil)
super
if dynamic_type.present?
Expand Down Expand Up @@ -767,9 +763,11 @@ def populate_stable_id
end
end

def remove_piece_justificative_template
def remove_attachment
if !piece_justificative? && piece_justificative_template.attached?
@remove_piece_justificative_template = true
piece_justificative_template.purge_later
elsif !explication? && notice_explicative.attached?
notice_explicative.purge_later
end
end

Expand Down

0 comments on commit 3c5749e

Please sign in to comment.