Patching up admin redirects to be MOAR UNIVERSAL

This commit is contained in:
Will Marshall
2014-05-30 12:52:14 +10:00
parent 206c947ea5
commit 368fbd2383
4 changed files with 33 additions and 12 deletions

View File

@@ -4,6 +4,11 @@ class ApplicationController < ActionController::Base
include EnterprisesHelper
def redirect_to(options = {}, response_status = {})
::Rails.logger.error("Redirected by #{caller(1).first rescue "unknown"}")
super(options, response_status)
end
def after_sign_in_path_for(resource)
if request.referer and referer_path = URI(request.referer).path
[main_app.checkout_path].include?(referer_path) ? referer_path : root_path

View File

@@ -11,4 +11,16 @@ Spree::Admin::BaseController.class_eval do
authorize! :admin, record
authorize! action, record
end
# This is in Spree::Core::ControllerHelpers::Auth
# But you can't easily reopen modules in Ruby
def unauthorized
if try_spree_current_user
flash[:error] = t(:authorization_failure)
redirect_to '/unauthorized'
else
store_location
redirect_to root_path(anchor: "login?after_login=#{request.env['PATH_INFO']}")
end
end
end

View File

@@ -4,16 +4,5 @@ Spree::Admin::OverviewController.class_eval do
@product_count = Spree::Product.active.managed_by(spree_current_user).count
@order_cycle_count = OrderCycle.active.managed_by(spree_current_user).count
end
# This is in Spree::Core::ControllerHelpers::Auth
# But you can't easily reopen modules in Ruby
def unauthorized
if try_spree_current_user
flash[:error] = t(:authorization_failure)
redirect_to '/unauthorized'
else
store_location
redirect_to root_path(anchor: "login?after_login=#{spree.admin_path}")
end
end
end

View File

@@ -0,0 +1,15 @@
require 'spec_helper'
describe Spree::Admin::BaseController do
controller(Spree::Admin::BaseController) do
def index
before_filter :unauthorized
render text: ""
end
end
it "redirects to Angular login" do
get :index
response.should redirect_to root_path(anchor: "login?after_login=#{spree.admin_path}")
end
end