Merge pull request #5780 from tchak/watermark-ameliorations
Show titre identite link only once watermark is added
This commit is contained in:
commit
8febbadad6
6 changed files with 25 additions and 9 deletions
|
@ -1,6 +1,4 @@
|
|||
class TitreIdentiteWatermarkJob < ApplicationJob
|
||||
queue_as :active_storage_watermark
|
||||
|
||||
MAX_IMAGE_SIZE = 1500
|
||||
SCALE = 0.9
|
||||
WATERMARK = Rails.root.join("app/assets/images/#{WATERMARK_FILE}")
|
||||
|
|
|
@ -5,18 +5,22 @@ module BlobTitreIdentiteWatermarkConcern
|
|||
after_update_commit :enqueue_watermark_job
|
||||
end
|
||||
|
||||
def watermark_pending?
|
||||
watermark_required? && !watermark_done?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def titre_identite?
|
||||
def watermark_required?
|
||||
attachments.find { |attachment| attachment.record.class.name == 'Champs::TitreIdentiteChamp' }
|
||||
end
|
||||
|
||||
def watermarked?
|
||||
def watermark_done?
|
||||
metadata[:watermark]
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
outer: true,
|
||||
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 ) %>
|
||||
<% 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
|
||||
- if should_display_link
|
||||
- attachment_check_url = false
|
||||
|
@ -19,6 +19,10 @@
|
|||
(analyse antivirus en cours
|
||||
= 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?
|
||||
- if user_can_upload
|
||||
(virus détecté, merci d’envoyer un autre fichier)
|
||||
|
|
|
@ -32,8 +32,7 @@ features = [
|
|||
:mini_profiler,
|
||||
:xray,
|
||||
:carte_ign,
|
||||
:localization,
|
||||
:titre_identite_watermark
|
||||
:localization
|
||||
]
|
||||
|
||||
def database_exists?
|
||||
|
|
|
@ -27,6 +27,17 @@ describe 'shared/attachment/_show.html.haml', type: :view do
|
|||
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
|
||||
let(:virus_scan_result) { ActiveStorage::VirusScanner::SAFE }
|
||||
|
||||
|
|
Loading…
Reference in a new issue