mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Remove try_spree_current_user
This can be done because the method is defined in OFN's ApplicationController, so spree_current_user is available in all controllers
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}\";"
|
||||
|
||||
@@ -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?
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user