-
Notifications
You must be signed in to change notification settings - Fork 356
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 rbac check to toolbar button for New Host Aggregates create new action #2980
Add rbac check to toolbar button for New Host Aggregates create new action #2980
Conversation
@miq-bot add_label gaprindashvili/yes |
b648a26
to
ed39718
Compare
@lpichler : I see no problem with the approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is good, everything else in the comments.
def disabled? | ||
super || ManageIQ::Providers::CloudManager.all.none? { |ems| ems.supports?(:create_host_aggregate) } | ||
self[:title] = _("No cloud providers support creating host aggregates.") unless supports_button_action? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No cloud provider supports creating host aggregates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also you should use @error_message
instead of the self[:title]
as in other buttons.
def supports_button_action? | ||
@supported_button_action ||= begin | ||
filtered_providers = Rbac::Filterer.filtered(ManageIQ::Providers::CloudManager) | ||
filtered_providers.empty? ? false : filtered_providers.all? { |ems| ems.supports?(:create_host_aggregate) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this here any?
instead of all?
, I assume it's enough to have a single provider that supports the thing. Also the ternary operator seems unnecessary to me, is it gaining some extra performance?
spec/support/rbac_helper.rb
Outdated
@group = FactoryGirl.create(:miq_group, :tenant => @tenant) | ||
@user = FactoryGirl.create(:user, :miq_groups => [@group]) | ||
login_as | ||
@user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't want this as login_as @user
on a single line?
spec/support/rbac_helper.rb
Outdated
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you REALLY need the instance variables in this module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure let
can be used here, maybe with a single let!
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot the keyword: https://relishapp.com/rspec/rspec-core/docs/example-groups/shared-context
|
||
it_behaves_like 'a disabled button' | ||
context 'when provider is not available due to RBAC rules' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when
is unnecessary, can be assumed from the context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but you can also go with due to RBAC rules
as the context will be concatenated with the previous one
setup_user_with_tenant | ||
end | ||
|
||
let!(:provider) { FactoryGirl.create(:ems_openstack, :tenant => @tenant) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use the !
here, rather force the provider
creation in a before block when necessary.
Also the @tenant
seems scary, you should not have instance variables as you can use let
...
|
||
describe '#disabled?' do | ||
subject { button[:title] } | ||
|
||
context 'no provider available' do | ||
before { button.calculate_properties } | ||
before do | ||
provider.destroy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YAGNI if the provider has let
only.
def disabled? | ||
super || ManageIQ::Providers::CloudManager.all.none? { |ems| ems.supports?(:create_host_aggregate) } | ||
self[:title] = _("No cloud providers support creating host aggregates.") unless supports_button_action? | ||
super || !supports_button_action? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're using the @error_message
, you can have super || @error_message.present?
here.
button.calculate_properties | ||
end | ||
|
||
it_behaves_like 'a disabled button', "No cloud providers support creating host aggregates." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is definitely invalid if you're testing against the same error message twice...it should have the error message you've set above.
def supports_button_action? | ||
@supported_button_action ||= begin | ||
filtered_providers = Rbac::Filterer.filtered(ManageIQ::Providers::CloudManager) | ||
filtered_providers.empty? ? false : filtered_providers.all? { |ems| ems.supports?(:create_host_aggregate) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this filtered_providers.all? { |ems| ems.supports?(:create_host_aggregate) }
?
Shouldn't this be filtered_providers.any? { |ems| ems.supports?(:create_host_aggregate) }
?
ed39718
to
23d66dd
Compare
@skateman @mzazrivec thanks a lot for your feedback, I updated PR according to your suggestions. Please re-review. |
23d66dd
to
1855f58
Compare
@@ -1,5 +1,13 @@ | |||
class ApplicationHelper::Button::NewHostAggregate < ApplicationHelper::Button::ButtonNewDiscover | |||
def supports_button_action? | |||
@supported_button_action ||= begin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it is not needed, I am not calling it twice now.
spec/support/rbac_helper.rb
Outdated
@@ -0,0 +1,31 @@ | |||
module Spec | |||
module Support | |||
module RBACHelper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the modules around, just put it into the folder where other shared examples live
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
5540b69
to
8e5fa55
Compare
@lpichler could you please be more specific in your last 2 commit messages? Or squash them with the previous one, thanks. |
96e0ac9
to
5843135
Compare
5843135
to
ff6646d
Compare
…essage for button
ff6646d
to
96cadc8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked commits lpichler/manageiq-ui-classic@171d5a2~...96cadc8 with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0 |
…_create_action Add rbac check to toolbar button for New Host Aggregates create new action (cherry picked from commit 31d234d)
Gaprindashvili backport details:
|
RBAC check to the toolbar button for New Host Aggregates for create new action:
Compute -> Cloud -> Host Aggregates
after
I am going to do similar thing in more screens, so please review and then I will use it in others screen.
What I am doing here:
cc @skateman
@miq-bot add_label bug, rbac
@miq-bot assign @martinpovolny
Links
https://bugzilla.redhat.com/show_bug.cgi?id=1516229 (around 10 % done by this PR)