Skip to content

Commit 1f30d6e

Browse files
authored
Do not redirect from home page when login is disabled (#2235)
fixes #2188
1 parent 10f9378 commit 1f30d6e

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

app/controllers/application_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ def return_to_self
127127
current_user.sysadmin = false
128128
end
129129

130-
def downtime_check
130+
def downtime_check(with_redirect: true)
131131
if Flipflop.disable_login?
132132
if current_user&.eligible_sysadmin?
133133
flash[:notice] = I18n.t(:only_sysadmin_users)
134134
else
135-
redirect_to root_path
135+
redirect_to root_path if with_redirect
136136
flash[:notice] = I18n.t(:no_login_currently)
137137
end
138138
end

app/controllers/welcome_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class WelcomeController < ApplicationController
77
def index
88
if current_user.blank?
99
render layout: "welcome"
10+
elsif Flipflop.disable_login?
11+
downtime_check(with_redirect: false)
12+
redirect_to dashboard_path if current_user&.eligible_sysadmin?
1013
else
1114
redirect_to dashboard_path
1215
end

spec/controllers/dashboard_controller_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,29 @@
112112
sign_in user
113113
end
114114

115+
it "does not show the admin tab" do
116+
get :index
117+
expect(response.body).not_to include("Administration")
118+
end
119+
120+
context "disable_login is true" do
121+
before do
122+
test_strategy = Flipflop::FeatureSet.current.test!
123+
test_strategy.switch!(:disable_login, true)
124+
end
125+
126+
after do
127+
test_strategy = Flipflop::FeatureSet.current.test!
128+
test_strategy.switch!(:disable_login, false)
129+
end
130+
131+
it "redirects to the home page" do
132+
get :index
133+
expect(response).to redirect_to root_path
134+
expect(flash.notice).to eq("You can not be signed in at this time.")
135+
end
136+
end
137+
115138
context "and the user is a sysadmin" do
116139
let(:user) { FactoryBot.create :sysadmin, mediaflux_session: SystemUser.mediaflux_session }
117140
render_views

spec/controllers/welcome_controller_spec.rb

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,57 @@
2323
sign_in user
2424
end
2525

26-
it "renders the index page" do
26+
it "redirects to the user dashboard" do
2727
get :index
2828
expect(response).to redirect_to(dashboard_path)
2929
end
30+
31+
context "disable_login is true" do
32+
before do
33+
test_strategy = Flipflop::FeatureSet.current.test!
34+
test_strategy.switch!(:disable_login, true)
35+
end
36+
37+
after do
38+
test_strategy = Flipflop::FeatureSet.current.test!
39+
test_strategy.switch!(:disable_login, false)
40+
end
41+
42+
it "displays a flash message" do
43+
get :index
44+
expect(response).to render_template("index")
45+
expect(flash.notice).to eq("You can not be signed in at this time.")
46+
end
47+
end
3048
end
3149

32-
context "when a user is logged in", connect_to_mediaflux: true do
33-
let(:user) { FactoryBot.create :user, mediaflux_session: SystemUser.mediaflux_session }
50+
context "when a sysadmin user is logged in", connect_to_mediaflux: true do
51+
let(:user) { FactoryBot.create :sysadmin, mediaflux_session: SystemUser.mediaflux_session }
3452
before do
3553
sign_in user
3654
end
55+
56+
it "redirects to the user dashboard" do
57+
get :index
58+
expect(response).to redirect_to(dashboard_path)
59+
end
60+
61+
context "disable_login is true" do
62+
before do
63+
test_strategy = Flipflop::FeatureSet.current.test!
64+
test_strategy.switch!(:disable_login, true)
65+
end
66+
67+
after do
68+
test_strategy = Flipflop::FeatureSet.current.test!
69+
test_strategy.switch!(:disable_login, false)
70+
end
71+
72+
it "displays a flash message and redirects to the user dashboard" do
73+
get :index
74+
expect(response).to redirect_to(dashboard_path)
75+
expect(flash.notice).to eq("System is only enabled for administrators currently")
76+
end
77+
end
3778
end
3879
end

0 commit comments

Comments
 (0)