Commit 1e75c7db authored by Lin Jen-Shin's avatar Lin Jen-Shin

Reset Jenkins password if username was left blank

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/22430
parent b200d112
...@@ -24,7 +24,7 @@ class JenkinsService < CiService ...@@ -24,7 +24,7 @@ class JenkinsService < CiService
before_update :reset_password before_update :reset_password
validates :username, validates :username,
presence: true, presence: true,
if: ->(service) { service.activated? && service.password.present? } if: ->(service) { service.activated? && service.password_touched? }
default_value_for :push_events, true default_value_for :push_events, true
default_value_for :merge_requests_events, false default_value_for :merge_requests_events, false
...@@ -34,7 +34,7 @@ class JenkinsService < CiService ...@@ -34,7 +34,7 @@ class JenkinsService < CiService
def reset_password def reset_password
# don't reset the password if a new one is provided # don't reset the password if a new one is provided
if jenkins_url_changed? && !password_touched? if (jenkins_url_changed? || username.blank?) && !password_touched?
self.password = nil self.password = nil
end end
end end
......
...@@ -13,15 +13,16 @@ ...@@ -13,15 +13,16 @@
- else - else
= form.label name, title, class: "control-label" = form.label name, title, class: "control-label"
.col-sm-10 .col-sm-10
- if type == 'text' - case type
- when 'text'
= form.text_field name, class: "form-control", placeholder: placeholder = form.text_field name, class: "form-control", placeholder: placeholder
- elsif type == 'textarea' - when 'textarea'
= form.text_area name, rows: 5, class: "form-control", placeholder: placeholder = form.text_area name, rows: 5, class: "form-control", placeholder: placeholder
- elsif type == 'checkbox' - when 'checkbox'
= form.check_box name = form.check_box name
- elsif type == 'select' - when 'select'
= form.select name, options_for_select(choices, value ? value : default_choice), {}, { class: "form-control" } = form.select name, options_for_select(choices, value ? value : default_choice), {}, { class: "form-control" }
- elsif type == 'password' - when 'password'
= form.password_field name, autocomplete: "new-password", class: 'form-control' = form.password_field name, autocomplete: "new-password", class: 'form-control'
- if help - if help
%span.help-block= help %span.help-block= help
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment