From bec52b10d5c8507094a4d0eaa21585924b81c901 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Thu, 13 Feb 2020 16:43:03 +0630 Subject: [PATCH] skip domain filter for api shops index --- app/controllers/api/shops_controller.rb | 25 +++++++++++++++++++++--- config/initializers/action_controller.rb | 4 +--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/shops_controller.rb b/app/controllers/api/shops_controller.rb index 108c4104..cb7a7f4d 100644 --- a/app/controllers/api/shops_controller.rb +++ b/app/controllers/api/shops_controller.rb @@ -1,9 +1,9 @@ class Api::ShopsController < Api::ApiController - skip_before_action :authenticate, only: [:index, :show] - skip_before_action :set_current_tenant_by_subdomain_or_name, only: [:index, :show] + skip_before_action :authenticate, only: [:index] + skip_before_action :set_current_tenant_by_subdomain_or_name, only: [:index] def index - @shops = Shop.select('id, logo, name, shop_code').all + @shops = Shop.select('id, logo, name, shop_code').where.not(cloud_url: nil).all end def show @@ -13,4 +13,23 @@ class Api::ShopsController < Api::ApiController def get_tax_profiles @inclusive_tax, @exclusive_tax = TaxProfile.calculate_tax("online_order") end + + def lookup_domain + unless action_name == "index" + if ENV["SERVER_CODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www" + @license = cache_license(ENV["SX_PROVISION_URL"], request.host) # request.subdomain.downcase + if (!@license.nil?) + logger.info "Location - " + @license.dbschema + ActiveRecord::Base.establish_connection(website_connection(@license)) + else + logger.info 'License is nil' + not_found + end + elsif ENV["SERVER_MODE"] == "application" || (request.subdomains.last && request.subdomains.last != "www") + not_found unless check_license(request.host) + end + else + super + end + end end diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 8931f599..7ab4c8fd 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -132,9 +132,7 @@ class ActionController::API # render :json => [{ status: false, message: 'Invalid Access!'}] end elsif ENV["SERVER_MODE"] == "application" || (request.subdomains.last && request.subdomains.last != "www") - unless check_license(request.host) - not_found - end + not_found unless check_license(request.host) else not_found end