ManageIQ / manageiq

ManageIQ Open-Source Management Platform
https://manageiq.org
Apache License 2.0
1.35k stars 900 forks source link

Fix missing 'storages' association on Datacenter #23252

Closed agrare closed 3 weeks ago

agrare commented 3 weeks ago

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.

#<ActiveRecord::AssociationNotFoundError: Association named 'storages' was not found on ManageIQ::Providers::Vmware::InfraManager::Folder; perhaps you misspelled it?>
gems/activerecord-6.1.7.8/lib/active_record/associations.rb:313:in `association'
gems/activerecord-virtual_attributes-6.1.2/lib/active_record/virtual_attributes/virtual_fields.rb:169:in `block in grouped_records'
gems/activerecord-virtual_attributes-6.1.2/lib/active_record/virtual_attributes/virtual_fields.rb:157:in `each'
gems/activerecord-virtual_attributes-6.1.2/lib/active_record/virtual_attributes/virtual_fields.rb:157:in `grouped_records'
gems/activerecord-virtual_attributes-6.1.2/lib/active_record/virtual_attributes/virtual_fields.rb:148:in                     `preloaders_for_one'
gems/activerecord-6.1.7.8/lib/active_record/associations/preloader.rb:110:in `preloaders_on'
gems/activerecord-6.1.7.8/lib/active_record/associations/preloader.rb:94:in `block in preload'
gems/activerecord-6.1.7.8/lib/active_record/associations/preloader.rb:93:in `each'
gems/activerecord-6.1.7.8/lib/active_record/associations/preloader.rb:93:in `flat_map'
gems/activerecord-6.1.7.8/lib/active_record/associations/preloader.rb:93:in `preload'
/var/www/miq/vmdb/lib/miq_preloader.rb:26:in `preload'
/var/www/miq/vmdb/lib/miq_preloader.rb:48:in `block in preload_and_map'
<internal:kernel>:90:in `tap'
/var/www/miq/vmdb/lib/miq_preloader.rb:48:in `preload_and_map'
/var/www/miq/vmdb/lib/rbac/filterer.rb:918:in `get_belongsto_matches_for_storage'
/var/www/miq/vmdb/lib/rbac/filterer.rb:846:in `get_belongsto_matches'
/var/www/miq/vmdb/lib/rbac/filterer.rb:594:in `get_belongsto_filter_object_ids'
/var/www/miq/vmdb/lib/rbac/filterer.rb:532:in `calc_filtered_ids'
/var/www/miq/vmdb/lib/rbac/filterer.rb:724:in `scope_targets'
/var/www/miq/vmdb/lib/rbac/filterer.rb:297:in `search'
/var/www/miq/vmdb/lib/rbac/filterer.rb:177:in `search'
/var/www/miq/vmdb/lib/rbac.rb:3:in `search'
/var/www/miq/vmdb/lib/rbac/filterer.rb:447:in `filtered'
/var/www/miq/vmdb/lib/rbac/filterer.rb:181:in `filtered'
/var/www/miq/vmdb/lib/rbac.rb:11:in `filtered'
/var/www/miq/vmdb/app/models/miq_search.rb:43:in `filtered'
/var/www/miq/vmdb/app/models/miq_request_workflow.rb:840:in `process_filter'
/var/www/miq/vmdb/app/models/miq_request_workflow.rb:1109:in `allowed_storages'
/var/www/miq/vmdb/app/models/miq_request_workflow.rb:293:in `get_field'
/var/www/miq/vmdb/app/models/miq_request_workflow.rb:280:in `block in get_all_fields'
/var/www/miq/vmdb/app/models/miq_request_workflow.rb:280:in `each_key'
/var/www/miq/vmdb/app/models/miq_request_workflow.rb:280:in `get_all_fields'
/var/www/miq/vmdb/app/models/miq_request_workflow.rb:272:in `get_dialog'
/var/www/miq/vmdb/app/models/miq_request_workflow.rb:264:in `block in get_all_dialogs'
/var/www/miq/vmdb/app/models/miq_request_workflow.rb:264:in `each_key'
/var/www/miq/vmdb/app/models/miq_request_workflow.rb:264:in `get_all_dialogs'
/var/www/miq/vmdb/app/models/miq_provision_virt_workflow.rb:84:in `refresh_field_values'
jrafanie commented 3 weeks ago

Let me know if you're able to write a test for this. 😉

agrare commented 3 weeks ago

Let me know if you're able to write a test for this. 😉

Ha yeah working on it, I thought I had it down but it doesn't fail without the change to EmsFolder so it isn't going down the same exact path. I'll push up what I have now

agrare commented 3 weeks ago

I thought I had it down but it doesn't fail without the change to EmsFolder so it isn't going down the same exact path

Fixed the issue described in :point_up: here: https://github.com/ManageIQ/manageiq/pull/23256

Fryguy commented 3 weeks ago

Backported to radjabov via merge of master into radjabov