From 070bf88bf5c3754d743766db8366671f59a63c12 Mon Sep 17 00:00:00 2001 From: jaisejose1123 Date: Mon, 8 Apr 2024 17:01:41 +0530 Subject: [PATCH] fixed the link errors --- lib/rbac/filterer.rb | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/rbac/filterer.rb b/lib/rbac/filterer.rb index 89f13b23dcf..42946a5f794 100644 --- a/lib/rbac/filterer.rb +++ b/lib/rbac/filterer.rb @@ -339,9 +339,9 @@ def search(options = {}) auth_count = inner_scope.except(:offset, :limit, :order).count(:all) end end - - targets = scope unless targets[0][:objectIds].present? - + + targets = scope if targets[0][:objectIds].blank? + unless options[:skip_counts] auth_count ||= attrs[:apply_limit_in_sql] && limit ? targets.except(:offset, :limit, :order).count(:all) : targets.length end @@ -368,14 +368,10 @@ 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 - if targets.kind_of?(Array) - targets = targets - else - targets = targets.sort_by { |a| target_ids.index(a.id) } - end + if !target_ids.nil? && !order && !targets.kind_of?(Array) + targets = targets.sort_by { |a| target_ids.index(a.id) } end targets = targets.to_a if targets.kind_of?(Enumerator::Lazy) @@ -512,7 +508,7 @@ def rbac_class(scope) # So once calc_filtered_ids uses pluck_ids for all, then that filter # can converted across to a 100% sql friendly query def pluck_ids(targets) - targets.pluck(:id) if targets + targets&.pluck(:id) end def self_service_ownership_scope?(miq_group, klass) @@ -596,14 +592,14 @@ def scope_by_ids(scope, filtered_ids) end def get_belongsto_filter_object_ids(klass, filter) - return nil if !BELONGSTO_FILTER_CLASSES.include?(safe_base_class(klass).name) || filter.blank? + return nil if BELONGSTO_FILTER_CLASSES.exclude?(safe_base_class(klass).name) || filter.blank? get_belongsto_matches(filter, rbac_class(klass)).collect(&:id) end def get_managed_filter_object_ids(scope, filter) klass = scope.respond_to?(:klass) ? scope.klass : scope - return nil if !TAGGABLE_FILTER_CLASSES.include?(safe_base_class(klass).name) || filter.blank? + return nil if TAGGABLE_FILTER_CLASSES.exclude?(safe_base_class(klass).name) || filter.blank? return scope.where(filter.to_sql.first) if filter.kind_of?(MiqExpression) scope.find_tags_by_grouping(filter, :ns => '*').reorder(nil) @@ -930,4 +926,3 @@ def matches_search_filters?(obj, filter, timezone, prune_sql: true) end end end -