update multi tenancy

This commit is contained in:
Thein Lin Kyaw
2020-01-16 17:04:31 +06:30
parent b5e8bbec43
commit 87ad49a069
7 changed files with 28 additions and 19 deletions

View File

@@ -1,5 +1,4 @@
class Api::AuthenticateController < Api::ApiController
skip_before_action :authenticate
def create
emp_id = params[:emp_id]

View File

@@ -1,5 +1,5 @@
class Api::CustomersController < Api::ApiController
skip_before_action :authenticate
#List all active customers by name
def index
@customers = Customer.order("name asc")

View File

@@ -1,14 +1,11 @@
class Api::MembershipsController < ActionController::API
#before :authenticate_token
#Add Membership to invoice
def create
end
private
def set_sale_params

View File

@@ -4,8 +4,6 @@ class Api::Restaurant::MoveController < Api::ApiController
def update
end
private
# Use callbacks to share common setup or constraints between actions.
def move_params

View File

@@ -1,4 +1,5 @@
class Api::ShopsController < Api::ApiController
skip_before_action :set_current_tenant_by_subdomain_or_first
def index
@shops = Shop.select('id,logo,name,shop_code,address,phone_no').all

View File

@@ -3,16 +3,25 @@ module MultiTenancy
included do
set_current_tenant_through_filter if respond_to? :set_current_tenant_through_filter
before_action :set_current_tenant_by_subdomain_or_frist if respond_to? :before_action
before_action :set_current_tenant_by_subdomain_or_first if respond_to? :before_action
helper_method :current_shop if respond_to? :helper_method
end
private
def set_current_tenant_by_subdomain_or_frist
def set_current_tenant_by_subdomain_or_first
find_tenant_by_subdomain_or_frist || not_found
end
def find_tenant_by_subdomain_or_frist
if request.subdomains.last && request.subdomains.last != 'www'
set_current_tenant(Shop.find_by(subdomain: request.subdomains.last))
elsif ENV["SERVER_MODE"] == "application"
set_current_tenant(Shop.first)
end
set_current_tenant(Shop.first) if current_tenant.nil?
end
def not_found
head :not_found
end
def current_shop

View File

@@ -4,7 +4,7 @@ class ActionController::Base
private
def lookup_domain
if request.subdomains.last && request.subdomains.last != "www" && ENV["SERVER_CODE"] = "cloud"
if request.subdomain.present? && request.subdomain != "www" && ENV["SERVER_MODE"] == "cloud"
from = request.host
@license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase
if (!@license.nil?)
@@ -18,15 +18,20 @@ class ActionController::Base
# redirect_to root_url(:host => request.domain) + "store_error"
render :json => [{ status: false, message: 'Invalid Access!'}]
end
else
elsif request.subdomain.present? && request.subdomain != "www" || ENV["SERVER_MODE"] == "application"
# check for license file
# if check_license
# current_license(ENV["SX_PROVISION_URL"])
# else
# redirect_to activate_path
# end
if check_license
current_license(ENV["SX_PROVISION_URL"])
else
redirect_to activate_path
end
else
render_not_found
end
end
def render_not_found
render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found
end
def current_license(url)
@@ -94,8 +99,8 @@ class ActionController::API
private
def lookup_domain
if request.subdomain.present? && request.subdomain != "www"
from = request.subdomain.downcase + "." + request.domain.downcase
if request.subdomain.present? && request.subdomain != "www" && ENV["SERVER_CODE"] == "cloud"
from = request.host
@license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase
if (!@license.nil?)
logger.info "Location - " + @license.dbschema