-
Notifications
You must be signed in to change notification settings - Fork 358
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
Conversation
app/helpers/configuration_helper.rb
Outdated
|
||
# Returns with a hash of allowed quadicons for the current user | ||
def allowed_quadicons | ||
MiqDecorator.descendants. # Get all the decorator classes |
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.
@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?
@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
@skateman unrecognized command 'add_reviwer', ignoring... Accepted commands are: add_label, add_reviewer, assign, close_issue, move_issue, remove_label, rm_label, set_milestone |
@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 add_reviewer @martinpovolny |
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. |
1423be7
to
dafe401
Compare
This pull request is not mergeable. Please rebase and repush. |
dafe401
to
9b9aa30
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.
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 |
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.
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| |
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.
very slick
|
||
# Returns with a hash of allowed quadicons for the current user | ||
def allowed_quadicons | ||
MiqDecorator.descendants # Get all the decorator classes |
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.
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| |
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.
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) |
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.
not a fan, but seems necessary
end | ||
|
||
# Returns with a hash of allowed quadicons for the current user | ||
def allowed_quadicons |
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.
really like that this is "allowed" quadicons
app/helpers/configuration_helper.rb
Outdated
# 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 |
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.
does method_defined?(:quadicon)
work instead of klass.new(nil).respond_to?(:quadicon)
?
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.
It does and I like it more, calling new
145 times less 😉
9b9aa30
to
dd53858
Compare
This pull request is not mergeable. Please rebase and repush. |
dd53858
to
817ded5
Compare
Checked commit skateman@817ded5 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 **
|
@kbrock is this one ok to merge? |
@mzazrivec I think @kbrock is okay with this, but I'd like @martinpovolny to take a look at this. |
I like it! We need to write more parts of the UI like this. I like this guy ;-) Let's merge it. @kbrock ? |
I do wish we could have written Lets just keep that in mind as we move forward and introduce similar refactoring |
@martinpovolny there's also a schema PR but it won't break anything if this gets merged first. |
@@ -46,8 +30,6 @@ | |||
@edit[:new][:display][:quad_truncate]), | |||
:class => "selectpicker") | |||
|
|||
:javascript | |||
miqSelectPickerEvent("quad_truncate", "#{url}") |
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.
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 theui_1.html.haml
. So instead of usingbase_model
+ exceptions I'm proposing to decorate the given class and remove theDecorator
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 inDEFAULT_SETTINGS
, as by default all of them default totrue
.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 usingui_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