diff --git a/app/models/orchestration_template.rb b/app/models/orchestration_template.rb index 173b2e38bbc..adee85e20a5 100644 --- a/app/models/orchestration_template.rb +++ b/app/models/orchestration_template.rb @@ -99,7 +99,7 @@ def parameter_groups # List managers that may be able to deploy this template def self.eligible_managers - ExtManagementSystem.where(:type => eligible_manager_types.collect(&:name)) + Rbac::Filterer.filtered(ExtManagementSystem, :where_clause => {:type => eligible_manager_types}) end delegate :eligible_managers, :to => :class diff --git a/spec/models/orchestration_template_spec.rb b/spec/models/orchestration_template_spec.rb index 00113ec6d0a..e473c765262 100644 --- a/spec/models/orchestration_template_spec.rb +++ b/spec/models/orchestration_template_spec.rb @@ -78,17 +78,31 @@ end describe "#eligible_managers" do + let!(:miq_server) { EvmSpecHelper.local_miq_server } + let(:user_admin) { FactoryGirl.create(:user_admin) } + let(:tenant) { FactoryGirl.create(:tenant) } + let(:other_tenant) { FactoryGirl.create(:tenant) } + let!(:user) { FactoryGirl.create(:user_with_group, :tenant => tenant) } + before do allow(OrchestrationTemplate).to receive_messages(:eligible_manager_types => [ManageIQ::Providers::Amazon::CloudManager, ManageIQ::Providers::Openstack::CloudManager]) @template = FactoryGirl.create(:orchestration_template) - @aws = FactoryGirl.create(:ems_amazon) - @openstack = FactoryGirl.create(:ems_openstack) + @aws = FactoryGirl.create(:ems_amazon, :tenant => other_tenant) + @openstack = FactoryGirl.create(:ems_openstack, :tenant => tenant) end it "lists all eligible managers for a template" do - expect(@template.eligible_managers).to match_array([@aws, @openstack]) + User.with_user(user_admin) do + expect(@template.eligible_managers).to match_array([@aws, @openstack]) + end + end + + it "lists all eligible managers for a template regard to user's tenant" do + User.with_user(user) do + expect(@template.eligible_managers).to match_array([@openstack]) + end end end