Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rbac no references array #19318

Merged
merged 1 commit into from
Oct 3, 2019
Merged

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Sep 20, 2019

This is part 2 of #19127 (look there or in #19295 for the description)

Before

Rbac is passed a hash of relations for use in includes(). It passes relations to references(), which is not correct.

After

The includes() relation hash is converted to an array of table names. So the table names are passed to references(). This lets active record work as it was designed.

This was referenced Sep 20, 2019
@@ -2479,7 +2471,7 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects)

it "adds .references to the scope" do
allow(subject).to receive(:warn)
expect(resulting_scope.references_values).to eq(["{:miq_server=>{}}", "{:host=>{}}"])
expect(resulting_scope.references_values).to eq(%w[miq_servers hosts])
Copy link
Member Author

@kbrock kbrock Sep 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically the fix:

- expect(resulting_scope.references_values).to eq(["{:miq_server=>{}}", "{:host=>{}}"])
+ expect(resulting_scope.references_values).to eq(%w[miq_servers hosts])

Before: there were 2 tables with very ugly names
After: there are 2 tables (with valid names)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was it working before? Is this where it would reference all?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would reference "all"

just looking at it it looks wrong. right?

@kbrock kbrock force-pushed the rbac_no_references_array branch 3 times, most recently from 5e06ee1 to 60a6509 Compare September 27, 2019 16:34
@kbrock
Copy link
Member Author

kbrock commented Sep 27, 2019

UPDATE:

Removed a change to reports as it was tangental.

This was going to remove conditions (i.e. a MiqExpresson) processing from generate_daily_metric_rollup_results because it was a duplicate.

Now, that processing remains.

# Given a nested hash of associations (used by includes)
# convert into an array of table names (used by references)
# If given an array of table names, will output the same array
def self.includes_to_references(klass, inc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a function of rbac? Rbac filtering? Or generic enough to be a AR mixin?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ar mixin

@@ -411,7 +431,7 @@ def include_references(scope, klass, include_for_find, exp_includes, skip)

ref_includes = Hash(include_for_find).merge(Hash(exp_includes))
unless polymorphic_include?(klass, ref_includes)
scope = scope.references(include_for_find).references(exp_includes)
scope = scope.references(self.class.includes_to_references(klass, include_for_find)).references(self.class.includes_to_references(klass, exp_includes))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RE: my comment about where this should be live, it feels like it might make sense to call this like klass.includes_to_references(include_for_find)... so maybe a module added to AR. I could be totally wrong. 😉

@kbrock kbrock force-pushed the rbac_no_references_array branch 2 times, most recently from 007e0f6 to 8d6a13d Compare October 3, 2019 15:45
We are now passing an array of table names into references.

We were passing a nested hash of relations into references which is not
valid.

This is undefined behavior, and not guaranteed to work in the future.
Currently, tails treats this as "just use references for all".

We are introducing includes_to_references.
It  converts an includes compatible (hash of references)
to a references compatible (array of table names)
@miq-bot
Copy link
Member

miq-bot commented Oct 3, 2019

Checked commit kbrock@254dd75 with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
7 files checked, 0 offenses detected
Everything looks fine. ⭐

Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jrafanie jrafanie merged commit a782229 into ManageIQ:master Oct 3, 2019
@jrafanie jrafanie added this to the Sprint 122 Ending Oct 14, 2019 milestone Oct 3, 2019
@jrafanie jrafanie self-assigned this Oct 3, 2019
@kbrock kbrock deleted the rbac_no_references_array branch October 4, 2019 13:54
@chessbyte chessbyte mentioned this pull request Mar 31, 2020
38 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants