Skip to content

Commit

Permalink
refactor(pj): don't poll on antivirus when submitting a pj
Browse files Browse the repository at this point in the history
Closes #9733
  • Loading branch information
colinux committed Dec 6, 2023
1 parent 189b9e5 commit ea97ed0
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.fr-py-1v
%span.attachment-filename.fr-mr-1w= link_to_if(viewable?, attachment.filename.to_s, helpers.url_for(attachment.blob), title: t(".open_file", filename: attachment.filename), **helpers.external_link_attributes)
= render Attachment::ProgressComponent.new(attachment: attachment)
= render Attachment::ProgressComponent.new(attachment: attachment, ignore_antivirus: true)
- if error?
%p.fr-error-text= error_message
Expand Down
2 changes: 1 addition & 1 deletion app/components/attachment/pending_poll_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ def as_dossier?
private

def pending_attachment?(attachment)
attachment.virus_scanner.pending? || attachment.watermark_pending?
attachment.watermark_pending?
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
en:
reload: Reload
explanation:
one: Scanning for viruses and processing your attachment takes longer than expected.
other: Scanning for viruses and processing your attachments takes longer than expected.
one: Processing your attachment takes longer than expected.
other: Processing your attachments takes longer than expected.
dossier_submittable: This does not prevent you from submitting your file if you wish.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
fr:
reload: Recharger
explanation:
one: L’analyse antivirus et le traitement de votre pièce jointe prend plus de temps que prévu.
other: L’analyse antivirus et le traitement de vos pièces jointes prend plus de temps que prévu.
one: Le traitement de votre pièce jointe prend plus de temps que prévu.
other: Le traitement de vos pièces jointes prend plus de temps que prévu.

dossier_submittable: Cela ne vous empêche pas de déposer votre dossier si vous le souhaitez.
6 changes: 4 additions & 2 deletions app/components/attachment/progress_component.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
class Attachment::ProgressComponent < ApplicationComponent
attr_reader :attachment
attr_reader :ignore_antivirus

def initialize(attachment:)
def initialize(attachment:, ignore_antivirus: false)
@attachment = attachment
@ignore_antivirus = ignore_antivirus
end

def progress_label
case
when attachment.virus_scanner.pending?
when !ignore_antivirus && attachment.virus_scanner.pending?
t(".antivirus_pending")
when attachment.watermark_pending?
t(".watermark_pending")
Expand Down
14 changes: 2 additions & 12 deletions app/views/root/patron.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@
%h1.fr-mt-4w Attachment::EditComponent
%span.fr-hint-text Note: direct upload, suppression ne marchent pas comme attendu ici.

- champ = @dossier.champs_public.first
- tdc = @dossier.champs_public.find { _1.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }.type_de_champ
- champ = @dossier.champs_public.find { _1.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
- tdc = champ.type_de_champ
- avis = Avis.new

- if attachment = ActiveStorage::Attachment.last
Expand All @@ -347,16 +347,6 @@
%h3.fr-mt-4w Existing attachment, user can not destroy
= render Attachment::EditComponent.new(champ:, attached_file: champ.piece_justificative_file, attachment:, user_can_destroy: false)

%h3.fr-mt-4w Existing attachment, antivirus in progress
- attachment.blob.metadata[:virus_scan_result] = ActiveStorage::VirusScanner::PENDING
- attachment.created_at = Time.zone.now
= render Attachment::EditComponent.new(champ:, attached_file: Champ.new.piece_justificative_file, attachment:)

%h3.fr-mt-4w Existing attachment, antivirus in progress since long time
- attachment.blob.metadata[:virus_scan_result] = ActiveStorage::VirusScanner::PENDING
- attachment.created_at = 2.minutes.ago
= render Attachment::EditComponent.new(champ:, attached_file: Champ.new.piece_justificative_file, attachment:)

%h3.fr-mt-4w Existing attachment, error
- attachment.blob.metadata[:virus_scan_result] = ActiveStorage::VirusScanner::INFECTED
= render Attachment::EditComponent.new(champ:, attached_file: Champ.new.piece_justificative_file, attachment:)
Expand Down
10 changes: 0 additions & 10 deletions spec/components/attachment/pending_poll_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@
it "does not render" do
expect(component).not_to be_render
end

context "when antivirus is in progress" do
before do
attachment.blob.virus_scan_result = ActiveStorage::VirusScanner::PENDING
end

it "renders" do
expect(component).to be_render
end
end
end

context "when it's a dossier context" do
Expand Down

0 comments on commit ea97ed0

Please sign in to comment.