diff --git a/app/models/custom_button.rb b/app/models/custom_button.rb index 72c297d0398..907a030fa54 100644 --- a/app/models/custom_button.rb +++ b/app/models/custom_button.rb @@ -206,14 +206,14 @@ def evaluate_enablement_expression_for(object) return true unless enablement_expression return false if enablement_expression && !object # list - enablement_expression.lenient_evaluate(object) + enablement_expression.evaluate(object, :lenient => true) end def evaluate_visibility_expression_for(object) return true unless visibility_expression return false if visibility_expression && !object # object == nil, method is called for list of objects - visibility_expression.lenient_evaluate(object) + visibility_expression.evaluate(object, :lenient => true) end # End - Helper methods to support moving automate columns to resource_actions table diff --git a/app/models/miq_report/generator/trend.rb b/app/models/miq_report/generator/trend.rb index 9917f522e8b..9b1df09aaa8 100644 --- a/app/models/miq_report/generator/trend.rb +++ b/app/models/miq_report/generator/trend.rb @@ -52,7 +52,7 @@ def build_results_for_report_trend(options) if conditions tz = User.lookup_by_userid(options[:userid]).get_timezone if options[:userid] - results = results.reject { |obj| conditions.lenient_evaluate(obj, tz) } + results = results.reject { |obj| conditions.evaluate(obj, tz, :lenient => true) } end results = results[0...options[:limit]] if options[:limit] [results] diff --git a/lib/miq_expression.rb b/lib/miq_expression.rb index 4f74c199ebf..05440ec3ca8 100644 --- a/lib/miq_expression.rb +++ b/lib/miq_expression.rb @@ -575,14 +575,9 @@ def self.get_col_info(field, options = {}) } end - def lenient_evaluate(obj, timezone = nil, prune_sql: false) + def evaluate(obj, timezone = nil, prune_sql: false, lenient: false) ruby_exp = to_ruby(timezone, :prune_sql => prune_sql) - ruby_exp.nil? || Condition.subst_matches?(ruby_exp, obj) - end - - def evaluate(obj, tz = nil) - ruby_exp = to_ruby(tz) - Condition.subst_matches?(ruby_exp, obj) + ruby_exp.nil? ? lenient : Condition.subst_matches?(ruby_exp, obj) end def self.evaluate_atoms(exp, obj) diff --git a/lib/rbac/filterer.rb b/lib/rbac/filterer.rb index 860604c7673..3af696099db 100644 --- a/lib/rbac/filterer.rb +++ b/lib/rbac/filterer.rb @@ -919,7 +919,7 @@ def get_belongsto_matches_for_storage(blist) end def matches_search_filters?(obj, filter, timezone, prune_sql: true) - filter.nil? || filter.lenient_evaluate(obj, timezone, :prune_sql => prune_sql) + filter.nil? || filter.evaluate(obj, timezone, :prune_sql => prune_sql, :lenient => true) end end end diff --git a/spec/lib/miq_expression_spec.rb b/spec/lib/miq_expression_spec.rb index 4ce0f2af171..94456447b70 100644 --- a/spec/lib/miq_expression_spec.rb +++ b/spec/lib/miq_expression_spec.rb @@ -1105,7 +1105,7 @@ end end - describe "#lenient_evaluate" do + describe "#evaluate with lenient" do describe "integration" do it "with a find/checkany expression" do host1, host2, host3, host4, host5, host6, host7, host8 = FactoryBot.create_list(:host, 8) @@ -1122,7 +1122,7 @@ "checkany" => {"FROM" => {"field" => "Host.vms-last_scan_on", "value" => ["2011-01-08 17:00", "2011-01-09 23:30:59"]}}, "search" => {"IS NOT NULL" => {"field" => "Host.vms-description"}}}) - result = Host.all.to_a.select { |rec| filter.lenient_evaluate(rec) } + result = Host.all.to_a.select { |rec| filter.evaluate(rec, :lenient => true) } expect(result).to contain_exactly(host3, host5) end @@ -1148,7 +1148,7 @@ "value" => ["2011-01-08 17:00", "2011-01-09 23:30:59"]}}, "checkall" => {"IS NOT NULL" => {"field" => "Host.vms-description"}}} ) - result = Host.all.to_a.select { |rec| filter.lenient_evaluate(rec) } + result = Host.all.to_a.select { |rec| filter.evaluate(rec, :lenient => true) } expect(result).to eq([host2]) end @@ -1156,7 +1156,7 @@ vm = FactoryBot.create(:vm_vmware) expect do - described_class.new("=" => {"field" => "Vm-destroy", "value" => true}).lenient_evaluate(vm) + described_class.new("=" => {"field" => "Vm-destroy", "value" => true}).evaluate(vm, :lenient => true) end.not_to change(Vm, :count) end end