Commit 9bdc0a00 by Tute Costa

Drop S3::DEFAULT_PERMISSION constant

This configuration constant was useful for supporting different versions
of AWS SDK. We don't any longer, and we can set the value directly.

[fixes #2148]
parent 3b4fd331
...@@ -115,8 +115,6 @@ module Paperclip ...@@ -115,8 +115,6 @@ module Paperclip
def self.extended base def self.extended base
begin begin
require 'aws-sdk' require 'aws-sdk'
const_set 'DEFAULT_PERMISSION', :"public-read"
rescue LoadError => e rescue LoadError => e
e.message << " (You may need to install the aws-sdk gem)" e.message << " (You may need to install the aws-sdk gem)"
raise e raise e
...@@ -133,7 +131,7 @@ module Paperclip ...@@ -133,7 +131,7 @@ module Paperclip
Proc.new do |style, attachment| Proc.new do |style, attachment|
permission = (@s3_permissions[style.to_s.to_sym] || @s3_permissions[:default]) permission = (@s3_permissions[style.to_s.to_sym] || @s3_permissions[:default])
permission = permission.call(attachment, style) if permission.respond_to?(:call) permission = permission.call(attachment, style) if permission.respond_to?(:call)
(permission == DEFAULT_PERMISSION) ? 'http'.freeze : 'https'.freeze (permission == :"public-read") ? 'http'.freeze : 'https'.freeze
end end
@s3_metadata = @options[:s3_metadata] || {} @s3_metadata = @options[:s3_metadata] || {}
@s3_headers = {} @s3_headers = {}
...@@ -283,7 +281,7 @@ module Paperclip ...@@ -283,7 +281,7 @@ module Paperclip
def set_permissions permissions def set_permissions permissions
permissions = { :default => permissions } unless permissions.respond_to?(:merge) permissions = { :default => permissions } unless permissions.respond_to?(:merge)
permissions.merge :default => (permissions[:default] || DEFAULT_PERMISSION) permissions.merge :default => (permissions[:default] || :"public-read")
end end
def set_storage_class(storage_class) def set_storage_class(storage_class)
......
...@@ -349,10 +349,10 @@ describe Paperclip::Storage::S3 do ...@@ -349,10 +349,10 @@ describe Paperclip::Storage::S3 do
object.expects(:upload_file) object.expects(:upload_file)
.with(anything, content_type: 'image/png', .with(anything, content_type: 'image/png',
acl: Paperclip::Storage::S3::DEFAULT_PERMISSION) acl: :"public-read")
object.expects(:upload_file) object.expects(:upload_file)
.with(anything, content_type: 'image/png', .with(anything, content_type: 'image/png',
acl: Paperclip::Storage::S3::DEFAULT_PERMISSION, acl: :"public-read",
cache_control: 'max-age=31557600') cache_control: 'max-age=31557600')
@dummy.save @dummy.save
end end
...@@ -772,8 +772,7 @@ describe Paperclip::Storage::S3 do ...@@ -772,8 +772,7 @@ describe Paperclip::Storage::S3 do
object = stub object = stub
@dummy.avatar.stubs(:s3_object).returns(object) @dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:upload_file) object.expects(:upload_file)
.with(anything, content_type: 'image/png', .with(anything, content_type: 'image/png', acl: :"public-read")
acl: Paperclip::Storage::S3::DEFAULT_PERMISSION)
@dummy.save @dummy.save
end end
...@@ -924,7 +923,7 @@ describe Paperclip::Storage::S3 do ...@@ -924,7 +923,7 @@ describe Paperclip::Storage::S3 do
object.expects(:upload_file) object.expects(:upload_file)
.with(anything, .with(anything,
content_type: 'image/png', content_type: 'image/png',
acl: Paperclip::Storage::S3::DEFAULT_PERMISSION, acl: :"public-read",
cache_control: 'max-age=31557600') cache_control: 'max-age=31557600')
@dummy.save @dummy.save
end end
...@@ -965,7 +964,7 @@ describe Paperclip::Storage::S3 do ...@@ -965,7 +964,7 @@ describe Paperclip::Storage::S3 do
object.expects(:upload_file) object.expects(:upload_file)
.with(anything, .with(anything,
content_type: 'image/png', content_type: 'image/png',
acl: Paperclip::Storage::S3::DEFAULT_PERMISSION, acl: :"public-read",
metadata: { "color" => "red" }) metadata: { "color" => "red" })
@dummy.save @dummy.save
end end
...@@ -1006,7 +1005,7 @@ describe Paperclip::Storage::S3 do ...@@ -1006,7 +1005,7 @@ describe Paperclip::Storage::S3 do
object.expects(:upload_file) object.expects(:upload_file)
.with(anything, .with(anything,
content_type: 'image/png', content_type: 'image/png',
acl: Paperclip::Storage::S3::DEFAULT_PERMISSION, acl: :"public-read",
metadata: { "color" => "red" }) metadata: { "color" => "red" })
@dummy.save @dummy.save
end end
...@@ -1048,7 +1047,7 @@ describe Paperclip::Storage::S3 do ...@@ -1048,7 +1047,7 @@ describe Paperclip::Storage::S3 do
object.expects(:upload_file) object.expects(:upload_file)
.with(anything, .with(anything,
content_type: 'image/png', content_type: 'image/png',
acl: Paperclip::Storage::S3::DEFAULT_PERMISSION, acl: :"public-read",
storage_class: "reduced_redundancy") storage_class: "reduced_redundancy")
@dummy.save @dummy.save
end end
...@@ -1094,7 +1093,7 @@ describe Paperclip::Storage::S3 do ...@@ -1094,7 +1093,7 @@ describe Paperclip::Storage::S3 do
expected_options = { expected_options = {
:content_type => "image/png", :content_type => "image/png",
:acl => Paperclip::Storage::S3::DEFAULT_PERMISSION acl: :"public-read"
} }
expected_options.merge!(:storage_class => :reduced_redundancy) if style == :thumb expected_options.merge!(:storage_class => :reduced_redundancy) if style == :thumb
...@@ -1143,7 +1142,7 @@ describe Paperclip::Storage::S3 do ...@@ -1143,7 +1142,7 @@ describe Paperclip::Storage::S3 do
object.expects(:upload_file) object.expects(:upload_file)
.with(anything, :content_type => "image/png", .with(anything, :content_type => "image/png",
:acl => Paperclip::Storage::S3::DEFAULT_PERMISSION, acl: :"public-read",
:storage_class => :reduced_redundancy) :storage_class => :reduced_redundancy)
end end
@dummy.save @dummy.save
...@@ -1185,8 +1184,7 @@ describe Paperclip::Storage::S3 do ...@@ -1185,8 +1184,7 @@ describe Paperclip::Storage::S3 do
@dummy.avatar.stubs(:s3_object).returns(object) @dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:upload_file) object.expects(:upload_file)
.with(anything, :content_type => "image/png", .with(anything, :content_type => "image/png", acl: :"public-read")
:acl => Paperclip::Storage::S3::DEFAULT_PERMISSION)
@dummy.save @dummy.save
end end
...@@ -1226,7 +1224,7 @@ describe Paperclip::Storage::S3 do ...@@ -1226,7 +1224,7 @@ describe Paperclip::Storage::S3 do
object.expects(:upload_file) object.expects(:upload_file)
.with(anything, content_type: "image/png", .with(anything, content_type: "image/png",
acl: Paperclip::Storage::S3::DEFAULT_PERMISSION, acl: :"public-read",
server_side_encryption: :aes256) server_side_encryption: :aes256)
@dummy.save @dummy.save
end end
...@@ -1267,7 +1265,7 @@ describe Paperclip::Storage::S3 do ...@@ -1267,7 +1265,7 @@ describe Paperclip::Storage::S3 do
object.expects(:upload_file) object.expects(:upload_file)
.with(anything, .with(anything,
content_type: "image/png", content_type: "image/png",
acl: Paperclip::Storage::S3::DEFAULT_PERMISSION, acl: :"public-read",
storage_class: :reduced_redundancy) storage_class: :reduced_redundancy)
@dummy.save @dummy.save
end end
...@@ -1359,9 +1357,7 @@ describe Paperclip::Storage::S3 do ...@@ -1359,9 +1357,7 @@ describe Paperclip::Storage::S3 do
@dummy.avatar.stubs(:s3_object).returns(object) @dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:upload_file) object.expects(:upload_file)
.with(anything, .with(anything, content_type: "image/png", acl: :"public-read")
content_type: "image/png",
acl: Paperclip::Storage::S3::DEFAULT_PERMISSION)
@dummy.save @dummy.save
end end
...@@ -1472,7 +1468,7 @@ describe Paperclip::Storage::S3 do ...@@ -1472,7 +1468,7 @@ describe Paperclip::Storage::S3 do
'secret_access_key' => "54321" 'secret_access_key' => "54321"
}, },
s3_permissions: lambda {|attachment, style| s3_permissions: lambda {|attachment, style|
attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : Paperclip::Storage::S3::DEFAULT_PERMISSION attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :"public-read"
} }
) )
end end
...@@ -1540,7 +1536,7 @@ describe Paperclip::Storage::S3 do ...@@ -1540,7 +1536,7 @@ describe Paperclip::Storage::S3 do
object.expects(:upload_file) object.expects(:upload_file)
.with(anything, .with(anything,
content_type: "image/png", content_type: "image/png",
acl: Paperclip::Storage::S3::DEFAULT_PERMISSION, acl: :"public-read",
content_disposition: 'attachment; filename="Custom Avatar Name.png"') content_disposition: 'attachment; filename="Custom Avatar Name.png"')
end end
@dummy.save @dummy.save
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment