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 rbac check to toolbar button for New Host Aggregates create new action #2980

Conversation

lpichler
Copy link
Contributor

@lpichler lpichler commented Dec 7, 2017

RBAC check to the toolbar button for New Host Aggregates for create new action:
Compute -> Cloud -> Host Aggregates
after
screen shot 2017-12-07 at 17 50 29

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:

  • added rbac check
  • add disabled message
  • added specs
  • added spec module to be able simply use restricted user

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)

@lpichler
Copy link
Contributor Author

lpichler commented Dec 7, 2017

@miq-bot add_label gaprindashvili/yes

@lpichler lpichler force-pushed the add_rbac_checks_to_buttons_for_create_action branch from b648a26 to ed39718 Compare December 7, 2017 17:17
@martinpovolny
Copy link
Member

@lpichler : I see no problem with the approach.

Copy link
Member

@skateman skateman left a 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?
Copy link
Member

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.

Copy link
Member

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) }
Copy link
Member

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?

@group = FactoryGirl.create(:miq_group, :tenant => @tenant)
@user = FactoryGirl.create(:user, :miq_groups => [@group])
login_as
@user
Copy link
Member

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?

end
end
end
end
Copy link
Member

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?

Copy link
Member

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!.

Copy link
Member

Choose a reason for hiding this comment

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


it_behaves_like 'a disabled button'
context 'when provider is not available due to RBAC rules' do
Copy link
Member

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

Copy link
Member

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) }
Copy link
Member

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
Copy link
Member

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?
Copy link
Member

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."
Copy link
Member

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) }
Copy link
Contributor

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) } ?

@lpichler lpichler force-pushed the add_rbac_checks_to_buttons_for_create_action branch from ed39718 to 23d66dd Compare December 13, 2017 13:56
@lpichler
Copy link
Contributor Author

@skateman @mzazrivec thanks a lot for your feedback, I updated PR according to your suggestions. Please re-review.

@lpichler lpichler force-pushed the add_rbac_checks_to_buttons_for_create_action branch from 23d66dd to 1855f58 Compare December 13, 2017 14:13
@lpichler lpichler closed this Dec 13, 2017
@lpichler lpichler reopened this Dec 13, 2017
@@ -1,5 +1,13 @@
class ApplicationHelper::Button::NewHostAggregate < ApplicationHelper::Button::ButtonNewDiscover
def supports_button_action?
@supported_button_action ||= begin
Copy link
Member

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?

Copy link
Contributor Author

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.

@@ -0,0 +1,31 @@
module Spec
module Support
module RBACHelper
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@lpichler lpichler force-pushed the add_rbac_checks_to_buttons_for_create_action branch 2 times, most recently from 5540b69 to 8e5fa55 Compare December 14, 2017 16:29
@skateman
Copy link
Member

@lpichler could you please be more specific in your last 2 commit messages? Or squash them with the previous one, thanks.

@lpichler lpichler force-pushed the add_rbac_checks_to_buttons_for_create_action branch 2 times, most recently from 96e0ac9 to 5843135 Compare December 14, 2017 16:59
@lpichler lpichler force-pushed the add_rbac_checks_to_buttons_for_create_action branch from 5843135 to ff6646d Compare December 15, 2017 11:00
@lpichler lpichler force-pushed the add_rbac_checks_to_buttons_for_create_action branch from ff6646d to 96cadc8 Compare December 15, 2017 11:01
Copy link
Member

@skateman skateman left a comment

Choose a reason for hiding this comment

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

The Seal of Approval

@mzazrivec mzazrivec added this to the Sprint 76 Ending Jan 1, 2018 milestone Dec 15, 2017
@miq-bot
Copy link
Member

miq-bot commented Dec 15, 2017

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
2 files checked, 0 offenses detected
Everything looks fine. 👍

@mzazrivec mzazrivec merged commit 31d234d into ManageIQ:master Dec 15, 2017
@lpichler lpichler deleted the add_rbac_checks_to_buttons_for_create_action branch December 15, 2017 12:33
simaishi pushed a commit that referenced this pull request Dec 18, 2017
…_create_action

Add rbac check to toolbar button for New Host Aggregates create new action
(cherry picked from commit 31d234d)
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit b30d04f54b03c011d39228e8a4328c0b0d0e6532
Author: Milan Zázrivec <[email protected]>
Date:   Fri Dec 15 13:02:36 2017 +0100

    Merge pull request #2980 from lpichler/add_rbac_checks_to_buttons_for_create_action
    
    Add rbac check to toolbar button for New Host Aggregates create new action
    (cherry picked from commit 31d234da1f0fa625fec67765162494bcda7c4abd)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants