Skip to content

Commit

Permalink
Always include ActiveStorage::SetCurrent in base controllers
Browse files Browse the repository at this point in the history
ActiveStorage disk service needs current host to be correctly set by
ActiveStorage:SetCurrent concern. The concern should always included in
in controllers, there's non need to check if we are currently using
ActiveStorage based attachment adapters since Solidus already loads
ActivStorage by default. This way we avoid loading uneccessary modules
during initialization process that could potentially conflict with
custom attachment adapters.
  • Loading branch information
filippoliverani committed May 15, 2020
1 parent 83ea392 commit 8e67e75
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 8 deletions.
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class BaseController < ActionController::Base
respond_to :json
protect_from_forgery unless: -> { request.format.json? }

include ActiveStorage::SetCurrent
include CanCan::ControllerAdditions
include Spree::Core::ControllerHelpers::Store
include Spree::Core::ControllerHelpers::Pricing
include Spree::Core::ControllerHelpers::StrongParameters
include ActiveStorage::SetCurrent if Spree::Config.active_storage_enabled?

class_attribute :admin_line_item_attributes
self.admin_line_item_attributes = [:price, :variant_id, :sku]
Expand Down
2 changes: 1 addition & 1 deletion core/app/controllers/spree/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
require_dependency 'spree/core/controller_helpers/strong_parameters'

class Spree::BaseController < ApplicationController
include ActiveStorage::SetCurrent
include Spree::Core::ControllerHelpers::Auth
include Spree::Core::ControllerHelpers::Common
include Spree::Core::ControllerHelpers::PaymentParameters
include Spree::Core::ControllerHelpers::Search
include Spree::Core::ControllerHelpers::Store
include Spree::Core::ControllerHelpers::StrongParameters
include ActiveStorage::SetCurrent if Spree::Config.active_storage_enabled?

respond_to :html
end
6 changes: 0 additions & 6 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,5 @@ def admin_vat_location
country: Spree::Country.find_by(iso: admin_vat_country_iso)
)
end

def active_storage_enabled?
@active_storage_enabled ||=
Spree::Config.image_attachment_module == Spree::Image::ActiveStorageAttachment ||
Spree::Config.taxon_attachment_module == Spree::Taxon::ActiveStorageAttachment
end
end
end

0 comments on commit 8e67e75

Please sign in to comment.