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

Refactor quadicon settings logic under My Settings #4034

Merged
merged 1 commit into from
Jun 14, 2018

Conversation

skateman
Copy link
Member

@skateman skateman commented Jun 4, 2018

Instead of explicitly specifying the quadicon settings in three different places, we can just determine things from our beloved decorators. When adding a new model, now it's enough to have the decorator with the quadicon method and everything will be sorted out automagically.

The key naming for quadicon types was too fragmented in DEFAULT_SETTINGS. Adding new exceptions just made the code more chaotic and it was necessary to keep this sync with the big ugly structure in the ui_1.html.haml. So instead of using base_model + exceptions I'm proposing to decorate the given class and remove the Decorator from the resulted class' name. Then this class should be demodulized and converted to snake_case and so we have our new key. We don't even have to declare each of those in DEFAULT_SETTINGS, as by default all of them default to true.

In the UI it's easy to retrieve all decorators that respond to the quadicon method and each of them can be mapped to the key described above using the same procedure. The proper model names can be retrieved using ui_lookup so we can get rid of the big ugly structure.

The RBAC is a little bit tricky, in general the feature field in the big ugly structure is not a good enough solution as not just the _show_list features can lead to quadicon rendering. As the quadicon settings are per-user, I assume the slider/checkbox hiding here has been introduced because we have deployments where only some features are exposed for a given user and we don't want this user to know about the possibility of others. Based on this I think we can be a little bit more permissive and display the quadicon setting if there's at least one rule allowed in the given feature subtree.

Mapping the models into RBAC features was made by calling model_name.singular_route_key on the given model class. I have a feeling that this is too good to be true and I might be totally wrong about this. There's a double twist with the storage managers, but I'm addressing this in a separate core PR.

If you have read all the text above, I have a little test, that if you pass, I will buy you a 🍺
If you want to read more, look at #4027 😉

Depends on:
ManageIQ/manageiq-schema#213
ManageIQ/manageiq#17512
ManageIQ/manageiq#17513
#4030
#4026

@miq-bot add_label refactoring, gaprindashvili/no, pending core


# Returns with a hash of allowed quadicons for the current user
def allowed_quadicons
MiqDecorator.descendants. # Get all the decorator classes
Copy link
Member Author

Choose a reason for hiding this comment

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

@kbrock I'm a little bit concerned about the descendants method here. It's a little bit slow for the first run in development, but I assume it's faster in production as we have eager_load. Is this correct?

@miq-bot
Copy link
Member

miq-bot commented Jun 4, 2018

@skateman unrecognized command 'add_reviwer', ignoring...

Accepted commands are: add_label, add_reviewer, assign, close_issue, move_issue, remove_label, rm_label, set_milestone

2 similar comments
@miq-bot
Copy link
Member

miq-bot commented Jun 4, 2018

@skateman unrecognized command 'add_reviwer', ignoring...

Accepted commands are: add_label, add_reviewer, assign, close_issue, move_issue, remove_label, rm_label, set_milestone

@miq-bot
Copy link
Member

miq-bot commented Jun 4, 2018

@skateman unrecognized command 'add_reviwer', ignoring...

Accepted commands are: add_label, add_reviewer, assign, close_issue, move_issue, remove_label, rm_label, set_milestone

@miq-bot miq-bot added the wip label Jun 4, 2018
@skateman
Copy link
Member Author

skateman commented Jun 4, 2018

@miq-bot add_reviewer @martinpovolny
@miq-bot add_reviewer @himdel
@miq-bot add_reviewer @PanSpagetka

@skateman
Copy link
Member Author

skateman commented Jun 4, 2018

We might need to write a migration that converts old settings keys to the new format in the DB, but I'm not sure about this.

@skateman skateman force-pushed the quadicon-selection-logic branch 4 times, most recently from 1423be7 to dafe401 Compare June 4, 2018 16:58
@miq-bot
Copy link
Member

miq-bot commented Jun 4, 2018

This pull request is not mergeable. Please rebase and repush.

Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

sure gets rid of a bunch of hardcoded lists \o/

:storage => true,
:vm => true
},
:quadicons => Hash.new(true), # Show quad icons by resource type, true by default
Copy link
Member

Choose a reason for hiding this comment

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

nice

@edit[:new][:quadicons][:miq_template] = params[:quadicons_miq_template] == "true" if params[:quadicons_miq_template]
if ::Settings.product.proto # Hide behind proto setting - Sprint 34
@edit[:new][:quadicons][:service] = params[:quadicons_service] == "true" if params[:quadicons_service]
view_context.allowed_quadicons.each_key do |key|
Copy link
Member

Choose a reason for hiding this comment

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

very slick


# Returns with a hash of allowed quadicons for the current user
def allowed_quadicons
MiqDecorator.descendants # Get all the decorator classes
Copy link
Member

Choose a reason for hiding this comment

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

descendants make me nervous. but seems to be our trend

@edit[:new][:quadicons][icons_checkbox[2].to_sym], :data => {:on_text => _('Yes'), :off_text => _('No')})
:javascript
miqInitBootstrapSwitch("quadicons_#{icons_checkbox[2]}", "#{url}")
- allowed_quadicons.each do |key, name|
Copy link
Member

Choose a reason for hiding this comment

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

nice

@@ -1,3 +1,31 @@
module ConfigurationHelper
include_concern 'ConfigurationViewHelper'

# Model class name comparison method that sorts provider models first
def compare_decorator_class(a, b)
Copy link
Member

Choose a reason for hiding this comment

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

not a fan, but seems necessary

end

# Returns with a hash of allowed quadicons for the current user
def allowed_quadicons
Copy link
Member

Choose a reason for hiding this comment

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

really like that this is "allowed" quadicons

# Returns with a hash of allowed quadicons for the current user
def allowed_quadicons
MiqDecorator.descendants # Get all the decorator classes
.select { |klass| klass.new(nil).respond_to?(:quadicon) } # Select only the decorators that define a quadicon
Copy link
Member

Choose a reason for hiding this comment

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

does method_defined?(:quadicon) work instead of klass.new(nil).respond_to?(:quadicon)?

Copy link
Member Author

Choose a reason for hiding this comment

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

It does and I like it more, calling new 145 times less 😉

@miq-bot miq-bot changed the title [WIP] Refactor quadicon settings logic under My Settings Refactor quadicon settings logic under My Settings Jun 6, 2018
@miq-bot miq-bot removed the wip label Jun 6, 2018
@skateman skateman changed the title Refactor quadicon settings logic under My Settings [WIP] Refactor quadicon settings logic under My Settings Jun 6, 2018
@mzazrivec mzazrivec added the wip label Jun 6, 2018
@miq-bot
Copy link
Member

miq-bot commented Jun 6, 2018

This pull request is not mergeable. Please rebase and repush.

@miq-bot
Copy link
Member

miq-bot commented Jun 6, 2018

Checked commit skateman@817ded5 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
5 files checked, 1 offense detected

**

  • 💣 💥 🔥 🚒 - Linter/Haml - Linter::Haml STDERR:
warning: parser/current is loading parser/ruby23, which recognizes
warning: 2.3.6-compliant syntax, but you are running 2.3.3.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.

@skateman skateman changed the title [WIP] Refactor quadicon settings logic under My Settings Refactor quadicon settings logic under My Settings Jun 6, 2018
@miq-bot miq-bot removed the wip label Jun 6, 2018
@mzazrivec
Copy link
Contributor

@kbrock is this one ok to merge?

@skateman
Copy link
Member Author

@mzazrivec I think @kbrock is okay with this, but I'd like @martinpovolny to take a look at this.

@martinpovolny
Copy link
Member

I like it! We need to write more parts of the UI like this. I like this guy ;-)

Let's merge it. @kbrock ?

@kbrock
Copy link
Member

kbrock commented Jun 13, 2018

I do wish we could have written allowed_quadicons differently. We are calculating essentially static information on each page load.

Lets just keep that in mind as we move forward and introduce similar refactoring
LGTM 👍 :shipit:

@skateman
Copy link
Member Author

@martinpovolny there's also a schema PR but it won't break anything if this gets merged first.

@mzazrivec mzazrivec self-assigned this Jun 14, 2018
@mzazrivec mzazrivec added this to the Sprint 88 Ending Jun 18, 2018 milestone Jun 14, 2018
@mzazrivec mzazrivec merged commit f206593 into ManageIQ:master Jun 14, 2018
@skateman skateman deleted the quadicon-selection-logic branch June 14, 2018 09:42
@@ -46,8 +30,6 @@
@edit[:new][:display][:quad_truncate]),
:class => "selectpicker")

:javascript
miqSelectPickerEvent("quad_truncate", "#{url}")
Copy link
Contributor

Choose a reason for hiding this comment

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

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