Skip to content

Commit

Permalink
Redirect requests to the root path to admin root path
Browse files Browse the repository at this point in the history
When the `multitenancy_management_mode` is enabled.
  • Loading branch information
taitus committed Dec 28, 2022
1 parent 4056a05 commit aaf0b57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -15,6 +15,7 @@ class ApplicationController < ActionController::Base
around_action :switch_locale
before_action :track_email_campaign
before_action :set_return_url
before_action :redirect_to_admin, if: :multitenancy_management_mode?

check_authorization unless: :devise_controller?
self.responder = ApplicationResponder
Expand Down Expand Up @@ -117,6 +118,10 @@ def redirect_with_query_params_to(options, response_status = {})
redirect_to path, response_status
end

def redirect_to_admin
redirect_to admin_root_path if request.path == root_path
end

def multitenancy_management_mode?
Rails.application.config.multitenancy &&
Tenant.default? &&
Expand Down
16 changes: 16 additions & 0 deletions spec/system/multitenancy_management_mode_spec.rb
Expand Up @@ -29,6 +29,22 @@
expect(page).to have_css "li", count: 1
end
end

scenario "redirects root path requests to the admin root path" do
visit root_path

expect(page).to have_current_path admin_root_path
end

scenario "does not redirect other tenants to the admin root path", :seed_tenants do
create(:tenant, schema: "mars")

with_subdomain("mars") do
visit root_path

expect(page).to have_current_path root_path
end
end
end

context "when multitenancy_management_mode is set to false" do
Expand Down

0 comments on commit aaf0b57

Please sign in to comment.