Poltergeist in the green, and resourceful refactor
This commit is contained in:
@@ -5,7 +5,6 @@ module Suppliers
|
||||
attr_reader :current_supplier
|
||||
helper_method :current_supplier
|
||||
layout 'supplier/app'
|
||||
class_attribute :after_authentication_hooks
|
||||
|
||||
rescue_from 'RestClient::Conflict' do |e|
|
||||
#binding.pry
|
||||
@@ -17,22 +16,14 @@ module Suppliers
|
||||
end
|
||||
end
|
||||
|
||||
def self.after_authentication(options, &blk)
|
||||
self.after_authentication_hooks ||= []
|
||||
after_authentication_hooks << {options: options, block: blk}
|
||||
end
|
||||
|
||||
def setup_employee_and_supplier!
|
||||
authenticate_employee!
|
||||
find_current_supplier!
|
||||
return unless current_supplier.present?
|
||||
current_employee.enrich_with_settings current_supplier.settings_for(current_employee)
|
||||
raise CanCan::AccessDenied unless current_employee.active?
|
||||
@current_ability = ::Ability.new( current_employee )
|
||||
Array.wrap(after_authentication_hooks).each do |hook|
|
||||
next if hook[:options][:only].present? && !Array.wrap(hook[:options][:only]).include?(action_name.to_sym)
|
||||
instance_eval &hook[:block]
|
||||
end
|
||||
@current_ability = Suppliers::Ability.new( current_employee )
|
||||
run_after_authentication_hooks!
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user