diff --git a/app/views/gestionnaires/avis/instruction.html.haml b/app/views/gestionnaires/avis/instruction.html.haml index 3d81ac7b5..25f03d299 100644 --- a/app/views/gestionnaires/avis/instruction.html.haml +++ b/app/views/gestionnaires/avis/instruction.html.haml @@ -13,7 +13,7 @@ = form_for @avis, url: gestionnaire_avis_path(@avis), html: { class: 'form' } do |f| = f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true - = render partial: "shared/piece_jointe/pj_upload_field", locals: { pj: @avis.piece_justificative_file, object: @avis, form: f } + = render partial: "shared/attachment/update", locals: { pj: @avis.piece_justificative_file, object: @avis, form: f } .flex.justify-between.align-baseline %p.confidentiel.flex diff --git a/app/views/gestionnaires/shared/avis/_list.html.haml b/app/views/gestionnaires/shared/avis/_list.html.haml index 25f6866ed..cc3c25282 100644 --- a/app/views/gestionnaires/shared/avis/_list.html.haml +++ b/app/views/gestionnaires/shared/avis/_list.html.haml @@ -28,6 +28,7 @@ Réponse donnée le #{l(avis.updated_at, format: '%d/%m/%y à %H:%M')} - else %span.waiting En attente de réponse - = render partial: 'shared/piece_jointe/pj_link', locals: { pj: avis.piece_justificative_file, user_can_upload: false } + - if avis.piece_justificative_file.attached? + = render partial: 'shared/attachment/show', locals: { attachment: avis.piece_justificative_file.attachment } .answer-body = simple_format(avis.answer) diff --git a/app/views/new_user/dossiers/show/_download_justificatif.html.haml b/app/views/new_user/dossiers/show/_download_justificatif.html.haml index 3df94f6bd..ce596c299 100644 --- a/app/views/new_user/dossiers/show/_download_justificatif.html.haml +++ b/app/views/new_user/dossiers/show/_download_justificatif.html.haml @@ -1,12 +1,2 @@ -- if dossier.present? - - justificatif = dossier.justificatif_motivation - - if justificatif.attached? - - if justificatif.virus_scanner.safe? - .action - = link_to (justificatif), target: '_blank', class: 'button primary' do - %span.icon.download - Télécharger le justificatif - - elsif justificatif.virus_scanner.pending? - %p - Un justificatif a été joint. L'analyse antivirus de ce document est en cours. - = link_to "rafraichir", request.path +- if dossier.present? && dossier.justificatif_motivation.attached? + = render partial: "shared/attachment/show", locals: { attachment: dossier.justificatif_motivation.attachment } diff --git a/app/views/shared/attachment/_show.html.haml b/app/views/shared/attachment/_show.html.haml new file mode 100644 index 000000000..501a6da7d --- /dev/null +++ b/app/views/shared/attachment/_show.html.haml @@ -0,0 +1,26 @@ +- should_display_link = attachment.virus_scanner.safe? || !attachment.virus_scanner.started? +- user_can_upload = defined?(user_can_upload) ? user_can_upload : false +- if should_display_link + - attachment_check_url = false +- else + - attachment_check_url = attachment_url(attachment.id, { signed_id: attachment.blob.signed_id, user_can_upload: user_can_upload }) + +.pj-link{ 'data-attachment-id': attachment.id, 'data-attachment-check-url': attachment_check_url } + - if should_display_link + = link_to url_for(attachment.blob), target: '_blank', rel: 'noopener', title: "Télécharger la pièce jointe" do + %span.icon.attachment + = attachment.filename.to_s + - if !attachment.virus_scanner.started? + (ce fichier n’a pas été analysé par notre antivirus, téléchargez-le avec précaution) + + - else + = attachment.filename.to_s + - if attachment.virus_scanner.pending? + (analyse antivirus en cours + = link_to "rafraichir", request.path + ) + - elsif attachment.virus_scanner.infected? + - if user_can_upload + (virus détecté, merci d’envoyer un autre fichier) + - else + (virus détecté, le téléchargement de ce fichier est bloqué) diff --git a/app/views/shared/piece_jointe/_pj_upload_field.haml b/app/views/shared/attachment/_update.html.haml similarity index 80% rename from app/views/shared/piece_jointe/_pj_upload_field.haml rename to app/views/shared/attachment/_update.html.haml index 8faf0d3de..eb5c9dc83 100644 --- a/app/views/shared/piece_jointe/_pj_upload_field.haml +++ b/app/views/shared/attachment/_update.html.haml @@ -2,7 +2,7 @@ - if pj.attached? .piece-justificative-actions{ id: "piece_justificative_#{object.id}" } .piece-justificative-action - = render partial: "shared/piece_jointe/pj_link", locals: { pj: pj, user_can_upload: true } + = render partial: "shared/attachment/show", locals: { attachment: pj.attachment, user_can_upload: true } .piece-justificative-action = button_tag 'Remplacer', type: 'button', class: 'button small', data: { 'toggle-target': "#champs_#{object.id}" } diff --git a/app/views/shared/champs/piece_justificative/_show.html.haml b/app/views/shared/champs/piece_justificative/_show.html.haml index c02510d25..a9d7ae19c 100644 --- a/app/views/shared/champs/piece_justificative/_show.html.haml +++ b/app/views/shared/champs/piece_justificative/_show.html.haml @@ -1,5 +1,5 @@ - pj = champ.piece_justificative_file - if pj.attached? - = render partial: "shared/piece_jointe/pj_link", locals: { pj: pj, user_can_upload: false } + = render partial: "shared/attachment/show", locals: { attachment: pj.attachment } - else Pièce justificative non fournie diff --git a/app/views/shared/dossiers/_infos_generales.html.haml b/app/views/shared/dossiers/_infos_generales.html.haml index 9d2748899..e4b139f72 100644 --- a/app/views/shared/dossiers/_infos_generales.html.haml +++ b/app/views/shared/dossiers/_infos_generales.html.haml @@ -8,4 +8,4 @@ %th.libelle Justificatif : %td .action - = render partial: 'shared/piece_jointe/pj_link', locals: { object: dossier, pj: dossier.justificatif_motivation } + = render partial: 'shared/attachment/show', locals: { attachment: dossier.justificatif_motivation.attachment } diff --git a/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml b/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml index 63cbc411b..346317669 100644 --- a/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml +++ b/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml @@ -9,7 +9,7 @@ - if pj.attached? .piece-justificative-actions{ id: "piece_justificative_#{champ.id}" } .piece-justificative-action - = render partial: "shared/piece_jointe/pj_link", locals: { pj: pj, user_can_upload: true } + = render partial: "shared/attachment/show", locals: { attachment: pj.attachment, user_can_upload: true } .piece-justificative-action - if champ.private? = link_to 'Supprimer', gestionnaire_champ_purge_champ_piece_justificative_path(procedure_id: champ.dossier.procedure_id, dossier_id: champ.dossier_id, champ_id: champ.id), remote: true, method: :delete, class: 'button small danger' diff --git a/app/views/shared/piece_jointe/_pj_link.html.haml b/app/views/shared/piece_jointe/_pj_link.html.haml deleted file mode 100644 index 1821ebf70..000000000 --- a/app/views/shared/piece_jointe/_pj_link.html.haml +++ /dev/null @@ -1,20 +0,0 @@ -- if pj.attached? - .pj-link - - if pj.virus_scanner.safe? || !pj.virus_scanner.started? - = link_to url_for(pj), target: '_blank', rel: 'noopener', title: "Télécharger la pièce jointe" do - %span.icon.attachment - = pj.filename.to_s - - if !pj.virus_scanner.started? - (ce fichier n’a pas été analysé par notre antivirus, téléchargez-le avec précaution) - - - else - = pj.filename.to_s - - if pj.virus_scanner.pending? - (analyse antivirus en cours - = link_to "rafraichir", request.path - ) - - elsif pj.virus_scanner.infected? - - if user_can_upload - (virus détecté, merci d’envoyer un autre fichier) - - else - (virus détecté, le téléchargement de ce fichier est bloqué) diff --git a/spec/views/shared/piece_jointe/_pj_link.html.haml_spec.rb b/spec/views/shared/attachment/_show.html.haml_spec.rb similarity index 90% rename from spec/views/shared/piece_jointe/_pj_link.html.haml_spec.rb rename to spec/views/shared/attachment/_show.html.haml_spec.rb index 04fbe495b..81cf9024d 100644 --- a/spec/views/shared/piece_jointe/_pj_link.html.haml_spec.rb +++ b/spec/views/shared/attachment/_show.html.haml_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe 'shared/piece_jointe/_pj_link.html.haml', type: :view do +describe 'shared/attachment/_show.html.haml', type: :view do let(:champ) { create(:champ_piece_justificative) } let(:virus_scan_result) { nil } @@ -8,7 +8,7 @@ describe 'shared/piece_jointe/_pj_link.html.haml', type: :view do champ.piece_justificative_file.blob.update(metadata: champ.piece_justificative_file.blob.metadata.merge(virus_scan_result: virus_scan_result)) end - subject { render 'shared/piece_jointe/pj_link', pj: champ.piece_justificative_file, user_can_upload: false } + subject { render 'shared/attachment/show', attachment: champ.piece_justificative_file.attachment } context 'when there is no anti-virus scan' do let(:virus_scan_result) { nil }