Skip to content
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

Redo presence check after possible reset of user to nil #18462

Merged
merged 1 commit into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -130,7 +130,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 @@ -142,6 +142,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 @@ -209,11 +209,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