From 91f2d7d706acbfe88c032d37554590db2ecab691 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 25 Apr 2019 12:56:25 +0200 Subject: [PATCH 1/2] Remove deprecated virus_scan model --- app/models/avis.rb | 21 ------------------- app/models/champ.rb | 1 - .../champs/piece_justificative_champ.rb | 19 +---------------- app/models/virus_scan.rb | 9 -------- .../gestionnaires/shared/avis/_list.html.haml | 2 +- .../piece_justificative/_show.html.haml | 2 +- .../_piece_justificative.html.haml | 2 +- .../shared/piece_jointe/_pj_link.html.haml | 8 +++---- .../shared/piece_jointe/_pj_upload_field.haml | 2 +- spec/factories/virus_scan.rb | 17 --------------- .../piece_jointe/_pj_link.html.haml_spec.rb | 2 +- 11 files changed, 10 insertions(+), 75 deletions(-) delete mode 100644 app/models/virus_scan.rb delete mode 100644 spec/factories/virus_scan.rb diff --git a/app/models/avis.rb b/app/models/avis.rb index 4d12a64a1..7203870ea 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -37,27 +37,6 @@ class Avis < ApplicationRecord Avis.find_by(id: avis_id)&.email == email end - # FIXME remove this after migrating virus_scan to blob metadata - def virus_scan - VirusScan.find_by(blob_key: piece_justificative_file.blob.key) - end - - def virus_scan_safe? - virus_scan&.safe? || piece_justificative_file.virus_scanner.safe? - end - - def virus_scan_infected? - virus_scan&.infected? || piece_justificative_file.virus_scanner.infected? - end - - def virus_scan_pending? - virus_scan&.pending? || piece_justificative_file.virus_scanner.pending? - end - - def virus_scan_no_scan? - virus_scan.blank? && !piece_justificative_file.virus_scanner.analyzed? - end - private def notify_gestionnaire diff --git a/app/models/champ.rb b/app/models/champ.rb index a41e732f3..06bc65871 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -4,7 +4,6 @@ class Champ < ApplicationRecord belongs_to :parent, class_name: 'Champ' has_many :commentaires has_one_attached :piece_justificative_file - has_one :virus_scan # We declare champ specific relationships (Champs::CarteChamp and Champs::SiretChamp) # here because otherwise we can't easily use includes in our queries. diff --git a/app/models/champs/piece_justificative_champ.rb b/app/models/champs/piece_justificative_champ.rb index bf9a6b453..00ec3a559 100644 --- a/app/models/champs/piece_justificative_champ.rb +++ b/app/models/champs/piece_justificative_champ.rb @@ -46,25 +46,8 @@ class Champs::PieceJustificativeChamp < Champ errors end - # FIXME remove this after migrating virus_scan to blob metadata - def virus_scan_safe? - virus_scan&.safe? || piece_justificative_file.virus_scanner.safe? - end - - def virus_scan_infected? - virus_scan&.infected? || piece_justificative_file.virus_scanner.infected? - end - - def virus_scan_pending? - virus_scan&.pending? || piece_justificative_file.virus_scanner.pending? - end - - def virus_scan_no_scan? - virus_scan.blank? && !piece_justificative_file.virus_scanner.analyzed? - end - def for_api - if piece_justificative_file.attached? && (virus_scan_safe? || virus_scan_pending?) + if piece_justificative_file.attached? && (piece_justificative_file.virus_scanner.safe? || piece_justificative_file.virus_scanner.pending?) Rails.application.routes.url_helpers.url_for(piece_justificative_file) end end diff --git a/app/models/virus_scan.rb b/app/models/virus_scan.rb deleted file mode 100644 index c6d108164..000000000 --- a/app/models/virus_scan.rb +++ /dev/null @@ -1,9 +0,0 @@ -class VirusScan < ApplicationRecord - belongs_to :champ - - enum status: { - pending: 'pending', - safe: 'safe', - infected: 'infected' - } -end diff --git a/app/views/gestionnaires/shared/avis/_list.html.haml b/app/views/gestionnaires/shared/avis/_list.html.haml index c5837aac5..25f6866ed 100644 --- a/app/views/gestionnaires/shared/avis/_list.html.haml +++ b/app/views/gestionnaires/shared/avis/_list.html.haml @@ -28,6 +28,6 @@ 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: { object: avis, pj: avis.piece_justificative_file } + = render partial: 'shared/piece_jointe/pj_link', locals: { pj: avis.piece_justificative_file, user_can_upload: false } .answer-body = simple_format(avis.answer) diff --git a/app/views/shared/champs/piece_justificative/_show.html.haml b/app/views/shared/champs/piece_justificative/_show.html.haml index 2332a8fc7..c02510d25 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: { object: champ, pj: pj, user_can_upload: false } + = render partial: "shared/piece_jointe/pj_link", locals: { pj: pj, user_can_upload: false } - else Pièce justificative non fournie 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 a20ba19d7..63cbc411b 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: { object: champ, pj: champ.piece_justificative_file, user_can_upload: true } + = render partial: "shared/piece_jointe/pj_link", locals: { pj: pj, 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 index e6d804918..0c75f967c 100644 --- a/app/views/shared/piece_jointe/_pj_link.html.haml +++ b/app/views/shared/piece_jointe/_pj_link.html.haml @@ -1,19 +1,19 @@ - if pj.attached? .pj-link - - if object.virus_scan_safe? || object.virus_scan_no_scan? + - if pj.virus_scanner.safe? || !pj.virus_scanner.analyzed? = 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_no_scan? + - if !pj.virus_scanner.analyzed? (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 pj.virus_scanner.pending? (analyse antivirus en cours = link_to "rafraichir", request.path ) - - elsif object.virus_scan_infected? + - elsif pj.virus_scanner.infected? - if user_can_upload (virus détecté, merci d’envoyer un autre fichier) - else diff --git a/app/views/shared/piece_jointe/_pj_upload_field.haml b/app/views/shared/piece_jointe/_pj_upload_field.haml index 1c2e95dce..8faf0d3de 100644 --- a/app/views/shared/piece_jointe/_pj_upload_field.haml +++ b/app/views/shared/piece_jointe/_pj_upload_field.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: { object: object, pj: object.piece_justificative_file, user_can_upload: true } + = render partial: "shared/piece_jointe/pj_link", locals: { pj: pj, user_can_upload: true } .piece-justificative-action = button_tag 'Remplacer', type: 'button', class: 'button small', data: { 'toggle-target': "#champs_#{object.id}" } diff --git a/spec/factories/virus_scan.rb b/spec/factories/virus_scan.rb deleted file mode 100644 index 1ffade312..000000000 --- a/spec/factories/virus_scan.rb +++ /dev/null @@ -1,17 +0,0 @@ -FactoryBot.define do - factory :virus_scan do - add_attribute(:status) { VirusScan.statuses.fetch(:pending) } - - trait :pending do - add_attribute(:status) { VirusScan.statuses.fetch(:pending) } - end - - trait :safe do - add_attribute(:status) { VirusScan.statuses.fetch(:safe) } - end - - trait :infected do - add_attribute(:status) { VirusScan.statuses.fetch(:infected) } - end - end -end diff --git a/spec/views/shared/piece_jointe/_pj_link.html.haml_spec.rb b/spec/views/shared/piece_jointe/_pj_link.html.haml_spec.rb index 9bf655204..04fbe495b 100644 --- a/spec/views/shared/piece_jointe/_pj_link.html.haml_spec.rb +++ b/spec/views/shared/piece_jointe/_pj_link.html.haml_spec.rb @@ -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', object: champ, pj: champ.piece_justificative_file, user_can_upload: false } + subject { render 'shared/piece_jointe/pj_link', pj: champ.piece_justificative_file, user_can_upload: false } context 'when there is no anti-virus scan' do let(:virus_scan_result) { nil } From 078732e318561c917fda3021e0a7f84957249de5 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 3 May 2019 16:34:47 +0200 Subject: [PATCH 2/2] Update to latest jquery to fix IE11 exception --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d33cbdce5..61fbe0f21 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "debounce": "^1.2.0", "dom4": "^2.1.4", "highcharts": "^6.1.2", - "jquery": "^3.4.0", + "jquery": "^3.4.1", "leaflet": "^1.4.0", "leaflet-freedraw": "^2.10.0", "prop-types": "^15.7.2", diff --git a/yarn.lock b/yarn.lock index e319784e1..1b9ccd07f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4510,10 +4510,10 @@ jquery-mousewheel@~3.1.13: resolved "https://registry.yarnpkg.com/jquery-mousewheel/-/jquery-mousewheel-3.1.13.tgz#06f0335f16e353a695e7206bf50503cb523a6ee5" integrity sha1-BvAzXxbjU6aV5yBr9QUDy1I6buU= -jquery@^3.4.0: - version "3.4.0" - resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.4.0.tgz#8de513fa0fa4b2c7d2e48a530e26f0596936efdf" - integrity sha512-ggRCXln9zEqv6OqAGXFEcshF5dSBvCkzj6Gm2gzuR5fWawaX8t7cxKVkkygKODrDAzKdoYw3l/e3pm3vlT4IbQ== +jquery@^3.4.1: + version "3.4.1" + resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.4.1.tgz#714f1f8d9dde4bdfa55764ba37ef214630d80ef2" + integrity sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw== js-base64@^2.1.8: version "2.5.1"