-
Notifications
You must be signed in to change notification settings - Fork 293
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
Conversation
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 |
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.
@jlsherrill thoughts on using the block pattern for throw_resource_not_found
?
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.
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) |
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'd rather have all the missing ids and one error thrown.
235064f
to
383755a
Compare
@parthaa updated! |
…, applicable_errata routes
@@ -3,37 +3,41 @@ module Concerns | |||
module Api::V2::BulkHostsExtensions | |||
extend ActiveSupport::Concern | |||
|
|||
def bulk_hosts_relation(permission, org) |
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.
@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
intoif
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)) |
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 believe .merge gives us the same functionality here without the ugliness
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 the UI. Seems to work well. APJ
…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)
* 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)
…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
Addresses the various resources in HostBulkActionsController and adds a new helper method
throw_each_resource_not_found