Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add option s3_acl_enabled #92

Merged
merged 2 commits into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/paperclip/storage/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def self.extended(base)
@s3_headers = {}
merge_s3_headers(@options[:s3_headers], @s3_headers, @s3_metadata)

@s3_acl_enabled = @options[:s3_acl_enabled]
@s3_acl_enabled = true if @s3_acl_enabled.nil?

@s3_storage_class = set_storage_class(@options[:s3_storage_class])

@s3_server_side_encryption = "AES256"
Expand Down Expand Up @@ -359,9 +362,12 @@ def flush_writes #:nodoc:
log("saving #{path(style)}")
write_options = {
content_type: file.content_type,
acl: s3_permissions(style)
}

if @s3_acl_enabled
write_options[:acl] = s3_permissions(style)
end

# add storage class for this style if defined
storage_class = s3_storage_class(style)
write_options.merge!(storage_class: storage_class) if storage_class
Expand Down
56 changes: 56 additions & 0 deletions spec/paperclip/storage/s3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,62 @@ def counter
end
end

context "An attachment that uses S3 for storage with acl disabled" do
before do
rebuild_model(
aws2_add_region.merge(
storage: :s3,
styles: { thumb: ["90x90#", :jpg] },
bucket: "bucket",
s3_acl_enabled: false,
s3_credentials: {
"access_key_id" => "12345",
"secret_access_key" => "54321"
}
)
)

@file = File.new(fixture_file("5k.png"), "rb")
@dummy = Dummy.new
@dummy.avatar = @file
@dummy.save
end

context "reprocess" do
before do
@object = double
allow(@dummy.avatar).to receive(:s3_object).with(:original).and_return(@object)
allow(@dummy.avatar).to receive(:s3_object).with(:thumb).and_return(@object)
allow(@object).to receive(:get).and_yield(@file.read)
allow(@object).to receive(:exists?).and_return(true)
allow(@object).to receive(:download_file).with(anything)
end

it "uploads original" do
expect(@object).to receive(:upload_file).with(
anything,
content_type: "image/png",
).and_return(true)
@dummy.avatar.reprocess!
expect(@object).to receive(:upload_file).with(
anything,
content_type: "image/png",
).and_return(true)
@dummy.avatar.reprocess!
end

it "doesn't upload original" do
expect(@object).to receive(:upload_file).with(
anything,
content_type: "image/png",
).and_return(true)
@dummy.avatar.reprocess!
end
end

after { @file.close }
end

context "An attachment that uses S3 for storage and has styles" do
before do
rebuild_model(
Expand Down