Show titre identite link only once watermark is added
This commit is contained in:
parent
984818c051
commit
3c6e30a326
6 changed files with 25 additions and 9 deletions
|
@ -1,6 +1,4 @@
|
||||||
class TitreIdentiteWatermarkJob < ApplicationJob
|
class TitreIdentiteWatermarkJob < ApplicationJob
|
||||||
queue_as :active_storage_watermark
|
|
||||||
|
|
||||||
MAX_IMAGE_SIZE = 1500
|
MAX_IMAGE_SIZE = 1500
|
||||||
SCALE = 0.9
|
SCALE = 0.9
|
||||||
WATERMARK = Rails.root.join("app/assets/images/#{WATERMARK_FILE}")
|
WATERMARK = Rails.root.join("app/assets/images/#{WATERMARK_FILE}")
|
||||||
|
|
|
@ -5,18 +5,22 @@ module BlobTitreIdentiteWatermarkConcern
|
||||||
after_update_commit :enqueue_watermark_job
|
after_update_commit :enqueue_watermark_job
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def watermark_pending?
|
||||||
|
watermark_required? && !watermark_done?
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def titre_identite?
|
def watermark_required?
|
||||||
attachments.find { |attachment| attachment.record.class.name == 'Champs::TitreIdentiteChamp' }
|
attachments.find { |attachment| attachment.record.class.name == 'Champs::TitreIdentiteChamp' }
|
||||||
end
|
end
|
||||||
|
|
||||||
def watermarked?
|
def watermark_done?
|
||||||
metadata[:watermark]
|
metadata[:watermark]
|
||||||
end
|
end
|
||||||
|
|
||||||
def enqueue_watermark_job
|
def enqueue_watermark_job
|
||||||
if titre_identite? && !watermarked? && analyzed? && virus_scanner.done? && Flipper.enabled?(:titre_identite_watermark)
|
if analyzed? && virus_scanner.done? && watermark_pending?
|
||||||
TitreIdentiteWatermarkJob.perform_later(self)
|
TitreIdentiteWatermarkJob.perform_later(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
outer: true,
|
outer: true,
|
||||||
locals: { attachment: @attachment, user_can_upload: @user_can_upload }) %>
|
locals: { attachment: @attachment, user_can_upload: @user_can_upload }) %>
|
||||||
|
|
||||||
<% if @attachment.virus_scanner.pending? %>
|
<% if @attachment.virus_scanner.pending? || @attachment.watermark_pending? %>
|
||||||
<%= fire_event('attachment:update', { url: attachment_url(@attachment.id, { signed_id: @attachment.blob.signed_id, user_can_upload: @user_can_upload }) }.to_json ) %>
|
<%= fire_event('attachment:update', { url: attachment_url(@attachment.id, { signed_id: @attachment.blob.signed_id, user_can_upload: @user_can_upload }) }.to_json ) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
- should_display_link = attachment.virus_scanner.safe? || !attachment.virus_scanner.started?
|
- should_display_link = (attachment.virus_scanner.safe? || !attachment.virus_scanner.started?) && !attachment.watermark_pending?
|
||||||
- user_can_upload = defined?(user_can_upload) ? user_can_upload : false
|
- user_can_upload = defined?(user_can_upload) ? user_can_upload : false
|
||||||
- if should_display_link
|
- if should_display_link
|
||||||
- attachment_check_url = false
|
- attachment_check_url = false
|
||||||
|
@ -19,6 +19,10 @@
|
||||||
(analyse antivirus en cours
|
(analyse antivirus en cours
|
||||||
= link_to "rafraichir", request.path, data: { 'attachment-refresh': true }
|
= link_to "rafraichir", request.path, data: { 'attachment-refresh': true }
|
||||||
)
|
)
|
||||||
|
- elsif attachment.watermark_pending?
|
||||||
|
(traitement de la pièce en cours
|
||||||
|
= link_to "rafraichir", request.path, data: { 'attachment-refresh': true }
|
||||||
|
)
|
||||||
- elsif attachment.virus_scanner.infected?
|
- elsif attachment.virus_scanner.infected?
|
||||||
- if user_can_upload
|
- if user_can_upload
|
||||||
(virus détecté, merci d’envoyer un autre fichier)
|
(virus détecté, merci d’envoyer un autre fichier)
|
||||||
|
|
|
@ -32,8 +32,7 @@ features = [
|
||||||
:mini_profiler,
|
:mini_profiler,
|
||||||
:xray,
|
:xray,
|
||||||
:carte_ign,
|
:carte_ign,
|
||||||
:localization,
|
:localization
|
||||||
:titre_identite_watermark
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def database_exists?
|
def database_exists?
|
||||||
|
|
|
@ -27,6 +27,17 @@ describe 'shared/attachment/_show.html.haml', type: :view do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when watermark is pending' do
|
||||||
|
let(:champ) { create(:champ_titre_identite) }
|
||||||
|
|
||||||
|
it 'displays the filename, but doesn’t allow to download the file' do
|
||||||
|
pp champ.piece_justificative_file.attachment.watermark_pending?
|
||||||
|
expect(subject).to have_text(champ.piece_justificative_file.filename.to_s)
|
||||||
|
expect(subject).not_to have_link(champ.piece_justificative_file.filename.to_s)
|
||||||
|
expect(subject).to have_text('traitement de la pièce en cours')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when the file is scanned and safe' do
|
context 'when the file is scanned and safe' do
|
||||||
let(:virus_scan_result) { ActiveStorage::VirusScanner::SAFE }
|
let(:virus_scan_result) { ActiveStorage::VirusScanner::SAFE }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue