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

Add middleware models to direct RBAC #15011

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
6 changes: 6 additions & 0 deletions lib/rbac/filterer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class Filterer
Host
LoadBalancer
MiqCimInstance
MiddlewareDatasource
MiddlewareDeployment
MiddlewareDomain
MiddlewareMessaging
MiddlewareServer
MiddlewareServerGroup
NetworkPort
NetworkRouter
OrchestrationTemplate
Expand Down
41 changes: 36 additions & 5 deletions spec/lib/rbac/filterer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,45 @@
}
end

context "with User and Group" do
def get_rbac_results_for_and_expect_objects(klass, expected_objects)
User.current_user = user
def get_rbac_results_for_and_expect_objects(klass, expected_objects)
User.current_user = user

results = described_class.search(:class => klass).first
expect(results).to match_array(expected_objects)
end

results = described_class.search(:class => klass).first
expect(results).to match_array(expected_objects)
context 'with Middleware models' do
context 'with tags' do
before do
group.entitlement = Entitlement.new
group.entitlement.set_belongsto_filters([])
group.entitlement.set_managed_filters([["/managed/environment/prod"]])
group.save!
end

let(:count_of_created_instances) { 2 }

%w(
MiddlewareDatasource
MiddlewareDeployment
MiddlewareDomain
MiddlewareMessaging
MiddlewareServer
MiddlewareServerGroup
).each do |middleware_model|
it "returns tagged instance of #{middleware_model}" do
middleware_instances = FactoryGirl.create_list(middleware_model.tableize.singularize.to_sym,
count_of_created_instances)
middleware_instances[0].tag_with('/managed/environment/prod', :ns => '*')
middleware_model_class = middleware_model.constantize
expect(middleware_model_class.count).to eq(count_of_created_instances)
get_rbac_results_for_and_expect_objects(middleware_model_class, [middleware_instances[0]])
end
end
end
end

context "with User and Group" do
context 'with tags' do
let!(:tagged_group) { FactoryGirl.create(:miq_group, :tenant => default_tenant) }
let!(:user) { FactoryGirl.create(:user, :miq_groups => [tagged_group]) }
Expand Down