diff --git a/app/models/mixins/inter_region_api_method_relay.rb b/app/models/mixins/inter_region_api_method_relay.rb index f12653985ce..9def3c4b8ea 100644 --- a/app/models/mixins/inter_region_api_method_relay.rb +++ b/app/models/mixins/inter_region_api_method_relay.rb @@ -71,7 +71,9 @@ def self.api_client_connection_for_region(region_number, user = User.current_use def self.exec_api_call(region, collection_name, action, api_args = nil, id = nil) require 'manageiq-api-client' api_args ||= {} - collection = api_client_connection_for_region(region).public_send(collection_name) + user_name = api_args[:requester]&.fetch("user_name") + user_name = User.current_user&.userid if user_name.blank? + collection = api_client_connection_for_region(region, user_name).public_send(collection_name) collection_or_instance = id ? collection.find(id) : collection result = collection_or_instance.public_send(action, api_args) case result diff --git a/spec/models/mixins/inter_region_api_method_relay_spec.rb b/spec/models/mixins/inter_region_api_method_relay_spec.rb index d8ed9685d74..34843b2185a 100644 --- a/spec/models/mixins/inter_region_api_method_relay_spec.rb +++ b/spec/models/mixins/inter_region_api_method_relay_spec.rb @@ -208,6 +208,7 @@ def expect_api_call(expected_action, expected_args = nil) describe ".exec_api_call" do let(:region) { 0 } + let(:userid) { nil } let(:action) { :the_action } let(:api_connection) { double("ManageIQ::API::Client Connection") } let(:api_collection) { double("ManageIQ::API::Client Collection", :name => collection_name) } @@ -216,7 +217,7 @@ def expect_api_call(expected_action, expected_args = nil) let(:api_resource) { ManageIQ::API::Client::Resource.subclass("test_resource").new(api_collection, {}) } before do - expect(described_class).to receive(:api_client_connection_for_region).with(region).and_return(api_connection) + expect(described_class).to receive(:api_client_connection_for_region).with(region, userid).and_return(api_connection) expect(api_connection).to receive(collection_name).and_return(api_collection) end