Module: ActiveStorageAuthorization
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/active_storage_authorization.rb
Overview
This authorizes all ActiveStorage downloads This is included automatically by the engine It can be disabled by setting config.authorize_active_storage = false in config/initializers/effective_storage.rb
There are 3 ways to add permissions: 1.) can?(:show, resource) 2.) can?(:show, ActionText::RichText) { |text| … } 3.) can?(:show, ActiveStorage::Attachment) { |attachment| … }
The :show and :edit will both work.
Constant Summary collapse
- AUTHORIZED_EFFECTIVE_DOWNLOADS =
[ 'Effective::CarouselItem', 'Effective::PageBanner', 'Effective::PageSection', 'Effective::Permalink' ]
Instance Method Summary collapse
-
#authorize_active_storage_download! ⇒ Object
Authorize ActiveStorage DiskController downloads Used for local storage.
-
#authorize_active_storage_redirect! ⇒ Object
Authorize ActiveStorage Blob and Representation redirects Used for amazon storage.
-
#unauthorized_active_storage_request(exception) ⇒ Object
Send an ExceptionNotification email with the unauthorized details This is not visible to users.
Instance Method Details
#authorize_active_storage_download! ⇒ Object
Authorize ActiveStorage DiskController downloads Used for local storage
30 31 32 33 |
# File 'app/models/concerns/active_storage_authorization.rb', line 30 def @blob || set_download_blob() end |
#authorize_active_storage_redirect! ⇒ Object
Authorize ActiveStorage Blob and Representation redirects Used for amazon storage
37 38 39 40 |
# File 'app/models/concerns/active_storage_authorization.rb', line 37 def @blob || set_blob() end |
#unauthorized_active_storage_request(exception) ⇒ Object
Send an ExceptionNotification email with the unauthorized details This is not visible to users
44 45 46 47 48 49 50 51 52 |
# File 'app/models/concerns/active_storage_authorization.rb', line 44 def (exception) if defined?(ExceptionNotifier) data = { 'current_user_id': current_user&.id || 'none' }.merge(@blob&.attributes || {}) ExceptionNotifier.notify_exception(exception, env: request.env, data: data) else raise(exception) end end |