diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index 344dd89174..423a4fb104 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -53,7 +53,7 @@ module Api # Use logged in user (spree_current_user) for API authentication (current_api_user) def authenticate_user - return if @current_api_user = try_spree_current_user + return if @current_api_user = spree_current_user if api_key.blank? # An anonymous user diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 6d640b5d7b..7488fa8c4d 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -68,7 +68,7 @@ class EnterprisesController < BaseController # reset_distributor must be called before any call to current_customer or current_distributor order_cart_reset = OrderCartReset.new(order, params[:id]) order_cart_reset.reset_distributor - order_cart_reset.reset_other!(try_spree_current_user, current_customer) + order_cart_reset.reset_other!(spree_current_user, current_customer) rescue ActiveRecord::RecordNotFound flash[:error] = I18n.t(:enterprise_shop_show_error) redirect_to shops_path diff --git a/app/controllers/spree/admin/base_controller.rb b/app/controllers/spree/admin/base_controller.rb index 7ce02d4a38..4f9cdbb4d0 100644 --- a/app/controllers/spree/admin/base_controller.rb +++ b/app/controllers/spree/admin/base_controller.rb @@ -24,7 +24,7 @@ module Spree # This is in Spree::Core::ControllerHelpers::Auth # But you can't easily reopen modules in Ruby def unauthorized - if try_spree_current_user + if spree_current_user flash[:error] = t(:authorization_failure) redirect_to '/unauthorized' else diff --git a/app/controllers/spree/admin/mail_methods_controller.rb b/app/controllers/spree/admin/mail_methods_controller.rb index aba6ad239f..70d573f319 100644 --- a/app/controllers/spree/admin/mail_methods_controller.rb +++ b/app/controllers/spree/admin/mail_methods_controller.rb @@ -15,7 +15,7 @@ module Spree end def testmail - if TestMailer.test_email(try_spree_current_user).deliver + if TestMailer.test_email(spree_current_user).deliver flash[:success] = Spree.t('admin.mail_methods.testmail.delivery_success') else flash[:error] = Spree.t('admin.mail_methods.testmail.delivery_error') diff --git a/app/controllers/spree/admin/orders_controller.rb b/app/controllers/spree/admin/orders_controller.rb index 22715108e9..8cde99be81 100644 --- a/app/controllers/spree/admin/orders_controller.rb +++ b/app/controllers/spree/admin/orders_controller.rb @@ -27,7 +27,7 @@ module Spree def new @order = Order.create - @order.created_by = try_spree_current_user + @order.created_by = spree_current_user @order.save redirect_to edit_admin_order_url(@order) end diff --git a/app/views/spree/layouts/_admin_body.html.haml b/app/views/spree/layouts/_admin_body.html.haml index d5aa05dbee..7b1d643dee 100644 --- a/app/views/spree/layouts/_admin_body.html.haml +++ b/app/views/spree/layouts/_admin_body.html.haml @@ -66,4 +66,4 @@ %div{"data-hook" => "admin_footer_scripts"} %script - = raw "Spree.api_key = \"#{try_spree_current_user.try(:spree_api_key).to_s}\";" + = raw "Spree.api_key = \"#{spree_current_user.try(:spree_api_key).to_s}\";" diff --git a/lib/spree/core/controller_helpers/auth.rb b/lib/spree/core/controller_helpers/auth.rb index 7fb5672eff..494d45eaa9 100644 --- a/lib/spree/core/controller_helpers/auth.rb +++ b/lib/spree/core/controller_helpers/auth.rb @@ -8,7 +8,6 @@ module Spree included do before_filter :ensure_api_key - helper_method :try_spree_current_user rescue_from CanCan::AccessDenied do unauthorized @@ -17,7 +16,7 @@ module Spree # Needs to be overriden so that we use Spree's Ability rather than anyone else's. def current_ability - @current_ability ||= Spree::Ability.new(try_spree_current_user) + @current_ability ||= Spree::Ability.new(spree_current_user) end # Redirect as appropriate when an access request fails. The default action is to redirect @@ -25,7 +24,7 @@ module Spree # special behavior in case the user is not authorized to access the requested action. # For example, a popup window might simply close itself. def unauthorized - if try_spree_current_user + if spree_current_user flash[:error] = Spree.t(:authorization_failure) redirect_to '/unauthorized' else @@ -50,11 +49,6 @@ module Spree session['spree_user_return_to'] = request.fullpath.gsub('//', '/') end - # This was a proxy method in spree, in OFN this just redirects to spree_current_user - def try_spree_current_user - respond_to?(:spree_current_user) ? spree_current_user : nil - end - def redirect_back_or_default(default) redirect_to(session["spree_user_return_to"] || default) session["spree_user_return_to"] = nil @@ -63,7 +57,7 @@ module Spree # Need to generate an API key for a user due to some actions potentially # requiring authentication to the Spree API def ensure_api_key - return unless (user = try_spree_current_user) + return unless (user = spree_current_user) return unless user.respond_to?(:spree_api_key) && user.spree_api_key.blank? diff --git a/lib/spree/core/controller_helpers/common.rb b/lib/spree/core/controller_helpers/common.rb index ca95fe79da..e88920eaf6 100644 --- a/lib/spree/core/controller_helpers/common.rb +++ b/lib/spree/core/controller_helpers/common.rb @@ -27,7 +27,7 @@ module Spree # This method can be overriden to provide additional data when # responding to a notification def default_notification_payload - { user: try_spree_current_user, order: current_order } + { user: spree_current_user, order: current_order } end # This can be used in views as well as controllers. diff --git a/lib/spree/core/controller_helpers/order.rb b/lib/spree/core/controller_helpers/order.rb index cfdce6b9b5..0d979b33d6 100644 --- a/lib/spree/core/controller_helpers/order.rb +++ b/lib/spree/core/controller_helpers/order.rb @@ -39,13 +39,13 @@ module Spree if create_order_if_necessary && (@current_order.nil? || @current_order.completed?) @current_order = Spree::Order.new(currency: current_currency) - @current_order.user ||= try_spree_current_user + @current_order.user ||= spree_current_user # See https://github.com/spree/spree/issues/3346 for reasons why this line is here - @current_order.created_by ||= try_spree_current_user + @current_order.created_by ||= spree_current_user @current_order.save! # Verify that the user has access to the order (if they are a guest) - if try_spree_current_user.nil? + if spree_current_user.nil? session[:access_token] = @current_order.token end end @@ -59,9 +59,9 @@ module Spree def associate_user @order ||= current_order - if try_spree_current_user && @order + if spree_current_user && @order if @order.user.blank? || @order.email.blank? - @order.associate_user!(try_spree_current_user) + @order.associate_user!(spree_current_user) end end @@ -69,7 +69,7 @@ module Spree # Assuming of course that this session variable was set correctly in # the authentication provider's registrations controller if session[:spree_user_signup] && @order - fire_event('spree.user.signup', user: try_spree_current_user, + fire_event('spree.user.signup', user: spree_current_user, order: @order) session[:spree_user_signup] = nil end @@ -80,7 +80,7 @@ module Spree # Do not attempt to merge incomplete and current orders. # Instead, destroy the incomplete orders. def set_current_order - return unless (user = try_spree_current_user) + return unless (user = spree_current_user) last_incomplete_order = user.last_incomplete_spree_order diff --git a/spec/controllers/api/base_controller_spec.rb b/spec/controllers/api/base_controller_spec.rb index d501aa98fb..1ebd3eca15 100644 --- a/spec/controllers/api/base_controller_spec.rb +++ b/spec/controllers/api/base_controller_spec.rb @@ -14,7 +14,7 @@ describe Api::BaseController do context "signed in as a user using an authentication extension" do before do - allow(controller).to receive_messages try_spree_current_user: + allow(controller).to receive_messages spree_current_user: double(email: "ofn@example.com") end diff --git a/spec/controllers/spree/admin/mail_methods_controller_spec.rb b/spec/controllers/spree/admin/mail_methods_controller_spec.rb index 422491660e..1a706462a7 100644 --- a/spec/controllers/spree/admin/mail_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/mail_methods_controller_spec.rb @@ -18,8 +18,10 @@ describe Spree::Admin::MailMethodsController do spree_api_key: 'fake', id: nil, owned_groups: nil) - allow(user).to receive_messages(enterprises: [create(:enterprise)], has_spree_role?: true) - allow(controller).to receive_messages(try_spree_current_user: user) + allow(user).to receive_messages(enterprises: [create(:enterprise)], + has_spree_role?: true, + locale: nil) + allow(controller).to receive_messages(spree_current_user: user) Spree::Config[:enable_mail_delivery] = "1" ActionMailer::Base.perform_deliveries = true