-
Notifications
You must be signed in to change notification settings - Fork 356
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
Update the User data only if the validation passes #3345
Merged
h-kataria
merged 2 commits into
ManageIQ:master
from
lgalis:user_no_group_validation_fix
Feb 1, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lgalis, change looks good, but i am curious why is invalid record being updated, shouldn't it skip save if record is not valid at https://github.com/lgalis/manageiq-ui-classic/blob/62358a3c6baef44122cb963fab2e576678aac7ba/app/controllers/ops_controller/ops_rbac.rb#L736
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rbac_user_set_record_vars updates the user's HABTM miq_groups link directly, without save being called for the User, this is how Rails' has_many and has_and_belongs_to_many associations work.
I also do not think there's a reason to set the record values if the UI validation is not successful. ( The validation for the Role doesn ot have this issue because the miq_user_role's features are not assigned directly).