From 77267dbdc396267b739959f00f1f29729b320046 Mon Sep 17 00:00:00 2001 From: Lucy Fu Date: Thu, 27 Jul 2017 17:46:38 -0400 Subject: [PATCH] Need to pass the user's group in to automate when the provision starts. 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 --- .../engine/miq_ae_engine.rb | 3 ++- .../engine/miq_ae_engine/miq_ae_object.rb | 2 +- spec/miq_ae_engine_spec.rb | 20 +++++++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/miq_automation_engine/engine/miq_ae_engine.rb b/lib/miq_automation_engine/engine/miq_ae_engine.rb index ea599b4d3..1b7a8c2f9 100644 --- a/lib/miq_automation_engine/engine/miq_ae_engine.rb +++ b/lib/miq_automation_engine/engine/miq_ae_engine.rb @@ -307,7 +307,8 @@ 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? 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]) if options[:miq_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 diff --git a/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb b/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb index 38bbeffa6..7dd70d19c 100644 --- a/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb +++ b/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb @@ -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 diff --git a/spec/miq_ae_engine_spec.rb b/spec/miq_ae_engine_spec.rb index f954e7888..a0ba3cc83 100644 --- a/spec/miq_ae_engine_spec.rb +++ b/spec/miq_ae_engine_spec.rb @@ -79,7 +79,8 @@ def call_automate(obj_type, obj_id) object_type = @cluster.class.name object_id = @cluster.id automate_attrs = {"#{object_type}::#{object_type.underscore}" => object_id, - "User::user" => @user.id} + "User::user" => @user.id, + "MiqGroup::miq_group" => @user.current_group.id} expect(MiqAeEngine).to receive(:create_automation_object).with(@instance_name, automate_attrs, {:vmdb_object => @cluster}).and_return('uri') expect(call_automate(object_type, object_id)).to be_nil end @@ -89,7 +90,8 @@ def call_automate(obj_type, obj_id) object_type = @ems.class.name object_id = @ems.id automate_attrs = {"#{base_name}::#{base_name.underscore}" => object_id, - "User::user" => @user.id} + "User::user" => @user.id, + "MiqGroup::miq_group" => @user.current_group.id} expect(MiqAeEngine).to receive(:create_automation_object).with(@instance_name, automate_attrs, {:vmdb_object => @ems}).and_return('uri') expect(call_automate(object_type, object_id)).to be_nil end @@ -467,6 +469,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) + 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"