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

Require cloud tenant list permission for cloud volume #3189

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
2 changes: 2 additions & 0 deletions app/controllers/cloud_volume_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ def detach_finished

def new
assert_privileges("cloud_volume_new")
assert_privileges("cloud_tenant_show_list")

@volume = CloudVolume.new
@in_a_form = true
if params[:storage_manager_id]
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/application_helper/button/cloud_volume_new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def calculate_properties
end
end

def role_allows_feature?
role_allows?(:feature => 'cloud_tenant_show_list')
Copy link
Contributor

Choose a reason for hiding this comment

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

Also missing super && ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok 👍 I will add it in follow up PR #3227

end

# disable button if no active providers support create action
def disabled?
ExtManagementSystem.all.none? { |ems| CloudVolume.class_by_ems(ems).supports_create? }
Expand Down
21 changes: 21 additions & 0 deletions spec/controllers/cloud_volume_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@
end
end

describe "#new" do
let(:feature) { MiqProductFeature.find_all_by_identifier(%w(cloud_volume_new)) }
let(:role) { FactoryGirl.create(:miq_user_role, :miq_product_features => feature) }
let(:group) { FactoryGirl.create(:miq_group, :miq_user_role => role) }
let(:user) { FactoryGirl.create(:user, :miq_groups => [group]) }

before do
EvmSpecHelper.create_guid_miq_server_zone
EvmSpecHelper.seed_specific_product_features(%w(cloud_volume_new))
ApplicationController.handle_exceptions = false

allow(User).to receive(:current_user).and_return(user)
allow(Rbac).to receive(:role_allows?).and_call_original
login_as user
end

it "raises exception wheh used have not privilege" do
expect { post :new, :params => {:button => "new", :format => :js} }.to raise_error(MiqException::RbacPrivilegeException)
end
end

describe "#restore_backup" do
before do
stub_user(:features => :all)
Expand Down