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

Use base class only when it is supported by direct rbac #14665

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/rbac/filterer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ def search(options = {})
target_ids = targets
# assume klass is passed in
else
target_ids = targets.collect(&:id)
klass = targets.first.class.base_class unless klass.respond_to?(:find)
target_ids = targets.collect(&:id)
klass = targets.first.class
klass = base_class if !klass.respond_to?(:find) && (base_class = rbac_base_class(klass))
end
scope = apply_scope(klass, scope)
scope = apply_select(klass, scope, options[:extra_cols]) if options[:extra_cols]
Expand All @@ -213,7 +214,7 @@ def search(options = {})
klass = targets
klass = klass.klass if klass.respond_to?(:klass)
# working around MiqAeDomain not being in rbac_class
klass = klass.base_class if klass.respond_to?(:base_class) && rbac_class(klass).nil? && rbac_class(klass.base_class)
klass = base_class if (base_class = rbac_base_class(klass))
end
scope = apply_select(klass, scope, options[:extra_cols]) if options[:extra_cols]
end
Expand Down Expand Up @@ -303,6 +304,10 @@ def apply_rbac_through_association?(klass)
klass != VimPerformanceDaily && (klass < MetricRollup || klass < Metric)
end

def rbac_base_class(klass)
klass.base_class if klass.respond_to?(:base_class) && rbac_class(klass).nil? && rbac_class(klass.base_class)
end

def safe_base_class(klass)
klass = klass.base_class if klass.respond_to?(:base_class)
klass
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/rbac/filterer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
end
end

context 'when class does not participate in RBAC' do
let(:miq_ae_domain) { FactoryGirl.create(:miq_ae_domain) }

it 'returns same class as input' do
User.with_user(admin_user) do
results = described_class.search(:targets => [miq_ae_domain]).first
expect(results.first).to be_an_instance_of(MiqAeDomain)
expect(results).to match_array [miq_ae_domain]
end
end
end

describe "with find_options_for_tenant filtering" do
before do
owned_vm # happy path
Expand Down