Commit Graph

284 Commits

Author SHA1 Message Date
Peter Zhu 235f2636cd Deprecate `service_url` in favour of `url` 2019-12-02 14:59:03 -05:00
Patrik Bóna f3b63538af Fix actions order in the comment
The order of performed actions changed in 07ecaa614b but the comment
stayed the same.
2019-11-25 16:30:37 +01:00
Gannon McGibbon e2efd62c35 Fix ActiveStorage::Blob#service method redefined warning 2019-11-13 15:31:23 -05:00
George Claghorn 709cee9c9a
Defer Active Storage service configuration until use 2019-11-08 15:03:42 -05:00
Jean Boussier 1d2a2d9143 Avoid using require_dependency is Zeitwerk is enabled 2019-10-30 17:14:23 +01: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
Kyle Ribordy 698e9ce0ff Set Content-Type on variant uploads 2019-10-01 20:51:13 -04:00
DmitryTsepelev e7f798c3f5 Allow configure services for individual attachments 2019-10-01 21:24:05 +03:00
Eugene Kenny 47e563781c Always use 28 characters for Active Storage keys
Active Storage keys are generated in two ways: in the `before_create`
callback added by `has_secure_token`, or by calling `key` before the
blob is saved. a273da7619 broke the
former code path, and the latter was previously untested.
2019-10-01 00:24:41 +01:00
Rafael Mendonça França a273da7619 Merge pull request #35915 from bernardoamc/allow-has-secure-token-length-manipulation
Allow token length configuration for has_secure_token method
2019-09-30 15:13:04 -04:00
George Claghorn 4dba136c83 Allow providing a custom key per blob
Closes #37315.
2019-09-29 20:07:09 -04:00
George Claghorn 0069400326 Use Module#deprecate 2019-09-29 15:52:12 -04:00
George Claghorn 06f8baf73c Discard ActiveStorage::AnalyzeJobs on ActiveRecord::RecordNotFound
Fixes #37305.
2019-09-28 10:28:21 -04:00
George Claghorn 436e3ffe03 Fix typo: overwrittein → overwritten 2019-09-24 08:00:48 -04:00
Julik Tarkhanov 3c35de7933 Always create ActiveStorage::Blob before uploading to service 2019-09-24 07:32:59 -04:00
Ryuta Kamizono db6884a772 Fix typo /a HTTP/an HTTP/ [ci skip]
Follow up #37281.
2019-09-24 08:43:31 +09:00
Connor Shea 2bd56a1e7c Note ActiveStorage::Blob methods in Attachment docs [ci skip] 2019-09-20 21:43:29 -04:00
Akira Matsuda dea19d4ead Passing in a Hash instance as kwargs parameters requires the "double splat" prefix 2019-09-07 02:44:36 +09:00
Gannon McGibbon 7fd006de0b Pass optional record in blob finder methods
Allow record to be optionally passed to blob finders to make sharding
easier.
2019-08-07 14:38:05 -04:00
Akira Matsuda 530f7805ed It may be better to explicitly require 'object/try' where we call `try`
In most cases it works now without explicit require because it's accidentally required through
active_support/core_ext/date_and_time/calculations.rb where we still call `try`,
but that would stop working if we changed the Calculations implementation and remove the require call there.
2019-08-01 18:51:51 +09:00
George Claghorn d5a2f7ec14
Mirror direct uploads 2019-05-22 15:07:35 -04:00
George Claghorn 5f50f4d63b Inline anemic methods 2019-05-15 15:53:43 -04: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
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 002684e36e.
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 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
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
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
George Claghorn ed51351536
Permit sending Active Storage purge and analysis jobs to separate queues 2019-01-01 19:40:59 -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
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
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
Kyle Keesling 79e086efc4
update activestorage attachment model documentation reflect recent behavior changes 2018-10-24 09:08:45 -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
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
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
Fumiaki MATSUSHIMA 890485cfce Encode Content-Disposition filenames on send_data and send_file 2018-09-13 21:38:46 +09:00
Marcelo Perini Veloso 0d4ba40688 Fix zero-byte files upload 2018-09-06 20:04:21 -03: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
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
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 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 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 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
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
George Claghorn 6c45b04a73 Discard ActiveStorage::PurgeJobs on ActiveRecord::InvalidForeignKey 2018-07-20 11:18:37 -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 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 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 e8682c5bf0
Store newly-uploaded files on save rather than assignment 2018-07-07 23:25:33 -04:00
George Claghorn b21f50d8ae Permit configuring the default service URL expiry 2018-06-21 11:06:32 -04:00
utilum d70bd73f05 Update ffmpeg -> FFmpeg, mutools|mupdf -> muPDF
[ci skip]
2018-06-08 11:28:11 +02:00
George Claghorn a6d80e164f Include blob ID in tempfile name for debugging convenience 2018-05-30 20:05:39 -04:00
George Claghorn 1bdaccc0b8 Verify integrity after chunked download 2018-05-28 16:28:46 -04:00
utilum f6f8fc2ca0 Avoid 2.6 warning: shadowing outer local variable - list 2018-05-23 23:48:32 +02: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
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
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 847342c25c Stream blobs from disk 2018-05-02 18:56:09 -04:00
Javan Makhmali 56fc1f812a Unminify activestorage.js 2018-04-25 08:46:56 -05:00
Janko Marohnić f2e2cef15b
Don't swallow LoadError raised for missing libvips 2018-04-23 22:07:50 +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
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
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
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 ccac681122 Generate root-relative paths in Active Storage disk service URL methods
Fixes #32129.
2018-03-05 11:54:43 -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
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
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
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
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
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
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 c2ba530c43
Extract content types from blob data 2018-01-15 13:06:17 -05:00
George Claghorn 2c08446e0c Instrument image transformation 2018-01-10 21:50:14 -05:00
George Claghorn 96f5930610 Update error names in docs [ci skip] 2018-01-10 12:37:07 -05:00
Ryuta Kamizono 7e78d2cc94 Add missing `# frozen_string_literal: true` 2018-01-11 02:33:41 +09:00
George Claghorn 3320e80b93 Correct comment [ci skip] 2018-01-10 12:15:30 -05:00
George Claghorn d4cdd4a05f Extract Analyzable and Representable concerns 2018-01-10 12:12:04 -05:00
Javan Makhmali f17137b0a1 Rebuild activestorage.js
To pick up 21417e02e9
2018-01-08 17:13:18 -05:00
Javan Makhmali 21417e02e9 Work around Firefox's refusal to dispatch events on disabled elements. Fixes #31393
Brought to you by a 12 year old Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=329509
2018-01-08 17:07:32 -05:00
Rosa Gutierrez 8f52d93576
Allow overriding filename in `Blob#service_url`
This is useful when we have several representations for the same
underlying file, each one with a different name, and we need to provide
a custom download URL based on that name and not that of the underlying
file.
2018-01-08 15:44:14 +01:00
Rosa Gutierrez d40284b1a4
Force content disposition to attachment for specific content types
In this way we avoid HTML, XML, SVG and other files that can be rendered
by the browser to be served inline by default. Depending on the origin
from where these files are served, this might lead to XSS
vulnerabilities, and in the best case, to more realistic phishing
attacks and open redirects.

We force it rather than falling back to it when other disposition is not
provided. Otherwise it would be possible for someone to force inline
just by passing `disposition=inline` in the URL.

The list of content types to be served as attachments is configurable.
2018-01-05 16:32:32 +01:00
George Claghorn dbff1cee55 Exclude ActiveStorage::SetBlob from API docs [ci skip] 2018-01-02 22:49:18 -05:00
George Claghorn 921b877c2f Restore support for the -layers transformation 2018-01-02 07:20:23 -05:00
Dorian Marié 6f035067e4 prevent shadowing outer variables 2017-12-25 22:47:55 +01:00
Javan Makhmali 1a5bf01fe0 Active Storage: Fix direct uploads in IE 11
Fixes #31531
Closes #31540
2017-12-23 11:21:54 -05:00
Robert Glaser 7a3a991f6d Add support for combined MiniMagick transformations 2017-12-22 16:44:34 +01:00
Yoshiyuki Hirano d8c49d88f6 [ci skip] Remove needless from doc for ActiveStorage::Variant 2017-12-22 05:04:25 +09:00
George Claghorn 2df99f8bc5 Delete MiniMagick tempfile when transformation fails 2017-12-18 22:01:48 -05:00
George Claghorn a6eb2a27c3 Ensure MiniMagick tempfiles are properly unlinked after image transformation 2017-12-18 13:14:26 -05:00
George Claghorn 95117a2ce2 Convert non-web image (e.g. PSD) variants to PNG 2017-12-18 07:49:24 -05:00
George Claghorn 7b1dfac291 Update ActiveStorage::Blob#transformation docs [ci skip] 2017-12-16 19:41:43 -05:00
George Claghorn af0caadb8d Handle invalid signed blob IDs gracefully 2017-12-15 19:26:53 -05:00
George Claghorn 311af752cf Restrict variants to variable image blobs 2017-12-15 10:45:00 -05:00
George Claghorn 74c4017daf Exclude ActiveStorage::Filename{#parameters,::Parameters} from API docs [ci skip] 2017-12-13 08:34:49 -05:00
George Claghorn 6129d1f937 Fix optimizing GIF variants using mogrify's -layers option 2017-12-11 18:32:14 -05:00
George Claghorn 931fe37aa7 Revert "Invoke mogrify once when transforming an image"
This reverts commit a80f81af05.
2017-12-11 18:30:21 -05:00
George Claghorn a80f81af05 Invoke mogrify once when transforming an image
Execute a single mogrify command with multiple options rather than one command per option. Permit the use of all mogrify options, not just the ones that fall through to MiniMagick::Image#method_missing.
2017-12-11 13:28:05 -05:00
George Claghorn 8c5a7fbefd
Purge variants with their blobs 2017-12-02 22:43:28 -05:00
George Claghorn 4d5f0bb30b Fix loading ActiveStorage::DiskController when CSRF protection is disabled by default 2017-11-21 14:59:30 -05:00
George Claghorn 2d20a7696a Fix direct uploads to local service
Disable CSRF protection for ActiveStorage::DiskController#update. The local disk service is intended to imitate a third-party service like S3 or GCS, so we don't care where direct uploads originate: they’re authorized by signed tokens.

Closes #30290.

[Shinichi Maeshima & George Claghorn]
2017-11-20 10:54:46 -05:00
George Claghorn 704a7e425c Preserve existing metadata when analyzing a blob
Closes #31138.
2017-11-13 16:36:39 -05:00
George Claghorn 9ec6736205 Permit configuring Active Storage's job queue 2017-11-03 11:29:21 -04:00
George Claghorn 605484079d Extract metadata from images and videos 2017-10-22 13:16:59 -04:00