Skip to content

Commit

Permalink
vm_infras API changes for manageiq
Browse files Browse the repository at this point in the history
  • Loading branch information
jaisejose1123 committed Apr 10, 2024
1 parent dfbf8e7 commit 74cd750
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
10 changes: 10 additions & 0 deletions db/fixtures/miq_product_features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 18 additions & 5 deletions lib/rbac/filterer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -337,7 +339,18 @@ def search(options = {})
auth_count = inner_scope.except(:offset, :limit, :order).count(:all)
end
end
targets = scope

if targets.count != 1
targets = scope
else
first_target = targets.first

if first_target.is_a?(Hash) && first_target[:objectIds].blank?
targets = scope
elsif targets.all? { |element| Integer === element }
targets = scope
end
end

unless options[:skip_counts]
auth_count ||= attrs[:apply_limit_in_sql] && limit ? targets.except(:offset, :limit, :order).count(:all) : targets.length
Expand Down Expand Up @@ -367,7 +380,7 @@ def search(options = {})
end

# Preserve sort order of incoming target_ids
if !target_ids.nil? && !order
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)
Expand Down Expand Up @@ -505,7 +518,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)
Expand Down Expand Up @@ -589,14 +602,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)
Expand Down

0 comments on commit 74cd750

Please sign in to comment.