Commit Graph

699 Commits

Author SHA1 Message Date
Sharang Dashputre
71ca83786e Update changelog for a bug-fix to read better [ci skip] 2019-04-24 18:17:39 +05:30
Guilherme Mansur
6133dad869 Don't fail ImageAnalyzer on unsupported types
Fix: #36065

The IamgeAnalyzer passes a image to ImageMagick without checking if the
image is supported by ImageMagick. This patch checks that image is
supported and if not logs an error and returns an empty hash instead of
raising an error. This is the same error handling we do when we
encounter a LoadError when mini_magick is not installed.
2019-04-24 07:59:12 -04:00
George Claghorn
a89e9cccb2
Merge pull request #36045 from yfxie/fix-normalize-the-hash-of-transformations
ActiveStorage - normalize the hash of transformations
2019-04-21 16:07:54 -04:00
Younes SERRAJ
bcf370d689 Allow ActiveStorage to generate variants of BMP images 2019-04-21 19:07:22 +02:00
Yi Feng
6be1446fc7 normalize the hash of transformations 2019-04-20 18:05:58 +08:00
Bernardo Araujo
0a8ff0be0c Set default of 28 characters in ActiveStorage::Blob.generate_unique_secure_token
The minimum character length is now 24 characters since it's inherited
from ActiveRecord::Base, but the default behaviour is still using 28
characters.
2019-04-09 19:45:26 -04:00
Fumiaki MATSUSHIMA
61c4be4777 Output junit format test report 2019-04-04 14:34:46 +09:00
Sharang Dashputre
771973c13d url -> URL where apt except inside actionpack/ 2019-04-01 22:56:35 +05:30
George Claghorn
7c5814c6e0 Revert "Add ActiveStorage.service_configurations and ActiveStorage.service"
This reverts commit 002684e36e813469c3585e193f0698784c88278b.
2019-03-31 19:23:11 -04:00
George Claghorn
002684e36e Add ActiveStorage.service_configurations and ActiveStorage.service
* Allow plugins to access the global service and alternative service configs before ActiveStorage::Blob loads.

* Make ActiveStorage.service_configurations the default second argument to ActiveStorage::Service.configure. Plugins that just want to use an alternative service defined in config/storage.yml needn't pass in the config themselves.
2019-03-31 07:46:18 -04:00
George Claghorn
197fe2222e Require railties for all Active Storage dependencies 2019-03-30 10:03:41 -04:00
George Claghorn
11d66a8e4c Specify Active Storage's dependency on Active Job 2019-03-30 10:03:19 -04:00
George Claghorn
da2c92377c Add load hook for ActiveStorage::Attachment 2019-03-28 18:52:02 -04:00
George Claghorn
562f3a2d21 Add ActiveStorage::Service#open 2019-03-28 18:47:42 -04:00
Eugeniu Tambur
135d8a0dc1 Traducir del: inglés
44/5000
Checking for the existence of only one table
2019-03-19 13:16:57 +01:00
Eugeniu Tambur
417c625ab2 Fix for migration active_storage migration
*ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "active_storage_attachments" does not exist*

Updating to rails 6.0.0.beta3 if the command rake app:update is used a new migration file is generated:

```ruby
# db/migrate/add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb
class AddForeignKeyConstraintToActiveStorageAttachmentsForBlobId < ActiveRecord::Migration[6.0]
  def up
    unless foreign_key_exists?(:active_storage_attachments, column: :blob_id)
  		add_foreign_key :active_storage_attachments, :active_storage_blobs, column: :blob_id
    end
  end
end
```

**If the project does not have previously installed active storage** this mgiration causes an error:

    ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "active_storage_attachments" does not exist

**Error output:**

    PG::UndefinedTable: ERROR:  relation "active_storage_attachments" does not exist
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/postgresql/database_statements.rb:90:in `async_exec'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/postgresql/database_statements.rb:90:in `block (2 levels) in execute'
    activesupport-6.0.0.beta3/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
    activesupport-6.0.0.beta3/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
    activesupport-6.0.0.beta3/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/postgresql/database_statements.rb:89:in `block in execute'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract_adapter.rb:643:in `block (2 levels) in log'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract_adapter.rb:642:in `block in log'
    activesupport-6.0.0.beta3/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract_adapter.rb:633:in `log'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/postgresql/database_statements.rb:88:in `execute'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract/schema_statements.rb:977:in `add_foreign_key'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:875:in `block in method_missing'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:843:in `block in say_with_time'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:843:in `say_with_time'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:864:in `method_missing'
    /db/migrate/20190315102607_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb:5:in `up'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:816:in `exec_migration'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:797:in `block (2 levels) in migrate'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:796:in `block in migrate'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `with_connection'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:795:in `migrate'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:985:in `migrate'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1293:in `block in execute_migration_in_transaction'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1344:in `block in ddl_transaction'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract/database_statements.rb:265:in `block in transaction'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract/transaction.rb:272:in `block in within_new_transaction'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract/transaction.rb:270:in `within_new_transaction'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract/database_statements.rb:265:in `transaction'
    activerecord-6.0.0.beta3/lib/active_record/transactions.rb:212:in `transaction'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1344:in `ddl_transaction'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1292:in `execute_migration_in_transaction'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1264:in `block in migrate_without_lock'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1263:in `each'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1263:in `migrate_without_lock'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1211:in `block in migrate'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1364:in `with_advisory_lock'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1211:in `migrate'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1044:in `up'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1019:in `migrate'
    activerecord-6.0.0.beta3/lib/active_record/tasks/database_tasks.rb:191:in `migrate'
    activerecord-6.0.0.beta3/lib/active_record/railties/databases.rake:78:in `block (3 levels) in <main>'
    activerecord-6.0.0.beta3/lib/active_record/railties/databases.rake:76:in `each'
    activerecord-6.0.0.beta3/lib/active_record/railties/databases.rake:76:in `block (2 levels) in <main>'
    railties-6.0.0.beta3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
    railties-6.0.0.beta3/lib/rails/commands/rake/rake_command.rb:20:in `perform'
    railties-6.0.0.beta3/lib/rails/command.rb:48:in `invoke'
    railties-6.0.0.beta3/lib/rails/commands.rb:18:in `<main>'
    bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    bootsnap-1.4.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:83:in `register'
    bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    activesupport-6.0.0.beta3/lib/active_support/dependencies.rb:297:in `block in require'
    activesupport-6.0.0.beta3/lib/active_support/dependencies.rb:263:in `load_dependency'
    activesupport-6.0.0.beta3/lib/active_support/dependencies.rb:297:in `require'
    bin/rails:4:in `<main>'
2019-03-15 12:54:42 +01:00
George Claghorn
43fc7b476b GCS service: skip unnecessary bucket lookups 2019-03-14 10:56:41 -04:00
eileencodes
a2bd669ed2 v6.0.0.beta3 release
-----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEEvJkGf0BARV+D0L2ulxXUSC76N8FAlyJN4cACgkQulxXUSC7
 6N9ZXAf/Wx7edIct8kZzcC6irlROx4DzpNbrrH792sO1OAcnoFDE7DPkokllTEP/
 4kzC42lca/XG27MCl7E0dtVD8hIyAl89nxid6cwKFVZVTPIRVc1wjXkoiWy/cvd7
 6+9IjxhlgrzxGnw3aWZJG7H3iqz69yr55aoSDU/TbMqq5kQrqNF95vr2nc8LEUco
 SLQj0pO/tfJdHquSeX0JiXn3VSEHT+5TdLGQ3J/w0wFU6mkecH4MJMJvMwLFx/v4
 llnvF6HyfSLASWbrpdD3h6MQHpImDoee5vILXAHzPdSaEVcVa1cDFtMcPMYiu8Dw
 AGdCAaHQhZFFGoYK472+o6pur0dxEA==
 =5dET
 -----END PGP SIGNATURE-----

Merge tag 'v6.0.0.beta3'

v6.0.0.beta3 release
2019-03-13 13:11:10 -04:00
eileencodes
7c87fd5635 Prep release
* Update RAILS_VERSION
* Bundle
* rake update_versions
* rake changelog:header
2019-03-11 11:58:15 -04:00
Prathamesh Sonpatki
538a459a3b
Squish the deprecation messages across the codebase
Sample example ->

Before:

prathamesh@Prathameshs-MacBook-Pro-2 blog *$ rails server thin
DEPRECATION WARNING: Passing the Rack server name as a regular argument is deprecated
and will be removed in the next Rails version. Please, use the -u
option instead.

After:

prathamesh@Prathameshs-MacBook-Pro-2 squish_app *$ rails server thin
DEPRECATION WARNING: Passing the Rack server name as a regular argument is deprecated and will be removed in the next Rails version. Please, use the -u option instead.
2019-03-11 19:22:37 +05:30
Kasper Timm Hansen
0fc1397784
Merge pull request #35559 from ashishprajapati/ashishprajapati/important_textual_improvements
Added missing guide links in documentation and minor wording fix
2019-03-09 22:54:21 +01:00
ashishprajapati
e3ef12b310 Added missing guide links in README documentation and minor wording fix [ci skip] 2019-03-10 03:17:01 +05:30
Abhay Nikam
027e492b6f Fix links in gemspec and docs from http to https. 2019-03-09 19:42:35 +05:30
Abhay Nikam
476abd403b Updated links from http to https in guides, docs, etc 2019-03-09 16:43:47 +05:30
Matthew Draper
5083f3fd60 Decrypt the ASt test config if available 2019-03-05 15:33:00 +10:30
George Claghorn
7c95c52247
Merge pull request #35412 from abhchand/correctly-load-blob-association
Ensure that the `_blob` association is properly loaded when attaching `::One`
2019-02-26 12:11:50 -05:00
Abhishek Chandrasekhar
32438ed64f [ActiveStorage] Ensure that the _blob association is properly loaded when attaching ::One
Consider a model with `One` and `Many` attachments configured:

    class User < ActiveRecord::Base
      has_one_attached :avatar
      has_many_attached :highlights
    end

=== One Attachment

After attaching `One` attachment (`:avatar`), we can see that the associated
`_blob` record (`:avatar_blob`) still returns as `nil`.

    user.avatar.attach(blob)
    user.avatar_attachment.present?  => true
    user.avatar_blob.present?        => false    # Incorrect!

This is a false negative. It happens because after the attachment and blob
are built:

  1. The record already has its `_blob` association loaded, as `nil`
  2. the `::Attachment` is associated with the record but the `::Blob` only gets
    associated with the `::Attachment`, not the record itself

In reality, the blob does in fact exist. We can verify this as follows:

    user.avatar.attach(blob)
    user.avatar_attachment.blob.present?    => true  # Blob does exist!

The fix in this change is to simply assign the `::Blob` when assigning
the `::Attachment`. After this fix is applied, we correctly observe:

    user.avatar.attach(blob)
    user.avatar_attachment.present?  => true
    user.avatar_blob.present?        => true    # Woohoo!

=== Many Attachments

We don't see this issue with `Many` attachments because the `_blob` association
is already loaded as part of attaching more/newer blobs.

    user.highlights.attach(blob)
    user.highlights_attachments.any?    => true
    user.highlights_blobs.any?          => true
2019-02-26 11:10:38 -05:00
Rafael Mendonça França
5e6e505083
Preparing for 6.0.0.beta2 release 2019-02-25 17:45:04 -05:00
Eugene Kenny
817ffc08bf Add missing require to active_storage.rb
Since b21f50d8ae36d9b50b673579e17bccbe55363b34, requiring active_storage
on its own has failed with the following error:

    activestorage/lib/active_storage.rb:55:in `<module:ActiveStorage>': undefined method `minutes' for 5:Integer (NoMethodError)
2019-02-20 21:07:34 +00:00
Abhay Nikam
d3f9226190 Delegated path_for to primary in the MirrorService 2019-02-14 23:06:42 +05:30
garytaylor
457dfc0621 Allow configuring the Azure Storage service with extra client options 2019-02-04 09:08:55 -05:00
Eileen M. Uchitelle
300c62f75c
Merge pull request #35043 from simoleone/activestorage/s3/content-type
include the content type when uploading to S3
2019-02-01 09:37:08 -05:00
alkesh26
a57f4defa7 ActiveStorage typo fix. 2019-01-31 19:42:32 +05:30
Carlos Ramirez III
f70defa1ba
Fix usage documentation in VideoAnalyzer
The code snippet within the usage documentation comment used the wrong object namespace for the ActiveStorage::Analyzer::VideoAnalyzer
2019-01-28 21:13:11 -08:00
Javan Makhmali
e3d43333db Add CHANGELOG entries for npm package renames [ci skip] 2019-01-28 06:29:26 -05:00
Simo Leone
c5b71c9bae
include the content type when uploading to S3 2019-01-24 17:05:49 +00:00
George Claghorn
c1e949e9e6 Prefer ImageProcessing's resize_to_limit macro over resize_to_fit
Don't upsize images smaller than the specified dimensions.
2019-01-24 11:46:42 -05:00
Gannon McGibbon
2e0ca9284a Revert ensure external redirects are explicitly allowed 2019-01-22 11:40:13 -05:00
Yuichi Takeuchi
ee65ca46e5 Fix ArgumentError: Unsafe redirect 2019-01-21 14:15:34 +09:00
Rafael Mendonça França
5a0230c67f
Preparing for 6.0.0.beta1 release 2019-01-18 15:42:12 -05:00
George Claghorn
9e34df0003
Merge pull request #33419 from bogdanvlviv/update-active_storage
`rake app:update` should update active_storage
2019-01-16 17:04:47 -06:00
Javan Makhmali
385d31d209 Minimize boilerplate setup code for JavaScript libraries 2019-01-16 16:15:43 -05:00
bogdanvlviv
2bad3f46cd
Add foreign key to active_storage_attachments for blob_id via new migration
We need this in order to be able to add this migration for users that
use ActiveStorage during update their apps from Rails 5.2 to Rails 6.0.

Related to #33405

`rake app:update` should update active_storage

`rake app:update` should execute `rake active_storage:update`
if it is used in the app that is being updated.
It will add new active_storage's migrations to users' apps during update Rails.

Context https://github.com/rails/rails/pull/33405#discussion_r204239399

Also, see a related discussion in the Campfire:
https://3.basecamp.com/3076981/buckets/24956/chats/12416418@1236713081
2019-01-16 13:13:23 +00:00
Javan Makhmali
86b489e3d6 Move all npm packages to @rails scope
Fixes #33083
2019-01-10 11:01:57 -05:00
Kasper Timm Hansen
647d7e6167
Revert "Revert "Merge pull request #34387 from yhirano55/rails_info_properties_json""
I reverted the wrong commit. Damn it.

This reverts commit f66a977fc7ae30d2a07124ad91924c4ee638a703.
2019-01-08 22:19:22 +01:00
Kasper Timm Hansen
f66a977fc7
Revert "Merge pull request #34387 from yhirano55/rails_info_properties_json"
We had a discussion on the Core team and we don't want to expose this information
as a JSON endpoint and not by default.

It doesn't make sense to expose this JSON locally and this controller is only
accessible in dev, so the proposed access from a production app seems off.

This reverts commit 8eaffe7e89719ac62ff29c2e4208cfbeb1cd1c38, reversing
changes made to b6e4305c3bca4c673996d0af9db0f4cfbf50215e.
2019-01-08 22:16:58 +01:00
Rafael França
1858614219
Merge pull request #34132 from ConfusedVorlon/enable_fragment_cache_log_in_dev
enable_fragment_cache_logging in dev by default
2019-01-08 14:15:16 -05:00
George Claghorn
ed51351536
Permit sending Active Storage purge and analysis jobs to separate queues 2019-01-01 19:40:59 -05:00
Arun Agrawal
50e3680768 Bump license years for 2019 2018-12-31 10:24:38 +07:00
Luciano Sousa
c329d323fc Permit generating variants of TIFF images 2018-12-30 18:14:49 -05:00
Julik Tarkhanov
e5f4162b61 Make Active Storage blob keys lowercase
Accommodate case-insensitive filesystems and database collations.
2018-12-30 11:56:22 -05:00
bogdanvlviv
2cfbdff63e
Use 6.0 default configs in Active Storage test dummy app 2018-12-30 03:10:31 +02:00
Cameron Bothner
372dda2a29 Don’t include an undefined X-CSRF-Token header
If there is not a `csrf-token` meta tag in the document, the blob record
XHR was including an `X-CSRF-Token` header set to the string
"undefined." Instead of setting it to undefined, it should not be
included in the absence of a meta tag.
2018-12-27 12:44:19 -05:00
Ryuta Kamizono
892e38c78e Enable Style/RedundantBegin cop to avoid newly adding redundant begin block
Currently we sometimes find a redundant begin block in code review
(e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205).

I'd like to enable `Style/RedundantBegin` cop to avoid that, since
rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5
(https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with
that situation than before.
2018-12-21 06:12:42 +09:00
Ryuta Kamizono
8034dde023 Module#{define_method,alias_method,undef_method,remove_method} become public since Ruby 2.5
https://bugs.ruby-lang.org/issues/14133
2018-12-21 01:39:18 +09:00
Kasper Timm Hansen
1b7c3222e8
Require Ruby 2.5 for Rails 6.
Generally followed the pattern for https://github.com/rails/rails/pull/32034

* Removes needless CI configs for 2.4
* Targets 2.5 in rubocop
* Updates existing CHANGELOG entries for fewer merge conflicts
* Removes Hash#slice extension as that's inlined on Ruby 2.5.
* Removes the need for send on define_method in MethodCallAssertions.
2018-12-19 21:47:50 +01:00
Yuji Yaginuma
222757618e
Merge pull request #34585 from marceloperini/marceloperini/33795
add require 'database/setup' in activestorage/test/service/s3_service_test.rb
2018-12-03 08:29:57 +09:00
Richard Macklin
fb0c81d349 Remove obsolete yarn.lock files and check in root yarn.lock file 2018-12-02 10:02:14 -08:00
Marcelo Perini Veloso
ce40e85194
add require 'database/setup' in activestorage/test/service/s3_service_test.rb 2018-12-01 15:47:54 -02:00
yuuji.yaginuma
6ca2f2acb2 metadata is not passed to service
Ref: 604fac6d71/activestorage/app/models/active_storage/blob.rb (L256-L264)

This fixes broken `GCSServiceTest`.
https://travis-ci.org/rails/rails/jobs/461868394#L6624-L6626

Follow up to  #34576.
2018-12-01 09:12:55 +09:00
Yannick Schutz
7bd21e8575
Add a test with extra keys to active_storage Service#upload 2018-11-30 15:54:38 +01:00
Hiroki Sanpei
4deb88ca26 Fix ArgumentError when uploading to amazon s3 2018-11-28 17:06:29 +09:00
yuuji.yaginuma
ac721c8552 Fix "warning: ambiguous first argument; put parentheses or a space even after `/' operator" 2018-11-28 11:29:03 +09:00
yuuji.yaginuma
b7ec129de5 text is treated as attachment 2018-11-28 10:35:57 +09:00
yuuji.yaginuma
c2ef8bbf52 Fix broken ActiveStorage::BlobTest
`ActiveStorage::Filename#parameters` was removed by #33829.
2018-11-28 10:16:07 +09:00
yuuji.yaginuma
7e7a60bd3f Remove duplicated test
Since 06ab7b27ea1c1ab357085439abacdb464f6742bf,
`GCSServiceTest#test_signed_URL_response_headers` is broken.
https://travis-ci.org/rails/rails/jobs/460454477#L7084-L7087

This seems to be due to lack of `content_type` at upload.
This is solved by specifying `conten_type`.

However, since the same content is also tested with `test_upload_with_content_type`,
it will be duplicated content, so I think that can remove `test_signed_URL_response_headers`.
2018-11-28 10:01:03 +09:00
Adrian Hawrylak
2c279aa980 Fix minor Active Storage docs typo [ci skip] 2018-11-28 00:27:58 +01:00
Rosa Gutierrez
06ab7b27ea Prevent content type and disposition bypass in storage service URLs
* Force content-type to binary on service urls for relevant content types

We have a list of content types that must be forcibly served as binary,
but in practice this only means to serve them as attachment always. We
should also set the Content-Type to the configured binary type.

As a bonus: add text/cache-manifest to the list of content types to be
served as binary by default.

* Store content-disposition and content-type in GCS

Forcing these in the service_url when serving the file works fine for S3
and Azure, since these services include params in the signature.
However, GCS specifically excludes response-content-disposition and
response-content-type from the signature, which means an attacker can
modify these and have files that should be served as text/plain attachments
served as inline HTML for example. This makes our attempt to force
specific files to be served as binary and as attachment can be easily
bypassed.

The only way this can be forced in GCS is by storing
content-disposition and content-type in the object metadata.

* Update GCS object metadata after identifying blob

In some cases we create the blob and upload the data before identifying
the content-type, which means we can't store that in GCS right when
uploading. In these, after creating the attachment, we enqueue a job to
identify the blob, and set the content-type.

In other cases, files are uploaded to the storage service via direct
upload link. We create the blob before the direct upload, which happens
independently from the blob creation itself. We then mark the blob as
identified, but we have already the content-type we need without having
put it in the service.

In these two cases, then, we need to update the metadata in the GCS
service.

* Include content-type and disposition in the verified key for disk service

This prevents an attacker from modifying these params in the service
signed URL, which is particularly important when we want to force them
to have specific values for security reasons.

* Allow only a list of specific content types to be served inline

This is different from the content types that must be served as binary
in the sense that any content type not in this list will be always
served as attachment but with its original content type. Only types in
this list are allowed to be served either inline or as attachment.

Apart from forcing this in the service URL, for GCS we need to store the
disposition in the metadata.

Fix CVE-2018-16477.
2018-11-27 15:36:27 -05:00
Tasos Maschalidis
d6fcc419fe ASt direct uploads: account for <button type="submit"> elements 2018-11-24 14:54:05 -05:00
Maurice Kühlborn
455a122ef0 Add progressive JPG to default variable content types 2018-11-21 23:21:01 +01:00
Gannon McGibbon
e74fdbe00c Amend CVE note and security guide section wordings
Reword first sentence of dep management and CVE section of
security guide. Also, reword and move gemspec notes above deps.

[ci skip]
2018-11-06 18:06:57 -05:00
Gannon McGibbon
1c11688b56 Add CVE note to security guide and gemspecs
[ci skip]
2018-11-06 14:25:36 -05:00
Kyle Keesling
79e086efc4
update activestorage attachment model documentation reflect recent behavior changes 2018-10-24 09:08:45 -04:00
Rob Jonson
d8707e0dfc enable_fragment_cache_logging
fragment caching was refactored in (I think 5.2) and by default doesn't log cache info

this is confusing in development where rails dev:cache now turns on caching, but doesn't show any different logging output

better to enable debugging by default for dev - and let people turn it off if preferred
2018-10-09 11:48:40 +01:00
Donnie Propst
b4e827d80a Point to requiring the ASt engine in the installation instructions [ci skip] 2018-10-08 11:26:51 -04:00
Graham Conzett
bba5ecc923 Use content_mime_type 2018-10-08 09:50:51 -04:00
Graham Conzett
1986048d27 Fix issue ActiveStorage direct upload disk
Fix an issue in ActiveStorage where a direct upload to disk storage
would fail due to a content type mismatch if the file was uploaded using
a mime-type synonym.
2018-10-07 16:07:09 -04:00
David Heinemeier Hansson
4838c1716a
Make Webpacker the default JavaScript compiler for Rails 6 (#33079)
* Use Webpacker by default on new apps

* Stop including coffee-rails by default

* Drop using a js_compressor by default

* Drop extra test for coffeescript inclusion by default

* Stick with skip_javascript to signify skipping webpack

* Don't install a JS runtime by default any more

* app/javascript will be the new default directory for JS

* Make it clear that this is just for configuring the default Webpack framework setup now

* Start using the Webpack tag in the default layout

* Irrelevant test

* jQuery is long gone

* Stop having asset pipeline compile default application.js

* Add rails-ujs by default to the Webpack setup

* Add Active Storage JavaScript to application.js pack by default

* Consistent quoting

* Add Turbolinks to default pack

* Add Action Cable to default pack

Need some work on how to set the global consumer that channels will
work with. @javan?

* Require all channels by default and use a separate consumer stub

* Channel generator now targets Webpack style

* Update task docs to match new generator style

* Use uniform import style

* Drop the JS assets generator

It was barely helpful as it was. It’s no longer helpful in a Webpacked
world. Sayonara!

* Add app/javascript to the stats directories

* Simpler import style

Which match the other imports.

* Address test failures from dropping JS compilation (and compression)

* webpacker-default: Modify `AssetsGeneratorTest`

Before:

```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 46201

F

Failure:
AssetsGeneratorTest#test_assets [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:12]:
Expected file "app/assets/javascripts/posts.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:10

.

Finished in 0.031343s, 63.8101 runs/s, 95.7152 assertions/s.
2 runs, 3 assertions, 1 failures, 0 errors, 0 skips
```

After:

```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 43571

..

Finished in 0.030370s, 65.8545 runs/s, 65.8545 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
```

* webpacker-default: Modify `ChannelGeneratorTest`

Before:

```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 8986

.F

Failure:
ChannelGeneratorTest#test_channel_with_multiple_actions_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:43]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:34

.F

Failure:
ChannelGeneratorTest#test_channel_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:29]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:22

E

Error:
ChannelGeneratorTest#test_cable_js_is_created_if_not_present_already:
Errno::ENOENT: No such file or directory @ apply2files - /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/fixtures/tmp/app/assets/javascripts/cable.js

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:60

F

Failure:
ChannelGeneratorTest#test_channel_suffix_is_not_duplicated [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:87]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:80

F

Failure:
ChannelGeneratorTest#test_channel_on_revoke [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:77]:
Expected file "app/assets/javascripts/cable.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:68

Finished in 0.064384s, 108.7227 runs/s, 481.4861 assertions/s.
7 runs, 31 assertions, 4 failures, 1 errors, 0 skips
```

After:

```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 44857

.......

Finished in 0.060243s, 116.1961 runs/s, 697.1764 assertions/s.
7 runs, 42 assertions, 0 failures, 0 errors, 0 skips
```

* Fix shared generator tests.

* webpacker-default: Modify `ControllerGeneratorTest`

The JS assets generator was dropped. ref. 46215b1794

* Revert "Simpler import style". It's currently failing with an error of "TypeError: undefined is not an object (evaluating '__WEBPACK_IMPORTED_MODULE_2_activestorage___default.a.start')". Waiting for @javan to have a look.

This reverts commit 5d3ebb71059f635d3756cbda4ab9752027e09256.

* require webpacker in test app

* Add webpacker without making the build hang/timeout. (#33640)

* use yarn workspaces to allow for installing unreleased packages and only generate js/bootsnap when required

* no longer need to have webpacker in env templates as webpacker moved this config to yml file

* Fix rubocop violation

* Got the test passing for the running scaffold

* update expected lines of code

* update middleware tests to account for webpacker

* disable js in plugins be default to get the tests passing (#34009)

* clear codeclimate report issues

* Anything newer than currently released is good

* Use Webpacker development version during development of Rails

* Edge should get development webpacker as well

* Add changelog entry for Webpacker change
2018-09-30 22:31:21 -07:00
Rafael Mendonça França
f679933daa
Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
Kasper Timm Hansen
ed56a03104
Merge pull request #33829 from mtsmfm/encode-filename
Encode Content-Disposition filenames on send_data and send_file
2018-09-23 19:43:06 +02:00
yuuji.yaginuma
1b86d90136 Enable Performance/UnfreezeString cop
In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.

```ruby
# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report('+@') { +"" }
  x.report('dup') { "".dup }
  x.compare!
end
```

```
$ ruby -v benchmark.rb
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Warming up --------------------------------------
                  +@   282.289k i/100ms
                 dup   187.638k i/100ms
Calculating -------------------------------------
                  +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                 dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s

Comparison:
                  +@:  6775299.3 i/s
                 dup:  3320400.7 i/s - 2.04x  slower

```
2018-09-23 08:56:55 +09:00
bogdanvlviv
be0d22a8e1
Raise ActiveRecord::InvalidForeignKey in before_destroy for a blob if attachments exist
The issue #32584 was fixed in #33405 by adding foreign key constraint
to the `active_storage_attachments` table for blobs.
This commit implements fix on app-level in order to ensure that users
can't delete a blob with attachments even if they don't have the foreign key constraint.
See a related discussion in the Campfire:
https://3.basecamp.com/3076981/buckets/24956/chats/12416418@1236718899

Note that, we should backport it to `5-2-stable` too.

Related to #33405
2018-09-16 22:44:30 +03:00
Chris Bisnett
7dd9916c0d Configure Active Storage route prefix
Applications can configure the route prefix prepended to the Active
Storage routes. By default this maintains the previous prefix
`/rails/active_storage` but supports custom prefixes.

Before this change the route for serving blobs is fixed to
`/rails/active_storage/blobs/:signed_id/*filename`. After this change
it's possible to configure the route to something like
`/files/blobs/:signed_id/*filename`.
2018-09-14 10:40:18 -04:00
Fumiaki MATSUSHIMA
890485cfce Encode Content-Disposition filenames on send_data and send_file 2018-09-13 21:38:46 +09:00
Xavier Noria
f589e20b0a use "minitest" consistently
The name of the minitest library is spelled that way: regular font, and
lowercase. Lowercase is used even at the beginning of sentences, see

    http://docs.seattlerb.org/minitest/

I double-checked this with @zenspider too (thanks!).
2018-09-11 23:57:25 +02:00
Marcelo Perini Veloso
0d4ba40688 Fix zero-byte files upload 2018-09-06 20:04:21 -03:00
Cameron Bothner
aae56c3529 Handle only specifically relevant Azure HTTPErrors
The Azure gem uses `Azure::Core::Http::HTTPError` for everything:
checksum mismatch, missing object, network unavailable, and many more.
(https://www.rubydoc.info/github/yaxia/azure-storage-ruby/Azure/Core/Http/HTTPError).
Rescuing that class obscures all sorts of  configuration errors. We
should check the type of error in those rescue  blocks, and reraise when
needed.
2018-08-23 23:36:43 -04:00
George Claghorn
3868648cae Revert "Merge pull request #33667 from cbothner/azure-service-swallowing-all-errors"
This reverts commit b204d167c5cfebd59f771d406178e371811ac43a, reversing
changes made to de6a200f82a3de399fa685d583503bc88dbc5e9f.
2018-08-23 19:07:29 -04:00
Cameron Bothner
6acf2fa363 Handle only specifically relevant Azure HTTPErrors
The Azure gem uses `Azure::Core::Http::HTTPError` for everything:
checksum mismatch, missing object, network unavailable, and many more.
(https://www.rubydoc.info/github/yaxia/azure-storage-ruby/Azure/Core/Http/HTTPError).
Rescuing that class obscures all sorts of  configuration errors. We
should check the type of error in those rescue  blocks, and reraise when
needed.
2018-08-23 17:54:35 -04:00
George Claghorn
dc001dbd58
Merge pull request #33666 from cbothner/fail-gracefully-from-activestorage-file-not-found
Fail more gracefully from ActiveStorage missing file exceptions
2018-08-22 22:56:10 -04:00
Cameron Bothner
22efb2ec49 Respond with 404 in ActiveStorage::DiskController#show when file missing
`ActiveStorage::DiskController#show` generates a 404 Not Found response when
the requested file is missing from the disk service. It previously raised
`Errno::ENOENT`.
2018-08-21 15:35:58 -04:00
Cameron Bothner
5cd2d07bdc Translate service-specific missing object exceptions into a generic one
`ActiveStorage::Blob#download` and `ActiveStorage::Blob#open` raise
`ActiveStorage::FileNotFoundError` when the corresponding file is missing
from the storage service. Services translate service-specific missing
object exceptions (e.g. `Google::Cloud::NotFoundError` for the GCS service
and `Errno::ENOENT` for the disk service) into
`ActiveStorage::FileNotFoundError`.
2018-08-21 15:31:14 -04:00
bogdanvlviv
0e77706dc5
activestorage: yarn build
Context https://github.com/rails/rails/pull/33413#issuecomment-414137587
2018-08-19 19:33:16 +03:00
George Claghorn
093d8d3953 Retry ActiveStorage::AnalyzeJobs on download integrity check failures 2018-08-19 01:19:51 -04:00
George Claghorn
116fae6ef9 Remove superfluous test
This test no longer covers the behavior of ActiveStorage::PurgeJob. Attached blobs are ignored by ActiveStorage::Blob#purge as of 934fccd, which includes an equivalent model test.
2018-08-19 01:10:50 -04:00
Chris Seelus
880f977925 Enable multiple submit buttons for Active Storage forms 2018-08-18 19:31:39 +02:00
George Claghorn
e33c3cd8cc Extract ActiveStorage::SetCurrent
Provide a handy concern for custom Active Storage controllers that can't inherit from ActiveStorage::BaseController.
2018-08-16 01:41:15 -04:00
George Claghorn
2d3a28b949 Document all Active Storage error classes [ci skip] 2018-08-10 18:38:28 -04:00
George Claghorn
18425b8371 Add a generic base class for Active Storage exceptions
Closes #33292.

[Andrei Makarov & George Claghorn]
2018-08-10 18:35:49 -04:00
George Claghorn
697f4a93ad Extract transformers 2018-08-10 12:42:14 -04:00
George Claghorn
10129fbf57 DRY up web image checks in ActiveStorage::Variant 2018-08-09 19:53:12 -04:00
George Claghorn
79573b3aff Camelize instead of classifying
Avoid mangling service names that end in S:

    "GCS".classify # => "GC"
    "GCS".camelize # => "GCS"
2018-08-06 22:23:47 -04:00
Joel Taylor
3082786be6 Improve ActiveStorage service adapter error handling 2018-08-06 18:17:49 -07:00
George Claghorn
bd680dd59a Fix uploading Tempfiles to Azure Storage
Closes #32530.
2018-08-03 22:41:19 -04:00
George Claghorn
bba4d2dd8c Remove another unused require 2018-08-02 14:38:33 -04:00
George Claghorn
bd01f9831c Remove unused require 2018-08-01 09:59:04 -04:00
George Claghorn
fee7fba893 Retry ActiveStorage::PurgeJobs on DB deadlock 2018-07-31 19:29:23 -04:00
George Claghorn
cd2fe237f7 Guard against missing blobs caused by concurrent purges 2018-07-30 21:42:20 -04:00
George Claghorn
362042c0d7 Ignore concurrently-deleted files when deleting by prefix from GCS 2018-07-30 13:13:00 -04:00
George Claghorn
6a0b0154e3 Update ActiveStorage::Previewer docs
PDFPreviewer became MuPDFPreviewer in 0b717c2. Previewers are simple enough that we can just provide a single example.
2018-07-29 11:48:11 -04:00
George Claghorn
046bd75b0e Clarify condition
&& binds tighter than || in JavaScript, but we ought not expect readers to remember language trivia.
2018-07-27 00:20:47 -04:00
George Claghorn
195463736c Fix directly uploading zero-byte files
Closes #33450.
2018-07-27 00:11:22 -04:00
George Claghorn
e03add2248 Log streaming downloads 2018-07-26 18:48:04 -04:00
Jasper Martin
934fccd522 Ignore ActiveRecord::InvalidForeignKey in ActiveStorage::Blob#purge
Do nothing instead of raising an error when it’s called on an attached blob.
2018-07-26 09:24:31 -04:00
Matthew Draper
ec387c6dd9
Merge pull request #33229 from albertoalmagro/albertoalmagro/prefer-rails-command-over-bin-rails
Prefer rails command over bin/rails
2018-07-25 04:10:29 +09:30
George Claghorn
0f57f75008 Remove unused attribute 2018-07-21 14:21:14 -04:00
George Claghorn
6c45b04a73 Discard ActiveStorage::PurgeJobs on ActiveRecord::InvalidForeignKey 2018-07-20 11:18:37 -04:00
George Claghorn
562ec3dcd1 Test that ActiveStorage::Blob#purge fails when attachments exist 2018-07-20 10:28:14 -04:00
George Claghorn
2ae3a29508 Add a foreign-key constraint to the attachments table for blobs 2018-07-19 20:43:33 -04:00
George Claghorn
3f53296f18 Delete attachment before purging blob 2018-07-19 20:26:56 -04:00
George Claghorn
07ecaa614b Destroy blob record before deleting stored data 2018-07-19 20:26:40 -04:00
George Claghorn
3ccec9b80d Link between ActiveStorage::Blob#purge, #purge_later, and #delete [ci skip] 2018-07-18 22:06:15 -04:00
George Claghorn
ac6e6c6b99 Clarify the ActiveStorage::Attachment#purge and #purge_later docs
Link to the corresponding ActiveStorage::Blob methods, whose docs more accurately describe their effects. [ci skip]
2018-07-18 21:59:31 -04:00
George Claghorn
af02b9b78f Remove unnecessary tap 2018-07-17 16:23:53 -04:00
George Claghorn
e13e16f5ad Fix replacing many attachments via assign and attach 2018-07-17 09:33:48 -04:00
George Claghorn
379d98dcd4 Correct test name 2018-07-16 15:59:17 -04:00
George Claghorn
36ec5428bf Fix that successive ActiveStorage::Attached::Many#attach calls would overwrite previous attachments 2018-07-16 15:57:43 -04:00
George Claghorn
1d13de4e39 Test removing attachments via #attach 2018-07-16 08:59:23 -04:00
George Claghorn
94f2558f6a Restore inadvertently-removed fallback 2018-07-15 20:12:53 -04:00
George Claghorn
390097531b Support HTTP Range downloads from disk
Closes #32193.
2018-07-15 19:58:14 -04:00
George Claghorn
bd5eba1adf Clear attachment changes on reload 2018-07-13 14:48:45 -04:00
George Claghorn
28db8ba60e Implement ActiveStorage::Attached::{One,Many}#attach in terms of changes 2018-07-13 13:29:33 -04:00
George Claghorn
d20d6c7326 Fix that detaching could purge 2018-07-13 12:17:33 -04:00
George Claghorn
63951072af Fix analyzing new blobs from uploaded files on attach 2018-07-13 06:33:45 -04:00
George Claghorn
16f435f931 Discard ActiveStorage::PurgeJobs for missing blobs 2018-07-11 22:09:23 -04:00
George Claghorn
a1735a0dde Remove overly-broad retry in ActiveStorage::PurgeJob
We've never intentionally tripped this retry in production. Add retries for specific errors as needed.
2018-07-11 22:04:42 -04:00
George Claghorn
0b85123cd8 Raise an ArgumentError instead of a RuntimeError 2018-07-08 11:35:27 -04:00
George Claghorn
e8682c5bf0
Store newly-uploaded files on save rather than assignment 2018-07-07 23:25:33 -04:00
George Claghorn
03afddd2eb Fix that models can clobber each others' attachment reflections
Consider the following model definitions:

    class User < ApplicationRecord
      has_one_attached :avatar
    end

    class Group < ApplicationRecord
      has_one_attached :avatar
    end

If you attempt to reflect on the User model's avatar attachment via User.reflect_on_attachment, you could receive a reflection for the Group model's avatar attachment. Fix this by ensuring that each model class uses its own Hash object to track attachment reflections.
2018-07-07 17:09:31 -04:00
Alberto Almagro
40b209db53 Recommend use of rails over bin/rails
As discussed in #33203 rails command already looks for, and runs,
bin/rails if it is present.

We were mixing recommendations within guides and USAGE guidelines,
in some files we recommended using rails, in others bin/rails and
in some cases we even had both options mixed together.
2018-07-06 22:46:35 +02:00
Bibek Shrestha
637a8cde59 Remove vestigial require on ActiveStorage GCSService
The file `filename.rb` as mentioned in `require "active_storage/filename"`
belongs to the `app` folder while GCSService belongs to the lib folder.

Looking at the git blame, it was added in commit ccac681122 (diff-bda6a610ef1575b2c8458c96b7f12578)
where ActiveStorage::Filename was actually used. But it is no longer
required on master and therefore can be removed.

This allows anyone to use GCSService directly without enabling
ActiveStorage engine.
2018-07-04 17:04:26 -04:00
utilum
875ef6e748 Tweak Previewer::PopplerPDFPreviewer#pdftoppm_exists?
Does not warn `instance variable @pdftoppm_exists not initialized`.
2018-06-29 07:58:28 +02:00
George Claghorn
56b9d0fd3a Generate a new key for each service test
Sidestep Google Cloud Storage's restrictive per-object rate limit.
2018-06-25 18:49:26 -04:00
ishanray
d3715e67f1
Update service.rb 2018-06-24 00:09:31 -04:00
George Claghorn
b21f50d8ae Permit configuring the default service URL expiry 2018-06-21 11:06:32 -04:00
yuuji.yaginuma
38dbc8e2b8 Fix "warning: Net::HTTPResponse#header is obsolete"
Ref: cc77a81129/lib/net/http/response.rb (L138-L155)
2018-06-17 21:35:07 +09:00
utilum
d70bd73f05 Update ffmpeg -> FFmpeg, mutools|mupdf -> muPDF
[ci skip]
2018-06-08 11:28:11 +02:00
bogdanvlviv
8bc9062aee
Refactor activestorage/test/models/attached_test.rb
Don't include `ActiveJob::TestHelper` since there is no test that uses it.

Ensure removing of overridden User's methods.

Related to https://github.com/rails/rails/pull/33085#issuecomment-395548563
Module#remove_method is private in Ruby 2.4.

Related to fd0bd1bf682622f064ac437ceee4e1b2a6b6d3b9
2018-06-07 23:29:03 +03:00
George Claghorn
d3e0a9f110 Exclude upload time from instrumented preview time 2018-06-03 20:24:51 -04:00
Rafael França
c1844477a1
Merge pull request #33018 from kddeisz/defined-attachments
ActiveStorage reflection
2018-06-01 14:24:06 -04:00
Kevin Deisz
6c7e6abfaa
Ensure reflection_class_for is private 2018-05-31 21:15:51 -04:00
Kevin Deisz
ce337d1757
Move ActiveStorage reflection logic entirely into ActiveStorage 2018-05-31 09:33:46 -04:00
George Claghorn
bd7ebf61fb Remove errant debugger call 2018-05-30 20:09:30 -04:00
George Claghorn
a6d80e164f Include blob ID in tempfile name for debugging convenience 2018-05-30 20:05:39 -04:00
Kevin Deisz
bc3b6ea461
Reflection for attachments
Add the ability to reflect on the attachments that have been defined using ActiveRecord::Reflection.
2018-05-30 13:28:22 -04:00
George Claghorn
cfb493a3a3 Fix reference 2018-05-28 16:30:26 -04:00
George Claghorn
1bdaccc0b8 Verify integrity after chunked download 2018-05-28 16:28:46 -04:00
utilum
39192e39ad Hide Active Storage migration installation task (#33007)
Resolves #33006
2018-05-28 18:09:38 +02:00
George Claghorn
097650c194
Merge pull request #32968 from utilum/shadowing_outer_variable
Avoid 2.6 warning: shadowing outer local variable - list
2018-05-23 21:56:33 -04:00
utilum
f6f8fc2ca0 Avoid 2.6 warning: shadowing outer local variable - list 2018-05-23 23:48:32 +02:00
utilum
a48f6a5d9f Enable warnings in all test tasks
Also normalize AJ task use t, like all other Rails test tasks.
2018-05-23 23:05:03 +02:00
Javan Makhmali
b60ee86d94 Change video preview format from PNG to JPG 2018-05-23 14:32:34 -04:00
George Claghorn
bdd8b6843c
Merge pull request #32144 from kazu9su/master
Add ActiveStorage::Service::DiskService#url_for_direct_upload test
2018-05-22 17:34:19 -04:00
Jacob Smith
0210ac0b43 Disable variant options when false or nil present
In response to https://github.com/rails/rails/issues/32917

In the current implementation, ActiveStorage passes all options to the underlying processor,
including when a key has a value of false.

For example, passing:

```
avatar.variant(resize: "100x100", monochrome: false, flip: "-90")
```

will return a monochrome image (or an error, pending on ImageMagick configuration) because
it passes `-monochrome false` to the command (but the command line does not allow disabling
flags this way, as usually a user would omit the flag entirely to disable that feature).

This fix only passes those keys forward to the underlying processor if the value responds to
`present?`. In practice, this means that `false` or `nil` will be filtered out before going
to the processor.

One possible use case would be for a user to be able to apply different filters to an avatar.
The code might look something like:

```
  variant_options = {
    monochrome: params[:monochrome],
    resize:     params[:resize]
  }

  avatar.variant(*variant_options)
```

Obviously some sanitization may be beneficial in a real-world scenario, but this type of
configuration object could be used in many other places as well.

- Add removing falsy values from varaints to changelog

- The entirety of #image_processing_transformation inject block was wrapped in `list.tap`
 to guard against the default `nil` being returned if no conditional was called.

- add test for explicitly true variant options
2018-05-21 10:38:15 -04:00
George Claghorn
9f95767979 Permit opening a blob in a custom tempdir 2018-05-17 19:14:11 -04:00
Josh Susser
fd0bd1bf68 Generate getter and setter methods in mixin
Generated attachment getter and setter methods are created within
the model's `GeneratedAssociationMethods` module to allow overriding
and composition using `super`.

Includes tests for new functionality.

Co-authored-by: Josh Susser <josh@hasmanythrough.com>
Co-authored-by: Jamon Douglas <terrildouglas@gmail.com>
2018-05-17 14:51:15 -07:00
Ryuta Kamizono
16c0cd1870 Fix formatting of author credit [ci skip] 2018-05-17 21:01:11 +09:00
lucfranken
8cc79f502e
Active storage: Image variant options not correct
### Steps to reproduce

Using Rails 5.2.0

When following this example:

http://api.rubyonrails.org/classes/ActiveStorage/Variant.html

`avatar.variant(resize: "100x100", monochrome: true, flip: "-90")`

### Expected behavior

Image should be rendered as flipped.

### Actual behavior

I get an error:

> failed with error: gm mogrify: Unrecognized option (-90).

### Fix:

According to: https://github.com/minimagick/minimagick the option should be called rotate:

`avatar.variant(resize: "100x100", monochrome: true, rotate: "-90")`

So **flip** changed to **rotate**.

### System configuration
**Rails version**: 5.2.0

**Ruby version**: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
2018-05-17 12:49:11 +02:00
Ryuta Kamizono
a1f9fe8bdd Remove unused require "active_support/core_ext/string/filters" 2018-05-17 15:30:49 +09:00
George Claghorn
e092cae49c Add ActiveStorage::Previewer#tempdir 2018-05-16 22:55:09 -04:00
George Claghorn
ff3210556b Add missing block parameters 2018-05-16 22:50:24 -04:00
George Claghorn
ee21b7c2eb Add ActiveStorage::Blob#open
[David Robertson & George Claghorn]
2018-05-16 22:12:31 -04:00
Ryan Davidson
8e98bb7758 Add option to ActiveStorage::Blob to set extract_content_type_from_io
This adds a boolean argument called identify to ActiveStorage::Blob
methods #create_after_upload, #build_after_upload and #upload. It
allows a user to bypass the automatic content_type inference from
the io.
2018-05-08 23:01:57 +01:00
George Claghorn
8ae38dab52 Assert correct response body 2018-05-03 09:03:48 -04:00
George Claghorn
847342c25c Stream blobs from disk 2018-05-02 18:56:09 -04:00
George Claghorn
bf5f41d948
Support streaming downloads from Google Cloud Storage 2018-05-01 23:20:56 -04:00
George Claghorn
7097514d1e Avoid duplicating downloads from Google Cloud Storage in memory
References #32703.
2018-04-29 09:34:14 -04:00
George Claghorn
5f2ee4c0bb Stream blobs from disk in 5 MB chunks
Match other services, which all use a 5 MB chunk size.
2018-04-29 07:07:59 -04:00
Eileen M. Uchitelle
ad0220a71a
Merge pull request #31956 from fatkodima/has_attached-presence-validation
has_(one/many)_attached presence validation
2018-04-27 14:35:21 -04:00
Ricardo Díaz
36e0ac3b53 Move #extract_metadata_from to ActiveStorage's TestHelper
ImageAnalyzerTest and VideoAnalyzerTest are defining the same helper,
since both use `#create_file_blob` that is defined in TestHelper, it
makes sense to move `#extract_metadata_from` to that side.
2018-04-25 15:28:30 -05:00
George Claghorn
052fcef0cb Simplify URL generation for partial downloads from GCS 2018-04-25 12:47:58 -05:00
Javan Makhmali
56fc1f812a Unminify activestorage.js 2018-04-25 08:46:56 -05:00
George Claghorn
e4c5186428 Flush tempfile after populating it
Ensure that other processes like ImageMagick and FFmpeg see the complete contents of the file.
2018-04-23 16:44:13 -05:00
George Claghorn
ef5902a2f1
Merge pull request #32471 from janko-m/use-image_processing-gem
Use ImageProcessing gem for ActiveStorage variants
2018-04-23 16:01:16 -05:00
Janko Marohnić
f2e2cef15b
Don't swallow LoadError raised for missing libvips 2018-04-23 22:07:50 +02:00
Janko Marohnić
19770d6ca3
Halve memory allocation in S3Service#download
Aws::S3::Object#get returns a response with object content wrapped in an
in-memory StringIO object. StringIO#read will return a copy of the
content, which is not necessary because we can return the content
directly using StringIO#string. This halves memory allocation of
S3Service#download, because we remove unnecessary content duplication.
2018-04-23 21:29:55 +02:00
Janko Marohnić
151167eb3d
Add CHANGELOG entry 2018-04-23 21:27:28 +02:00
Janko Marohnić
eef0bd0c0a
Recommend using :resize_to_fit after all 2018-04-23 21:04:35 +02:00
Janko Marohnić
e40091648b
Remove warning that image will be loaded into memory
This is not true anymore, the image will be downloaded into a temporary
file in a streaming fashion.
2018-04-23 12:24:26 +02:00
Janko Marohnić
7fc8b6d82c
Show ImageProcessing macros in a dedicated example 2018-04-23 12:21:42 +02:00
Janko Marohnić
0d811fd482
Ensure result file is deleted on uploading errors 2018-04-22 23:43:11 +02:00
Janko Marohnić
f01e249890
Rename ActiveStorage.processor to .variant_processor 2018-04-22 23:40:42 +02:00
Janko Marohnić
ca12968587
Use ImageProcessing gem for ActiveStorage variants
ImageProcessing gem is a wrapper around MiniMagick and ruby-vips, and
implements an interface for common image resizing and processing. This
is the canonical image processing gem recommended in [Shrine], and
that's where it developed from. The initial implementation was extracted
from Refile, which also implements on-the-fly transformations.

Some features that ImageProcessing gem adds on top of MiniMagick:

  * resizing macros
    - #resize_to_limit
    - #resize_to_fit
    - #resize_to_fill
    - #resize_and_pad
  * automatic orientation
  * automatic thumbnail sharpening
  * avoids the complex and inefficient MiniMagick::Image class
  * will use "magick" instead of "convert" on ImageMagick 7

However, the biggest feature of the ImageProcessing gem is that it has
an alternative implementation that uses libvips. Libvips is an
alternative to ImageMagick that can process images very rapidly (we've
seen up 10x faster than ImageMagick).

What's great is that the ImageProcessing gem provides the same interface
for both implementations. The macros are named the same, and the libvips
implementation does auto orientation and thumbnail sharpening as well;
only the operations/options specific to ImageMagick/libvips differ. The
integration provided by this PR should work for both implementations.

The plan is to introduce the ImageProcessing backend in Rails 6.0 as the
default backend and deprecate the MiniMagick backend, then in Rails 6.1
remove the MiniMagick backend.
2018-04-18 17:46:25 +02:00
Javan Makhmali
efb7dc65d9 Always exclude JSON root from direct_uploads#create response
The JavaScript component expects a bare response.

Fixes #32365
2018-04-10 06:36:47 -04:00
Ryuta Kamizono
d729bc7488
Merge pull request #32494 from dixpac/as_fix_outdated_documentation_for_variants
Fix leftover references to VariantsController in AS documentation [ci skip]
2018-04-08 21:18:31 +09:00
dixpac
c520417ad1 Fix leftover references to VariantsController [ci skip]
VariantsController has been merged to RepresentationsController, this
PR fixes outdated references to VariantsController in ActiveStorage documentation.
2018-04-08 14:07:21 +02:00
Yoshiyuki Hirano
2cf522eef5 Enable verbose option in ActiveStorage 2018-04-08 06:30:06 +09:00
Andrew White
9436c22e2a
Use a current model to provide the host for service urls
Trying to pass the current request down to the service so that it can
create full urls instead of paths makes the API messy so use a model
based on ActiveSupport::CurrentAttributes to provide the current host
to services that need it (primarily the disk service).
2018-04-06 20:07:52 +01:00
Rafael Mendonça França
03bd370c02
Protect all active storage controllers agains CSRF
Before it was possible to for example use the direct upload controller
without using the site.
2018-04-06 14:28:44 -04:00
kylekeesling
a7cdad8d26
fixes a bug in IE11 that broke direct uploads 2018-04-06 10:20:25 -04:00
Dwight Watson
8e8f09fa18 Flip the order of the after_create callbacks
Addresses rails/rails#32247

Add test that checks identify and analyze work in correct order

Break out direct upload test helper

Review changes for direct-upload test helper
2018-03-27 12:58:19 +11:00
Andrew White
d7b7276104 Remove backported CHANGELOG entry [ci skip] 2018-03-19 15:30:23 +00:00
Brian Knight
c1600009b2 Allow full use of the AWS S3 SDK authentication options (#32270)
If an explicit AWS key pair and/or region is not provided in
config/storage.yml, attempt to use environment variables, shared
credentials, or IAM role credentials. Order of precedence is
determined by the AWS SDK[1].

[1]: https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html
2018-03-19 15:25:40 +00:00
Rafael Mendonça França
ba0ae542ca
Remove changelog header for unreleased version
We only add the header when releasing to avoid some conflicts.

[ci skip]
2018-03-13 15:20:57 -04:00
George Claghorn
fcbe17137d Fix Azure signed URL generation with newer client lib 2018-03-12 23:14:20 -04:00
George Claghorn
0443cb130c Update ASt test services config 2018-03-12 19:00:54 -04:00
Andrew White
309bb6c4d0 Remove path config option from Azure service
The Active Storage service for Azure Storage has an option called `path`
that is ambiguous in meaning. It needs to be set to the primary blob
storage endpoint but that can be determined from the blobs client anyway.

To simplify the configuration this commit removes the `path` option and
gets the endpoint from the blobs client instead.

Closes #32225.
2018-03-12 17:39:58 +00:00
Terence Lee
0b717c2045 Provide an alternative PDF previewer based on Poppler
mutool is licensed under the Affero GPL, which has strict distribution requirements.

Poppler is licensed under the more liberal GPL, making it a good alternative for those who can't use mutool.
2018-03-06 13:33:33 -05:00
George Claghorn
060ed201e4 Update test to reflect GCS direct upload header change 2018-03-06 13:09:22 -05:00
Nicholas Shirley
f9a5839083 Allow selectively purging attached blobs 2018-03-06 13:03:02 -05:00
George Claghorn
40d3fa5dfe Remove blank Content-Type from GCS direct upload headers
Since we started clearing the client-side blob's type in e0867b3, we no longer need to set a blank Content-Type header before issuing the direct upload request. Fixes that Safari 9 would combine the blank Content-Type header with the blank blob type to produce a Content-Type header containing a single comma, invalidating the request.
2018-03-06 10:05:50 -05:00
George Claghorn
9cc88043e7 Fix purging dependent blobs when attachments aren't loaded 2018-03-05 17:01:31 -05:00
George Claghorn
8228d12a43 Delete dependent attachments with record
[Matt Jones & George Claghorn]
2018-03-05 15:57:52 -05:00
George Claghorn
e83575ff53 Correct the ActiveStorage::Service#download_chunk docs [ci skip] 2018-03-05 13:27:14 -05:00
George Claghorn
ccac681122 Generate root-relative paths in Active Storage disk service URL methods
Fixes #32129.
2018-03-05 11:54:43 -05:00
George Claghorn
7e658588fa Handle another case where a blob might be erroneously purged 2018-03-04 18:54:31 -05:00
George Claghorn
4ed4c75c1f Avoid purging attached blob when replacing it with itself 2018-03-04 17:56:45 -05:00
Kasper Timm Hansen
0f302b8970
Merge Previews/Variants controller into one Representations controller.
Since ActiveStorage::Blob::Representable unifies the idea of previews and
variants under one roof as representation, we may as well have the
controllers follow suit.

Thus ActiveStorage::RepresenationsController enters the fray. I've copied
the old tests for both previews and variants and unified those as well.
2018-03-03 21:36:43 +01:00
yuuji.yaginuma
acbcec8ea8 Deprecate active_support/core_ext/hash/compact
Ruby 2.4+ provides `Hash#compact` and `Hash#compact!` natively,
so `active_support/core_ext/hash/compact` is no longer necessary.
2018-03-02 16:40:55 -08:00
tommy
a21d11ce80 Add ActiveStorage::Service::DiskService#url_for_direct_upload test 2018-03-01 08:59:00 +09:00
George Claghorn
f008562dd3 Rebuild activestorage.js 2018-02-28 14:10:51 -05:00
George Claghorn
5a66a14226 Handle file checksumming errors 2018-02-28 14:04:36 -05:00
George Claghorn
e0867b3672 Clear Blob's type before sending it
Prevent older versions of Chrome from appending a Content-Type header containing the Blob type, rendering the request invalid if we intend not to provide a Content-Type. This behavior was observed in Chrome 58.
2018-02-26 17:20:55 -05:00
George Claghorn
87de79e9cc Update test to reflect direct upload header changes 2018-02-26 13:56:54 -05:00
George Claghorn
8a79d04e4d Avoid specifying content types for direct uploads to Google Cloud Storage
Fix customizing the download Content-Type for a directly-uploaded blob via a signed URL. See e8286ee.
2018-02-26 12:00:24 -05:00
bogdanvlviv
ae3e241b57
Remove changelogs for Rails 6.0 since they were backported to 5-2-stable
Remove railties' changelog added by 7340596de45dc4c0f62a287b6acc4e71d8ee6c60
since it was backported to `5-2-stable` via ac99916fcf7bf27bb1519d4f7387c6b4c5f0463d

Remove activesupport's changelog added by 1077ae96b34b5a1dfbf10ee0c40b1ceb1eb6b30b
since it was backported to `5-2-stable` via a2b97e4ffef971607a1be8fc7909f099b6840f36

Remove activesupport's changelog added by 0d41a76d0c693000005d79456dee7f9299f5e8d4
since it was backported to `5-2-stable` via cdce6a709e1cbc98fff009effc3b1b3ce4c7e8db

Remove activestorage's changelog added by d57c52a385eb57c6ce8c6d124ab5e186f931d142
since it was backported to `5-2-stable` via 5292cdf59a2052c453d6016c69b90b790cbf2547

Follow up c113bdc9d0c2cffd535ca97aff85c4bdc46b11f6
2018-02-26 00:10:57 +02:00
Eugene Kenny
eb834811dc Use lazy load hook to configure ActiveStorage::Blob
`to_prepare` callbacks are run during initialization; using one here
meant that `ActiveStorage::Blob` would be loaded when the app boots,
which would in turn load `ActiveRecord::Base`.

By using a lazy load hook to configure `ActiveStorage::Blob` instead,
we can avoid loading `ActiveRecord::Base` unnecessarily.
2018-02-25 00:54:27 +00:00
George Claghorn
3915a470d2 Support varying ICO files
Closes #32096.
2018-02-24 15:27:57 -05:00
Andrew White
7dce840dee Allow S3 tests against buckets in other regions
Only us-east-1 gives URLs like bucket.s3.amazonaws.com whereas other
regions have URLs like s3-eu-west-1.amazonaws.com/ubxd-rails
2018-02-21 12:06:25 +00:00
George Claghorn
9794e85351 Hoist update for clarity 2018-02-20 18:08:14 -05:00
George Claghorn
d94db07774 Undocument ActiveStorage::Identification 2018-02-20 18:03:44 -05:00
George Claghorn
9208a52220 Correct Range header syntax 2018-02-20 14:45:54 -05:00
Jeremy Daer
d4eb0dc89e Rails 6 requires Ruby 2.4.1+
Skipping over 2.4.0 to sidestep the `"symbol_from_string".to_sym.dup` bug.

References #32028
2018-02-17 15:34:57 -08:00
bogdanvlviv
0f98954a83
Clean up and consolidate .gitignores
* Global ignores at toplevel .gitignore
* Component-specific ignores in each toplevel directory
* Remove `actionview/test/tmp/.keep` for JRuby

```
rm actionview/test/tmp/ -fr
cd actionview/
bundle exec jruby -Itest test/template/digestor_test.rb
```

Related to #11743, #30392.

Closes #29978.
2018-02-17 14:26:19 -08:00
Rafael Mendonça França
0ea8e7db1a Remove support to Ruby 2.2
Rails 6 will only support Ruby >= 2.3.
2018-02-16 18:52:10 -05:00
Eugene Kenny
1e55ee5a28 Use require_dependency inside Active Storage
Active Storage is an engine which means its models, jobs and controllers
are autoloaded by Rails rather than Ruby. Unfortunately this means it's
subject to the same gotchas as applications, including this one:

http://guides.rubyonrails.org/v5.1.4/autoloading_and_reloading_constants.html#when-constants-aren-t-missed-qualified-references

On Ruby < 2.5, constants nested under classes can't be autoloaded by
Rails if a top level constant already exists with the same name.

To avoid clashing with constants defined in users' applications or gems,
we can use `require_dependency` to ensure that the nested constants are
loaded before they're used.
2018-02-14 23:15:12 +00:00
George Claghorn
c476969b44 Document MuPDF version requirement 2018-02-13 10:47:39 -05:00
fatkodima
0c463f50ea Add ActiveStorage::Blob.unattached scope 2018-02-12 22:13:00 +02:00
Wojtek Wrona
40fabc3cc1
Use full class names when including concerns to avoid collisions 2018-02-12 16:37:54 +01:00
George Claghorn
cfcb92f9ea Add missing require 2018-02-11 18:30:09 -05:00
fatkodima
42259ce904 has_(one/many)_attached presence validation 2018-02-11 17:53:23 +02:00
Eileen M. Uchitelle
b6ee4e4b98
Merge pull request #31927 from mrreynolds/patch-2
Document :combine_options
2018-02-09 09:18:11 -05:00
Robert Glaser
6ee504b1d7 Document :combine_options
Turns out this is still undocumented functionality.
2018-02-08 21:54:29 +01:00
Jason Lee
0625a2ba80 Fix blob.service_url for supports string or nil :filename option.
- Make sure `blob.service_url` present a `ActiveStorage::Filename` type to `serivce.url`.
- Add `ActiveStorage::Filename.wrap` method.

before:

```rb
blob.service_url(filename: ActiveStorage::Filename.new("new.txt"))

blob.service_url(filename: "new.txt")
=> NoMethodError: undefined method `parameters' for "new.txt":String

params = {}
blob.service_url(filename: params[:filename])
=> NoMethodError: undefined method `parameters' for nil:NilClass
```

after:

```rb
blob.service_url(filename: "new.txt")
blob.service_url(filename: nil)
```
2018-02-08 10:15:55 +08:00
Richard Macklin
c0368ad090 Include source code in published activestorage npm package
This allows activestorage users to ship smaller javascript bundles to
visitors using modern browsers, as demonstrated in this repository:
https://github.com/rmacklin/activestorage-es2015-build-example

In that example, the bundle shrinks by 5K (24%).

In addition to allowing smaller bundles for those who ship untranspiled
code to modern browsers, including the source code in the published
package can be useful in other ways:

1. Users can import individual modules rather than the whole library
2. As a result of (1), users can also monkey patch parts of
   activestorage by importing the relevant module, modifying the
   exported object, and then importing the rest of activestorage (which
   would then use the patched object).

Note:
In order to allow the source code to be depended on rather than the
compiled code, we have to declare the external dependency on spark-md5
as a regular dependency, not a development dependency.

This means that even users who depend on the compiled code will have to
download this package. However, spark-md5 is a small package, so this
tradeoff seems worth it.
2018-02-06 08:18:21 -08:00
George Claghorn
74aa62cb69
Merge pull request #31854 from huacnlee/allow-more-options-for-service-url
Allow ActiveStorage::Blob#service_url to pass addition options to service.url
2018-02-01 21:57:09 -05:00
Jason Lee
69ae9fe6b5 Allow ActiveStorage::Blob#service_url to pass addition options to service.url.
Because there have some service needs more parameters for file URL:

https://www.alibabacloud.com/help/doc-detail/44687.htm

```rb
class AliyunService < Service
  def url(key, options = {})
    image_process = options[:oss_process] || "image/resize,w_800"
    "http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=#{image_process}"
  end
end
```

Use case:

```erb
<%= image_tag @user.avatar.service_url(oss_process: "image/resize,m_fill,h_100,w_100" %>
```
2018-02-01 23:49:25 +08:00
Renaud Chaput
eafe2c16cd Use the full class name for the JSON coder, as there may be another
`JSON` constant defined.

For example when using the `representable` gem: https://github.com/trailblazer/representable/issues/224
2018-02-01 11:17:11 +00:00
George Claghorn
57cc6f4030 Correct orientation detection 2018-01-31 16:50:30 -05:00
George Claghorn
f9b806eaa1 Swap encoded image width and height if angle is 90 or 270 degrees 2018-01-31 15:43:29 -05:00