Skip to content

Commit 008f4f4

Browse files
arvindsvzabil
authored andcommitted
Fix checkbox for allowOnlyKnownUsersToLogin #736 (#2756)
* Fix checkbox for allowOnlyKnownUsersToLogin #736 * Default checkbox value to true #736 * Without this, when the checkbox is disabled, it tries to unset it (since the browser won't send its value, since it's disabled). * Change auto login help message #736
1 parent e116274 commit 008f4f4

File tree

5 files changed

+71
-15
lines changed

5 files changed

+71
-15
lines changed

server/webapp/WEB-INF/rails.new/app/views/admin/server/index.html.erb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@
3131

3232
<div class="form_item required">
3333
<div class="form_item checkbox_row">
34-
<%- html_options = {:include_hidden => false} %>
34+
<%- html_options = { } %>
3535
<%- html_options = {:include_hidden => false, :disabled => true, :title => l.string("CANNOT_TURN_OFF_AUTO_LOGIN")} unless @allow_user_to_turn_off_auto_login %>
36-
<%- allow_auto_login_value = @server_configuration_form.allow_auto_login ? "1" : "0" %>
37-
<%= form.hidden_field :allow_auto_login, :value => allow_auto_login_value %>
38-
<%= form.check_box :allow_auto_login, html_options, "1", "0" %>
36+
<%= form.check_box :allow_auto_login, html_options, "true", "false" %>
3937
<label class="inline" for="server_configuration_form_allow_auto_login"><%= l.string("ALLOW_AUTO_LOGIN_MESSAGE") -%></label>
4038
</div>
4139

server/webapp/WEB-INF/rails.new/lib/server_configuration_form.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def self.from_server_config(server_config)
4646
security_config, mail_host = server_config.security(),server_config.mailHost()
4747
ldap_config = security_config.ldapConfig()
4848
password_file_path = security_config.passwordFileConfig().path()
49-
auto_login = (!security_config.isAllowOnlyKnownUsersToLogin()) ? "1" : "0"
49+
auto_login = security_config.isAllowOnlyKnownUsersToLogin() ? "false" : "true"
5050

5151
allow_auto_login = {:allow_auto_login => auto_login}
5252
mail_host_params= {:hostName => mail_host.getHostName(), :port => mail_host.getPort().to_s, :username => mail_host.getUserName(),
@@ -94,7 +94,7 @@ def to_password_file_config
9494
end
9595

9696
def should_allow_auto_login
97-
allow_auto_login == "1"
97+
allow_auto_login != "false"
9898
end
9999

100100
def to_security

server/webapp/WEB-INF/rails.new/spec/lib/server_configuration_form_spec.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,41 @@
6363
end
6464

6565
describe "allow_auto_login" do
66+
it "should default it to true when a new instance is created without a value being provided for it" do
67+
form = ServerConfigurationForm.new({})
68+
expect(form.allow_auto_login).to eq nil
69+
expect(form.should_allow_auto_login).to eq true
70+
end
71+
6672
it "should set it when a new instance is created" do
67-
form = ServerConfigurationForm.new({:allow_auto_login => "1"})
68-
expect(form.allow_auto_login).to eq "1"
73+
form = ServerConfigurationForm.new({:allow_auto_login => "true"})
74+
expect(form.allow_auto_login).to eq "true"
6975
expect(form.should_allow_auto_login).to eq true
7076

71-
form = ServerConfigurationForm.new({:allow_auto_login => "0"})
72-
expect(form.allow_auto_login).to eq "0"
77+
form = ServerConfigurationForm.new({:allow_auto_login => "false"})
78+
expect(form.allow_auto_login).to eq "false"
7379
expect(form.should_allow_auto_login).to eq false
7480
end
7581

76-
it "should set allow_auto_login to 1 when form is being created from_server_config and isAllowOnlyKnownUsersToLogin is false" do
82+
it "should set allow_auto_login to 'true' when form is being created from_server_config and isAllowOnlyKnownUsersToLogin is false" do
7783
@ldap_config = LdapConfig.new("ldap://test.com", "test", "password", @encrypted_password, true,BasesConfig.new([BaseConfig.new('base1'), BaseConfig.new('base2')].to_java(BaseConfig)), "searchFilter")
7884
@password_file_config = PasswordFileConfig.new("path")
7985
@security_config = SecurityConfig.new(@ldap_config, @password_file_config, false)
8086
@mail_host = MailHost.new("blrstdcrspair02", 9999, "pavan", "strong_password", true, true, "from@from.com", "admin@admin.com")
8187

8288
form = ServerConfigurationForm.from_server_config(com.thoughtworks.go.config.ServerConfig.new(@security_config, @mail_host))
83-
expect(form.allow_auto_login).to eq "1"
89+
expect(form.allow_auto_login).to eq "true"
8490
expect(form.should_allow_auto_login).to eq true
8591
end
8692

87-
it "should set allow_auto_login to 0 when form is being created from_server_config and isAllowOnlyKnownUsersToLogin is true" do
93+
it "should set allow_auto_login to 'false' when form is being created from_server_config and isAllowOnlyKnownUsersToLogin is true" do
8894
@ldap_config = LdapConfig.new("ldap://test.com", "test", "password", @encrypted_password, true,BasesConfig.new([BaseConfig.new('base1'), BaseConfig.new('base2')].to_java(BaseConfig)), "searchFilter")
8995
@password_file_config = PasswordFileConfig.new("path")
9096
@security_config = SecurityConfig.new(@ldap_config, @password_file_config, true)
9197
@mail_host = MailHost.new("blrstdcrspair02", 9999, "pavan", "strong_password", true, true, "from@from.com", "admin@admin.com")
9298

9399
form = ServerConfigurationForm.from_server_config(com.thoughtworks.go.config.ServerConfig.new(@security_config, @mail_host))
94-
expect(form.allow_auto_login).to eq "0"
100+
expect(form.allow_auto_login).to eq "false"
95101
expect(form.should_allow_auto_login).to eq false
96102
end
97103
end

server/webapp/WEB-INF/rails.new/spec/views/admin/server/index_html_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,56 @@ def method_missing method, *args
182182
end
183183
end
184184
end
185+
186+
describe "allow auto login (allow_auto_login)" do
187+
it "should disable the check box if changing it is not allowed (when no admins are enabled)" do
188+
server_config_form = ServerConfigurationForm.new({:allow_auto_login => "true"})
189+
assign(:server_configuration_form, server_config_form)
190+
assign(:allow_user_to_turn_off_auto_login, false)
191+
192+
render
193+
194+
Capybara.string(response.body).find('#user_management').tap do |div|
195+
expect(div).to have_selector("label[for='server_configuration_form_allow_auto_login']", :text => /Allow users that exist/)
196+
expect(div).to_not have_selector("input[name='server_configuration_form[allow_auto_login]'][type='hidden']")
197+
expect(div).to have_selector("input#server_configuration_form_allow_auto_login[name='server_configuration_form[allow_auto_login]'][disabled='disabled'][type='checkbox'][value='true']")
198+
end
199+
end
200+
201+
it "should enable the check box and set it to 'checked' when auto login is allowed" do
202+
server_config_form = ServerConfigurationForm.new({:allow_auto_login => "true"})
203+
assign(:server_configuration_form, server_config_form)
204+
assign(:allow_user_to_turn_off_auto_login, true)
205+
206+
render
207+
208+
Capybara.string(response.body).find('#user_management').tap do |div|
209+
div.find("input[name='server_configuration_form[allow_auto_login]'][type='hidden'][value='false']").tap do |hidden_value_for_checkbox|
210+
expect(hidden_value_for_checkbox).to_not be_disabled
211+
end
212+
div.find("input#server_configuration_form_allow_auto_login[name='server_configuration_form[allow_auto_login]'][type='checkbox'][value='true']").tap do |checkbox|
213+
expect(checkbox).to_not be_disabled
214+
expect(checkbox).to be_checked
215+
end
216+
end
217+
end
218+
219+
it "should enable the check box and set it to not be 'checked' when auto login is not allowed" do
220+
server_config_form = ServerConfigurationForm.new({:allow_auto_login => "false"})
221+
assign(:server_configuration_form, server_config_form)
222+
assign(:allow_user_to_turn_off_auto_login, true)
223+
224+
render
225+
226+
Capybara.string(response.body).find('#user_management').tap do |div|
227+
div.find("input[name='server_configuration_form[allow_auto_login]'][type='hidden'][value='false']").tap do |hidden_value_for_checkbox|
228+
expect(hidden_value_for_checkbox).to_not be_disabled
229+
end
230+
div.find("input#server_configuration_form_allow_auto_login[name='server_configuration_form[allow_auto_login]'][type='checkbox'][value='true']").tap do |checkbox|
231+
expect(checkbox).to_not be_disabled
232+
expect(checkbox).to_not be_checked
233+
end
234+
end
235+
end
236+
end
185237
end

server/webapp/localize.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
<entry key="ABLE_TO_CONNECT_TO_LDAP">Connected to LDAP successfully.</entry>
256256
<entry key="PASSWORD_FILE_SETTINGS">Password File Settings</entry>
257257
<entry key="PASSWORD_FILE_PATH">Password File Path</entry>
258-
<entry key="ALLOW_AUTO_LOGIN_MESSAGE">Allow users that exist in LDAP or in the password file to log into Go, even if they haven't been explicitly added to Go.</entry>
258+
<entry key="ALLOW_AUTO_LOGIN_MESSAGE">Allow users that exist in LDAP or in the password file to log into GoCD, even if they haven't been explicitly added to GoCD.</entry>
259259
<entry key="FAILED_TO_SAVE_THE_SERVER_CONFIGURATION">Failed to save the server configuration. Reason: {0}</entry>
260260
<entry key="LICENSE_DETAILS">License Details</entry>
261261
<entry key="VIEW_FAILURE_DETAILS">View failure details</entry>

0 commit comments

Comments
 (0)