From 7eb283dba6ce3294bd6a2c48c6230409f7541e97 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Fri, 1 Nov 2024 12:13:33 -0400 Subject: [PATCH] Fix missing 'storages' association on Datacenter When provisioning a Vm as a user that belongs to a group with a belongs_to filter applying Rbac on storages fails due to a missing virtual_has_many on the Datacenter base class. --- app/models/ems_folder.rb | 1 + spec/models/miq_request_workflow_spec.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/models/ems_folder.rb b/app/models/ems_folder.rb index 5e965130be5..e89905e6265 100644 --- a/app/models/ems_folder.rb +++ b/app/models/ems_folder.rb @@ -18,6 +18,7 @@ class EmsFolder < ApplicationRecord virtual_has_many :vms, :uses => :all_relationships virtual_has_many :miq_templates, :uses => :all_relationships virtual_has_many :hosts, :uses => :all_relationships + virtual_has_many :storages, :uses => :all_relationships virtual_attribute :folder_path, :string, :uses => :all_relationships diff --git a/spec/models/miq_request_workflow_spec.rb b/spec/models/miq_request_workflow_spec.rb index 4529a26ddeb..d093d63c5bd 100644 --- a/spec/models/miq_request_workflow_spec.rb +++ b/spec/models/miq_request_workflow_spec.rb @@ -348,6 +348,23 @@ expect(workflow.allowed_storages.map(&:id)).to eq([storage_2.id]) end end + + context "with a user with a belongs_to_filter" do + before do + group = workflow.requester.miq_groups.first + group.entitlement = Entitlement.new + group.entitlement.set_managed_filters([]) + group.entitlement.set_belongsto_filters(["/belongsto/ExtManagementSystem|#{ems.name}/EmsFolder|Datacenters"]) + group.save! + end + + it "filters out storages" do + allow(workflow).to receive(:get_source_and_targets).and_return(:ems => workflow.ci_to_hash_struct(ems)) + allow(workflow).to receive(:allowed_hosts_obj).and_return([host]) + + expect(workflow.allowed_storages.map(&:id)).to be_empty + end + end end context "with read-only storages" do