From c1dfc0f5de08c23ab23fd9fe56d647aed2bf381e Mon Sep 17 00:00:00 2001 From: donrestarone Date: Sun, 1 Dec 2024 18:52:40 -0500 Subject: [PATCH] spike: capture and redirect accordingly --- app/controllers/comfy/cms/base_controller.rb | 33 ------------------- .../comfy/cms/content_controller.rb | 5 +++ app/controllers/content_controller.rb | 15 ++++++++- 3 files changed, 19 insertions(+), 34 deletions(-) delete mode 100644 app/controllers/comfy/cms/base_controller.rb diff --git a/app/controllers/comfy/cms/base_controller.rb b/app/controllers/comfy/cms/base_controller.rb deleted file mode 100644 index 33302c617..000000000 --- a/app/controllers/comfy/cms/base_controller.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -class Comfy::Cms::BaseController < ComfortableMexicanSofa.config.public_base_controller.to_s.constantize - - before_action :load_cms_site - - helper Comfy::CmsHelper - -protected - - def load_cms_site - @cms_site ||= - if params[:site_id] - ::Comfy::Cms::Site.find_by_id(params[:site_id]) - else - ::Comfy::Cms::Site.find_site(request.host_with_port.downcase, request.fullpath) - end - - if @cms_site - if @cms_site.path.present? && !params[:site_id] - if params[:cms_path]&.match(%r{\A#{@cms_site.path}}) - params[:cms_path].gsub!(%r{\A#{@cms_site.path}}, "") - params[:cms_path]&.gsub!(%r{\A/}, "") - else - raise ActionController::RoutingError, "Site Not Found" - end - end - else - raise ActionController::RoutingError, "Site Not Found" - end - end - -end \ No newline at end of file diff --git a/app/controllers/comfy/cms/content_controller.rb b/app/controllers/comfy/cms/content_controller.rb index 2035e9f8b..28fb14e6d 100644 --- a/app/controllers/comfy/cms/content_controller.rb +++ b/app/controllers/comfy/cms/content_controller.rb @@ -15,6 +15,11 @@ class Comfy::Cms::ContentController < Comfy::Cms::BaseController only: :show def show + if params[:s2_redirect_to] && params[:s2_query] && params[:s2_url_params] && params[:s2_subdomain] + # s2 link detected, process accordingly + return redirect_to "https://#{params[:s2_redirect_to]}" + end + if @cms_page.target_page.present? redirect_to @cms_page.target_page.url(relative: true) else diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 2796ad19a..552522014 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -1,3 +1,16 @@ class ContentController < ApplicationController - before_action :track_ahoy_visit, raise: false + before_action :track_ahoy_visit, :process_subdomain_smart_link_redirect, raise: false + + private + + def process_subdomain_smart_link_redirect + subdomain = request.subdomain + url_parameters = request.path + if !subdomain.blank? + unless Subdomain.all.pluck(:name).any?{|name| subdomain == name} + # process S2 link - append parameters for 2nd redirect + return redirect_to "#{root_url(subdomain: Subdomain.current.name)}?s2_redirect_to=#{subdomain}&s2_query=#{subdomain}&s2_url_params=#{url_parameters}&s2_subdomain=#{subdomain}" + end + end + end end