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

Fixes #31159 - Add authorization for HostBulkActionsController #9006

Merged
merged 6 commits into from
Nov 11, 2020

Conversation

jturel
Copy link
Member

@jturel jturel commented Oct 23, 2020

Addresses the various resources in HostBulkActionsController and adds a new helper method throw_each_resource_not_found

@theforeman-bot
Copy link

Issues: #31159

@@ -314,7 +314,9 @@ def find_errata
end

def find_host_collections
@host_collections = HostCollection.where(:id => params[:host_collection_ids])
throw_each_resource_not_found(name: 'host collection', expected_ids: params[:host_collection_ids]) do
Copy link
Member Author

Choose a reason for hiding this comment

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

@jlsherrill thoughts on using the block pattern for throw_resource_not_found ?

Copy link
Contributor

Choose a reason for hiding this comment

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

whats the alternative? Passing the expected_ids as parameter ?

found_ids = resources.map(&:id)
missing_ids = expected_ids.map(&:to_i) - found_ids
missing_ids.each do |id|
throw_resource_not_found(name: name, id: id)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather have all the missing ids and one error thrown.

@jturel
Copy link
Member Author

jturel commented Nov 9, 2020

@parthaa updated!

@@ -3,37 +3,41 @@ module Concerns
module Api::V2::BulkHostsExtensions
extend ActiveSupport::Concern

def bulk_hosts_relation(permission, org)
Copy link
Member Author

Choose a reason for hiding this comment

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

@parthaa after testing it, I don't think it makes much sense to throw error about the missing ids here. The reason being is that the scoped search or restrict parameters can alter the output and so ids which were included may ultimately be excluded. Opted to keep current behavior, but I did a few things to clean this concern up:

  • fail at the start if no ids or search given
  • framed a few of the unless into if for comprehension
  • de-duped some code for the hosts relation
  • used merge for the query when a scoped search is given + other improvement in that area

None of the tests broke, and I added another one for the .merge usage since we didn't have coverage in that case

search_hosts = search_hosts.where(:organization_id => @organization.id) if @organization
search_hosts = search_hosts.search_for(bulk_params[:included][:search])
if @hosts.any?
@hosts = ::Host.where(id: @hosts).or(::Host.where(id: search_hosts))
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe .merge gives us the same functionality here without the ugliness

Copy link
Contributor

@parthaa parthaa 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 the UI. Seems to work well. APJ

@jturel jturel merged commit 686c9c8 into Katello:master Nov 11, 2020
@jturel jturel deleted the host_bulk_actions_auth branch November 11, 2020 20:04
jturel added a commit to jturel/katello that referenced this pull request Nov 17, 2020
…lo#9006)

* Fixes #31159 - Add authorization for HostBulkActionsController

* Refs #31159 - join ids together in error

* Refs #31159 - remove redundant find_hosts call for installable_errata, applicable_errata routes

* Refs #31159 - refactor find_bulk_hosts

* Refs #31159 - clean up bulk host extensions tests

* Refs #31159 - add test for bulk host extensions when no params given

(cherry picked from commit 686c9c8)
jturel added a commit that referenced this pull request Nov 18, 2020
* Fixes #31159 - Add authorization for HostBulkActionsController

* Refs #31159 - join ids together in error

* Refs #31159 - remove redundant find_hosts call for installable_errata, applicable_errata routes

* Refs #31159 - refactor find_bulk_hosts

* Refs #31159 - clean up bulk host extensions tests

* Refs #31159 - add test for bulk host extensions when no params given

(cherry picked from commit 686c9c8)
ranjan pushed a commit to ranjan/katello that referenced this pull request Feb 9, 2021
…lo#9006)

* Fixes #31159 - Add authorization for HostBulkActionsController

* Refs #31159 - join ids together in error

* Refs #31159 - remove redundant find_hosts call for installable_errata, applicable_errata routes

* Refs #31159 - refactor find_bulk_hosts

* Refs #31159 - clean up bulk host extensions tests

* Refs #31159 - add test for bulk host extensions when no params given
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.

3 participants