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

Refactor combine_filtered_ids in RBAC #15346

Merged
merged 12 commits into from
Jun 14, 2017

Conversation

lpichler
Copy link
Contributor

@lpichler lpichler commented Jun 9, 2017

Goal ⚽

make method combine_filtered_ids more understandable

Motivation πŸ’‘

there is needed some change and it was hard to do it with the previous state.

Description πŸ“‹

This method contained a lot of ifs and it was confusing.

  • there is restructured algorithm in first commits with clarification of INTERSECTION and UNION operations here
  • the algorithm is written with using those operators

See comments in commits for the whole story.

@miq-bot add_label refactoring, rbac

cc @kbrock

@miq-bot assign @gtanzillo

lpichler added 12 commits June 12, 2017 15:03
There are operations like intersection and union in the algorithm.
But these operations are not same as we know from maths.
They can recieve also nil as operand and it means:
don't use this operand and don't apply operator here.

For example mentioned operators works in this way:

[1] INTERSECTION [1, 2] = [1]
[] INTERSECTION [1, 2] = []
nil INTERSECTION [1, 2] = [1, 2]

operands represents filter as array of ids,
when filter is not array but nil
it means don't apply the filter
put intersection of belongs_to and managed filters to one result
These operations are not applying the operation
when any operand is nil and when it is nil
the other operand is returned:

intersection.call([], [1,2])  => []
intersection.call(nil, [1,2]) => [1]
b_intersection_m = (b_filtered_ids INTERSECTION m_filtered_ids)
is
b_intersectionn_m = intersection.call(b_filtered_ids, m_filtered_ids)
and rewrite this line:
u_union_d_union_b_and_m = u_filtered_ids UNION d_filtered_ids UNION b_intersection_m
to
u_union_d_union_b_intersection_m = union.call(u_filtered_ids, d_filtered_ids, b_intersectionn_m)
filter = u_union_d_union_b_and_m INTERSECTION tenant_filter_ids
to
intersection.call(u_union_d_union_b_intersection_m, tenant_filter_ids)
@lpichler lpichler force-pushed the refactor_combine_filtered_ids branch from e260821 to ac0473d Compare June 12, 2017 13:04
@miq-bot
Copy link
Member

miq-bot commented Jun 12, 2017

Checked commits lpichler/manageiq@6b110ad~...ac0473d with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 🍰

Copy link
Member

@gtanzillo gtanzillo left a comment

Choose a reason for hiding this comment

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

This is a really elegant change!! πŸ‘

@gtanzillo gtanzillo added this to the Sprint 63 Ending Jun 19, 2017 milestone Jun 14, 2017
@gtanzillo gtanzillo merged commit dcdfb1d into ManageIQ:master Jun 14, 2017
@lpichler lpichler deleted the refactor_combine_filtered_ids branch June 14, 2017 14:37
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