Commit Graph

293 Commits

Author SHA1 Message Date
Rafael França 45d1efab51
Merge pull request #40766 from rafaelfranca/rm-queue-defaults
Change default queue name of all the internal jobs to be the job adapter's default
2020-12-08 22:47:47 +00:00
Rafael Mendonça França 59f7f5889e
Start Rails 6.2 development 🎉 2020-12-03 01:35:29 +00:00
Jonathan Hefner 3397924e66
Use FFmpeg scene detection for video previews
Generating a video preview by capturing only the first frame of a video
is problematic for videos that begin with a fade in from black.  By
using keyframe and scene detection that is built in to FFmpeg, we can
generate a more representative preview.
2020-11-17 17:25:01 -05:00
David Angulo 1db02b3896 Add strict loading for active storage 2020-11-16 22:09:15 +08:00
Rafael Mendonça França 8389f9902c
Preparing for 6.1.0.rc1 release 2020-11-02 21:12:47 +00:00
Rafael Mendonça França 62bda903be
Remove deprecated support to pass `:combine_options` operations to `ActiveStorage::Transformers::ImageProcessing` 2020-10-30 00:25:48 +00:00
Rafael Mendonça França bad3d0f6a3
Remove warning of undefined instance variable 2020-10-30 00:25:47 +00:00
Rafael Mendonça França 74476f0f90
Remove deprecated ActiveStorage::Transformers::MiniMagickTransformer
Now ActiveStorage only support mini_magick transformation through the
image_processing gem.
2020-10-30 00:25:47 +00:00
Rafael Mendonça França bc28e37de2
Remove deprecated `config.active_storage.queue` 2020-10-30 00:25:45 +00:00
Rafael Mendonça França 92a8e1d7c5
Remove deprecated `ActiveStorage::Downloading` 2020-10-30 00:25:44 +00:00
Pietro Moro 1e2cd7a75e
Support per-environment ASt service config 2020-09-29 09:59:52 -04:00
Vincent Robert 3803671a81 Generate a preview without print margins
When a PDF is used for both printing and displaying. It will most likely
contain a crop box in order to hide print margins when displaying the PDF.

Use Poppler's parameter to automatically use the crop box (visible box)
rather than the media box (printable box) in order to remove those margins
when drawing the PDF.

See https://manpages.debian.org/testing/poppler-utils/pdftoppm.1.en.html
2020-09-17 11:59:45 -04:00
Santiago Bartesaghi 4a78dcb326
Clarify ActiveStorage::Service#url docs [ci skip]
* Public services don’t respect `:disposition`, `:filename`, or `:content_type`.
* `:expires_in` is optional.
2020-09-12 12:47:33 -04:00
Jonathan Hefner a197d39e13
Fall back to video container for duration
Some video formats, such as WebM, do not store duration information at
the level of the video stream.  Instead, the duration is stored as part
of the container format information.

This commit modifies `VideoAnalyzer` to use the duration from the video
container when the duration from the video stream is not available.

Fixes #40130.
2020-08-31 08:48:06 -04:00
Jonathan Hefner 6aa26c30e2
Identify directly-uploaded blobs before saving the associated record
An Active Storage `Blob` must be identified before it can be reliably
validated.  For direct uploads, a `Blob` is identified when it is
attached, rather than when it is created.

Before this commit, the sequence of events when attaching a `Blob` was:

1. Find the `Blob`.
2. Assign the `Blob` to an `Attachment`.
3. Save the owner record.
4. Save the `Attachment`.
5. Identify the `Blob`'s true `content_type` from its file.
6. Save the `Blob`.

This meant that the owner record's validations might not see the
`Blob`'s true `content_type`.

After this commit, the sequence of events will be:

1. Find the `Blob`.
2. Identify the `Blob`'s true `content_type` from its file.
3. Assign the `Blob` to an `Attachment`.
4. Save the owner record.
5. Save the `Attachment`.
6. Save the `Blob`.

Thus the `Blob`'s true `content_type` will be available when running the
owner record's validations.
2020-08-11 18:08:09 -04:00
Lawrence Chou eb5f5ed0be
Fix attaching blobs via nested attributes
Closes #37411.
2020-08-04 00:26:27 -04:00
Santiago Bartesaghi 31148cd6be Use Active Record signed IDs in Active Storage 2020-07-04 21:09:00 -04:00
Jonathan Hefner d02d259b61
Fix Active Storage behavior on record dup
Prior to this commit, a `dup`ed record and its originating record would
share the same `Attached` proxy objects.  Those proxy objects, in turn,
would point to the same `Attachment` associations, causing changes made
through the proxy interface to affect both records.
2020-05-25 22:03:32 -04:00
Paul Blaze 84057dab16
Update aws-sdk-s3 dependency
whitelist_headers support added in 1.48.0:
https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-s3/CHANGELOG.md#1480-2019-08-30
2020-05-19 23:09:39 +08:00
Ryuta Kamizono 393df7425f Fix syntax error 2020-05-19 01:04:22 +09:00
Travis Pew c0ab9a7d29
Include Content-Length in signature for ActiveStorage direct upload
[CVE-2020-8162]
2020-05-15 14:32:19 -07:00
Jonathan Fleckenstein dfb5a82b25
Active Storage: allow serving files by proxying 2020-05-11 16:21:58 -04:00
George Claghorn 3a38c07211 Revert "Set a public ACL for files uploaded to a public GCS service"
This reverts commit 43503bdfec.
2020-04-28 17:16:47 -04:00
Brendan Abbott 43503bdfec
Set a public ACL for files uploaded to a public GCS service 2020-04-28 15:44:17 -04:00
Mikel Kew cf7c27f2ff
Ensure direct uploads to a public S3 service have a public ACL 2020-04-28 15:42:17 -04:00
Abhay Nikam 68846bdc1f
Verify FFmpeg presence before attempting to preview videos 2020-04-27 08:51:34 -04:00
William Carey 4c5e4ea476
Fix autosave association bug with ActiveStorage::Attachments
Closes #37701.
2020-04-24 13:16:16 -04:00
Godfrey Chan 1064c51609 Fix typos [ci skip]
I wrote this shell script to find words from the Rails repo,
so I can paste them into https://www.horsepaste.com/ for
the [codenames game](https://en.m.wikipedia.org/wiki/Codenames_(board_game)).

```bash
git grep -Il '' | \
  grep -v -E "CHANGELOG|Gemfile|gemspec|package\.json|yarn\.lock" | \
  xargs cat | \
  sed '/[^ ]\{10,\}/d' | \
  sed 's/\([A-Z]\)/ \1/g' | \
  tr 'A-Z' 'a-z' | \
  tr -c -s 'a-z' '\n' | \
  sed '/^.\{0,3\}$/d' | \
  sort | \
  uniq | \
  tr '\n' ',' | \
  pbcopy
```

You can see the result in https://www.horsepaste.com/rails-fixed.
Click "Next game" to cycle the words.

Found some typos in the codebase from this 😂

This is how I generated the list of possible typos:

```bash
git grep -Il '' | \
  grep -v -E "CHANGELOG|Gemfile|gemspec|package\.json|yarn\.lock" | \
  xargs cat | \
  sed '/[^ ]\{10,\}/d' | \
  sed 's/\([A-Z]\)/ \1/g' | \
  tr 'A-Z' 'a-z' | \
  tr -c -s 'a-z' '\n' | \
  sed '/^.\{0,3\}$/d' | \
  sort | \
  uniq | \
  aspell --ignore-case list
```

I manually reviewed the list and made the corrections
in this commit. The rest on the list are either:

* Bugs in my script: it split things like "doesn't" into
  "doesn" and "t", if find things like `#ffffff` and
  extracts "ffffff" as a word, etc
* British spelling: honour, optimised
* Foreign words: bonjour, espanol
* Names: nginx, hanekawa
* Technical words: mutex, xhtml
* Portmanteau words: autosave, nodelist
* Invented words: camelize, coachee
* Shortened words: attrs, repo
* Deliberate typos: hllo, hillo (used in code examples, etc)
* Lorem ipsum words: arcu, euismod

This is the [output](https://gist.github.com/chancancode/eb0b573d667dc31906f33f1fb0b22313)
of the script *after* fixing the typos included in this
commit. In theory, someone can run that command again in
the future and compare the output to catch new typos (i.e.
using my list to filter out known typos).

Limitations: the aspell dictionary could be wrong, I
could have miss things, and my script ignores words that
are less than 3 characters or longer than 10 characters.
2020-04-22 21:43:37 -07:00
JvH 2a12b723bb Add web_image_content_types config option for ActiveStorage
Add `config.active_storage.web_image_content_types` to allow applications
to add content types (like `image/webp`) in which variants can be processed,
instead of letting those images be converted to the fallback PNG format.
2020-04-21 14:00:41 -04:00
Yasuo Honda dad4026f94 Unlock `azure-storage-blob` version to use version 2.0
`azure-storage-blob` 2.0.0 has been released.
https://rubygems.org/gems/azure-storage-blob/versions/2.0.0

According to this commit and changelog, `azure-storage-blob` 1.1.0 did not support Ruby 2.6 and higher.
As of right now, Rails master branch should support Ruby 2.5.0, 2.6.0 and 2.7.0
then it should be appropriate to unlock `azure-storage-blob` version.

252e3f06a5

This commit addresses this following error:

```ruby
% cd activestorage
% bundle exec rake test

Traceback (most recent call last):
	14: from /Users/yahonda/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:5:in `<main>'
	13: from /Users/yahonda/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:5:in `select'
	12: from /Users/yahonda/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:17:in `block in <main>'
	11: from /Users/yahonda/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
	10: from /Users/yahonda/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
	 9: from /Users/yahonda/src/github.com/rails/rails/activestorage/test/service/azure_storage_service_test.rb:7:in `<top (required)>'
	 8: from /Users/yahonda/src/github.com/rails/rails/activestorage/test/service/azure_storage_service_test.rb:8:in `<class:AzureStorageServiceTest>'
	 7: from /Users/yahonda/src/github.com/rails/rails/activestorage/lib/active_storage/service.rb:51:in `configure'
	 6: from /Users/yahonda/src/github.com/rails/rails/activestorage/lib/active_storage/service/configurator.rb:8:in `build'
	 5: from /Users/yahonda/src/github.com/rails/rails/activestorage/lib/active_storage/service/configurator.rb:17:in `build'
	 4: from /Users/yahonda/src/github.com/rails/rails/activestorage/lib/active_storage/service/configurator.rb:30:in `resolve'
	 3: from /Users/yahonda/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
	 2: from /Users/yahonda/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
	 1: from /Users/yahonda/src/github.com/rails/rails/activestorage/lib/active_storage/service/azure_storage_service.rb:3:in `<top (required)>'
/Users/yahonda/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/rubygems_integration.rb:346:in `block (2 levels) in replace_gem': can't activate azure-storage-blob (~> 1.1), already activated azure-storage-blob-2.0.0. Make sure all dependencies are added to Gemfile. (Gem::LoadError)
	11: from /Users/yahonda/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:5:in `<main>'
	10: from /Users/yahonda/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:5:in `select'
	 9: from /Users/yahonda/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb:17:in `block in <main>'
	 8: from /Users/yahonda/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
	 7: from /Users/yahonda/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
	 6: from /Users/yahonda/src/github.com/rails/rails/activestorage/test/service/azure_storage_service_test.rb:7:in `<top (required)>'
	 5: from /Users/yahonda/src/github.com/rails/rails/activestorage/test/service/azure_storage_service_test.rb:8:in `<class:AzureStorageServiceTest>'
	 4: from /Users/yahonda/src/github.com/rails/rails/activestorage/lib/active_storage/service.rb:51:in `configure'
	 3: from /Users/yahonda/src/github.com/rails/rails/activestorage/lib/active_storage/service/configurator.rb:8:in `build'
	 2: from /Users/yahonda/src/github.com/rails/rails/activestorage/lib/active_storage/service/configurator.rb:17:in `build'
	 1: from /Users/yahonda/src/github.com/rails/rails/activestorage/lib/active_storage/service/configurator.rb:29:in `resolve'
/Users/yahonda/src/github.com/rails/rails/activestorage/lib/active_storage/service/configurator.rb:33:in `rescue in resolve': Missing service adapter for "AzureStorage" (RuntimeError)
rake aborted!
```

* Update Gemfile.lock to bump azure-storage-blob version

```
% bundle update --conservative faraday azure-storage-blob google-cloud-storage`
```

- How to find gem name to update by setting `gem "azure-storage-blob", "= 2.0.0"` temporarily

```ruby
% git diff
diff --git a/Gemfile b/Gemfile
index 5fdaceab2f..6be7dccf4b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -84,7 +84,7 @@ end
 group :storage do
   gem "aws-sdk-s3", require: false
   gem "google-cloud-storage", "~> 1.11", require: false
-  gem "azure-storage-blob", require: false
+  gem "azure-storage-blob", "= 2.0.0", require: false # Use 2.0.0 temporarily to find which gems need bump

   gem "image_processing", "~> 1.2"
 end
% bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies.....
Bundler could not find compatible versions for gem "faraday":
  In snapshot (Gemfile.lock):
    faraday (= 0.17.1)

  In Gemfile:
    azure-storage-blob (= 2.0.0) was resolved to 2.0.0, which depends on
      azure-storage-common (~> 2.0) was resolved to 2.0.1, which depends on
        faraday (~> 1.0)

    google-cloud-storage (~> 1.11) was resolved to 1.25.0, which depends on
      googleauth (~> 0.9) was resolved to 0.10.0, which depends on
        faraday (~> 0.12)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
% git checkout -f Gemfile
% bundle update --conservative faraday azure-storage-blob google-cloud-storage
```
2020-03-17 07:49:57 +09:00
Dino Maric 2a0823ecba Support creating variants of `webp` images out of the box
This PR adds `image/webp` to the default array of variable content
types. Without this commit if we want to "handle" webp images
overwriting `config.active_storage.variable_content_types` was
necessary.
2020-03-10 12:38:17 -04:00
Ryuta Kamizono 1ef8c60dfc Avoid extra string allocation in the methods generated by eval 2020-03-10 17:43:35 +09:00
Kurtis Rainbolt-Greene ef7599fe91
Extract internal ActiveSupport::ConfigurationFile object
Rails has a number of places where a YAML configuration file is read,
then ERB is evaluated and finally the YAML is parsed.

This consolidates that into one common class.

Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
2020-02-10 02:50:12 +01:00
Carlos Antonio da Silva 776d4bd633 Fix typo [ci skip] 2020-01-16 17:15:47 -03:00
Gannon McGibbon ed81601723 Only enqueue analysis jobs when blob is analyzable 2020-01-16 14:14:28 -05:00
Abhay Nikam d8beb77252 Bump license years from 2019 to 2020 [ci skip] 2020-01-01 15:10:31 +05:30
Ryuta Kamizono 797ae91543 `Google::Cloud::Storage.new` takes keyword arguments 2019-12-29 03:03:51 +09:00
Peter Zhu 4203093ad3 Store previews in the same service as the original blob 2019-12-20 15:06:03 -05:00
Peter Zhu 2e15092942 Remove query params in DiskService 2019-12-06 16:52:30 -05:00
Peter Zhu fbb83d78c3 Use DiskController for both public and private files 2019-12-06 16:02:16 -05:00
George Claghorn 7d0327bbbf Track Active Storage variants in the database 2019-12-06 13:26:51 -05:00
Peter Zhu 235f2636cd Deprecate `service_url` in favour of `url` 2019-12-02 14:59:03 -05:00
George Claghorn 709cee9c9a
Defer Active Storage service configuration until use 2019-11-08 15:03:42 -05:00
Jason Lee 5ae3b01e97 Ensure public-read ACL for S3 service with public mode. 2019-10-17 15:24:00 +08:00
Gannon McGibbon d1b39eaf12
Merge pull request #37448 from gmcgibbon/fix_flaky_activestorage_tests
Fix flaky activestorage tests
2019-10-12 21:39:00 -04:00
Kasper Timm Hansen cd30ec1fe5
Match convention to use Ruby semantics for predicates 2019-10-12 02:48:58 +02:00
Gannon McGibbon bf3525c8bb Move downloader require to service 2019-10-11 18:20:39 -04:00
Peter Zhu feab7031b5 Permanent URLs for public storage blobs
Services can be configured in `config/storage.yml` with a new key
`public: true | false` to indicate whether a service holds public
blobs or private blobs. Public services will always return a
permanent URL.

Deprecates `Blob#service_url` in favor of `Blob#url`.
2019-10-11 15:14:43 -04:00
Gannon McGibbon e6487e84fc Make Active Storage services aware of configuration names 2019-10-03 13:08:30 -04:00
DmitryTsepelev e7f798c3f5 Allow configure services for individual attachments 2019-10-01 21:24:05 +03:00