Skip to content

Commit

Permalink
Merge pull request ManageIQ#18462 from d-m-u/bz1677569
Browse files Browse the repository at this point in the history
Redo presence check after possible reset of user to nil
  • Loading branch information
bdunne authored Feb 20, 2019
2 parents d6776df + df5dca9 commit 1680ffb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
8 changes: 4 additions & 4 deletions app/models/mixins/retirement_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ def current_user
end

def q_user_info(q_options, requester)
if requester.present?
if requester.kind_of?(String)
requester = User.find_by(:userid => requester)
end
if requester && requester.kind_of?(String)
requester = User.find_by(:userid => requester)
end
if requester
q_options[:user_id] = requester.id
if requester.current_group.present? && requester.current_tenant.present?
q_options[:group_id] = requester.current_group.id
Expand Down
14 changes: 13 additions & 1 deletion spec/models/orchestration_stack/retirement_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
expect(@stack.retirement_due?).to be_truthy
end

it "#raise_retirement_event" do
it "#raise_retirement_event without user" do
event_name = 'foo'
event_hash = {
:userid => nil,
Expand All @@ -167,6 +167,18 @@
@stack.raise_retirement_event(event_name)
end

it "#raise_retirement_event with user" do
event_name = 'foo'
event_hash = {
:userid => user.userid,
:orchestration_stack => @stack,
:type => "OrchestrationStack",
}

expect(MiqEvent).to receive(:raise_evm_event).with(@stack, event_name, event_hash, :zone => @zone.name, :user_id => user.id, :group_id => user.current_group.id, :tenant_id => user.current_tenant.id)
@stack.raise_retirement_event(event_name, user.userid)
end

it "#raise_audit_event" do
event_name = 'foo'
message = 'bar'
Expand Down
26 changes: 21 additions & 5 deletions spec/models/service/retirement_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,27 @@
expect(@service.retirement_due?).to be_truthy
end

it "#raise_retirement_event" do
event_name = 'foo'
event_hash = {:userid => nil, :service => @service, :type => "Service"}
expect(MiqEvent).to receive(:raise_evm_event).with(@service, event_name, event_hash, {})
@service.raise_retirement_event(event_name)
describe "#raise_retirement_event " do
it "without user" do
event_name = 'foo'
event_hash = {:userid => nil, :service => @service, :type => "Service"}
expect(MiqEvent).to receive(:raise_evm_event).with(@service, event_name, event_hash, {})
@service.raise_retirement_event(event_name)
end

it "with user" do
event_name = 'foo'
event_hash = {:userid => "admin", :service => @service, :type => "Service"}
expect(MiqEvent).to receive(:raise_evm_event).with(@service, event_name, event_hash, :user_id => user.id, :group_id => user.current_group.id, :tenant_id => user.current_tenant.id)
@service.raise_retirement_event(event_name, "admin")
end

it "with user that isn't found" do
event_name = 'foo'
event_hash = {:userid => "nonexistent_username", :service => @service, :type => "Service"}
expect(MiqEvent).to receive(:raise_evm_event).with(@service, event_name, event_hash, {})
@service.raise_retirement_event(event_name, "nonexistent_username")
end
end

it "#raise_audit_event" do
Expand Down

0 comments on commit 1680ffb

Please sign in to comment.