kt-paperclip 7.1.0 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 157a08d6afe54c6a2b058e2a1fb8f9f8b11b19c49e565d28fba6e9bda226ba8e
4
- data.tar.gz: 07a4071fdde88ed97090788de2ee932c61478517952f79f59d0f2bea437706a6
3
+ metadata.gz: ada7e8b864e1b23b9bd7064be5e30202ce2f89869de43d136df1a915951fc97d
4
+ data.tar.gz: fbe391dc1f775274f4e3f6972991c2883fc30c5d4970c925b43a48c651c6f9e3
5
5
  SHA512:
6
- metadata.gz: 95a1f25661bbeae438168c7145fe36662b5926b7a9bf6ebddeec6a7d2424995764cd3875ca8eb224cbeb0ddf3b8f764ab3d646518cf1b19b031e684edc249894
7
- data.tar.gz: 34263d2e70b9698db8a90dd547e1225451a664ac6e3a5aa44cc17287b80d00d9ca8216740fe9ab4c9f808df0757d228b1a29d8e3ef46954b0ee835321d49581f
6
+ metadata.gz: bb686418ce534696a30cb0610b7af967b608a889c2f1efb68ce577ab65334df366177674887cadb98be6739b54c06158cae9de7d98a8adaf011d23e245128ed8
7
+ data.tar.gz: b19cd6cd395d65fa25d90f63f597fbe4585890a2c257d0636791613410ea53b6d9df441512e581160e4c16e2d3e0e8dff55910038165449516a3c00067a99eb3
data/README.md CHANGED
@@ -592,9 +592,9 @@ Storage
592
592
 
593
593
  Paperclip ships with 3 storage adapters:
594
594
 
595
- * File Storage
596
- * S3 Storage (via `aws-sdk-s3`)
597
- * Fog Storage
595
+ * File Storage (`storage: :filesystem`)
596
+ * S3 Storage (via `aws-sdk-s3`) (`storage: :s3`)
597
+ * Fog Storage (`storage: :fog`)
598
598
 
599
599
  If you would like to use Paperclip with another storage, you can install these
600
600
  gems along side with Paperclip:
@@ -74,6 +74,7 @@ module Paperclip
74
74
  # Marcel::MineType returns 'application/octet-stream' if it can't find
75
75
  # a valid type.
76
76
  @type_from_marcel = nil if @type_from_marcel == SENSIBLE_DEFAULT
77
+ @type_from_marcel
77
78
  end
78
79
 
79
80
  def type_from_file_command
@@ -54,10 +54,14 @@ module Paperclip
54
54
  # Returns the interpolated URL. Will raise an error if the url itself
55
55
  # contains ":url" to prevent infinite recursion. This interpolation
56
56
  # is used in the default :path to ease default specifications.
57
- RIGHT_HERE = "#{__FILE__.gsub(%r{\A\./}, '')}:#{__LINE__ + 3}"
58
57
  def url(attachment, style_name)
59
- raise Errors::InfiniteInterpolationError if caller.any? { |b| b.index(RIGHT_HERE) }
58
+ if Thread.current.thread_variable_get(:kt_paperclip_no_recursion)
59
+ raise Errors::InfiniteInterpolationError
60
+ end
61
+ Thread.current.thread_variable_set(:kt_paperclip_no_recursion, true)
60
62
  attachment.url(style_name, timestamp: false, escape: false)
63
+ ensure
64
+ Thread.current.thread_variable_set(:kt_paperclip_no_recursion, false)
61
65
  end
62
66
 
63
67
  # Returns the timestamp as defined by the <attachment>_updated_at field
@@ -76,6 +76,8 @@ module Paperclip
76
76
  Paperclip.run("file", "-b --mime :file", file: @file.path).
77
77
  split(/[:;\s]+/).first
78
78
  rescue Terrapin::CommandLineError
79
+ Paperclip.log("Problem getting type from `file` command. Possible that `file` doesn't exist on this system. Content Type validations don't work without this.")
80
+
79
81
  ""
80
82
  end
81
83
 
@@ -6,7 +6,7 @@ module Paperclip
6
6
  COLUMNS = { file_name: :string,
7
7
  content_type: :string,
8
8
  file_size: :bigint,
9
- updated_at: :datetime }.freeze
9
+ updated_at: :datetime }
10
10
 
11
11
  def self.included(_base)
12
12
  ActiveRecord::ConnectionAdapters::Table.include TableDefinition
@@ -137,6 +137,9 @@ module Paperclip
137
137
  @s3_headers = {}
138
138
  merge_s3_headers(@options[:s3_headers], @s3_headers, @s3_metadata)
139
139
 
140
+ @s3_acl_enabled = @options[:s3_acl_enabled]
141
+ @s3_acl_enabled = true if @s3_acl_enabled.nil?
142
+
140
143
  @s3_storage_class = set_storage_class(@options[:s3_storage_class])
141
144
 
142
145
  @s3_server_side_encryption = "AES256"
@@ -359,9 +362,12 @@ module Paperclip
359
362
  log("saving #{path(style)}")
360
363
  write_options = {
361
364
  content_type: file.content_type,
362
- acl: s3_permissions(style)
363
365
  }
364
366
 
367
+ if @s3_acl_enabled
368
+ write_options[:acl] = s3_permissions(style)
369
+ end
370
+
365
371
  # add storage class for this style if defined
366
372
  storage_class = s3_storage_class(style)
367
373
  write_options.merge!(storage_class: storage_class) if storage_class
@@ -427,9 +433,9 @@ module Paperclip
427
433
  def find_credentials(creds)
428
434
  case creds
429
435
  when File
430
- YAML::safe_load(ERB.new(File.read(creds.path)).result, [], [], true)
436
+ load_credentials_from_file(creds.path)
431
437
  when String, Pathname
432
- YAML::safe_load(ERB.new(File.read(creds)).result, [], [], true)
438
+ load_credentials_from_file(creds)
433
439
  when Hash
434
440
  creds
435
441
  when NilClass
@@ -439,6 +445,14 @@ module Paperclip
439
445
  end
440
446
  end
441
447
 
448
+ def load_credentials_from_file(path)
449
+ if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("3.1.0")
450
+ YAML::safe_load(ERB.new(File.read(path)).result, aliases: true)
451
+ else
452
+ YAML::safe_load(ERB.new(File.read(path)).result, [], [], true)
453
+ end
454
+ end
455
+
442
456
  def use_secure_protocol?(style_name)
443
457
  s3_protocol(style_name) == "https"
444
458
  end
@@ -35,7 +35,7 @@ module Paperclip
35
35
  options.slice(*AVAILABLE_CHECKS).each do |option, option_value|
36
36
  option_value = option_value.call(record) if option_value.is_a?(Proc)
37
37
  option_value = extract_option_value(option, option_value)
38
- operator = Rails::VERSION::MAJOR >= 7 ? COMPARE_CHECKS[option] : CHECKS[option]
38
+ operator = ActiveRecord::VERSION::MAJOR >= 7 ? COMPARE_CHECKS[option] : CHECKS[option]
39
39
 
40
40
  unless value.send(operator, option_value)
41
41
  error_message_key = options[:in] ? :in_between : option
@@ -1,3 +1,3 @@
1
1
  module Paperclip
2
- VERSION = "7.1.0" unless defined?(Paperclip::VERSION)
2
+ VERSION = "7.2.0" unless defined?(Paperclip::VERSION)
3
3
  end
@@ -411,6 +411,62 @@ describe Paperclip::Storage::S3 do
411
411
  end
412
412
  end
413
413
 
414
+ context "An attachment that uses S3 for storage with acl disabled" do
415
+ before do
416
+ rebuild_model(
417
+ aws2_add_region.merge(
418
+ storage: :s3,
419
+ styles: { thumb: ["90x90#", :jpg] },
420
+ bucket: "bucket",
421
+ s3_acl_enabled: false,
422
+ s3_credentials: {
423
+ "access_key_id" => "12345",
424
+ "secret_access_key" => "54321"
425
+ }
426
+ )
427
+ )
428
+
429
+ @file = File.new(fixture_file("5k.png"), "rb")
430
+ @dummy = Dummy.new
431
+ @dummy.avatar = @file
432
+ @dummy.save
433
+ end
434
+
435
+ context "reprocess" do
436
+ before do
437
+ @object = double
438
+ allow(@dummy.avatar).to receive(:s3_object).with(:original).and_return(@object)
439
+ allow(@dummy.avatar).to receive(:s3_object).with(:thumb).and_return(@object)
440
+ allow(@object).to receive(:get).and_yield(@file.read)
441
+ allow(@object).to receive(:exists?).and_return(true)
442
+ allow(@object).to receive(:download_file).with(anything)
443
+ end
444
+
445
+ it "uploads original" do
446
+ expect(@object).to receive(:upload_file).with(
447
+ anything,
448
+ content_type: "image/png",
449
+ ).and_return(true)
450
+ @dummy.avatar.reprocess!
451
+ expect(@object).to receive(:upload_file).with(
452
+ anything,
453
+ content_type: "image/png",
454
+ ).and_return(true)
455
+ @dummy.avatar.reprocess!
456
+ end
457
+
458
+ it "doesn't upload original" do
459
+ expect(@object).to receive(:upload_file).with(
460
+ anything,
461
+ content_type: "image/png",
462
+ ).and_return(true)
463
+ @dummy.avatar.reprocess!
464
+ end
465
+ end
466
+
467
+ after { @file.close }
468
+ end
469
+
414
470
  context "An attachment that uses S3 for storage and has styles" do
415
471
  before do
416
472
  rebuild_model(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kt-paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.0
4
+ version: 7.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Surendra Singhi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-04 00:00:00.000000000 Z
11
+ date: 2023-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -587,8 +587,114 @@ required_rubygems_version: !ruby/object:Gem::Requirement
587
587
  version: '0'
588
588
  requirements:
589
589
  - ImageMagick
590
- rubygems_version: 3.0.1
591
- signing_key:
590
+ rubygems_version: 3.1.6
591
+ signing_key:
592
592
  specification_version: 4
593
593
  summary: File attachments as attributes for ActiveRecord
594
- test_files: []
594
+ test_files:
595
+ - features/basic_integration.feature
596
+ - features/migration.feature
597
+ - features/rake_tasks.feature
598
+ - features/step_definitions/attachment_steps.rb
599
+ - features/step_definitions/html_steps.rb
600
+ - features/step_definitions/rails_steps.rb
601
+ - features/step_definitions/s3_steps.rb
602
+ - features/step_definitions/web_steps.rb
603
+ - features/support/env.rb
604
+ - features/support/fakeweb.rb
605
+ - features/support/file_helpers.rb
606
+ - features/support/fixtures/boot_config.txt
607
+ - features/support/fixtures/gemfile.txt
608
+ - features/support/fixtures/preinitializer.txt
609
+ - features/support/paths.rb
610
+ - features/support/rails.rb
611
+ - features/support/selectors.rb
612
+ - spec/database.yml
613
+ - spec/paperclip/attachment_definitions_spec.rb
614
+ - spec/paperclip/attachment_processing_spec.rb
615
+ - spec/paperclip/attachment_registry_spec.rb
616
+ - spec/paperclip/attachment_spec.rb
617
+ - spec/paperclip/content_type_detector_spec.rb
618
+ - spec/paperclip/file_command_content_type_detector_spec.rb
619
+ - spec/paperclip/filename_cleaner_spec.rb
620
+ - spec/paperclip/geometry_detector_spec.rb
621
+ - spec/paperclip/geometry_parser_spec.rb
622
+ - spec/paperclip/geometry_spec.rb
623
+ - spec/paperclip/glue_spec.rb
624
+ - spec/paperclip/has_attached_file_spec.rb
625
+ - spec/paperclip/integration_spec.rb
626
+ - spec/paperclip/interpolations_spec.rb
627
+ - spec/paperclip/io_adapters/abstract_adapter_spec.rb
628
+ - spec/paperclip/io_adapters/attachment_adapter_spec.rb
629
+ - spec/paperclip/io_adapters/data_uri_adapter_spec.rb
630
+ - spec/paperclip/io_adapters/empty_string_adapter_spec.rb
631
+ - spec/paperclip/io_adapters/file_adapter_spec.rb
632
+ - spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb
633
+ - spec/paperclip/io_adapters/identity_adapter_spec.rb
634
+ - spec/paperclip/io_adapters/nil_adapter_spec.rb
635
+ - spec/paperclip/io_adapters/registry_spec.rb
636
+ - spec/paperclip/io_adapters/stringio_adapter_spec.rb
637
+ - spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb
638
+ - spec/paperclip/io_adapters/uri_adapter_spec.rb
639
+ - spec/paperclip/matchers/have_attached_file_matcher_spec.rb
640
+ - spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb
641
+ - spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb
642
+ - spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb
643
+ - spec/paperclip/media_type_spoof_detector_spec.rb
644
+ - spec/paperclip/meta_class_spec.rb
645
+ - spec/paperclip/paperclip_missing_attachment_styles_spec.rb
646
+ - spec/paperclip/paperclip_spec.rb
647
+ - spec/paperclip/plural_cache_spec.rb
648
+ - spec/paperclip/processor_helpers_spec.rb
649
+ - spec/paperclip/processor_spec.rb
650
+ - spec/paperclip/rails_environment_spec.rb
651
+ - spec/paperclip/rake_spec.rb
652
+ - spec/paperclip/schema_spec.rb
653
+ - spec/paperclip/storage/filesystem_spec.rb
654
+ - spec/paperclip/storage/fog_spec.rb
655
+ - spec/paperclip/storage/s3_live_spec.rb
656
+ - spec/paperclip/storage/s3_spec.rb
657
+ - spec/paperclip/style_spec.rb
658
+ - spec/paperclip/tempfile_factory_spec.rb
659
+ - spec/paperclip/tempfile_spec.rb
660
+ - spec/paperclip/thumbnail_spec.rb
661
+ - spec/paperclip/url_generator_spec.rb
662
+ - spec/paperclip/validators/attachment_content_type_validator_spec.rb
663
+ - spec/paperclip/validators/attachment_file_name_validator_spec.rb
664
+ - spec/paperclip/validators/attachment_presence_validator_spec.rb
665
+ - spec/paperclip/validators/attachment_size_validator_spec.rb
666
+ - spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb
667
+ - spec/paperclip/validators_spec.rb
668
+ - spec/spec_helper.rb
669
+ - spec/support/assertions.rb
670
+ - spec/support/fake_model.rb
671
+ - spec/support/fake_rails.rb
672
+ - spec/support/fixtures/12k.png
673
+ - spec/support/fixtures/50x50.png
674
+ - spec/support/fixtures/5k.png
675
+ - spec/support/fixtures/animated
676
+ - spec/support/fixtures/animated.gif
677
+ - spec/support/fixtures/animated.unknown
678
+ - spec/support/fixtures/aws_s3.yml
679
+ - spec/support/fixtures/bad.png
680
+ - spec/support/fixtures/empty.html
681
+ - spec/support/fixtures/empty.xlsx
682
+ - spec/support/fixtures/fog.yml
683
+ - spec/support/fixtures/rotated.jpg
684
+ - spec/support/fixtures/s3.yml
685
+ - spec/support/fixtures/sample.xlsm
686
+ - spec/support/fixtures/spaced file.jpg
687
+ - spec/support/fixtures/spaced file.png
688
+ - spec/support/fixtures/text.txt
689
+ - spec/support/fixtures/twopage.pdf
690
+ - spec/support/fixtures/uppercase.PNG
691
+ - spec/support/matchers/accept.rb
692
+ - spec/support/matchers/exist.rb
693
+ - spec/support/matchers/have_column.rb
694
+ - spec/support/mock_attachment.rb
695
+ - spec/support/mock_interpolator.rb
696
+ - spec/support/mock_url_generator_builder.rb
697
+ - spec/support/model_reconstruction.rb
698
+ - spec/support/reporting.rb
699
+ - spec/support/test_data.rb
700
+ - spec/support/version_helper.rb