activestorage 7.1.1 → 7.1.3

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: c5191c2c08c3cf6683595f664612b36f0df861a027b6674e804fe0e8065cff4a
4
- data.tar.gz: 791d7ee3f601bfaba5822619cdef840c902289895734fcdbc309f850ebbe463e
3
+ metadata.gz: b815d6fed50a14fe82602e35311e37ccece872b1d41c54c9154748b63c388456
4
+ data.tar.gz: 67b71203864af875c16e762c76839c1867dacb0fc2a1e6d5d09d6bce4e044049
5
5
  SHA512:
6
- metadata.gz: 2cb516e85268a2ccbb78a8ee5ac9b6bd52c51053ae0592b7f22572627eb34c9e38b461ff5dcf3b45ab7940dc22b977cf997ed55745b3672d65b7bcf8bfae31ae
7
- data.tar.gz: 9c79ef5fda487863703d324f829250ef42255ea5c3ae1213acc34a7c6a82b04bc244bb8a57b223552a0783f04cdb9d64e15dcb0b8cb946a3400f439a015fff1e
6
+ metadata.gz: fe00e4b4db1a83ff95b5c2d1ae52c1aacc5994b46de0b7b473a8d816b85a0621b7ead8f42d826ad88d5bc31fa627e5b0689a20750bded392c001f317af8330e8
7
+ data.tar.gz: 94ac2b137a96a722d3d6200379d2156b91fa6a24952d3daba83530d7a6b60a9c55899671066fc0aa9d638d721b9f2f32b017b77c0c67d6c6f1e232c2f850f9fd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,57 @@
1
+ ## Rails 7.1.3 (January 16, 2024) ##
2
+
3
+ * Fix N+1 query when fetching preview images for non-image assets.
4
+
5
+ *Aaron Patterson & Justin Searls*
6
+
7
+ * Fix all Active Storage database related models to respect
8
+ `ActiveRecord::Base.table_name_prefix` configuration.
9
+
10
+ *Chedli Bourguiba*
11
+
12
+ * Fix `ActiveStorage::Representations::ProxyController` not returning the proper
13
+ preview image variant for previewable files.
14
+
15
+ *Chedli Bourguiba*
16
+
17
+ * Fix `ActiveStorage::Representations::ProxyController` to proxy untracked
18
+ variants.
19
+
20
+ *Chedli Bourguiba*
21
+
22
+ * Fix direct upload forms when submit button contains nested elements.
23
+
24
+ *Marc Köhlbrugge*
25
+
26
+ * When using the `preprocessed: true` option, avoid enqueuing transform jobs
27
+ for blobs that are not representable.
28
+
29
+ *Chedli Bourguiba*
30
+
31
+ * Process preview image variant when calling `ActiveStorage::Preview#processed`.
32
+ For example, `attached_pdf.preview(:thumb).processed` will now immediately
33
+ generate the full-sized preview image and the `:thumb` variant of it.
34
+ Previously, the `:thumb` variant would not be generated until a further call
35
+ to e.g. `processed.url`.
36
+
37
+ *Chedli Bourguiba* and *Jonathan Hefner*
38
+
39
+ * Prevent `ActiveRecord::StrictLoadingViolationError` when strict loading is
40
+ enabled and the variant of an Active Storage preview has already been
41
+ processed (for example, by calling `ActiveStorage::Preview#url`).
42
+
43
+ *Jonathan Hefner*
44
+
45
+ * Fix `preprocessed: true` option for named variants of previewable files.
46
+
47
+ *Nico Wenterodt*
48
+
49
+
50
+ ## Rails 7.1.2 (November 10, 2023) ##
51
+
52
+ * No changes.
53
+
54
+
1
55
  ## Rails 7.1.1 (October 11, 2023) ##
2
56
 
3
57
  * No changes.
@@ -771,9 +771,9 @@ function start() {
771
771
  }
772
772
 
773
773
  function didClick(event) {
774
- const {target: target} = event;
775
- if ((target.tagName == "INPUT" || target.tagName == "BUTTON") && target.type == "submit" && target.form) {
776
- submitButtonsByForm.set(target.form, target);
774
+ const button = event.target.closest("button, input");
775
+ if (button && button.type === "submit" && button.form) {
776
+ submitButtonsByForm.set(button.form, button);
777
777
  }
778
778
  }
779
779
 
@@ -754,9 +754,9 @@
754
754
  }
755
755
  }
756
756
  function didClick(event) {
757
- const {target: target} = event;
758
- if ((target.tagName == "INPUT" || target.tagName == "BUTTON") && target.type == "submit" && target.form) {
759
- submitButtonsByForm.set(target.form, target);
757
+ const button = event.target.closest("button, input");
758
+ if (button && button.type === "submit" && button.form) {
759
+ submitButtonsByForm.set(button.form, button);
760
760
  }
761
761
  }
762
762
  function didSubmitForm(event) {
@@ -12,7 +12,7 @@ class ActiveStorage::Representations::ProxyController < ActiveStorage::Represent
12
12
 
13
13
  def show
14
14
  http_cache_forever public: true do
15
- send_blob_stream @representation.image, disposition: params[:disposition]
15
+ send_blob_stream @representation, disposition: params[:disposition]
16
16
  end
17
17
  end
18
18
  end
@@ -15,9 +15,9 @@ export function start() {
15
15
  }
16
16
 
17
17
  function didClick(event) {
18
- const { target } = event
19
- if ((target.tagName == "INPUT" || target.tagName == "BUTTON") && target.type == "submit" && target.form) {
20
- submitButtonsByForm.set(target.form, target)
18
+ const button = event.target.closest("button, input")
19
+ if (button && button.type === "submit" && button.form) {
20
+ submitButtonsByForm.set(button.form, button)
21
21
  }
22
22
  }
23
23
 
@@ -3,10 +3,10 @@
3
3
  class ActiveStorage::TransformJob < ActiveStorage::BaseJob
4
4
  queue_as { ActiveStorage.queues[:transform] }
5
5
 
6
- discard_on ActiveRecord::RecordNotFound
6
+ discard_on ActiveRecord::RecordNotFound, ActiveStorage::UnrepresentableError
7
7
  retry_on ActiveStorage::IntegrityError, attempts: 10, wait: :polynomially_longer
8
8
 
9
9
  def perform(blob, transformations)
10
- blob.variant(transformations).processed
10
+ blob.representation(transformations).processed
11
11
  end
12
12
  end
@@ -18,8 +18,6 @@ require "active_support/core_ext/module/delegation"
18
18
  # # preloads blobs and variant records (if using `ActiveStorage.track_variants`)
19
19
  # User.first.avatars.with_all_variant_records
20
20
  class ActiveStorage::Attachment < ActiveStorage::Record
21
- self.table_name = "active_storage_attachments"
22
-
23
21
  ##
24
22
  # :method:
25
23
  #
@@ -44,7 +42,10 @@ class ActiveStorage::Attachment < ActiveStorage::Record
44
42
  # Eager load all variant records on an attachment at once.
45
43
  #
46
44
  # User.first.avatars.with_all_variant_records
47
- scope :with_all_variant_records, -> { includes(blob: { variant_records: { image_attachment: :blob } }) }
45
+ scope :with_all_variant_records, -> { includes(blob: {
46
+ variant_records: { image_attachment: :blob },
47
+ preview_image_attachment: { blob: { variant_records: { image_attachment: :blob } } }
48
+ }) }
48
49
 
49
50
  # Synchronously deletes the attachment and {purges the blob}[rdoc-ref:ActiveStorage::Blob#purge].
50
51
  def purge
@@ -99,7 +99,7 @@ module ActiveStorage::Blob::Representable
99
99
  end
100
100
 
101
101
  def preprocessed(transformations) # :nodoc:
102
- ActiveStorage::TransformJob.perform_later(self, transformations)
102
+ ActiveStorage::TransformJob.perform_later(self, transformations) if representable?
103
103
  end
104
104
 
105
105
  private
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveStorage::Blob::Servable # :nodoc:
4
+ def content_type_for_serving
5
+ forcibly_serve_as_binary? ? ActiveStorage.binary_content_type : content_type
6
+ end
7
+
8
+ def forced_disposition_for_serving
9
+ if forcibly_serve_as_binary? || !allowed_inline?
10
+ :attachment
11
+ end
12
+ end
13
+
14
+ private
15
+ def forcibly_serve_as_binary?
16
+ ActiveStorage.content_types_to_serve_as_binary.include?(content_type)
17
+ end
18
+
19
+ def allowed_inline?
20
+ ActiveStorage.content_types_allowed_inline.include?(content_type)
21
+ end
22
+ end
@@ -20,8 +20,7 @@ class ActiveStorage::Blob < ActiveStorage::Record
20
20
  include Analyzable
21
21
  include Identifiable
22
22
  include Representable
23
-
24
- self.table_name = "active_storage_blobs"
23
+ include Servable
25
24
 
26
25
  MINIMUM_TOKEN_LENGTH = 28
27
26
 
@@ -138,7 +137,10 @@ class ActiveStorage::Blob < ActiveStorage::Record
138
137
 
139
138
  def scope_for_strict_loading # :nodoc:
140
139
  if strict_loading_by_default? && ActiveStorage.track_variants
141
- includes(variant_records: { image_attachment: :blob }, preview_image_attachment: :blob)
140
+ includes(
141
+ variant_records: { image_attachment: :blob },
142
+ preview_image_attachment: { blob: { variant_records: { image_attachment: :blob } } }
143
+ )
142
144
  else
143
145
  all
144
146
  end
@@ -226,16 +228,6 @@ class ActiveStorage::Blob < ActiveStorage::Record
226
228
  service.headers_for_direct_upload key, filename: filename, content_type: content_type, content_length: byte_size, checksum: checksum, custom_metadata: custom_metadata
227
229
  end
228
230
 
229
- def content_type_for_serving # :nodoc:
230
- forcibly_serve_as_binary? ? ActiveStorage.binary_content_type : content_type
231
- end
232
-
233
- def forced_disposition_for_serving # :nodoc:
234
- if forcibly_serve_as_binary? || !allowed_inline?
235
- :attachment
236
- end
237
- end
238
-
239
231
 
240
232
  # Uploads the +io+ to the service on the +key+ for this blob. Blobs are intended to be immutable, so you shouldn't be
241
233
  # using this method after a file has already been uploaded to fit with a blob. If you want to create a derivative blob,
@@ -354,14 +346,6 @@ class ActiveStorage::Blob < ActiveStorage::Record
354
346
  Marcel::MimeType.for io, name: filename.to_s, declared_type: content_type
355
347
  end
356
348
 
357
- def forcibly_serve_as_binary?
358
- ActiveStorage.content_types_to_serve_as_binary.include?(content_type)
359
- end
360
-
361
- def allowed_inline?
362
- ActiveStorage.content_types_allowed_inline.include?(content_type)
363
- end
364
-
365
349
  def web_image?
366
350
  ActiveStorage.web_image_content_types.include?(content_type)
367
351
  end
@@ -31,15 +31,19 @@
31
31
  # These libraries are not provided by \Rails. You must install them yourself to use the built-in previewers. Before you
32
32
  # install and use third-party software, make sure you understand the licensing implications of doing so.
33
33
  class ActiveStorage::Preview
34
+ include ActiveStorage::Blob::Servable
35
+
34
36
  class UnprocessedError < StandardError; end
35
37
 
38
+ delegate :filename, :content_type, to: :variant
39
+
36
40
  attr_reader :blob, :variation
37
41
 
38
42
  def initialize(blob, variation_or_variation_key)
39
43
  @blob, @variation = blob, ActiveStorage::Variation.wrap(variation_or_variation_key)
40
44
  end
41
45
 
42
- # Processes the preview if it has not been processed yet. Returns the receiving Preview instance for convenience:
46
+ # Processes the preview if it has not been processed yet. Returns the receiving +ActiveStorage::Preview+ instance for convenience:
43
47
  #
44
48
  # blob.preview(resize_to_limit: [100, 100]).processed.url
45
49
  #
@@ -47,6 +51,7 @@ class ActiveStorage::Preview
47
51
  # image is stored with the blob, it is only generated once.
48
52
  def processed
49
53
  process unless processed?
54
+ variant.processed
50
55
  self
51
56
  end
52
57
 
@@ -53,6 +53,8 @@
53
53
  # * {ImageProcessing::Vips}[https://github.com/janko/image_processing/blob/master/doc/vips.md#methods]
54
54
  # * {ruby-vips reference}[http://www.rubydoc.info/gems/ruby-vips/Vips/Image]
55
55
  class ActiveStorage::Variant
56
+ include ActiveStorage::Blob::Servable
57
+
56
58
  attr_reader :blob, :variation
57
59
  delegate :service, to: :blob
58
60
  delegate :content_type, to: :variation
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ActiveStorage::VariantRecord < ActiveStorage::Record
4
- self.table_name = "active_storage_variant_records"
5
-
6
4
  belongs_to :blob
7
5
  has_one_attached :image
8
6
  end
@@ -5,6 +5,8 @@
5
5
  # Like an ActiveStorage::Variant, but keeps detail about the variant in the database as an
6
6
  # ActiveStorage::VariantRecord. This is only used if +ActiveStorage.track_variants+ is enabled.
7
7
  class ActiveStorage::VariantWithRecord
8
+ include ActiveStorage::Blob::Servable
9
+
8
10
  attr_reader :blob, :variation
9
11
  delegate :service, to: :blob
10
12
  delegate :content_type, to: :variation
@@ -116,7 +116,10 @@ module ActiveStorage
116
116
 
117
117
  scope :"with_attached_#{name}", -> {
118
118
  if ActiveStorage.track_variants
119
- includes("#{name}_attachment": { blob: { variant_records: { image_attachment: :blob } } })
119
+ includes("#{name}_attachment": { blob: {
120
+ variant_records: { image_attachment: :blob },
121
+ preview_image_attachment: { blob: { variant_records: { image_attachment: :blob } } }
122
+ } })
120
123
  else
121
124
  includes("#{name}_attachment": :blob)
122
125
  end
@@ -203,7 +206,10 @@ module ActiveStorage
203
206
 
204
207
  scope :"with_attached_#{name}", -> {
205
208
  if ActiveStorage.track_variants
206
- includes("#{name}_attachments": { blob: { variant_records: { image_attachment: :blob } } })
209
+ includes("#{name}_attachments": { blob: {
210
+ variant_records: { image_attachment: :blob },
211
+ preview_image_attachment: { blob: { variant_records: { image_attachment: :blob } } }
212
+ } })
207
213
  else
208
214
  includes("#{name}_attachments": :blob)
209
215
  end
@@ -26,9 +26,13 @@ module ActiveStorage
26
26
  # has_one_attached :thumbnail
27
27
  # end
28
28
  #
29
+ # <code></code>
30
+ #
29
31
  # # fixtures/active_storage/blobs.yml
30
32
  # first_thumbnail_blob: <%= ActiveStorage::FixtureSet.blob filename: "first.png" %>
31
33
  #
34
+ # <code></code>
35
+ #
32
36
  # # fixtures/active_storage/attachments.yml
33
37
  # first_thumbnail_attachment:
34
38
  # name: thumbnail
@@ -48,7 +52,7 @@ module ActiveStorage
48
52
  #
49
53
  # === Examples
50
54
  #
51
- # # tests/fixtures/action_text/blobs.yml
55
+ # # tests/fixtures/active_storage/blobs.yml
52
56
  # second_thumbnail_blob: <%= ActiveStorage::FixtureSet.blob(
53
57
  # filename: "second.svg",
54
58
  # ) %>
@@ -9,7 +9,7 @@ module ActiveStorage
9
9
  module VERSION
10
10
  MAJOR = 7
11
11
  MINOR = 1
12
- TINY = 1
12
+ TINY = 3
13
13
  PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activestorage
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.1
4
+ version: 7.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-11 00:00:00.000000000 Z
11
+ date: 2024-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 7.1.1
19
+ version: 7.1.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 7.1.1
26
+ version: 7.1.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: actionpack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 7.1.1
33
+ version: 7.1.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 7.1.1
40
+ version: 7.1.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activejob
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 7.1.1
47
+ version: 7.1.3
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 7.1.1
54
+ version: 7.1.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activerecord
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 7.1.1
61
+ version: 7.1.3
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 7.1.1
68
+ version: 7.1.3
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: marcel
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +123,7 @@ files:
123
123
  - app/models/active_storage/blob/analyzable.rb
124
124
  - app/models/active_storage/blob/identifiable.rb
125
125
  - app/models/active_storage/blob/representable.rb
126
+ - app/models/active_storage/blob/servable.rb
126
127
  - app/models/active_storage/current.rb
127
128
  - app/models/active_storage/filename.rb
128
129
  - app/models/active_storage/named_variant.rb
@@ -188,10 +189,10 @@ licenses:
188
189
  - MIT
189
190
  metadata:
190
191
  bug_tracker_uri: https://github.com/rails/rails/issues
191
- changelog_uri: https://github.com/rails/rails/blob/v7.1.1/activestorage/CHANGELOG.md
192
- documentation_uri: https://api.rubyonrails.org/v7.1.1/
192
+ changelog_uri: https://github.com/rails/rails/blob/v7.1.3/activestorage/CHANGELOG.md
193
+ documentation_uri: https://api.rubyonrails.org/v7.1.3/
193
194
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
194
- source_code_uri: https://github.com/rails/rails/tree/v7.1.1/activestorage
195
+ source_code_uri: https://github.com/rails/rails/tree/v7.1.3/activestorage
195
196
  rubygems_mfa_required: 'true'
196
197
  post_install_message:
197
198
  rdoc_options: []