Skip to content

Commit 4058426

Browse files
committed
Don't show omniauth options in a space where they won't work
1 parent 23ca169 commit 4058426

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

app/helpers/spaces_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ def space_feature_options
1111
[t("features.#{f}.short"), f]
1212
end
1313
end
14+
15+
def space_supports_omniauth?(space = current_space)
16+
space.nil? || space.default? || space.is_subdomain?(TeSS::Config.base_uri.domain)
17+
end
1418
end

app/views/layouts/_login_menu.html.erb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
<strong>Log In</strong> <span class="caret"></span>
1010
</a>
1111
<ul class="dropdown-menu dropdown-menu-right">
12-
<% Devise.omniauth_configs.each do |provider, config| -%>
13-
<li class="dropdown-item"><%= omniauth_login_link(provider, config) %></li>
12+
<% if space_supports_omniauth? %>
13+
<% Devise.omniauth_configs.each do |provider, config| -%>
14+
<li class="dropdown-item"><%= omniauth_login_link(provider, config) %></li>
15+
<% end %>
1416
<% end %>
1517

1618
<li class="dropdown-item">

config/application.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ def _sentry_dsn
170170
def sentry_enabled?
171171
_sentry_dsn.present? && Rails.env.production?
172172
end
173+
174+
def base_uri
175+
@base_uri ||= Addressable::URI.parse(base_url)
176+
end
173177
end
174178

175179
Config = TessConfig.new(tess_config)

test/controllers/static_controller_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,4 +712,26 @@ class StaticControllerTest < ActionController::TestCase
712712
end
713713
end
714714
end
715+
716+
test 'show omniauth login options when on subdomain space' do
717+
space = spaces(:plants)
718+
space.update!(host: 'plants.example.com')
719+
with_host(space.host) do
720+
get :home
721+
assert_select 'ul.user-options.nav.navbar-nav.navbar-right' do
722+
assert_select "a[href=\"/users/auth/oidc?space_id=#{space.id}\"]", count: 1
723+
end
724+
end
725+
end
726+
727+
test 'do not show omniauth login options when on non-subdomain space' do
728+
space = spaces(:plants)
729+
space.update!(host: 'other-host.com')
730+
with_host(space.host) do
731+
get :home
732+
assert_select 'ul.user-options.nav.navbar-nav.navbar-right' do
733+
assert_select "a[href=\"/users/auth/oidc?space_id=#{space.id}\"]", count: 0
734+
end
735+
end
736+
end
715737
end

test/unit/config_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ class ConfigTest < ActiveSupport::TestCase
2727
end
2828
assert_equal exp, TeSS::Config.redis_url
2929
end
30+
31+
test 'base_uri' do
32+
assert_equal 'example.com', TeSS::Config.base_uri.domain
33+
end
3034
end

0 commit comments

Comments
 (0)