cleanup switch_to supplier and make facebook image https

This commit is contained in:
2020-03-07 11:11:06 -05:00
parent eda3fc280b
commit 68f7d4dd54
6 changed files with 16 additions and 14 deletions
@@ -17,7 +17,6 @@ module Suppliers
end
# GET
#NOTE: temporary solution for development, if I am in production something is wrong
def employee_and_supplier
# database optimization, preloading
FlatKeys.as_nested_structure(Supplier::PRELOAD_INCLUDES).last.each do |relation_name, includes|
@@ -43,12 +42,14 @@ module Suppliers
def find_current_supplier!
return current_supplier if current_supplier.present?
if session[:supplier_id]
supplier = Supplier.find(session[:supplier_id])
supplier_id = request.headers['HTTP_SUPPLIER_ID'].presence || session[:supplier_id].presence
if supplier_id and supplier_id != 'null' and supplier_id != 'undefined' # crying face icon! but javascript nulls and ruby presence are not brothers
supplier = Supplier.find(supplier_id)
if supplier.employee_ids.include?(current_employee.id)
@current_supplier = supplier
else
session[:supplier_id] = nil
raise CanCan::AccessDenied unless current_employee.active?
end
else
@current_supplier = current_employee.suppliers.first
@@ -29,14 +29,6 @@ module Suppliers
render json: current_supplier
end
def switch_to
@switch_supplier = Supplier.find(params[:id])
#TODO sessions currently not working, just tokens
session[:supplier_id] = @switch_supplier.id if @switch_supplier.employee_ids.include? current_employee.id
render json: {ok: true}
#redirect_to supplier_root_path(other: '/my-account')
end
def mark_as_open
current_supplier.mark_as_open!
head :ok