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
Ownership refactor #1578
Ownership refactor #1578
Conversation
1b7b0e4
to
ca1e904
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.
@PanSpagetka please see the comments and update PR
@refresh_partial = "layouts/flash_msg" | ||
return | ||
end | ||
ownership_items = recs.collect(&:to_i) |
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 we need ownership_items
variable here in set_ownership
method?
user = record.evm_owner if ownership_items.length == 1 | ||
@user = user ? user.id.to_s : nil | ||
ownershipitems = find_records_with_rbac(klass, ownership_items).sort_by(&:name) | ||
record = ownershipitems.first |
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 part can be extracted in new method, you are using the same code in build_ownership_hash
ownershipitems = find_records_with_rbac(klass, ownership_items).sort_by(&:name)
record = ownershipitems.first
if ownership_items.length > 1
@user = @group = 'dont-change'
else
@user = record.evm_owner&.id&.to_s
@group = record.miq_group&.id&.to_s
end
add_flash(_("All changes have been reset"), :warning) | ||
request.parameters[:controller] == "service" ? replace_right_cell(:nodetype => "ownership") : replace_right_cell | ||
result = klass.set_ownership(param_ids, opts) | ||
unless result == true |
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.
unless result == true
can we get rid of this?
@@ -136,7 +116,7 @@ def build_ownership_hash(ownership_items) | |||
@group = group ? group.id.to_s : nil | |||
Rbac.filtered(MiqGroup).each { |g| @groups[g.description] = g.id.to_s } | |||
@user = @group = 'dont-change' if ownership_items.length > 1 | |||
@ownershipitems = Rbac.filtered(klass.where(:id => ownership_items).order(:name), :class => klass) | |||
@ownershipitems = find_records_with_rbac(klass, ownership_items).sort_by(&: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.
you can use SQL for ordering
@ownershipitems = find_records_with_rbac(klass.order(:name), ownership_items)
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 am getting error:
F, [2017-06-28T15:20:08.564031 #32689] FATAL -- : Error caught: [ActionView::Template::Error] undefined method `count' for nil:NilClass
/Users/liborpichler/manageiq/manageiq-ui-classic/app/views/shared/views/_ownership.html.haml:47:in `___sers_liborpichler_manageiq_manageiq_ui_classic_app_views_shared_views__ownership_html_haml__795864017557801983_70221982635380'
/usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionview-5.0.4/lib/action_view/template.rb:159:in `block in render'
/usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.4/lib/active_support/notifications.rb:166:in `instrument'
/usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionview-5.0.4/lib/action_view/template.rb:354:in `instrument'
/usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionview-5.0.4/lib/action_view/template.rb:157:in `render'
/usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionview-5.0.4/lib/action_view/renderer/partial_renderer.rb:343:in `render_partial'
/usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionview-5.0.4/lib/action_view/renderer/partial_renderer.rb:311:in `block in render'
/usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionview-5.0.4/lib/action_view/renderer/abstract_renderer.rb:42:in `block in instrument'
/usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.4/lib/active_support/notifications.rb:164:in `block in instrument'
/usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
with this scenario:
Test scenario - reach set ownership screen from non-explorer screen
(Steps to Reproduce:
- Add RHOS provider with OSP mapping enabled as Admin user
- Navigate to Compute -> Clouds -> Providers -> RHOS7GA -> Images
- Select one image (without clicking on it).
- Configuration -> Set ownership)
taken from #843
0635b87
to
b71c2b0
Compare
b71c2b0
to
1723e38
Compare
end | ||
|
||
recs = session[:checked_items] | ||
recs = checked_or_params if recs.nil? |
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.
recs = session[:checked_items] || checked_or_params
?
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.
👍
ownership_items = params[:rec_ids] if params[:rec_ids] | ||
build_ownership_info(ownership_items) | ||
ownership_ids = params[:rec_ids] if params[:rec_ids] | ||
@origin_ownership_items = ownership_ids |
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 we really need to introduce a new instance variable in refactored code?
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's not new instance variable, I just change the location where it's set. It's used in ownership.html.haml
.
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 see 👍
opts[:group] = MiqGroup.find_by_id(params[:group]) | ||
end | ||
unless params[:group] == 'dont-change' | ||
if params[:group].blank? # to clear previously set group |
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.
opts[:group] = if ...
def ownership_handle_save_button | ||
opts = {} | ||
unless params[:user] == 'dont-change' | ||
if params[:user].blank? # to clear previously set 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.
params[:user] = if ...
f4db12b
to
b4b864f
Compare
…commit by mistake
20d3477
to
03842bb
Compare
03842bb
to
d6ac2d8
Compare
Checked commits PanSpagetka/manageiq-ui-classic@d116446~...d6ac2d8 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 app/controllers/mixins/actions/vm_actions/ownership.rb
|
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.
Tested in UI, works for me 👍
|
||
def ownership_handle_save_button | ||
opts = {} | ||
opts[:owner] = unless params[:user] == 'dont-change' |
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 breaks multi-target set ownership...
Before, owner
or group
only got assigned to if the user chose to clear the previously set owner/group.
Now, this is always nil, so it's impossible to change user without resetting groups, and vice versa.
Fixing in #5064
Ownership refactor
Compute -> Infrastructure -> VMs -> select VM -> Lifecycle -> Retire/Set Retirement date