Skip to content

Commit

Permalink
Revert "Merge pull request ManageIQ#15367 from lpichler/make_user_fil…
Browse files Browse the repository at this point in the history
…ter_as_restriction"

This reverts commit ed5da67, reversing
changes made to ed707ba.
  • Loading branch information
lpichler committed Apr 20, 2018
1 parent b64c360 commit 2d9d8bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions lib/rbac/filterer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ def calc_filtered_ids(scope, user_filters, user, miq_group, scope_tenant_filter)
end

#
# Algorithm: b_intersection_m = (b_filtered_ids INTERSECTION m_filtered_ids)
# d_union_b_and_m = d_filtered_ids UNION b_intersection_m
# filter = d_union_b_and_m INTERSECTION tenant_filter_ids INTERSECTION u_filtered_ids
# Algorithm: b_intersection_m = (b_filtered_ids INTERSECTION m_filtered_ids)
# u_union_d_union_b_and_m = u_filtered_ids UNION d_filtered_ids UNION b_intersection_m
# filter = u_union_d_union_b_and_m INTERSECTION tenant_filter_ids
#
# a nil as input for any field means it DOES NOT apply the operation(INTERSECTION, UNION)
# a nil as output means there is not filter
Expand All @@ -447,13 +447,13 @@ def calc_filtered_ids(scope, user_filters, user, miq_group, scope_tenant_filter)
# @return [Array<Integer>] target ids for filter

def combine_filtered_ids(u_filtered_ids, b_filtered_ids, m_filtered_ids, d_filtered_ids, tenant_filter_ids)
intersection = ->(operand1, operand2, operand3 = nil) { [operand1, operand2, operand3].compact.reduce(&:&) }
union = ->(operand1, operand2) { [operand1, operand2].compact.reduce(&:|) }
intersection = ->(operand1, operand2) { [operand1, operand2].compact.reduce(&:&) }
union = ->(operand1, operand2, operand3 = nil) { [operand1, operand2, operand3].compact.reduce(&:|) }

b_intersection_m = intersection.call(b_filtered_ids, m_filtered_ids)
d_union_b_intersection_m = union.call(d_filtered_ids, b_intersection_m)
b_intersection_m = intersection.call(b_filtered_ids, m_filtered_ids)
u_union_d_union_b_intersection_m = union.call(u_filtered_ids, d_filtered_ids, b_intersection_m)

intersection.call(d_union_b_intersection_m, tenant_filter_ids, u_filtered_ids)
intersection.call(u_union_d_union_b_intersection_m, tenant_filter_ids)
end

# @param parent_class [Class] Class of parent (e.g. Host)
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/rbac/filterer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def create_group_with_expression(expression)

describe '.combine_filtered_ids' do
# Algorithm (from Rbac::Filterer.combine_filtered_ids):
# Algorithm: b_intersection_m = (b_filtered_ids INTERSECTION m_filtered_ids)
# d_union_b_and_m = d_filtered_ids UNION b_intersection_m
# filter = d_union_b_and_m INTERSECTION tenant_filter_ids INTERSECTION u_filtered_ids
# b_intersection_m = (belongsto_filtered_ids INTERSECTION managed_filtered_ids)
# u_union_d_union_b_and_m = user_filtered_ids UNION descendant_filtered_ids UNION belongsto_filtered_ids
# filter = u_union_d_union_b_and_m INTERSECTION tenant_filter_ids

def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filtered_ids, descendant_filtered_ids, tenant_filter_ids)
Rbac::Filterer.new.send(:combine_filtered_ids, user_filtered_ids, belongsto_filtered_ids, managed_filtered_ids, descendant_filtered_ids, tenant_filter_ids)
Expand Down Expand Up @@ -88,15 +88,15 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt
end

it 'user filter, belongs to and managed filters(self service user, Host & Cluster filter and tags)' do
expect(combine_filtered_ids([1], [2, 3], [3, 4], nil, nil)).to be_empty
expect(combine_filtered_ids([1], [2, 3], [3, 4], nil, nil)).to match_array([1, 3])
end

it 'user filter, belongs to, managed filters and descendants filter(self service user, Host & Cluster filter and tags)' do
expect(combine_filtered_ids([1, 5, 6], [2, 3], [3, 4], [5, 6], nil)).to match_array([5, 6])
expect(combine_filtered_ids([1], [2, 3], [3, 4], [5, 6], nil)).to match_array([1, 3, 5, 6])
end

it 'user filter, belongs to managed filters, descendants filter and tenant filter(self service user, Host & Cluster filter and tags)' do
expect(combine_filtered_ids([1, 6], [2, 3], [3, 4], [5, 6], [1, 6])).to match_array([6])
expect(combine_filtered_ids([1], [2, 3], [3, 4], [5, 6], [1, 6])).to match_array([1, 6])
end

it 'belongs to managed filters, descendants filter and tenant filter(self service user, Host & Cluster filter and tags)' do
Expand Down

0 comments on commit 2d9d8bc

Please sign in to comment.