2018-02-13 18:18:20 +01:00
|
|
|
class Champs::PieceJustificativeChamp < Champ
|
2018-05-11 14:59:20 +02:00
|
|
|
after_commit :create_virus_scan
|
|
|
|
|
2018-06-14 17:44:03 +02:00
|
|
|
def mandatory_and_blank?
|
|
|
|
mandatory? && !piece_justificative_file.attached?
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-05-11 14:59:20 +02:00
|
|
|
def create_virus_scan
|
|
|
|
if self.piece_justificative_file&.attachment&.blob.present?
|
|
|
|
VirusScan.where(champ: self).where.not(blob_key: self.piece_justificative_file.blob.key).delete_all
|
|
|
|
VirusScan.find_or_create_by!(champ: self, blob_key: self.piece_justificative_file.blob.key) do |virus_scan|
|
|
|
|
virus_scan.status = "pending"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-02-13 18:18:20 +01:00
|
|
|
end
|