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

Ownership refactor #1578

Merged
merged 16 commits into from Jul 20, 2017
Merged

Conversation

PanSpagetka
Copy link
Contributor

@PanSpagetka PanSpagetka commented Jun 21, 2017

Ownership refactor

Compute -> Infrastructure -> VMs -> select VM -> Lifecycle -> Retire/Set Retirement date

@miq-bot miq-bot added the wip label Jun 21, 2017
@PanSpagetka PanSpagetka force-pushed the ownership-refactor branch 3 times, most recently from 1b7b0e4 to ca1e904 Compare June 22, 2017 12:54
@PanSpagetka PanSpagetka changed the title [WIP] Ownership refactor Ownership refactor Jun 27, 2017
@miq-bot miq-bot removed the wip label Jun 27, 2017
Copy link
Member

@romanblanco romanblanco left a 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)
Copy link
Member

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

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

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

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)

Copy link
Contributor

@lpichler lpichler left a 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:

  1. Add RHOS provider with OSP mapping enabled as Admin user
  2. Navigate to Compute -> Clouds -> Providers -> RHOS7GA -> Images
  3. Select one image (without clicking on it).
  4. Configuration -> Set ownership)

taken from #843

end

recs = session[:checked_items]
recs = checked_or_params if recs.nil?
Copy link
Member

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 ?

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

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.

Copy link
Member

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

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

Choose a reason for hiding this comment

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

params[:user] = if ...

@PanSpagetka PanSpagetka force-pushed the ownership-refactor branch 4 times, most recently from 20d3477 to 03842bb Compare July 19, 2017 10:37
@miq-bot
Copy link
Member

miq-bot commented Jul 19, 2017

Checked commits PanSpagetka/manageiq-ui-classic@d116446~...d6ac2d8 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
1 file checked, 5 offenses detected

app/controllers/mixins/actions/vm_actions/ownership.rb

Copy link
Member

@romanblanco romanblanco left a 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 👍

@martinpovolny martinpovolny merged commit 0719317 into ManageIQ:master Jul 20, 2017
@martinpovolny martinpovolny added this to the Sprint 65 Ending Jul 24, 2017 milestone Jul 20, 2017

def ownership_handle_save_button
opts = {}
opts[:owner] = unless params[:user] == 'dont-change'
Copy link
Contributor

@himdel himdel Dec 7, 2018

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

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.

None yet

8 participants