From 7ffb98e616732999e600c0a1d4aa8748fedaf95e Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 28 Aug 2019 13:11:58 +0200 Subject: [PATCH 1/4] Remove carrierwave uploaders --- .../admin/attestation_templates_controller.rb | 20 +-- .../admin/procedures_controller.rb | 8 +- app/mailers/application_mailer.rb | 28 ++-- app/models/attestation.rb | 12 +- app/models/attestation_template.rb | 77 +++++------ app/models/procedure.rb | 21 +-- .../attestation_template_logo_uploader.rb | 38 ------ ...attestation_template_signature_uploader.rb | 38 ------ app/uploaders/attestation_uploader.rb | 32 ----- app/uploaders/base_uploader.rb | 13 -- app/uploaders/local_downloader.rb | 41 ------ app/uploaders/procedure_logo_uploader.rb | 49 ------- app/uploaders/remote_downloader.rb | 17 --- .../_show.html.haml | 8 +- .../instructeurs/procedures/index.html.haml | 2 +- .../instructeurs/procedures/show.html.haml | 2 +- ...dmin_procedurescontroller_navbar.html.haml | 3 +- config/initializers/carrierwave.rb | 47 ------- config/initializers/urls.rb | 3 - .../2019_08_20_migrate_procedure_logo.rake | 33 ----- .../2019_08_22_migrate_attestation_files.rake | 97 ------------- .../attestation_templates_controller_spec.rb | 12 +- spec/factories/attestation_template.rb | 5 - spec/factories/procedure.rb | 4 - .../2019_08_20_migrate_procedure_logo_spec.rb | 60 -------- ...19_08_22_migrate_attestation_files_spec.rb | 128 ------------------ spec/models/attestation_template_spec.rb | 20 +-- spec/spec_helper.rb | 2 - spec/uploaders/base_uploader_spec.rb | 11 -- spec/uploaders/remote_downloader_spec.rb | 17 --- 30 files changed, 89 insertions(+), 759 deletions(-) delete mode 100644 app/uploaders/attestation_template_logo_uploader.rb delete mode 100644 app/uploaders/attestation_template_signature_uploader.rb delete mode 100644 app/uploaders/attestation_uploader.rb delete mode 100644 app/uploaders/base_uploader.rb delete mode 100644 app/uploaders/local_downloader.rb delete mode 100644 app/uploaders/procedure_logo_uploader.rb delete mode 100644 app/uploaders/remote_downloader.rb delete mode 100644 config/initializers/carrierwave.rb delete mode 100644 lib/tasks/2019_08_20_migrate_procedure_logo.rake delete mode 100644 lib/tasks/2019_08_22_migrate_attestation_files.rake delete mode 100644 spec/lib/tasks/2019_08_20_migrate_procedure_logo_spec.rb delete mode 100644 spec/lib/tasks/2019_08_22_migrate_attestation_files_spec.rb delete mode 100644 spec/uploaders/base_uploader_spec.rb delete mode 100644 spec/uploaders/remote_downloader_spec.rb diff --git a/app/controllers/admin/attestation_templates_controller.rb b/app/controllers/admin/attestation_templates_controller.rb index ad2b89ba5..729c66f9b 100644 --- a/app/controllers/admin/attestation_templates_controller.rb +++ b/app/controllers/admin/attestation_templates_controller.rb @@ -48,19 +48,15 @@ class Admin::AttestationTemplatesController < AdminController # In a case of a preview, when the user does not change its images, # the images are not uploaded and thus should be retrieved from previous # attestation_template - @logo = activated_attestation_params[:logo_active_storage] || @procedure.attestation_template&.proxy_logo - @signature = activated_attestation_params[:signature_active_storage] || @procedure.attestation_template&.proxy_signature + @logo = activated_attestation_params[:logo] || @procedure.attestation_template&.proxy_logo + @signature = activated_attestation_params[:signature] || @procedure.attestation_template&.proxy_signature render 'admin/attestation_templates/show', formats: [:pdf] end def delete_logo attestation_template = @procedure.attestation_template - - if attestation_template.logo.present? - attestation_template.remove_logo! - attestation_template.save - end + attestation_template.logo.purge_later attestation_template.logo_active_storage.purge_later flash.notice = 'le logo a bien été supprimée' @@ -69,11 +65,7 @@ class Admin::AttestationTemplatesController < AdminController def delete_signature attestation_template = @procedure.attestation_template - - if attestation_template.signature.present? - attestation_template.remove_signature! - attestation_template.save - end + attestation_template.signature.purge_later attestation_template.signature_active_storage.purge_later flash.notice = 'la signature a bien été supprimée' @@ -93,10 +85,10 @@ class Admin::AttestationTemplatesController < AdminController signature_file = params['attestation_template'].delete('signature') if logo_file.present? - @activated_attestation_params[:logo_active_storage] = uninterlaced_png(logo_file) + @activated_attestation_params[:logo] = uninterlaced_png(logo_file) end if signature_file.present? - @activated_attestation_params[:signature_active_storage] = uninterlaced_png(signature_file) + @activated_attestation_params[:signature] = uninterlaced_png(signature_file) end end diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 0b05d2824..c2c061e75 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -247,10 +247,7 @@ class Admin::ProceduresController < AdminController end def delete_logo - if @procedure.logo - @procedure.remove_logo! - @procedure.save - end + @procedure.logo.purge_later @procedure.logo_active_storage.purge_later flash.notice = 'le logo a bien été supprimé' @@ -284,9 +281,6 @@ class Admin::ProceduresController < AdminController else params.require(:procedure).permit(*editable_params, :duree_conservation_dossiers_dans_ds, :duree_conservation_dossiers_hors_ds, :for_individual, :path) end - if permited_params[:logo] - permited_params[:logo_active_storage] = permited_params.delete(:logo) - end permited_params end end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 021edddc3..ab6a5865e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -8,21 +8,19 @@ class ApplicationMailer < ActionMailer::Base def attach_logo(procedure) return nil if !procedure.logo? - begin - if procedure.logo_active_storage.attached? - logo_filename = procedure.logo_active_storage.filename.to_s - attachments.inline[logo_filename] = procedure.logo_active_storage.download - else - logo_filename = procedure.logo.filename - attachments.inline[logo_filename] = procedure.logo.read - end - attachments[logo_filename].url - - rescue StandardError => e - # A problem occured when reading logo, maybe the logo is missing and we should clean the procedure to remove logo reference ? - Raven.extra_context(procedure_id: procedure.id) - Raven.capture_exception(e) - nil + if procedure.logo.attached? + logo_filename = procedure.logo.filename.to_s + attachments.inline[logo_filename] = procedure.logo.download + elsif procedure.logo_active_storage.attached? + logo_filename = procedure.logo_active_storage.filename.to_s + attachments.inline[logo_filename] = procedure.logo_active_storage.download end + + attachments[logo_filename].url + rescue StandardError => e + # A problem occured when reading logo, maybe the logo is missing and we should clean the procedure to remove logo reference ? + Raven.extra_context(procedure_id: procedure.id) + Raven.capture_exception(e) + nil end end diff --git a/app/models/attestation.rb b/app/models/attestation.rb index f3051bddf..f5e291a59 100644 --- a/app/models/attestation.rb +++ b/app/models/attestation.rb @@ -1,18 +1,14 @@ class Attestation < ApplicationRecord belongs_to :dossier - mount_uploader :pdf, AttestationUploader - + has_one_attached :pdf has_one_attached :pdf_active_storage def pdf_url - if pdf_active_storage.attached? + if pdf.attached? + Rails.application.routes.url_helpers.url_for(pdf) + elsif pdf_active_storage.attached? Rails.application.routes.url_helpers.url_for(pdf_active_storage) - elsif Rails.application.secrets.fog[:enabled] - RemoteDownloader.new(pdf.path).url - elsif pdf&.url - # FIXME: this is horrible but used only in dev and will be removed after migration - File.join(LOCAL_DOWNLOAD_URL, pdf.url) end end end diff --git a/app/models/attestation_template.rb b/app/models/attestation_template.rb index 4d8d3a3ae..fb6863493 100644 --- a/app/models/attestation_template.rb +++ b/app/models/attestation_template.rb @@ -4,10 +4,9 @@ class AttestationTemplate < ApplicationRecord belongs_to :procedure - mount_uploader :logo, AttestationTemplateLogoUploader - mount_uploader :signature, AttestationTemplateSignatureUploader - + has_one_attached :logo has_one_attached :logo_active_storage + has_one_attached :signature has_one_attached :signature_active_storage validates :footer, length: { maximum: 190 } @@ -16,7 +15,7 @@ class AttestationTemplate < ApplicationRecord def attestation_for(dossier) attestation = Attestation.new(title: replace_tags(title, dossier)) - attestation.pdf_active_storage.attach( + attestation.pdf.attach( io: build_pdf(dossier), filename: "attestation-dossier-#{dossier.id}.pdf", content_type: 'application/pdf', @@ -45,80 +44,82 @@ class AttestationTemplate < ApplicationRecord def dup attestation_template = AttestationTemplate.new(title: title, body: body, footer: footer, activated: activated) - if logo_active_storage.attached? - attestation_template.logo_active_storage.attach( + if logo.attached? + attestation_template.logo.attach( + io: StringIO.new(logo.download), + filename: logo.filename.to_s, + content_type: logo.content_type, + # we don't want to run virus scanner on duplicated file + metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE } + ) + elsif logo_active_storage.attached? + attestation_template.logo.attach( io: StringIO.new(logo_active_storage.download), - filename: logo_active_storage.filename, + filename: logo_active_storage.filename.to_s, content_type: logo_active_storage.content_type, # we don't want to run virus scanner on duplicated file metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE } ) - elsif logo.present? - CopyCarrierwaveFile::CopyFileService.new(self, attestation_template, :logo).set_file end - if signature_active_storage.attached? - attestation_template.signature_active_storage.attach( + if signature.attached? + attestation_template.signature.attach( + io: StringIO.new(signature.download), + filename: signature.filename.to_s, + content_type: signature.content_type, + # we don't want to run virus scanner on duplicated file + metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE } + ) + elsif signature_active_storage.attached? + attestation_template.signature.attach( io: StringIO.new(signature_active_storage.download), - filename: signature_active_storage.filename, + filename: signature_active_storage.filename.to_s, content_type: signature_active_storage.content_type, # we don't want to run virus scanner on duplicated file metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE } ) - elsif signature.present? - CopyCarrierwaveFile::CopyFileService.new(self, attestation_template, :signature).set_file end attestation_template end def logo? - logo_active_storage.attached? || logo.present? + logo.attached? || logo_active_storage.attached? end def signature? - signature_active_storage.attached? || signature.present? + signature.attached? || signature_active_storage.attached? end def logo_url - if logo_active_storage.attached? + if logo.attached? + Rails.application.routes.url_helpers.url_for(logo) + elsif logo_active_storage.attached? Rails.application.routes.url_helpers.url_for(logo_active_storage) - elsif logo.present? - if Rails.application.secrets.fog[:enabled] - RemoteDownloader.new(logo.path).url - elsif logo&.url - # FIXME: this is horrible but used only in dev and will be removed after migration - File.join(LOCAL_DOWNLOAD_URL, logo.url) - end end end def signature_url - if signature_active_storage.attached? + if signature.attached? + Rails.application.routes.url_helpers.url_for(signature) + elsif signature_active_storage.attached? Rails.application.routes.url_helpers.url_for(signature_active_storage) - elsif signature.present? - if Rails.application.secrets.fog[:enabled] - RemoteDownloader.new(signature.path).url - elsif signature&.url - # FIXME: this is horrible but used only in dev and will be removed after migration - File.join(LOCAL_DOWNLOAD_URL, signature.url) - end end end def proxy_logo - if logo_active_storage.attached? - logo_active_storage - else + if logo.attached? logo + elsif logo_active_storage.attached? + logo_active_storage end end def proxy_signature - if signature_active_storage.attached? - signature_active_storage - else + if signature.attached? signature + elsif signature_active_storage.attached? + signature_active_storage end end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 120d96ef7..d14ce7098 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -25,6 +25,7 @@ class Procedure < ApplicationRecord has_one :refused_mail, class_name: "Mails::RefusedMail", dependent: :destroy has_one :without_continuation_mail, class_name: "Mails::WithoutContinuationMail", dependent: :destroy + has_one_attached :logo has_one_attached :logo_active_storage has_one_attached :notice has_one_attached :deliberation @@ -32,8 +33,6 @@ class Procedure < ApplicationRecord accepts_nested_attributes_for :types_de_champ, reject_if: proc { |attributes| attributes['libelle'].blank? }, allow_destroy: true accepts_nested_attributes_for :types_de_champ_private, reject_if: proc { |attributes| attributes['libelle'].blank? }, allow_destroy: true - mount_uploader :logo, ProcedureLogoUploader - default_scope { where(hidden_at: nil) } scope :brouillons, -> { where(aasm_state: :brouillon) } scope :publiees, -> { where(aasm_state: :publiee) } @@ -221,10 +220,6 @@ class Procedure < ApplicationRecord procedure.test_started_at = nil procedure.archived_at = nil procedure.published_at = nil - procedure.logo_secure_token = nil - if logo.present? - procedure.remote_logo_url = self.logo_url - end procedure.lien_notice = nil if is_different_admin || from_library @@ -264,6 +259,7 @@ class Procedure < ApplicationRecord if original.is_a?(TypeDeChamp) clone_attachment(:piece_justificative_template, original, kopy) elsif original.is_a?(Procedure) + clone_attachment(:logo, original, kopy) clone_attachment(:logo_active_storage, original, kopy) clone_attachment(:notice, original, kopy) clone_attachment(:deliberation, original, kopy) @@ -466,21 +462,16 @@ class Procedure < ApplicationRecord end def logo? - logo.present? || logo_active_storage.attached? + logo.attached? || logo_active_storage.attached? end def logo_url - if !logo? - ActionController::Base.helpers.image_url("marianne.svg") + if logo.attached? + Rails.application.routes.url_helpers.url_for(logo) elsif logo_active_storage.attached? Rails.application.routes.url_helpers.url_for(logo_active_storage) else - if Rails.application.secrets.fog[:enabled] - RemoteDownloader.new(logo.filename).url - else - # FIXME: this is horrible but used only in dev and will be removed after migration - File.join(LOCAL_DOWNLOAD_URL, logo.url) - end + ActionController::Base.helpers.image_url("marianne.svg") end end diff --git a/app/uploaders/attestation_template_logo_uploader.rb b/app/uploaders/attestation_template_logo_uploader.rb deleted file mode 100644 index a74bc8dc6..000000000 --- a/app/uploaders/attestation_template_logo_uploader.rb +++ /dev/null @@ -1,38 +0,0 @@ -class AttestationTemplateLogoUploader < BaseUploader - def root - Rails.root.join("public") - end - - # Choose what kind of storage to use for this uploader: - if Rails.application.secrets.fog[:enabled] - storage :fog - else - storage :file - end - - # Override the directory where uploaded files will be stored. - # This is a sensible default for uploaders that are meant to be mounted: - def store_dir - if !Rails.application.secrets.fog[:enabled] - "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" - end - end - - # Add a white list of extensions which are allowed to be uploaded. - # For images you might use something like this: - def extension_whitelist - ['jpg', 'jpeg', 'png'] - end - - def filename - if file.present? - "attestation-template-logo-#{secure_token}.#{file.extension.downcase}" - end - end - - private - - def secure_token - model.logo_secure_token ||= SecureRandom.uuid - end -end diff --git a/app/uploaders/attestation_template_signature_uploader.rb b/app/uploaders/attestation_template_signature_uploader.rb deleted file mode 100644 index 50be72cae..000000000 --- a/app/uploaders/attestation_template_signature_uploader.rb +++ /dev/null @@ -1,38 +0,0 @@ -class AttestationTemplateSignatureUploader < BaseUploader - def root - Rails.root.join("public") - end - - # Choose what kind of storage to use for this uploader: - if Rails.application.secrets.fog[:enabled] - storage :fog - else - storage :file - end - - # Override the directory where uploaded files will be stored. - # This is a sensible default for uploaders that are meant to be mounted: - def store_dir - if !Rails.application.secrets.fog[:enabled] - "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" - end - end - - # Add a white list of extensions which are allowed to be uploaded. - # For images you might use something like this: - def extension_whitelist - ['jpg', 'jpeg', 'png'] - end - - def filename - if file.present? - "attestation-template-signature-#{secure_token}.#{file.extension.downcase}" - end - end - - private - - def secure_token - model.signature_secure_token ||= SecureRandom.uuid - end -end diff --git a/app/uploaders/attestation_uploader.rb b/app/uploaders/attestation_uploader.rb deleted file mode 100644 index 523086227..000000000 --- a/app/uploaders/attestation_uploader.rb +++ /dev/null @@ -1,32 +0,0 @@ -class AttestationUploader < BaseUploader - def root - Rails.root.join("public") - end - - # Choose what kind of storage to use for this uploader: - if Rails.application.secrets.fog[:enabled] - storage :fog - else - storage :file - end - - # Override the directory where uploaded files will be stored. - # This is a sensible default for uploaders that are meant to be mounted: - def store_dir - if !Rails.application.secrets.fog[:enabled] - "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" - end - end - - def filename - if file.present? - "attestation-#{secure_token}.pdf" - end - end - - private - - def secure_token - model.content_secure_token ||= SecureRandom.uuid - end -end diff --git a/app/uploaders/base_uploader.rb b/app/uploaders/base_uploader.rb deleted file mode 100644 index f3d8d9386..000000000 --- a/app/uploaders/base_uploader.rb +++ /dev/null @@ -1,13 +0,0 @@ -class BaseUploader < CarrierWave::Uploader::Base - def cache_dir - Rails.application.secrets.carrierwave[:cache_dir] - end - - # https://github.com/carrierwaveuploader/carrierwave/wiki/how-to:-silently-ignore-missing-files-on-destroy-or-overwrite - def remove! - begin - super - rescue Fog::OpenStack::Storage::NotFound - end - end -end diff --git a/app/uploaders/local_downloader.rb b/app/uploaders/local_downloader.rb deleted file mode 100644 index 011a29b52..000000000 --- a/app/uploaders/local_downloader.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'securerandom' - -class LocalDownloader - BASE_PATH_DISK = Rails.root.join("public", "downloads") - - def initialize(filename, filename_suffix = '') - @filename = filename.to_s - @filename_suffix = filename_suffix.empty? ? '' : "_#{filename_suffix}" - @extension = @filename.split(/[.]/).last - - generate_random_base_path! - - FileUtils.ln_s @filename, "#{@base_path}/#{@filename_suffix}.#{@extension}" - end - - def url - @url ||= File.join(LOCAL_DOWNLOAD_URL, 'downloads', random_folder_name, "#{@filename_suffix}.#{@extension}") - end - - protected - - attr_accessor :random_folder_name - - def generate_random_base_path! - @base_path ||= begin - loop do - self.random_folder_name = SecureRandom.hex - base_path = File.join(BASE_PATH_DISK, self.random_folder_name) - - if !File.directory?(BASE_PATH_DISK) - Dir.mkdir(BASE_PATH_DISK) - end - - if !File.directory?(base_path) - Dir.mkdir(base_path) - break base_path - end - end - end - end -end diff --git a/app/uploaders/procedure_logo_uploader.rb b/app/uploaders/procedure_logo_uploader.rb deleted file mode 100644 index 0d774d514..000000000 --- a/app/uploaders/procedure_logo_uploader.rb +++ /dev/null @@ -1,49 +0,0 @@ -class ProcedureLogoUploader < BaseUploader - def root - Rails.root.join("public") - end - - # Choose what kind of storage to use for this uploader: - if Rails.application.secrets.fog[:enabled] - storage :fog - else - storage :file - end - - # Override the directory where uploaded files will be stored. - # This is a sensible default for uploaders that are meant to be mounted: - def store_dir - if !Rails.application.secrets.fog[:enabled] - "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" - end - end - - # Add a white list of extensions which are allowed to be uploaded. - # For images you might use something like this: - def extension_whitelist - ['jpg', 'jpeg', 'png'] - end - - def filename - if file.present? - if original_filename.present? || model.logo_secure_token - if Rails.application.secrets.fog[:enabled] - filename = "#{model.class.to_s.underscore}-#{secure_token}.#{file.extension&.downcase}" - else - filename = "logo-#{secure_token}.#{file.extension&.downcase}" - end - end - filename - end - end - - private - - def secure_token - model.logo_secure_token ||= generate_secure_token - end - - def generate_secure_token - SecureRandom.uuid - end -end diff --git a/app/uploaders/remote_downloader.rb b/app/uploaders/remote_downloader.rb deleted file mode 100644 index 44a6e6eec..000000000 --- a/app/uploaders/remote_downloader.rb +++ /dev/null @@ -1,17 +0,0 @@ -class RemoteDownloader - def initialize(filename) - @filename = filename - end - - def url - if @filename.present? - @url ||= File.join(base_url, CarrierWave::Uploader::Base.fog_directory, @filename) - end - end - - protected - - def base_url - FOG_BASE_URL - end -end diff --git a/app/views/fields/attestation_template_field/_show.html.haml b/app/views/fields/attestation_template_field/_show.html.haml index 60df84e18..e3f3f706b 100644 --- a/app/views/fields/attestation_template_field/_show.html.haml +++ b/app/views/fields/attestation_template_field/_show.html.haml @@ -5,8 +5,8 @@ %strong Logo %p - - if field.data.logo.present? - = image_tag field.data.logo.url + - if field.data.logo? + = image_tag field.data.logo_url - else Aucun @@ -20,8 +20,8 @@ %strong Signature %p - - if field.data.signature.present? - = image_tag field.data.signature.url + - if field.data.signature? + = image_tag field.data.signature_url - else Aucun diff --git a/app/views/instructeurs/procedures/index.html.haml b/app/views/instructeurs/procedures/index.html.haml index 1c35a6e94..af971bf01 100644 --- a/app/views/instructeurs/procedures/index.html.haml +++ b/app/views/instructeurs/procedures/index.html.haml @@ -9,7 +9,7 @@ = link_to(instructeur_procedure_path(p)) do .flex - .procedure-logo{ style: p.logo.present? ? "background-image: url(#{p.logo.url})" : nil } + .procedure-logo{ style: "background-image: url(#{p.logo_url})" } .procedure-details %p.procedure-title diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index 8c2b404ec..6dc7f9292 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -4,7 +4,7 @@ .sub-header .container.flex - .procedure-logo{ style: @procedure.logo? ? "background-image: url(#{@procedure.logo_url})" : nil, + .procedure-logo{ style: "background-image: url(#{@procedure.logo_url})", role: 'img', 'aria-label': "logo de la démarche #{@procedure.libelle}" } .procedure-header diff --git a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml index dd28f4914..f4b646548 100644 --- a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml +++ b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml @@ -1,7 +1,6 @@ #first-block .en-cours - - if @procedure.logo? - = image_tag @procedure.logo_url, style: 'width: 30px;' + = image_tag @procedure.logo_url, style: 'width: 30px;' %b = @procedure.libelle diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb deleted file mode 100644 index 2635e8012..000000000 --- a/config/initializers/carrierwave.rb +++ /dev/null @@ -1,47 +0,0 @@ -module Fog - module ServicesMixin - private - - def require_service_provider_library(service, provider) - # Monkey patch to fix https://github.com/fog/fog/issues/4014 - - # This method exists in fog to load legacy providers that have not yet been extracted to - # their own gem. - # fog-openstack has been extracted to its own gem and does not need this method. - # Furthermore, fog-openstack has recently been refactored in a way that breaks this method. - # - # Therefore, until either fog or fog-openstack fixes the problem, we have to neuter the method. - end - end -end - -CarrierWave.configure do |config| - # These permissions will make dir and files available only to the user running - # the servers - config.permissions = 0664 - config.directory_permissions = 0775 - - config.fog_provider = 'fog/openstack' - - if ENV['FOG_ENABLED'] == 'enabled' - config.fog_credentials = { - provider: 'OpenStack', - openstack_tenant: Rails.application.secrets.fog[:openstack_tenant], - openstack_api_key: Rails.application.secrets.fog[:openstack_api_key], - openstack_username: Rails.application.secrets.fog[:openstack_username], - openstack_auth_url: Rails.application.secrets.fog[:openstack_auth_url], - openstack_region: Rails.application.secrets.fog[:openstack_region], - openstack_identity_api_version: Rails.application.secrets.fog[:openstack_identity_api_version] - } - end - - # This avoids uploaded files from saving to public/ and so - # they will not be available for public (non-authenticated) downloading - config.root = Rails.root - - config.cache_dir = Rails.root.join("uploads") - - config.fog_public = true - - config.fog_directory = Rails.application.secrets.fog[:directory] -end diff --git a/config/initializers/urls.rb b/config/initializers/urls.rb index afd9bcbd9..19b442250 100644 --- a/config/initializers/urls.rb +++ b/config/initializers/urls.rb @@ -28,6 +28,3 @@ FAQ_ADMIN_URL = "https://faq.demarches-simplifiees.fr/collection/1-administrateu COMMENT_TROUVER_MA_DEMARCHE_URL = [FAQ_URL, "article", "59-comment-trouver-ma-demarche"].join("/") STATUS_PAGE_URL = "https://status.demarches-simplifiees.fr" MATOMO_IFRAME_URL = "https://stats.data.gouv.fr/index.php?module=CoreAdminHome&action=optOut&language=fr&&fontColor=333333&fontSize=16px&fontFamily=Muli" - -# FIXME: This is only used in dev in couple of places and should be removed after PJ migration -LOCAL_DOWNLOAD_URL = "http://#{ENV.fetch('APP_HOST', 'localhost:3000')}" diff --git a/lib/tasks/2019_08_20_migrate_procedure_logo.rake b/lib/tasks/2019_08_20_migrate_procedure_logo.rake deleted file mode 100644 index 11a593d7d..000000000 --- a/lib/tasks/2019_08_20_migrate_procedure_logo.rake +++ /dev/null @@ -1,33 +0,0 @@ -namespace :'2019_08_20_migrate_procedure_logo' do - task run: :environment do - procedures = Procedure.unscope(where: :hidden_at) - .where.not(logo: nil) - .left_joins(:logo_active_storage_attachment) - .where('active_storage_attachments.id IS NULL') - .order(:created_at) - - limit = ENV['LIMIT'] - if limit - procedures.limit!(limit.to_i) - end - - progress = ProgressReport.new(procedures.count) - procedures.find_each do |procedure| - if procedure.logo.present? - uri = URI.parse(URI.escape(procedure.logo_url)) - response = Typhoeus.get(uri) - if response.success? - filename = procedure.logo.filename || procedure.logo_identifier - procedure.logo_active_storage.attach( - io: StringIO.new(response.body), - filename: filename, - content_type: procedure.logo.content_type, - metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE } - ) - end - end - progress.inc - end - progress.finish - end -end diff --git a/lib/tasks/2019_08_22_migrate_attestation_files.rake b/lib/tasks/2019_08_22_migrate_attestation_files.rake deleted file mode 100644 index 9bf9e93f8..000000000 --- a/lib/tasks/2019_08_22_migrate_attestation_files.rake +++ /dev/null @@ -1,97 +0,0 @@ -namespace :'2019_08_22_migrate_attestation_files' do - task migrate_attestation_pdf: :environment do - attestations = Attestation.where - .not(pdf: nil) - .left_joins(:pdf_active_storage_attachment) - .where('active_storage_attachments.id IS NULL') - .order(:created_at) - - limit = ENV['LIMIT'] - if limit - attestations.limit!(limit.to_i) - end - - progress = ProgressReport.new(attestations.count) - attestations.find_each do |attestation| - if attestation.pdf.present? - uri = URI.parse(URI.escape(attestation.pdf_url)) - response = Typhoeus.get(uri) - if response.success? - filename = attestation.pdf.filename || attestation.pdf_identifier - attestation.pdf_active_storage.attach( - io: StringIO.new(response.body), - filename: filename, - content_type: attestation.pdf.content_type, - metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE } - ) - end - end - progress.inc - end - progress.finish - end - - task migrate_attestation_template_logo: :environment do - attestation_templates = AttestationTemplate.where - .not(logo: nil) - .left_joins(:logo_active_storage_attachment) - .where('active_storage_attachments.id IS NULL') - .order(:created_at) - - limit = ENV['LIMIT'] - if limit - attestation_templates.limit!(limit.to_i) - end - - progress = ProgressReport.new(attestation_templates.count) - attestation_templates.find_each do |attestation_template| - if attestation_template.logo.present? - uri = URI.parse(URI.escape(attestation_template.logo_url)) - response = Typhoeus.get(uri) - if response.success? - filename = attestation_template.logo.filename || attestation_template.logo_identifier - attestation_template.logo_active_storage.attach( - io: StringIO.new(response.body), - filename: filename, - content_type: attestation_template.logo.content_type, - metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE } - ) - end - end - progress.inc - end - progress.finish - end - - task migrate_attestation_template_signature: :environment do - attestation_templates = AttestationTemplate.where - .not(signature: nil) - .left_joins(:signature_active_storage_attachment) - .where('active_storage_attachments.id IS NULL') - .order(:created_at) - - limit = ENV['LIMIT'] - if limit - attestation_templates.limit!(limit.to_i) - end - - progress = ProgressReport.new(attestation_templates.count) - attestation_templates.find_each do |attestation_template| - if attestation_template.signature.present? - uri = URI.parse(URI.escape(attestation_template.signature_url)) - response = Typhoeus.get(uri) - if response.success? - filename = attestation_template.signature.filename || attestation_template.signature_identifier - attestation_template.signature_active_storage.attach( - io: StringIO.new(response.body), - filename: filename, - content_type: attestation_template.signature.content_type, - metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE } - ) - end - end - progress.inc - end - progress.finish - end -end diff --git a/spec/controllers/admin/attestation_templates_controller_spec.rb b/spec/controllers/admin/attestation_templates_controller_spec.rb index 6682ff6a9..be50deab0 100644 --- a/spec/controllers/admin/attestation_templates_controller_spec.rb +++ b/spec/controllers/admin/attestation_templates_controller_spec.rb @@ -48,8 +48,8 @@ describe Admin::AttestationTemplatesController, type: :controller do it { expect(subject.status).to eq(200) } it { expect(assigns).to include(upload_params.stringify_keys) } it { expect(assigns[:created_at]).to eq(Time.zone.now) } - it { expect(assigns(:logo).read).to eq(logo.read) } - it { expect(assigns(:signature).read).to eq(signature.read) } + it { expect(assigns(:logo).download).to eq(logo2.read) } + it { expect(assigns(:signature).download).to eq(signature2.read) } after { procedure.attestation_template.destroy } end end @@ -87,8 +87,8 @@ describe Admin::AttestationTemplatesController, type: :controller do it { expect(procedure.attestation_template).to have_attributes(attestation_params) } it { expect(procedure.attestation_template.activated).to be true } - it { expect(procedure.attestation_template.logo_active_storage.download).to eq(logo2.read) } - it { expect(procedure.attestation_template.signature_active_storage.download).to eq(signature2.read) } + it { expect(procedure.attestation_template.logo.download).to eq(logo2.read) } + it { expect(procedure.attestation_template.signature.download).to eq(signature2.read) } it { expect(response).to redirect_to edit_admin_procedure_attestation_template_path(procedure) } it { expect(flash.notice).to eq("L'attestation a bien été sauvegardée") } @@ -130,8 +130,8 @@ describe Admin::AttestationTemplatesController, type: :controller do end it { expect(procedure.attestation_template).to have_attributes(attestation_params) } - it { expect(procedure.attestation_template.logo_active_storage.download).to eq(logo2.read) } - it { expect(procedure.attestation_template.signature_active_storage.download).to eq(signature2.read) } + it { expect(procedure.attestation_template.logo.download).to eq(logo2.read) } + it { expect(procedure.attestation_template.signature.download).to eq(signature2.read) } it { expect(response).to redirect_to edit_admin_procedure_attestation_template_path(procedure) } it { expect(flash.notice).to eq("L'attestation a bien été modifiée") } diff --git a/spec/factories/attestation_template.rb b/spec/factories/attestation_template.rb index 297d9f7c2..0598960f9 100644 --- a/spec/factories/attestation_template.rb +++ b/spec/factories/attestation_template.rb @@ -7,11 +7,6 @@ FactoryBot.define do end trait :with_files do - logo_active_storage { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') } - signature_active_storage { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') } - end - - trait :with_legacy_files do logo { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') } signature { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') } end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index b652d1cc0..118b1c7d5 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -53,10 +53,6 @@ FactoryBot.define do end trait :with_logo do - logo_active_storage { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') } - end - - trait :with_legacy_logo do logo { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') } end diff --git a/spec/lib/tasks/2019_08_20_migrate_procedure_logo_spec.rb b/spec/lib/tasks/2019_08_20_migrate_procedure_logo_spec.rb deleted file mode 100644 index 313397f37..000000000 --- a/spec/lib/tasks/2019_08_20_migrate_procedure_logo_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -describe '2019_08_20_migrate_procedure_logo.rake' do - let(:rake_task) { Rake::Task['2019_08_20_migrate_procedure_logo:run'] } - - let(:procedures) do - [ - create(:procedure), - create(:procedure, :with_legacy_logo), - create(:procedure, :with_legacy_logo) - ] - end - - let(:run_task) do - rake_task.invoke - procedures.each(&:reload) - end - - before do - procedures.each do |procedure| - if procedure.logo.present? - stub_request(:get, procedure.logo_url) - .to_return(status: 200, body: File.read(procedure.logo.path)) - end - end - end - - after do - ENV['LIMIT'] = nil - rake_task.reenable - end - - it 'should migrate logo' do - expect(procedures.map(&:logo_active_storage).map(&:attached?)).to eq([false, false, false]) - - run_task - - expect(Procedure.where(logo: nil).count).to eq(1) - expect(procedures.map(&:logo_active_storage).map(&:attached?)).to eq([false, true, true]) - end - - it 'should migrate logo within limit' do - expect(procedures.map(&:logo_active_storage).map(&:attached?)).to eq([false, false, false]) - - ENV['LIMIT'] = '1' - run_task - - expect(Procedure.where(logo: nil).count).to eq(1) - expect(procedures.map(&:logo_active_storage).map(&:attached?)).to eq([false, true, false]) - end - - context 'when a procedure is hidden' do - let(:hidden_procedure) { create(:procedure, :hidden, :with_legacy_logo) } - let(:procedures) { [hidden_procedure] } - - it 'should migrate logo' do - run_task - - expect(hidden_procedure.logo_active_storage.attached?).to be true - end - end -end diff --git a/spec/lib/tasks/2019_08_22_migrate_attestation_files_spec.rb b/spec/lib/tasks/2019_08_22_migrate_attestation_files_spec.rb deleted file mode 100644 index 5a697ec47..000000000 --- a/spec/lib/tasks/2019_08_22_migrate_attestation_files_spec.rb +++ /dev/null @@ -1,128 +0,0 @@ -describe '2019_08_22_migrate_attestation_files.rake' do - let(:rake_task) { Rake::Task["2019_08_22_migrate_attestation_files:#{sub_task}"] } - - let(:run_task) do - rake_task.invoke - models.each(&:reload) - end - - after do - ENV['LIMIT'] = nil - rake_task.reenable - end - - context 'attestation' do - let(:models) do - [ - create(:attestation, created_at: 3.days.ago), - create(:attestation, :with_legacy_pdf, created_at: 2.days.ago), - create(:attestation, :with_legacy_pdf, created_at: 1.day.ago) - ] - end - - before do - first_attestation = models[0] - expect(first_attestation.pdf.present?).to be_falsey - expect(first_attestation.read_attribute(:pdf)).to be_nil - - models.each do |attestation| - if attestation.pdf.present? - stub_request(:get, attestation.pdf_url) - .to_return(status: 200, body: File.read(attestation.pdf.path)) - end - end - end - - context 'pdf' do - let(:sub_task) { 'migrate_attestation_pdf' } - - it 'should migrate pdf' do - expect(models.map(&:pdf_active_storage).map(&:attached?)).to eq([false, false, false]) - - run_task - - expect(Attestation.where(pdf: nil).count).to eq(1) - expect(models.map(&:pdf_active_storage).map(&:attached?)).to eq([false, true, true]) - end - - it 'should migrate pdf within limit' do - expect(models.map(&:pdf_active_storage).map(&:attached?)).to eq([false, false, false]) - - ENV['LIMIT'] = '1' - run_task - - expect(Attestation.where(pdf: nil).count).to eq(1) - expect(models.map(&:pdf_active_storage).map(&:attached?)).to eq([false, true, false]) - end - end - end - - context 'attestation_templates' do - let(:models) do - [ - create(:attestation_template), - create(:attestation_template, :with_legacy_files), - create(:attestation_template, :with_legacy_files) - ] - end - - before do - models.each do |attestation_template| - if attestation_template.logo.present? - stub_request(:get, attestation_template.logo_url) - .to_return(status: 200, body: File.read(attestation_template.logo.path)) - end - if attestation_template.signature.present? - stub_request(:get, attestation_template.signature_url) - .to_return(status: 200, body: File.read(attestation_template.signature.path)) - end - end - end - - context 'logo' do - let(:sub_task) { 'migrate_attestation_template_logo' } - - it 'should migrate logo' do - expect(models.map(&:logo_active_storage).map(&:attached?)).to eq([false, false, false]) - - run_task - - expect(AttestationTemplate.where(logo: nil).count).to eq(1) - expect(models.map(&:logo_active_storage).map(&:attached?)).to eq([false, true, true]) - end - - it 'should migrate logo within limit' do - expect(models.map(&:logo_active_storage).map(&:attached?)).to eq([false, false, false]) - - ENV['LIMIT'] = '1' - run_task - - expect(AttestationTemplate.where(logo: nil).count).to eq(1) - expect(models.map(&:logo_active_storage).map(&:attached?)).to eq([false, true, false]) - end - end - - context 'signature' do - let(:sub_task) { 'migrate_attestation_template_signature' } - - it 'should migrate signature' do - expect(models.map(&:signature_active_storage).map(&:attached?)).to eq([false, false, false]) - - run_task - - expect(AttestationTemplate.where(signature: nil).count).to eq(1) - expect(models.map(&:signature_active_storage).map(&:attached?)).to eq([false, true, true]) - end - - it 'should migrate signature within limit' do - expect(models.map(&:signature_active_storage).map(&:attached?)).to eq([false, false, false]) - - ENV['LIMIT'] = '1' - run_task - - expect(AttestationTemplate.where(signature: nil).count).to eq(1) - expect(models.map(&:signature_active_storage).map(&:attached?)).to eq([false, true, false]) - end - end - end -end diff --git a/spec/models/attestation_template_spec.rb b/spec/models/attestation_template_spec.rb index ced59e011..129c3c358 100644 --- a/spec/models/attestation_template_spec.rb +++ b/spec/models/attestation_template_spec.rb @@ -57,13 +57,11 @@ describe AttestationTemplate, type: :model do describe 'dup' do before do - @logo = File.open('spec/fixtures/files/white.png') - @signature = File.open('spec/fixtures/files/black.png') + @logo = Rack::Test::UploadedFile.new('spec/fixtures/files/white.png', 'image/png') + @signature = Rack::Test::UploadedFile.new('spec/fixtures/files/black.png', 'image/png') end after do - @logo.close - @signature.close subject.destroy end @@ -75,17 +73,17 @@ describe AttestationTemplate, type: :model do it { is_expected.to have_attributes(attributes) } it { is_expected.to have_attributes(id: nil) } - it { expect(subject.logo.file).to be_nil } + it { expect(subject.logo.attached?).to be_falsey } end context 'with an attestation with images' do let(:attributes) { { logo: @logo, signature: @signature } } - it { expect(subject.logo.file.file).not_to eq(attestation_template.logo.file.file) } - it { expect(subject.logo.file.read).to eq(attestation_template.logo.file.read) } + it { expect(subject.logo.blob).not_to eq(attestation_template.logo.blob) } + it { expect(subject.logo.download).to eq(attestation_template.logo.download) } - it { expect(subject.signature.file.file).not_to eq(attestation_template.signature.file.file) } - it { expect(subject.signature.file.read).to eq(attestation_template.signature.file.read) } + it { expect(subject.signature.blob).not_to eq(attestation_template.signature.blob) } + it { expect(subject.signature.download).to eq(attestation_template.signature.download) } end end @@ -113,14 +111,10 @@ describe AttestationTemplate, type: :model do end before do - @logo = File.open('spec/fixtures/files/white.png') - @signature = File.open('spec/fixtures/files/black.png') Timecop.freeze(Time.zone.now) end after do - @logo.close - @signature.close Timecop.return end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a0d20b465..ca4b4feed 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -139,8 +139,6 @@ RSpec.configure do |config| config.include FactoryBot::Syntax::Methods config.before(:each) do - allow_any_instance_of(ProcedureLogoUploader).to receive(:generate_secure_token).and_return("3dbb3535-5388-4a37-bc2d-778327b9f998") - Flipflop::FeatureSet.current.test!.reset! end diff --git a/spec/uploaders/base_uploader_spec.rb b/spec/uploaders/base_uploader_spec.rb deleted file mode 100644 index bee24d096..000000000 --- a/spec/uploaders/base_uploader_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'spec_helper' - -describe BaseUploader do - let(:uploader) { described_class.new } - - describe '#cache_dir' do - subject { uploader.cache_dir } - - it { is_expected.to eq '/tmp/tps-test-cache' } - end -end diff --git a/spec/uploaders/remote_downloader_spec.rb b/spec/uploaders/remote_downloader_spec.rb deleted file mode 100644 index e49e52ce8..000000000 --- a/spec/uploaders/remote_downloader_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'spec_helper' - -describe RemoteDownloader do - let(:filename) { 'file_name.pdf' } - - subject { described_class.new filename } - - describe '#url' do - it { expect(subject.url).to eq 'https://static.demarches-simplifiees.fr/tps_dev/file_name.pdf' } - - context 'no filename' do - let(:filename) { nil } - - it { expect(subject.url).to be_nil } - end - end -end From e975e2a0aa2076be5bc4859c6cf44c8f794cbf0b Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 28 Aug 2019 15:38:00 +0200 Subject: [PATCH 2/4] Add an active_storage attachmens rename task --- ...28130014_rename_active_storage_attachments.rake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lib/tasks/deployment/20190828130014_rename_active_storage_attachments.rake diff --git a/lib/tasks/deployment/20190828130014_rename_active_storage_attachments.rake b/lib/tasks/deployment/20190828130014_rename_active_storage_attachments.rake new file mode 100644 index 000000000..11e5fd671 --- /dev/null +++ b/lib/tasks/deployment/20190828130014_rename_active_storage_attachments.rake @@ -0,0 +1,14 @@ +namespace :after_party do + desc 'Deployment task: rename_active_storage_attachments' + task rename_active_storage_attachments: :environment do + puts "Running deploy task 'rename_active_storage_attachments'" + + ActiveStorage::Attachment.where(name: 'logo_active_storage').update_all(name: 'logo') + ActiveStorage::Attachment.where(name: 'signature_active_storage').update_all(name: 'signature') + ActiveStorage::Attachment.where(name: 'pdf_active_storage').update_all(name: 'pdf') + + # Update task as completed. If you remove the line below, the task will + # run with every deploy (or every time you call after_party:run). + AfterParty::TaskRecord.create version: '20190828130014' + end +end From 434210de2ec73d807f458b0954672b25c3f7fea6 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 28 Aug 2019 16:14:20 +0200 Subject: [PATCH 3/4] Ignore to be removed columns --- app/models/attestation.rb | 2 ++ app/models/attestation_template.rb | 2 ++ app/models/commentaire.rb | 2 ++ app/models/procedure.rb | 2 ++ 4 files changed, 8 insertions(+) diff --git a/app/models/attestation.rb b/app/models/attestation.rb index f5e291a59..33239b4a8 100644 --- a/app/models/attestation.rb +++ b/app/models/attestation.rb @@ -1,4 +1,6 @@ class Attestation < ApplicationRecord + self.ignored_columns = ['pdf'] + belongs_to :dossier has_one_attached :pdf diff --git a/app/models/attestation_template.rb b/app/models/attestation_template.rb index fb6863493..c53da0f6c 100644 --- a/app/models/attestation_template.rb +++ b/app/models/attestation_template.rb @@ -1,4 +1,6 @@ class AttestationTemplate < ApplicationRecord + self.ignored_columns = ['logo', 'signature'] + include ActionView::Helpers::NumberHelper include TagsSubstitutionConcern diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 4ff31f768..73f10ff9a 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -1,4 +1,6 @@ class Commentaire < ApplicationRecord + self.ignored_columns = ['file'] + belongs_to :dossier, inverse_of: :commentaires, touch: true belongs_to :user diff --git a/app/models/procedure.rb b/app/models/procedure.rb index d14ce7098..a714fe691 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -1,6 +1,8 @@ require Rails.root.join('lib', 'percentile') class Procedure < ApplicationRecord + self.ignored_columns = ['logo'] + MAX_DUREE_CONSERVATION = 36 has_many :types_de_champ, -> { root.public_only.ordered }, inverse_of: :procedure, dependent: :destroy From d8402fbd2cffa707ebe1d963eebe129e03fa4502 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 28 Aug 2019 16:42:32 +0200 Subject: [PATCH 4/4] Remove last reference to commentaire.file --- app/views/shared/dossiers/messages/_message.html.haml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/views/shared/dossiers/messages/_message.html.haml b/app/views/shared/dossiers/messages/_message.html.haml index 0c1dc7bb8..885f33c23 100644 --- a/app/views/shared/dossiers/messages/_message.html.haml +++ b/app/views/shared/dossiers/messages/_message.html.haml @@ -14,11 +14,6 @@ - if commentaire.piece_jointe.attached? .attachment-link = render partial: "shared/attachment/show", locals: { attachment: commentaire.piece_jointe.attachment } - - elsif commentaire.file.present? - .attachment-link - = link_to commentaire.file_url, class: "button", target: "_blank", rel: "noopener", title: "Télécharger" do - %span.icon.attachment - = commentaire.file_identifier - if show_reply_button = button_tag type: 'button', class: 'button small message-answer-button', onclick: 'document.querySelector("#commentaire_body").focus()' do