Permalink
Browse files

Replace calls to current_user with try_spree_current_user

This is due to Stack level too deep errors reported by multiple users
  • Loading branch information...
1 parent 1f975ac commit 279dca05658c2c92ccb86010be7422523500428b @radar radar committed Jun 1, 2012
@@ -3,7 +3,9 @@ module Admin
class BannersController < Spree::Admin::BaseController
def dismiss
if request.xhr? and params[:id]
- current_user.dismiss_banner(params[:id])
+ if user = try_spree_current_user
+ user.dismiss_banner(params[:id])
+ end
render :nothing => true
end
end
@@ -5,7 +5,7 @@ class MailMethodsController < ResourceController
def testmail
@mail_method = Spree::MailMethod.find(params[:id])
- if TestMailer.test_email(@mail_method, current_user).deliver
+ if TestMailer.test_email(@mail_method, try_spree_current_user).deliver
flash.notice = t('admin.mail_methods.testmail.delivery_success')
else
flash[:error] = t('admin.mail_methods.testmail.delivery_error')
@@ -41,16 +41,16 @@ def title
# proxy method to *possible* spree_current_user method
# Authentication extensions (such as spree_auth_devise) are meant to provide spree_current_user
- def current_user
+ def try_spree_current_user
respond_to?(:spree_current_user) ? spree_current_user : nil
end
- helper_method :current_user
+ helper_method :try_spree_current_user
protected
def set_current_order
- if current_user
- last_incomplete_order = current_user.last_incomplete_spree_order
+ if user = try_spree_current_user
+ last_incomplete_order = user.last_incomplete_spree_order
if session[:order_id].nil? && last_incomplete_order
session[:order_id] = last_incomplete_order.id
elsif current_order && last_incomplete_order && current_order != last_incomplete_order
@@ -61,7 +61,7 @@ def set_current_order
# Needs to be overriden so that we use Spree's Ability rather than anyone else's.
def current_ability
- @current_ability ||= Spree::Ability.new(current_user)
+ @current_ability ||= Spree::Ability.new(try_spree_current_user)
end
def store_location
@@ -86,7 +86,7 @@ def store_location
def unauthorized
respond_to do |format|
format.html do
- if current_user
+ if try_spree_current_user
flash.now[:error] = t(:authorization_failure)
render 'spree/shared/unauthorized', :layout => '/spree/layouts/spree_application', :status => 401
else
@@ -129,7 +129,7 @@ def fire_event(name, extra_payload = {})
# add additional keys as appropriate. Override this method if you need additional data when
# responding to a notification
def default_notification_payload
- {:user => current_user, :order => current_order}
+ {:user => try_spree_current_user, :order => current_order}
end
private
@@ -47,17 +47,17 @@ def load_order
end
def associate_user
- if current_user && @order
+ if try_spree_current_user && @order
if @order.user.blank? || @order.email.blank?
- @order.associate_user!(current_user)
+ @order.associate_user!(try_spree_current_user)
end
end
# This will trigger any "first order" promotions to be triggered
# Assuming of course that this session variable was set correctly in
# the authentication provider's registrations controller
if session[:spree_user_signup]
- fire_event('spree.user.signup', :user => current_user, :order => current_order(true))
+ fire_event('spree.user.signup', :user => try_spree_current_user, :order => current_order(true))
end
session[:guest_token] = nil
@@ -34,7 +34,7 @@ def accurate_title
end
def load_product
- if current_user.try(:has_spree_role?, "admin")
+ if try_spree_current_user.try(:has_spree_role?, "admin")
@product = Product.find_by_permalink!(params[:id])
else
@product = Product.active.find_by_permalink!(params[:id])
@@ -26,7 +26,7 @@
<div data-hook="admin_shipment_edit_form_buttons">
<p class="form-buttons">
- <% if @shipment.editable_by?(current_user) %>
+ <% if @shipment.editable_by?(try_spree_current_user) %>
<%= button @order.cart? ? t(:continue) : t(:update) %>
<%= t(:or) %> <%= link_to t(:cancel), admin_order_shipments_path(@order) %>
<% else %>
@@ -13,7 +13,7 @@
<p data-hook="links">
<%= link_to t(:back_to_store), spree.root_path, :class => "button" %>
<% unless params.has_key? :checkout_complete %>
- <% if current_user && respond_to?(:spree_account_path) %>
+ <% if try_spree_current_user && respond_to?(:spree_account_path) %>
<%= link_to t(:my_account), spree_account_path, :class => "button" %>
<% end %>
<% end %>
@@ -6,7 +6,7 @@ def sign_up
@store = {
:first_name => '',
:last_name => '',
- :email => current_user.email,
+ :email => try_spree_current_user.email,
:currency => 'USD',
:time_zone => Time.zone,
:name => Spree::Config.site_name,
@@ -11,7 +11,7 @@ def self.activate
Spree::BaseController.class_eval do
# Include list of visited paths in notification payload hash
def default_notification_payload
- { :user => current_user, :order => current_order, :visited_paths => session[:visited_paths] }
+ { :user => try_spree_current_user, :order => current_order, :visited_paths => session[:visited_paths] }
end
end
end

0 comments on commit 279dca0

Please sign in to comment.