Skip to content

Commit

Permalink
Merge pull request ManageIQ#15696 from lfu/service_user_in_groups_146…
Browse files Browse the repository at this point in the history
…7364

Set user's group to the requester group.
(cherry picked from commit 1d2c55f)

https://bugzilla.redhat.com/show_bug.cgi?id=1480007
  • Loading branch information
gmcculloug authored and d-m-u committed Jun 6, 2018
1 parent 8d3ca9c commit 740fcd1
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 740fcd1

Please sign in to comment.