Skip to content

Commit

Permalink
Users without groups should use admin retirement
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Sep 20, 2019
1 parent 76e3ac6 commit a392f02
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/models/mixins/retirement_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,18 @@ def valid_zone?
end

def system_context_requester
if try(:evm_owner_id).present?
if User.find_by(:id => evm_owner_id).present?
return evm_owner
else
$log.info("#{name} has evm_owner_id present but no user with that id found so defaulting to admin.")
return User.super_admin
user = User.find_by(:id => evm_owner_id) if try(:evm_owner_id)
return evm_owner if user.present? && user.current_group.present?

if user.present?
msg = "#{name} has evm_owner present"
if user.current_group.blank?
msg += " but user has no group so defaulting to admin."
end
else
msg = "System context defaulting to admin user because owner of #{name} not set."
end
$log.info("System context defaulting to admin user because owner of #{name} not set.")
$log.info(msg)
User.super_admin
end

Expand Down
19 changes: 19 additions & 0 deletions spec/models/vm/retirement_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@
expect(MiqRequest.first.userid).to eq("admin")
end
end

context "with user lacking group" do
let(:user1) { FactoryBot.create(:user) }
let(:vm_with_owner_no_group) { FactoryBot.create(:vm, :evm_owner => user1, :host => FactoryBot.create(:host)) }

it "uses admin as requester" do
vm_with_owner_no_group.update(:retires_on => 90.days.ago, :retirement_warn => 60, :retirement_last_warn => nil)

expect(vm_with_owner_no_group.retirement_last_warn).to be_nil
allow(MiqAeEngine).to receive_messages(:deliver => ['ok', 'success', MiqAeEngine::MiqAeWorkspaceRuntime.new])
vm_with_owner_no_group.retirement_check
status, message, result = MiqQueue.first.deliver
MiqQueue.first.delivered(status, message, result)

expect(vm_with_owner_no_group.retirement_last_warn).not_to be_nil
# the next test is only nil because we're not seeding a true super admin in these specs
expect(vm_with_owner_no_group.retirement_requester).to eq(nil)
end
end
end

it "#start_retirement" do
Expand Down

0 comments on commit a392f02

Please sign in to comment.