Refactor piece_jointe template to avoid repetition
This commit is contained in:
parent
f113d108c9
commit
6e8b9cf668
5 changed files with 16 additions and 39 deletions
|
@ -1,21 +0,0 @@
|
|||
- pj = champ.piece_justificative_file
|
||||
|
||||
.pj-link
|
||||
- if champ.virus_scan.blank? || champ.virus_scan.safe?
|
||||
= 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 champ.virus_scan.blank?
|
||||
(ce fichier n’a pas été analysé par notre antivirus, téléchargez-le avec précaution)
|
||||
|
||||
- else
|
||||
= pj.filename.to_s
|
||||
- if champ.virus_scan.pending?
|
||||
(analyse antivirus en cours
|
||||
= link_to "rafraichir", request.path
|
||||
)
|
||||
- elsif champ.virus_scan.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é)
|
|
@ -1,5 +1,5 @@
|
|||
- pj = champ.piece_justificative_file
|
||||
- if pj.attached?
|
||||
= render partial: "shared/champs/piece_justificative/pj_link", locals: { champ: champ, user_can_upload: false }
|
||||
= render partial: "shared/piece_jointe/pj_link", locals: { object: champ, pj: pj, user_can_upload: false }
|
||||
- else
|
||||
Pièce justificative non fournie
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
- if pj.attached?
|
||||
.piece-justificative-actions{ id: "piece_justificative_#{champ.id}" }
|
||||
.piece-justificative-action
|
||||
= render partial: "shared/champs/piece_justificative/pj_link", locals: { champ: champ, user_can_upload: true }
|
||||
= render partial: "shared/piece_jointe/pj_link", locals: { object: champ, pj: champ.piece_justificative_file, 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'
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
- if pj.attached?
|
||||
.pj-link
|
||||
- if object.virus_scan.blank? || object.virus_scan.safe?
|
||||
= link_to url_for(pj), target: '_blank', title: "Télécharger la pièce jointe" do
|
||||
- if object.virus_scan_safe? || object.virus_scan_no_scan?
|
||||
= 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 object.virus_scan.blank?
|
||||
- if object.virus_scan_no_scan?
|
||||
(ce fichier n’a pas été analysé par notre antivirus, téléchargez-le avec précaution)
|
||||
|
||||
- else
|
||||
= pj.filename.to_s
|
||||
- if object.virus_scan.pending?
|
||||
- if object.virus_scan_pending?
|
||||
(analyse antivirus en cours
|
||||
= link_to "rafraichir", request.path
|
||||
)
|
||||
- elsif object.virus_scan.infected?
|
||||
- elsif object.virus_scan_infected?
|
||||
- if user_can_upload
|
||||
(virus détecté, merci d’envoyer un autre fichier)
|
||||
- else
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe 'shared/champs/piece_justificative/_pj_link.html.haml', type: :view do
|
||||
let(:champ) { create(:champ, :piece_justificative, :with_piece_justificative_file) }
|
||||
let(:virus_scan) { nil }
|
||||
describe 'shared/piece_jointe/_pj_link.html.haml', type: :view do
|
||||
let(:champ) { create(:champ_piece_justificative) }
|
||||
let(:virus_scan_result) { nil }
|
||||
|
||||
before do
|
||||
if virus_scan
|
||||
champ.update(virus_scan: virus_scan)
|
||||
end
|
||||
champ.piece_justificative_file.blob.update(metadata: champ.piece_justificative_file.blob.metadata.merge(virus_scan_result: virus_scan_result))
|
||||
end
|
||||
|
||||
subject { render 'shared/champs/piece_justificative/pj_link', champ: champ, user_can_upload: false }
|
||||
subject { render 'shared/piece_jointe/pj_link', object: champ, pj: champ.piece_justificative_file, user_can_upload: false }
|
||||
|
||||
context 'when there is no anti-virus scan' do
|
||||
let(:virus_scan) { nil }
|
||||
let(:virus_scan_result) { nil }
|
||||
|
||||
it 'allows to download the file' do
|
||||
expect(subject).to have_link(champ.piece_justificative_file.filename.to_s)
|
||||
|
@ -22,7 +20,7 @@ describe 'shared/champs/piece_justificative/_pj_link.html.haml', type: :view do
|
|||
end
|
||||
|
||||
context 'when the anti-virus scan is pending' do
|
||||
let(:virus_scan) { create(:virus_scan, :pending) }
|
||||
let(:virus_scan_result) { ActiveStorage::VirusScanner::PENDING }
|
||||
|
||||
it 'displays the filename, but doesn’t allow to download the file' do
|
||||
expect(subject).to have_text(champ.piece_justificative_file.filename.to_s)
|
||||
|
@ -32,7 +30,7 @@ describe 'shared/champs/piece_justificative/_pj_link.html.haml', type: :view do
|
|||
end
|
||||
|
||||
context 'when the file is scanned and safe' do
|
||||
let(:virus_scan) { create(:virus_scan, :safe) }
|
||||
let(:virus_scan_result) { ActiveStorage::VirusScanner::SAFE }
|
||||
|
||||
it 'allows to download the file' do
|
||||
expect(subject).to have_link(champ.piece_justificative_file.filename.to_s)
|
||||
|
@ -40,7 +38,7 @@ describe 'shared/champs/piece_justificative/_pj_link.html.haml', type: :view do
|
|||
end
|
||||
|
||||
context 'when the file is scanned and infected' do
|
||||
let(:virus_scan) { create(:virus_scan, :infected) }
|
||||
let(:virus_scan_result) { ActiveStorage::VirusScanner::INFECTED }
|
||||
|
||||
it 'displays the filename, but doesn’t allow to download the file' do
|
||||
expect(subject).to have_text(champ.piece_justificative_file.filename.to_s)
|
Loading…
Reference in a new issue