diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index f5c406e617..dacb07f46a 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -484,7 +484,6 @@ Metrics/AbcSize: - lib/spree/core/calculated_adjustments.rb - lib/spree/core/controller_helpers/order.rb - lib/spree/core/controller_helpers/respond_with.rb - - lib/spree/core/controller_helpers/ssl.rb - lib/spree/core/delegate_belongs_to.rb - lib/spree/core/permalinks.rb - lib/spree/core/s3_support.rb @@ -528,7 +527,6 @@ Metrics/BlockLength: - app/models/spree/payment/processing.rb - app/models/spree/shipment.rb - lib/spree/core/controller_helpers/common.rb - - lib/spree/core/controller_helpers/ssl.rb - lib/tasks/data.rake - spec/controllers/spree/admin/invoices_controller_spec.rb - spec/factories/address_factory.rb @@ -607,7 +605,6 @@ Metrics/CyclomaticComplexity: - lib/spree/core/calculated_adjustments.rb - lib/spree/core/controller_helpers/order.rb - lib/spree/core/controller_helpers/respond_with.rb - - lib/spree/core/controller_helpers/ssl.rb - lib/spree/localized_number.rb - spec/models/product_importer_spec.rb @@ -651,7 +648,6 @@ Metrics/PerceivedComplexity: - lib/spree/core/calculated_adjustments.rb - lib/spree/core/controller_helpers/order.rb - lib/spree/core/controller_helpers/respond_with.rb - - lib/spree/core/controller_helpers/ssl.rb - lib/spree/localized_number.rb - spec/models/product_importer_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3d5daf5f69..d6472a4406 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -540,7 +540,6 @@ Rails/UnknownEnv: Exclude: - 'app/controllers/spree/admin/payment_methods_controller.rb' - 'app/models/spree/app_configuration.rb' - - 'lib/spree/core/controller_helpers/ssl.rb' # Offense count: 1 # Cop supports --auto-correct. diff --git a/app/controllers/api/v0/base_controller.rb b/app/controllers/api/v0/base_controller.rb index 0f3aec1189..c21e167e8a 100644 --- a/app/controllers/api/v0/base_controller.rb +++ b/app/controllers/api/v0/base_controller.rb @@ -2,7 +2,6 @@ # Base controller for OFN's API require "spree/api/controller_setup" -require "spree/core/controller_helpers/ssl" module Api module V0 @@ -11,7 +10,6 @@ module Api include ActionController::StrongParameters include ActionController::RespondWith include Spree::Api::ControllerSetup - include Spree::Core::ControllerHelpers::SSL include ::ActionController::Head include ::ActionController::ConditionalGet include ActionView::Layouts diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2fafbafcdd..077a264695 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,7 +5,6 @@ require "application_responder" require 'cancan' require 'spree/core/controller_helpers/auth' require 'spree/core/controller_helpers/respond_with' -require 'spree/core/controller_helpers/ssl' require 'spree/core/controller_helpers/common' require 'open_food_network/referer_parser' @@ -32,7 +31,6 @@ class ApplicationController < ActionController::Base include Spree::Core::ControllerHelpers::Auth include Spree::Core::ControllerHelpers::RespondWith - include Spree::Core::ControllerHelpers::SSL include Spree::Core::ControllerHelpers::Common prepend_before_action :restrict_iframes diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 312dee2063..beaf68ef28 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -1,14 +1,12 @@ # frozen_string_literal: true require 'spree/core/controller_helpers/order' -require 'spree/core/controller_helpers/ssl' require 'open_food_network/tag_rule_applicator' class BaseController < ApplicationController layout 'darkswarm' include Spree::Core::ControllerHelpers::Order - include Spree::Core::ControllerHelpers::SSL include I18nHelper include OrderCyclesHelper diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index b36a7ca278..095db28a49 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -10,8 +10,6 @@ class CheckoutController < ::BaseController helper 'terms_and_conditions' helper 'checkout' - ssl_required - # We need pessimistic locking to avoid race conditions. # Otherwise we fail on duplicate indexes or end up with negative stock. prepend_around_action CurrentOrderLocker, only: [:edit, :update] diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index c0fb7eadcc..47d2004dc2 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class PaymentsController < BaseController - ssl_required :redirect_to_authorize - respond_to :html prepend_before_action :require_logged_in, only: :redirect_to_authorize diff --git a/app/controllers/spree/admin/base_controller.rb b/app/controllers/spree/admin/base_controller.rb index 43115c5a46..a29d6eeb1c 100644 --- a/app/controllers/spree/admin/base_controller.rb +++ b/app/controllers/spree/admin/base_controller.rb @@ -3,8 +3,6 @@ module Spree module Admin class BaseController < ApplicationController - ssl_required - helper 'shared' helper 'spree/admin/navigation' helper 'spree/admin/orders' diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb index 8f0162420d..5990cf69c0 100644 --- a/app/controllers/spree/orders_controller.rb +++ b/app/controllers/spree/orders_controller.rb @@ -7,8 +7,6 @@ module Spree layout 'darkswarm' - ssl_required :show - before_action :check_authorization rescue_from ActiveRecord::RecordNotFound, with: :render_404 helper 'spree/products', 'spree/orders' diff --git a/app/controllers/spree/user_passwords_controller.rb b/app/controllers/spree/user_passwords_controller.rb index 2ecc034292..ab5f184123 100644 --- a/app/controllers/spree/user_passwords_controller.rb +++ b/app/controllers/spree/user_passwords_controller.rb @@ -3,7 +3,6 @@ require "spree/core/controller_helpers/auth" require "spree/core/controller_helpers/common" require "spree/core/controller_helpers/order" -require "spree/core/controller_helpers/ssl" module Spree class UserPasswordsController < Devise::PasswordsController @@ -13,9 +12,6 @@ module Spree include Spree::Core::ControllerHelpers::Auth include Spree::Core::ControllerHelpers::Common include Spree::Core::ControllerHelpers::Order - include Spree::Core::ControllerHelpers::SSL - - ssl_required # Overridden due to bug in Devise. # respond_with resource, :location => new_session_path(resource_name) diff --git a/app/controllers/spree/user_registrations_controller.rb b/app/controllers/spree/user_registrations_controller.rb index e4f4cf693f..c8127b1035 100644 --- a/app/controllers/spree/user_registrations_controller.rb +++ b/app/controllers/spree/user_registrations_controller.rb @@ -3,7 +3,6 @@ require "spree/core/controller_helpers/auth" require "spree/core/controller_helpers/common" require "spree/core/controller_helpers/order" -require "spree/core/controller_helpers/ssl" module Spree class UserRegistrationsController < Devise::RegistrationsController @@ -12,9 +11,7 @@ module Spree include Spree::Core::ControllerHelpers::Auth include Spree::Core::ControllerHelpers::Common include Spree::Core::ControllerHelpers::Order - include Spree::Core::ControllerHelpers::SSL - ssl_required before_action :check_permissions, only: [:edit, :update] skip_before_action :require_no_authentication diff --git a/app/controllers/spree/user_sessions_controller.rb b/app/controllers/spree/user_sessions_controller.rb index f090a281ca..0fb060733b 100644 --- a/app/controllers/spree/user_sessions_controller.rb +++ b/app/controllers/spree/user_sessions_controller.rb @@ -3,7 +3,6 @@ require "spree/core/controller_helpers/auth" require "spree/core/controller_helpers/common" require "spree/core/controller_helpers/order" -require "spree/core/controller_helpers/ssl" module Spree class UserSessionsController < Devise::SessionsController @@ -12,9 +11,7 @@ module Spree include Spree::Core::ControllerHelpers::Auth include Spree::Core::ControllerHelpers::Common include Spree::Core::ControllerHelpers::Order - include Spree::Core::ControllerHelpers::SSL - ssl_required :new, :create, :destroy, :update ssl_allowed :login_bar before_action :set_checkout_redirect, only: :create diff --git a/app/controllers/spree/users_controller.rb b/app/controllers/spree/users_controller.rb index f97c4674ca..1028022c67 100644 --- a/app/controllers/spree/users_controller.rb +++ b/app/controllers/spree/users_controller.rb @@ -3,7 +3,7 @@ module Spree class UsersController < ::BaseController layout 'darkswarm' - ssl_required + skip_before_action :set_current_order, only: :show prepend_before_action :load_object, only: [:show, :edit, :update] prepend_before_action :authorize_actions, only: :new diff --git a/lib/spree/core/controller_helpers/ssl.rb b/lib/spree/core/controller_helpers/ssl.rb deleted file mode 100644 index e9460f3d7d..0000000000 --- a/lib/spree/core/controller_helpers/ssl.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -module Spree - module Core - module ControllerHelpers - module SSL - extend ActiveSupport::Concern - - included do - before_action :force_non_ssl_redirect, if: proc { Spree::Config[:redirect_https_to_http] } - - def self.ssl_allowed(*actions) - class_attribute :ssl_allowed_actions - self.ssl_allowed_actions = actions - end - - def self.ssl_required(*actions) - class_attribute :ssl_required_actions - self.ssl_required_actions = actions - return unless ssl_supported? - - if ssl_required_actions.empty? || Rails.application.config.force_ssl - force_ssl - else - force_ssl only: ssl_required_actions - end - end - - def self.ssl_supported? - return Spree::Config[:allow_ssl_in_production] if Rails.env.production? - return Spree::Config[:allow_ssl_in_staging] if Rails.env.staging? - - false - end - - private - - # Redirect the existing request to use the HTTP protocol. - # - # ==== Parameters - # * host - Redirect to a different host name - def force_non_ssl_redirect(host = nil) - return true if defined?(ssl_allowed_actions) && - ssl_allowed_actions.include?(action_name.to_sym) - - return unless request.ssl? && - (!defined?(ssl_required_actions) || - !ssl_required_actions.include?(action_name.to_sym)) - - redirect_options = { protocol: 'http://', status: :moved_permanently } - redirect_options.merge!(host: host) if host - redirect_options.merge!(params: request.query_parameters) - flash.keep if respond_to?(:flash) - redirect_to redirect_options - end - end - end - end - end -end