Skip to content

Commit

Permalink
Need to pass the user's group in to automate when the provision starts.
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 sent into automate.

https://bugzilla.redhat.com/show_bug.cgi?id=1467364
  • Loading branch information
lfu committed Aug 9, 2017
1 parent 1439897 commit 660b111
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/miq_automation_engine/engine/miq_ae_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,11 @@ def self.resolve_automation_object(uri, user_obj, attr = nil, options = {}, read

def self.ae_user_object(options = {})
raise "user_id not specified in Automation request" if options[:user_id].blank?
# raise "group_id not specified in Automation request" if options[:miq_group_id].blank?
# raise "miq_group_id not specified in Automation request" if options[:miq_group_id].blank?

User.find_by!(:id => options[:user_id]).tap do |obj|
# obj.current_group = MiqGroup.find_by!(:id => options[:miq_group_id])
obj.current_group = MiqGroup.find_by!(:id => options[:miq_group_id]) unless options[:miq_group_id] == obj.current_group.id
$miq_ae_logger.info("User [#{obj.userid}] with current group ID [#{obj.current_group.id}] name [#{obj.current_group.description}]")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def process_assertions(message)

def user_info_attributes(user)
{'user' => user, 'tenant' => user.current_tenant, 'miq_group' => user.current_group}.each do |k, v|
value = MiqAeObject.convert_value_based_on_datatype(v.id, v.class.name)
value = MiqAeMethodService::MiqAeServiceModelBase.wrap_results(v)
@attributes[k] = value unless value.nil?
end
end
Expand Down
17 changes: 16 additions & 1 deletion spec/miq_ae_engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def call_automate(obj_type, obj_id)
args[:instance_name] = "DEFAULT"
args[:fqclass_name] = "Factory/StateMachines/ServiceProvision_template"
args[:user_id] = @user.id
args[:miq_group_id] = @user.current_group.id
expect(MiqAeEngine).to receive(:create_automation_object).with("DEFAULT", attrs, :fqclass => "Factory/StateMachines/ServiceProvision_template").and_return('uri')
expect(MiqAeEngine.deliver(args)).to eq(@ws)
end
Expand Down Expand Up @@ -467,6 +468,20 @@ def call_automate(obj_type, obj_id)
end
end

context ".ae_user_object" do
it "user stays in the same group" do
user_obj = MiqAeEngine.ae_user_object(:user_id => @user.id, :miq_group_id => @user.current_group.id)
expect(user_obj.current_group).to eq(@user.current_group)
end

it "user has changed the group" do
requester_group = FactoryGirl.create(:miq_group)
user_obj = MiqAeEngine.ae_user_object(:user_id => @user.id, :miq_group_id => requester_group.id)
expect(user_obj.current_group).to eq(requester_group)
expect(user_obj.current_group).not_to eq(@user.current_group)
end
end

it "a namespace containing a slash is parsed correctly " do
start = "namespace/more_namespace/my_favorite_class"
msg_attrs = "message=testmessage&object_name=REQUEST&request=NOT_THERE"
Expand Down Expand Up @@ -780,7 +795,7 @@ def before_ae_starts(_options); end
let(:test_class_instance) { test_class.new }
let(:workspace) { double("MiqAeEngine::MiqAeWorkspaceRuntime", :root => options) }
let(:user) { FactoryGirl.create(:user_with_group) }
let(:options) { {:user_id => user.id, :object_type => test_class_name} }
let(:options) { {:user_id => user.id, :miq_group_id => user.current_group.id, :object_type => test_class_name} }

it "#before_ae_starts" do
allow(MiqAeEngine).to receive(:create_automation_object).with(any_args).and_return(nil)
Expand Down

0 comments on commit 660b111

Please sign in to comment.