From 8694cd67369f595af33e8f7c2c710dc9cce8d5ff Mon Sep 17 00:00:00 2001 From: Gustavo Molinari Date: Thu, 23 Jan 2025 16:11:59 -0300 Subject: [PATCH] [FS-10] Refactor has company to be has current attributes --- app/controllers/admin/base_controller.rb | 2 +- .../{has_company.rb => has_current_attributes.rb} | 8 ++++++-- app/lib/current.rb | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) rename app/controllers/concerns/{has_company.rb => has_current_attributes.rb} (58%) diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index aeca210..258f785 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -1,6 +1,6 @@ module Admin class BaseController < ApplicationController - include HasCompany + include HasCurrentAttributes include ErrorHandler include ActionView::RecordIdentifier diff --git a/app/controllers/concerns/has_company.rb b/app/controllers/concerns/has_current_attributes.rb similarity index 58% rename from app/controllers/concerns/has_company.rb rename to app/controllers/concerns/has_current_attributes.rb index c06db61..3d3d7a8 100644 --- a/app/controllers/concerns/has_company.rb +++ b/app/controllers/concerns/has_current_attributes.rb @@ -1,11 +1,15 @@ -module HasCompany +module HasCurrentAttributes extend ActiveSupport::Concern included do before_action :set_current_attributes def set_current_attributes - Current.user = current_user if user_signed_in? + if user_signed_in? + Current.user = current_user + Current.customer = current_user.customer + end + Current.company = Company.find_by(subdomain: request.subdomain) end end diff --git a/app/lib/current.rb b/app/lib/current.rb index e37a2fc..330b142 100644 --- a/app/lib/current.rb +++ b/app/lib/current.rb @@ -1,4 +1,5 @@ class Current < ActiveSupport::CurrentAttributes attribute :user attribute :company + attribute :customer end