Skip to content

Commit

Permalink
Merge pull request #14852 from lpichler/allow_descendats_of_host_mode…
Browse files Browse the repository at this point in the history
…l_to_use_belongsto_filters

Allow descendants of Host model to use belongsto filters in RBAC
(cherry picked from commit 4bcba39)

https://bugzilla.redhat.com/show_bug.cgi?id=1445075
  • Loading branch information
jrafanie authored and simaishi committed Apr 24, 2017
1 parent 8c57f88 commit f33b7cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rbac/filterer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def apply_select(klass, scope, extra_cols)
end

def get_belongsto_matches(blist, klass)
return get_belongsto_matches_for_host(blist) if klass == Host
return get_belongsto_matches_for_host(blist) if klass <= Host
return get_belongsto_matches_for_storage(blist) if klass == Storage
association_name = klass.base_model.to_s.tableize

Expand Down
15 changes: 15 additions & 0 deletions spec/lib/rbac/filterer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,21 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects)
expect(attrs[:auth_count]).to eq(1)
expect(results3.length).to eq(1)
end

it 'searches Hosts with tag and host & cluster filters' do
group.entitlement = Entitlement.new
group.entitlement.set_belongsto_filters([@cluster_folder_path])
group.entitlement.set_managed_filters([['/managed/environment/prod']])
group.save!

@host_1.tag_with('/managed/environment/prod', :ns => '*')

results, attrs = described_class.search(:class => "Host", :user => user)

expect(attrs[:user_filters]).to eq("managed" => [['/managed/environment/prod']], "belongsto" => [@cluster_folder_path])
expect(attrs[:auth_count]).to eq(1)
expect(results.length).to eq(1)
end
end
end

Expand Down

0 comments on commit f33b7cc

Please sign in to comment.