Skip to content

Commit

Permalink
Set user's group to the requester group.
Browse files Browse the repository at this point in the history
User's current group might have changed before the provision finishes.
So the user's current group from DB may be different from the user's group when the request is made.

Need to set the user's group back to requester group the user is in when the provision is submitted.
Therefore the provisioned instances may belong to the right user/group/tenant.

https://bugzilla.redhat.com/show_bug.cgi?id=1467364
  • Loading branch information
lfu committed Aug 2, 2017
1 parent 1fdd17e commit 97b099d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/mixins/miq_request_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def get_option_last(key)
end

def get_user
@user ||= User.find_by_userid(userid)
@user ||= User.find_by(:userid => userid).tap do |u|
u.current_group_by_description = options[:requester_group] if options[:requester_group]
end
end
alias_method :tenant_identity, :get_user

Expand Down
20 changes: 20 additions & 0 deletions spec/models/miq_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,24 @@
expect { described_class.class_from_request_data({}) }.to raise_error("Invalid request_type")
end
end

context "#get_user" do
let(:root_tenant) { Tenant.seed }
let(:tenant1) { FactoryGirl.create(:tenant, :parent => root_tenant) }
let(:group1) { FactoryGirl.create(:miq_group, :description => 'Group 1', :tenant => root_tenant) }
let(:group2) { FactoryGirl.create(:miq_group, :description => 'Group 2', :tenant => tenant1) }
let(:user) { FactoryGirl.create(:user, :miq_groups => [group1, group2], :current_group => group1) }

it "takes the requester group" do
request = FactoryGirl.create(:miq_provision_request, :requester => user, :options => {:requester_group => group2.description})
expect(user.current_group).to eq(group1)
expect(request.get_user.current_group).to eq(group2)
end

it "stays with user's current group" do
request = FactoryGirl.create(:miq_provision_request, :requester => user)
expect(user.current_group).to eq(group1)
expect(request.get_user.current_group).to eq(group1)
end
end
end

0 comments on commit 97b099d

Please sign in to comment.