Skip to content

Commit

Permalink
Remove extra flash message 'Description can't be blank'
Browse files Browse the repository at this point in the history
Remove the flash message which did not make sense to be displayed
if user filled in a description and pressed Add button while adding new Group.
  • Loading branch information
Hilda Stastna committed Sep 10, 2019
1 parent efbf50e commit 65e24ce
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/controllers/ops_controller/ops_rbac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ def rbac_edit_save_or_add(what, rbac_suffix = what)
when :group then
record = @edit[:group_id] ? MiqGroup.find_by(:id => @edit[:group_id]) : MiqGroup.new
validated = rbac_group_validate?
rbac_group_set_record_description_role(record) # Set new Description, Role and Tenant for a new Group
rbac_group_set_record_vars(record) if validated
when :role then
record = @edit[:role_id] ? MiqUserRole.find_by(:id => @edit[:role_id]) : MiqUserRole.new
Expand Down Expand Up @@ -1216,10 +1217,6 @@ def rbac_group_filter_expression_vars(field_expression, field_expression_table)

# Set group record variables to new values
def rbac_group_set_record_vars(group)
role = MiqUserRole.find(@edit[:new][:role])
group.description = @edit[:new][:description]
group.miq_user_role = role
group.tenant = Tenant.find(@edit[:new][:group_tenant]) if @edit[:new][:group_tenant]
if @edit[:new][:use_filter_expression]
@edit[:new][:filters].clear
else
Expand All @@ -1230,6 +1227,13 @@ def rbac_group_set_record_vars(group)
rbac_group_set_filters(group) # Go set the filters for the group
end

# Set group record variables such as Description, Role and Tenant to new values
def rbac_group_set_record_description_role(group)
group.description = @edit[:new][:description]
group.miq_user_role = MiqUserRole.find(@edit[:new][:role]) if @edit[:new][:role]
group.tenant = Tenant.find(@edit[:new][:group_tenant]) if @edit[:new][:group_tenant]
end

# Set filters in the group record from the @edit[:new] hash values
def rbac_group_set_filters(group)
group.entitlement ||= Entitlement.new
Expand Down Expand Up @@ -1400,7 +1404,7 @@ def rbac_group_validate?
@assigned_filters = [] if @edit[:new][:filters].empty? || @edit[:new][:use_filter_expression]
@filter_expression = [] if @edit[:new][:filter_expression].empty? || @edit[:new][:use_filter_expression] == false
if @edit[:new][:role].nil? || @edit[:new][:role] == ""
add_flash(_("A User Group must be assigned a Role"), :error)
add_flash(_("A Role must be assigned to this Group"), :error)
return false
end
true
Expand Down
19 changes: 19 additions & 0 deletions spec/controllers/ops_controller/ops_rbac_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -806,4 +806,23 @@
end
end
end

describe '#rbac_edit_save_or_add' do
context 'adding new Group' do
before do
allow(controller).to receive(:load_edit).and_return(true)
allow(controller).to receive(:render_flash)
controller.instance_variable_set(:@edit, :new => {:description => 'Description',
:filters => {},
:filter_expression => {'???' => '???'},
:use_filter_expression => false})
controller.params = {:button => 'add'}
end

it 'sets @flash_array properly if user forgot to choose a Role for a Group' do
controller.send(:rbac_edit_save_or_add, 'group')
expect(controller.instance_variable_get(:@flash_array)).to eq([{:message => 'A Role must be assigned to this Group', :level => :error}])
end
end
end
end

0 comments on commit 65e24ce

Please sign in to comment.