-
Notifications
You must be signed in to change notification settings - Fork 365
Fix button form save button validation #9501
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
Open
GilbertCherrie
wants to merge
2
commits into
ManageIQ:master
Choose a base branch
from
GilbertCherrie:fix_button_form_change_field_validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 hidden or 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 |
---|---|---|
|
@@ -100,6 +100,38 @@ def group_update | |
# we need a "Provider" so adding an "ExtManagementSystem" to the list. | ||
MODEL_WITH_OPEN_URL = %w[ExtManagementSystem Service User MiqGroup Tenant CloudTenant GenericObject Vm].freeze | ||
|
||
# Types of visibility for the custom buttons | ||
VISIBILITY_TYPES = {'role' => 'role', 'all' => 'all'}.freeze | ||
ALL_ROLES = ["_ALL_", "all"].freeze | ||
FIELDS_EMPTY = [[""], ["", ""]].freeze | ||
|
||
def button_visibility_box_edit | ||
typ_changed = params[:visibility_typ].present? | ||
@edit[:new][:visibility_typ] = VISIBILITY_TYPES[params[:visibility_typ]] if typ_changed | ||
visibility_typ = @edit[:new][:visibility_typ] | ||
|
||
if visibility_typ.to_s == "role" | ||
plural = visibility_typ.pluralize | ||
key = plural.to_sym | ||
prefix = "#{plural}_" | ||
|
||
@edit[:new][key] = [] if typ_changed | ||
params.each do |var, value| | ||
next unless var.starts_with?(prefix) | ||
GilbertCherrie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
name = var.split(prefix).last.to_i | ||
if value == "1" | ||
@edit[:new][key] |= [name] # union | ||
elsif value.downcase == "null" | ||
@edit[:new][key].delete(name) | ||
GilbertCherrie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end | ||
else | ||
@edit[:new][:roles] ||= [] | ||
@edit[:new][:roles] |= ["_ALL_"] | ||
end | ||
end | ||
|
||
def automate_button_field_changed | ||
assert_privileges(feature_by_action) | ||
|
||
|
@@ -125,7 +157,7 @@ def automate_button_field_changed | |
@edit[:new][:dialog_id] = nil if params[:display_for].present? && params[:display_for] != 'single' | ||
|
||
@edit[:new][:dialog_id] = params[:dialog_id] == "" ? nil : params[:dialog_id] if params.key?("dialog_id") | ||
visibility_box_edit | ||
button_visibility_box_edit | ||
|
||
if params[:button_type] == 'default' | ||
clear_playbook_variables | ||
|
@@ -147,7 +179,55 @@ def automate_button_field_changed | |
page.replace("form_role_visibility", :partial => "layouts/role_visibility", :locals => {:rec_id => (@custom_button.id || "new").to_s, :action => "automate_button_field_changed"}) | ||
end | ||
unless params[:target_class] | ||
@changed = session[:changed] = (@edit[:new] != @edit[:current]) | ||
@changed = session[:changed] = false | ||
# This block checks if any of the fields have changed | ||
# Broken into different branches for specific fields | ||
# If no fields are changed it will not set @changed or session[:changed] to true | ||
@edit[:new].each_key do |key| | ||
if @edit[:new][key] != @edit[:current][key] | ||
if @edit[:new][key].blank? && @edit[:current][key].blank? # check empty string / nil case | ||
next | ||
elsif @edit[:new][key] == @edit[:current][key].to_s # check string / integer case | ||
next | ||
elsif key == :roles # check role values | ||
if (ALL_ROLES.include?(@edit[:new][key]) || @edit[:new][key].empty?) && (ALL_ROLES.include?(@edit[:current][key]) || @edit[:current][key].nil?) # if visibility is set to "To All" | ||
next | ||
elsif @edit[:new][key].collect(&:to_i).sort == @edit[:current][key].collect(&:to_i).sort # check if new roles array and current roles array are equal after sorting the ids | ||
next | ||
else # if new roles array and current roles array are not equal | ||
@changed = session[:changed] = true | ||
break | ||
|
||
end | ||
elsif key == :attrs # check attribute values | ||
@edit[:new][key].each_with_index do |_item, index| | ||
if FIELDS_EMPTY.include?(@edit[:new][:attrs][index]) && @edit[:current][:attrs][index].empty? # check if attribute and value field is empty | ||
next | ||
elsif @edit[:new][:attrs][index].empty? && @edit[:current][:attrs][index].empty? # check if attribute or value field is empty | ||
next | ||
else # if new attribute array and current attribute array are not equal | ||
@changed = session[:changed] = true | ||
break | ||
|
||
end | ||
end | ||
|
||
elsif key == :visibility_typ # check visibility type | ||
if @edit[:new][key] == "all" && @edit[:current][key].nil? # if visibility is set to "To All" | ||
next | ||
else # if new visibility type value and current visibility type value are not equal | ||
@changed = session[:changed] = true | ||
break | ||
|
||
end | ||
else # if new value and current value are not equal | ||
@changed = session[:changed] = true | ||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to extract methods out of these conditional where you can give a decent name to the logic... it's going to be hard to test this in a unit test without smaller methods. |
||
|
||
end | ||
end | ||
end | ||
|
||
page << javascript_for_miq_button_visibility(@changed) | ||
end | ||
page << "miqSparkle(false);" | ||
|
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.