From a607d24ef26aec5fcb5d063fd3285439338cbff3 Mon Sep 17 00:00:00 2001 From: jaisejose1123 Date: Mon, 8 Apr 2024 16:09:52 +0530 Subject: [PATCH] vm_infras API changes for manageiq --- db/fixtures/miq_product_features.yml | 10 ++++++++++ lib/rbac/filterer.rb | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/db/fixtures/miq_product_features.yml b/db/fixtures/miq_product_features.yml index 463a8f6dc552..dc0a8682ae28 100644 --- a/db/fixtures/miq_product_features.yml +++ b/db/fixtures/miq_product_features.yml @@ -4186,6 +4186,16 @@ :feature_type: view :identifier: cloud_database_flavor_show +# Vm Infra +- :name: Vm Infras + :description: Every thing to Vm infras + :feature_type: node + :identifier: vm_infra + :children: + - :name: View + :description: View Vm Infras + :feature_type: view + :identifier: vm_infra_view # Cloud Network - :name: Cloud Networks diff --git a/lib/rbac/filterer.rb b/lib/rbac/filterer.rb index be63e1466aa3..89f13b23dcf3 100644 --- a/lib/rbac/filterer.rb +++ b/lib/rbac/filterer.rb @@ -262,6 +262,8 @@ def search(options = {}) if targets.first.kind_of?(Numeric) target_ids = targets # assume klass is passed in + elsif targets.first.kind_of?(Hash) + target_ids = targets.first[:objectIds] else target_ids = targets.collect(&:id) klass = targets.first.class @@ -337,8 +339,9 @@ def search(options = {}) auth_count = inner_scope.except(:offset, :limit, :order).count(:all) end end - targets = scope - + + targets = scope unless targets[0][:objectIds].present? + unless options[:skip_counts] auth_count ||= attrs[:apply_limit_in_sql] && limit ? targets.except(:offset, :limit, :order).count(:all) : targets.length end @@ -365,10 +368,14 @@ def search(options = {}) end targets = targets.drop(offset.to_i).take(limit.to_i) end - + # Preserve sort order of incoming target_ids if !target_ids.nil? && !order - targets = targets.sort_by { |a| target_ids.index(a.id) } + if targets.kind_of?(Array) + targets = targets + else + targets = targets.sort_by { |a| target_ids.index(a.id) } + end end targets = targets.to_a if targets.kind_of?(Enumerator::Lazy) @@ -923,3 +930,4 @@ def matches_search_filters?(obj, filter, timezone, prune_sql: true) end end end +