From 2079443a508869371715b2d3e3d5076efcc9d7fb Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Tue, 3 Mar 2020 13:39:44 +0100 Subject: [PATCH] custom filename for logo. #443 --- app/models/provider.rb | 3 +++ config/application.rb | 2 +- config/environments/production.rb | 6 +++++- config/environments/stage.rb | 5 ++++- spec/models/provider_spec.rb | 1 + 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/models/provider.rb b/app/models/provider.rb index afeac79bc..7057b311a 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -600,5 +600,8 @@ def set_defaults self.billing_information = {} unless billing_information.present? self.consortium_id = nil unless member_type == "consortium_organization" self.non_profit_status = "non-profit" unless non_profit_status.present? + + # custom filename for attachment as data URLs don't support filenames + self.logo_file_name = symbol.downcase + "." + logo_content_type.split("/").last if logo_content_type.present? end end diff --git a/config/application.rb b/config/application.rb index 95d7b2efa..ef92425a5 100644 --- a/config/application.rb +++ b/config/application.rb @@ -135,7 +135,7 @@ class Application < Rails::Application config.paperclip_defaults = { storage: :filesystem, - url: "/images/members/:id_partition/:filename", + url: "/images/members/:filename", } end end diff --git a/config/environments/production.rb b/config/environments/production.rb index a5ad84a64..dc70baa48 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -63,7 +63,11 @@ config.paperclip_defaults = { storage: :s3, - url: "/images/members/:id_partition/:filename", + url: "https://assets.datacite.org/images/members/:filename", + s3_protocol: :https, + s3_host_alias: "sub.domain.com", + url: ":s3_alias_url", + path: "/images/members/:filename", preserve_files: true, s3_host_name: "s3-eu-west-1.amazonaws.com", s3_credentials: { diff --git a/config/environments/stage.rb b/config/environments/stage.rb index 895d11b2f..4722e1572 100644 --- a/config/environments/stage.rb +++ b/config/environments/stage.rb @@ -61,7 +61,10 @@ config.paperclip_defaults = { storage: :s3, - url: "/images/members/:id_partition/:filename", + s3_protocol: "https", + s3_host_alias: "assets.test.datacite.org", + url: ":s3_alias_url", + path: "/images/members/:filename", preserve_files: true, s3_host_name: "s3-eu-west-1.amazonaws.com", s3_credentials: { diff --git a/spec/models/provider_spec.rb b/spec/models/provider_spec.rb index f9d618b24..8231bd45a 100644 --- a/spec/models/provider_spec.rb +++ b/spec/models/provider_spec.rb @@ -83,6 +83,7 @@ expect(subject.logo.url).to start_with("/images/members/000") expect(subject.logo.url(:medium)).to start_with("/images/members/000") expect(subject.logo_url).to start_with("/images/members/000") + expect(subject.logo_file_name).to eq(subject.symbol.downcase + ".png") expect(subject.logo.content_type).to eq("image/png") expect(subject.logo.size).to be > 10 end