From 7c6c3608c93f13b93b9749c166b6721cc2be8f0d Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Fri, 5 Apr 2024 14:25:28 +0200 Subject: [PATCH] feat(gallery): use authorized content types --- .../dossiers/pieces_jointes.html.haml | 13 +++++++--- .../initializers/authorized_content_types.rb | 24 ++++++++++++------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/views/instructeurs/dossiers/pieces_jointes.html.haml b/app/views/instructeurs/dossiers/pieces_jointes.html.haml index 0384fbc6b..ce6cf923b 100644 --- a/app/views/instructeurs/dossiers/pieces_jointes.html.haml +++ b/app/views/instructeurs/dossiers/pieces_jointes.html.haml @@ -8,8 +8,8 @@ - champ.piece_justificative_file.each do |attachment| .gallery-item - blob = attachment.blob - - if blob.content_type == 'application/pdf' - = link_to blob.url, id: blob.id, data: { iframe: true, src: blob.url }, class: 'gallery-link', type: "application/pdf", title: "#{champ.libelle} -- #{blob.filename}" do + - if blob.content_type.in?(AUTHORIZED_PDF_TYPES) + = link_to blob.url, id: blob.id, data: { iframe: true, src: blob.url }, class: 'gallery-link', type: blob.content_type, title: "#{champ.libelle} -- #{blob.filename}" do .thumbnail = image_tag("pdf-placeholder.png") .fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button } @@ -18,7 +18,7 @@ = champ.libelle = render Attachment::ShowComponent.new(attachment: attachment, new_tab: true) - - else + - elsif blob.content_type.in?(AUTHORIZED_IMAGE_TYPES) = link_to image_url(blob.url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do .thumbnail = image_tag(blob.url) @@ -27,3 +27,10 @@ .champ-libelle = champ.libelle = render Attachment::ShowComponent.new(attachment: attachment, new_tab: true) + + - else + .thumbnail + = image_tag('apercu-indisponible.png') + .champ-libelle + = champ.libelle + = render Attachment::ShowComponent.new(attachment: attachment, new_tab: true) diff --git a/config/initializers/authorized_content_types.rb b/config/initializers/authorized_content_types.rb index fe5410266..e5af1c74f 100644 --- a/config/initializers/authorized_content_types.rb +++ b/config/initializers/authorized_content_types.rb @@ -1,15 +1,25 @@ -AUTHORIZED_CONTENT_TYPES = [ - # multimedia +AUTHORIZED_PDF_TYPES = [ + 'application/pdf', # text x 4628654 + 'application/x-pdf', # text x 30 + 'image/pdf', # text x 23 + 'text/pdf' # text x 12 +] + +AUTHORIZED_IMAGE_TYPES = [ 'image/jpeg', # multimedia x 1467465 'image/png', # multimedia x 126662 'image/tiff', # multimedia x 3985 'image/bmp', # multimedia x 3656 - 'video/mp4', # multimedia x 2075 'image/webp', # multimedia x 529 - 'video/quicktime', # multimedia x 486 'image/gif', # multimedia x 463 + 'image/vnd.dwg' # multimedia x 137 auto desk +] + +AUTHORIZED_CONTENT_TYPES = AUTHORIZED_IMAGE_TYPES + AUTHORIZED_PDF_TYPES + [ + # multimedia + 'video/mp4', # multimedia x 2075 + 'video/quicktime', # multimedia x 486 'video/3gpp', # multimedia x 216 - 'image/vnd.dwg', # multimedia x 137 auto desk 'audio/mpeg', # multimedia x 26 'video/x-ms-wm', # multimedia x 15 video microsoft ? 'audio/mp4', # audio .mp4, .m4a @@ -45,7 +55,6 @@ AUTHORIZED_CONTENT_TYPES = [ 'text/xml', # program x 10 # text / sheet / presentation - 'application/pdf', # text x 4628654 'application/vnd.ms-excel', # text x 166674 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', # text x 103879 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', # text x 86336 @@ -69,18 +78,15 @@ AUTHORIZED_CONTENT_TYPES = [ 'application/vnd.ms-word.document.macroenabled.12', # text x 61 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', # text x 59 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', # text x 32 - 'application/x-pdf', # text x 30 'application/kswps', # inconnu x 26 , text ? 'application/x-iwork-numbers-sffnumbers', # text x 25 'text/rtf', # text x 25 - 'image/pdf', # text x 23 'application/vnd.ms-xpsdocument', # text x 23 'application/vnd.ms-excel.sheet.binary.macroenabled.12', # text x 21 'application/vnd.ms-powerpoint.presentation.macroenabled.12', # text x 15 'application/x-msword', # text x 15 'application/vnd.oasis.opendocument.spreadsheet-template', # text x 14 'application/vnd.oasis.opendocument.text-master', # text x 12 - 'text/pdf', # text x 12 'application/x-abiword', # text x 11 'application/x-iwork-keynote-sffnumbers', # text x 11 'application/x-iwork-keynote-sffkey', # text x 10