Fixes to Rbac::Filterer#skip_references #17429
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a followup to #17141 which handles a few more edge cases that were found in the specs in
manageiq-ui-classic
, in thespec/product/reports_spec.rb
.This addresses two edge cases:
ActiveRecord::NullRelation
scopesWhen a
.none
is applied to the targets, which under the hood changes theActiveRecord::Relation
to aActiveRecord::NullRelation
. This causes.to_sql
method to change so that it always returns a empty string, which will break theEXPLAIN
inRbac::Filterer#include_references
.The fix here was to just update
#skip_references
to do some slight introspection into the scope to determine if the.none
had been applied, and to always return false on the#skip_references
call in the case.Partially SQL supported
MiqExpression
Turns out that
MiqExpression
objects have partial support for:supported_by_sql
, even though the boolean makes it seem like it is yes or no. This means that if you use an "AND" filters with a SQL supported operator like "=" and a none SQL supported operator like "FIND", theexp_sql
andexp_includes
returned fromMiqExpression#to_sql
can be non-nil even if options returned is{:supported_by_sql => false}
.This change does a simple check against the
exp_sql
andexp_includes
if{:supported_by_sql => false}
to confirm at least theexp_sql
is false, and if it isn't, that at least their isn't any includes being added by theMiqExpression
. This is a bit of a shortcut, but we probably can safely assume that theMiqExpression
would add it's own includes if theexp_sql
needed to reference another table, and doing this avoids having to analyze theexp_sql
against the main scope to determine that ourselves.Links