Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ops_controller/settings/zones.rb] Soft delete auth #7650

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions app/controllers/ops_controller/settings/zones.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ def zone_edit
unless @edit[:new][:description]
add_flash(_("Description can't be blank"), :error)
end
unless @edit[:new][:password] == @edit[:new][:verify]
add_flash(_('Password and Verify Password fields do not match'), :error)
end

# This is needed for cases when more than one required field is missing or is not correct, to prevent rendering same flash messages
if @flash_array
Expand All @@ -39,7 +36,8 @@ def zone_edit
end

zone_set_record_vars(@zone)
if valid_record?(@zone) && @zone.save
@edit[:errors] = []
if @zone.save
AuditEvent.success(build_created_audit(@zone, @edit))
if params[:button] == "save"
add_flash(_("Zone \"%{name}\" was saved") % {:name => @edit[:new][:name]})
Expand Down Expand Up @@ -115,30 +113,13 @@ def zone_set_record_vars(zone, mode = nil)
zone.settings ||= {}
zone.settings[:proxy_server_ip] = @edit[:new][:proxy_server_ip]
zone.settings[:concurrent_vm_scans] = @edit[:new][:concurrent_vm_scans]

zone.update_authentication({:windows_domain => {:userid => @edit[:new][:userid], :password => @edit[:new][:password]}}, {:save => (mode != :validate)})
end

# Validate the zone record fields
def valid_record?(zone)
valid = true
@edit[:errors] = []
if zone.authentication_password.present? && zone.authentication_userid.blank?
@edit[:errors].push(_("Username must be entered if Password is entered"))
valid = false
end
if @edit[:new][:password] != @edit[:new][:verify]
@edit[:errors].push(_("Password and Verify Password fields do not match"))
valid = false
end
valid
end

# Get variables from zone edit form
def zone_get_form_vars
@zone = @edit[:zone_id] ? Zone.find(@edit[:zone_id]) : Zone.new

copy_params_if_present(@edit[:new], params, %i[name description proxy_server_ip userid password verify])
copy_params_if_present(@edit[:new], params, %i[name description proxy_server_ip])
@edit[:new][:concurrent_vm_scans] = params[:max_scans].to_i if params[:max_scans]

set_verify_status
Expand All @@ -164,10 +145,6 @@ def zone_set_form_vars
@edit[:new][:proxy_server_ip] = @zone.settings ? @zone.settings[:proxy_server_ip] : nil
@edit[:new][:concurrent_vm_scans] = @zone.settings ? @zone.settings[:concurrent_vm_scans].to_i : 0

@edit[:new][:userid] = @zone.authentication_userid(:windows_domain)
@edit[:new][:password] = @zone.authentication_password(:windows_domain)
@edit[:new][:verify] = @zone.authentication_password(:windows_domain)

session[:verify_ems_status] = nil
set_verify_status

Expand Down
31 changes: 0 additions & 31 deletions app/views/ops/_zone_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,6 @@
= javascript_tag(javascript_focus('proxy_server_ip'))

%hr
%h3
= _("Credentials - Windows Domain")
.form-horizontal
.form-group
%label.control-label.col-md-2
= _("Username")
.col-md-8
= text_field_tag("userid",
@edit[:new][:userid],
:maxlength => 50,
:class => "form-control",
"data-miq_observe" => {:interval => '.5', :url => url}.to_json)
.form-group
%label.control-label.col-md-2
= _("Password")
.col-md-8
= password_field_tag("password",
@edit[:new][:password],
:maxlength => 50,
:class => "form-control",
"data-miq_observe" => {:interval => '.5', :url => url}.to_json)
.form-group
%label.control-label.col-md-2
= _("Verify Password")
.col-md-8
= password_field_tag("verify",
@edit[:new][:verify],
:maxlength => 50,
:class => "form-control",
"data-miq_observe" => {:interval => '.5', :url => url}.to_json)
%hr
%h3
= _("Settings")
.form-horizontal
Expand Down
3 changes: 1 addition & 2 deletions spec/controllers/ops_controller/settings/zones_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
it 'sets flash array according to the missing name, description and verify password' do
controller.send(:zone_edit)
expect(controller.instance_variable_get(:@flash_array)).to eq([{:message => "Name can't be blank", :level => :error},
{:message => "Description can't be blank", :level => :error},
{:message => "Password and Verify Password fields do not match", :level => :error}])
{:message => "Description can't be blank", :level => :error}])
end
end

Expand Down