Skip to content

Commit

Permalink
Merge pull request #3613 from filippoliverani/filippoliverani/simplif…
Browse files Browse the repository at this point in the history
…y-active-storage-checks

Always set ActiveStorage::Current.host in base controllers
  • Loading branch information
aldesantis authored May 22, 2020
2 parents bf6bdb9 + 89be98c commit 7e26f00
Show file tree
Hide file tree
Showing 5 changed files with 20 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 @@ -10,10 +10,10 @@ class BaseController < ActionController::Base
protect_from_forgery unless: -> { request.format.json? }

include CanCan::ControllerAdditions
include Spree::Core::ControllerHelpers::CurrentHost
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 Spree::Core::ControllerHelpers::CurrentHost
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
1 change: 1 addition & 0 deletions core/lib/spree/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class GatewayError < RuntimeError; end
require 'spree/core/current_store'
require 'spree/core/controller_helpers/auth'
require 'spree/core/controller_helpers/common'
require 'spree/core/controller_helpers/current_host'
require 'spree/core/controller_helpers/order'
require 'spree/core/controller_helpers/payment_parameters'
require 'spree/core/controller_helpers/pricing'
Expand Down
17 changes: 17 additions & 0 deletions core/lib/spree/core/controller_helpers/current_host.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Spree
module Core
module ControllerHelpers
module CurrentHost
extend ActiveSupport::Concern

included do
before_action do
ActiveStorage::Current.host = request.base_url
end
end
end
end
end
end

0 comments on commit 7e26f00

Please sign in to comment.