mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Patching up admin redirects to be MOAR UNIVERSAL
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
15
spec/controllers/spree/admin/base_controller_spec.rb
Normal file
15
spec/controllers/spree/admin/base_controller_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user