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

Menu item adding through settings #5617

Merged
merged 5 commits into from
Jun 21, 2019

Conversation

martinpovolny
Copy link
Member

@martinpovolny martinpovolny commented May 22, 2019

https://bugzilla.redhat.com/show_bug.cgi?id=1678151

Requirements:

  • only allow top-level items
  • only at the bottom of the menu
  • only allow items (not sections)

Example (under Server settings, Advanced settings):

:ui:
  :custom_menu:
  - :type: item
    :icon: fa fa-bug
    :id: custom_i1
    :name: Custom Item 1
    :href: https://www.redhat.com
    :rbac: vm_explorer
  - :type: item
    :icon: pficon pficon-help
    :id: custom_i2
    :name: Custom Item 2
    :href: https://www.hmpf.cz
    :rbac: vm_explorer

list of supported icons:

based on the source of the icon the specification is either fa fa-bug (where fa-bug is the font awesome icon) of pf pficon-help (where pficon-help is the patternfly icon) or ff fa-whatever (where ff-whatever is the font fabulous icon).

icons also can be seen in the font-picker when adding new custom buttons

rbac is an existing RBAC feature indentifier that must exist in the product or be added via the extension mechanism added in
ManageIQ/manageiq#18806

Added menu item does not appear as the top-level item in the RBAC tree (under Settings --> Access controll --> Roles).

@miq-bot miq-bot added the wip label May 22, 2019
@mzazrivec mzazrivec changed the title [WIP] Menu item/sections adding though settings [WIP] Menu item/sections adding through settings May 22, 2019
@martinpovolny martinpovolny changed the title [WIP] Menu item/sections adding through settings [WIP] Menu item adding through settings May 29, 2019
@martinpovolny martinpovolny force-pushed the menu_settings branch 2 times, most recently from ecba2b4 to 123ebb7 Compare May 29, 2019 09:07
include Singleton

def self.load
instance.load_from_settings
Copy link
Member

Choose a reason for hiding this comment

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

As this is effectively a cache, what happens when someone changes the settings? Are we expecting it to show the new menus or do we expect them to bounce the workers?

Copy link
Member Author

@martinpovolny martinpovolny May 30, 2019

Choose a reason for hiding this comment

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

Yes, it's a cache and I planned to document that a worker restart is needed for this to take effect. Do you have a better idea? Do you think it is better to load the settings each time? Or is there some invalidation mechanism (on Settings.save) that I could utilize?

def load_from_settings
begin
settings = ::Settings.ui.custom_menu
items = (settings || []).map { |i| create_custom_item(HashWithIndifferentAccess.new(i)) }
Copy link
Member

Choose a reason for hiding this comment

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

What happens if there is bad configuration? Will it blow up? I'm not sure what create_custom_menu_item does under the covers.

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea is that if there's a bad configuration something would get logged and the settings will be ignored.
Do you see any problem with this approach?

@Fryguy
Copy link
Member

Fryguy commented May 30, 2019

If we decide to go forward with this, can you also create a PR to add an empty :ui -> :custom_menu section to the built-in settings.yml? Alternately you can add it in this repo since settings is pluggable. I've been on a mission to get rid of "hidden" settings sections, and eventually put in a validator, so trying to avoid adding another one.

@martinpovolny martinpovolny force-pushed the menu_settings branch 5 times, most recently from d2a5d7c to 5738c6b Compare May 30, 2019 17:32
@martinpovolny martinpovolny force-pushed the menu_settings branch 2 times, most recently from de675a0 to e5b75bb Compare May 31, 2019 08:22
@martinpovolny martinpovolny changed the title [WIP] Menu item adding through settings Menu item adding through settings Jun 18, 2019
@miq-bot miq-bot removed the wip label Jun 18, 2019
@martinpovolny
Copy link
Member Author

@Fryguy : I see no further comments from you in the last 18 days (since I addressed your previous feedback).

I rebased now. Pinging @mzazrivec and @himdel to finish the review.

Thx!

@himdel
Copy link
Contributor

himdel commented Jun 18, 2019

Re failing tests... should the tree node be looking at @object.feature and not @object.rbac? What's the difference between feature and rbac?

@martinpovolny
Copy link
Member Author

Re failing tests... should the tree node be looking at @object.feature and not @object.rbac? What's the difference between feature and rbac?

https://github.com/ManageIQ/guides/blob/master/ui/menus.md says:

Feature key is used in parent section calculation such as visibility of the parent section.

Rbac_feature is a hash that is passed to role_allows? call when decision is being made about displaying the menu item. In most cases, this is would contain just the key :feature that will match the feature.

Honestly I do not remember details, but the :any => true part is needed. Someone could refactor this so that only one feature is needed.

Looking at the tests.

@miq-bot
Copy link
Member

miq-bot commented Jun 19, 2019

Checked commits martinpovolny/manageiq-ui-classic@590486d~...99d5cb8 with ruby 2.3.3, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
8 files checked, 0 offenses detected
Everything looks fine. 🍰

@mzazrivec mzazrivec self-assigned this Jun 21, 2019
@mzazrivec mzazrivec added this to the Sprint 114 Ending Jun 24, 2019 milestone Jun 21, 2019
@mzazrivec mzazrivec merged commit 5c66951 into ManageIQ:master Jun 21, 2019
@himdel himdel mentioned this pull request Nov 1, 2019
This was referenced May 22, 2020
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.

5 participants