Skip to content

Commit

Permalink
custom filename for logo. #443
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Mar 3, 2020
1 parent 83fdff8 commit 2079443
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
5 changes: 4 additions & 1 deletion config/environments/stage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions spec/models/provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2079443

Please sign in to comment.