2020-11-17 16:34:24 +01:00
|
|
|
module BlobTitreIdentiteWatermarkConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
after_update_commit :enqueue_watermark_job
|
|
|
|
end
|
|
|
|
|
2020-12-10 12:50:40 +01:00
|
|
|
def watermark_pending?
|
|
|
|
watermark_required? && !watermark_done?
|
|
|
|
end
|
|
|
|
|
2020-11-17 16:34:24 +01:00
|
|
|
private
|
|
|
|
|
2020-12-10 12:50:40 +01:00
|
|
|
def watermark_required?
|
2020-11-17 16:34:24 +01:00
|
|
|
attachments.find { |attachment| attachment.record.class.name == 'Champs::TitreIdentiteChamp' }
|
|
|
|
end
|
|
|
|
|
2020-12-10 12:50:40 +01:00
|
|
|
def watermark_done?
|
2020-11-17 16:34:24 +01:00
|
|
|
metadata[:watermark]
|
|
|
|
end
|
|
|
|
|
|
|
|
def enqueue_watermark_job
|
2020-12-10 12:50:40 +01:00
|
|
|
if analyzed? && virus_scanner.done? && watermark_pending?
|
2020-11-17 16:34:24 +01:00
|
|
|
TitreIdentiteWatermarkJob.perform_later(self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|