Skip to content

Commit

Permalink
Merge pull request #3345 from lgalis/user_no_group_validation_fix
Browse files Browse the repository at this point in the history
Update the User data only if the validation passes
(cherry picked from commit fbcf766)

https://bugzilla.redhat.com/show_bug.cgi?id=1552873
  • Loading branch information
h-kataria authored and simaishi committed Mar 7, 2018
1 parent b3565ee commit 7b10336
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/ops_controller/ops_rbac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def rbac_edit_save_or_add(what, rbac_suffix = what)
when :user
record = @edit[:user_id] ? User.find_by(:id => @edit[:user_id]) : User.new
validated = rbac_user_validate?
rbac_user_set_record_vars(record)
rbac_user_set_record_vars(record) if validated
when :group then
record = @edit[:group_id] ? MiqGroup.find_by(:id => @edit[:group_id]) : MiqGroup.new
validated = rbac_group_validate?
Expand Down
19 changes: 19 additions & 0 deletions spec/controllers/ops_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,25 @@
expect(flash_messages.first[:message]).to eq("A User must be assigned to a Group")
expect(flash_messages.first[:level]).to eq(:error)
end

it 'does not update the user without validation' do
user1 = FactoryGirl.create(:user, :name => "User1", :userid => "User1", :miq_groups => [group], :email => "[email protected]")

session[:edit] = {:key => "rbac_user_edit__#{user1.id}",
:new => {:name => 'test8',
:userid => 'test8',
:email => '[email protected]',
:group => nil,
:password => 'test8',
:verify => 'test8'}}
expect(controller).to receive(:render_flash)
post :rbac_user_edit, :params => {:button => 'save', :id => user1.id}
flash_messages = assigns(:flash_array)
expect(flash_messages.first[:message]).to eq("A User must be assigned to a Group")
expect(flash_messages.first[:level]).to eq(:error)
expect(user1.miq_groups).to eq([group])
expect(user1.name).to eq('User1')
end
end

context "#db_backup" do
Expand Down

0 comments on commit 7b10336

Please sign in to comment.