-
Notifications
You must be signed in to change notification settings - Fork 24
Fixes #39246 - Add sorting and searching to the new Leapp preupgrade report #171
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
03ad055
Fixes #39246 - Add sorting and searching to the new Leapp preupgrade …
kmalyjur 5ab4fd7
fix bulk_remediate and remove div
kmalyjur 4f667dc
address code review
kmalyjur 9b41075
fix "Fix Selected" with no fixable entries + replace redux-mock-store
kmalyjur 71e7469
add custom layout for preupgrade entries index because of fixable_count
kmalyjur 4c7cf07
replace NoReports snapshot test with RTL
kmalyjur 982e31a
Revert "add custom layout for preupgrade entries index because of fix…
kmalyjur 3721906
fetch fixable count on demand for Select All
kmalyjur 59cf0be
fix PreupgradeReportsTable.test.js
kmalyjur ab900db
fix SelectAllCheckbox count glitch and invalid prop
kmalyjur cf9031e
fix PreupgradeReportsTable.test.js
kmalyjur 8e566f5
review fix - SelectAllCheckbox in model_of_controller
kmalyjur ebbe407
fix subtotal fallback in pagination count
kmalyjur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
app/controllers/api/v2/preupgrade_report_entries_controller.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Api | ||
| module V2 | ||
| class PreupgradeReportEntriesController < ::Api::V2::BaseController | ||
| include ApiAuthorizer | ||
| include Foreman::Controller::AutoCompleteSearch | ||
|
|
||
| skip_before_action :store_redirect_to_url, :reset_redirect_to_url, raise: false | ||
| before_action :find_preupgrade_report, if: -> { params[:preupgrade_report_id].present? } | ||
|
|
||
| api :GET, '/preupgrade_reports/:preupgrade_report_id/preupgrade_report_entries', | ||
| N_('List entries for a specific preupgrade report') | ||
| api :GET, '/preupgrade_report_entries', N_('List all preupgrade report entries') | ||
| param :preupgrade_report_id, :identifier, required: false, | ||
| desc: N_('ID of the preupgrade report') | ||
| param_group :search_and_pagination, ::Api::V2::BaseController | ||
| def index | ||
| @total = resource_scope.count | ||
| @preupgrade_report_entries = resource_scope_for_index | ||
| @subtotal = @preupgrade_report_entries.total_entries | ||
| end | ||
|
|
||
| api :GET, '/preupgrade_report_entries/auto_complete_search', | ||
| N_('Search autocomplete for preupgrade report entries') | ||
| param :search, String, required: false, desc: N_('Search string') | ||
| param :preupgrade_report_id, :identifier, required: false, desc: N_('ID of the preupgrade report') | ||
|
|
||
| api :POST, '/preupgrade_reports/:preupgrade_report_id/preupgrade_report_entries/bulk_remediate', | ||
| N_('Trigger a remediation job for selected preupgrade report entries') | ||
| param :search, String, required: false, desc: N_('Search string') | ||
| param :excluded_ids, Array, required: false, desc: N_('Array of excluded entry IDs') | ||
| def bulk_remediate | ||
| entries = filtered_remediation_entries | ||
| remediation_ids = entries.pluck(:id) | ||
|
|
||
| if remediation_ids.empty? | ||
| return render json: { error: _('No fixable entries found matching the selection.') }, | ||
| status: :unprocessable_entity | ||
| end | ||
|
|
||
| composer = JobInvocationComposer.for_feature( | ||
| 'leapp_remediation_plan', | ||
| target_host_ids(entries), | ||
| { 'remediation_ids' => remediation_ids.join(',') } | ||
| ) | ||
| composer.trigger! | ||
| job_invocation = composer.job_invocation | ||
|
|
||
| render json: { id: job_invocation.id } | ||
| rescue StandardError => e | ||
| Foreman::Logging.exception('Failed to trigger bulk remediation job', e) | ||
| render json: { error: _('An unexpected error occurred while creating the remediation job.') }, | ||
| status: :internal_server_error | ||
| end | ||
|
|
||
| protected | ||
|
|
||
| def model_of_controller | ||
| PreupgradeReportEntry | ||
| end | ||
|
|
||
| def resource_scope(_options = {}) | ||
| scope = if @preupgrade_report | ||
| @preupgrade_report.preupgrade_report_entries | ||
| else | ||
| PreupgradeReportEntry | ||
| end | ||
| scope.joins(:host).merge(Host.authorized(:view_hosts, Host)) | ||
| end | ||
|
|
||
| def resource_scope_for_index(options = {}) | ||
| order_str = params[:order].to_s | ||
| return super unless order_str.match?(/^(severity|risk_factor)\b/i) | ||
| direction = order_str.match?(/desc$/i) ? 'DESC' : 'ASC' | ||
|
|
||
| resource_scope(options) | ||
| .search_for(params[:search].to_s) | ||
| .order_by_severity(direction) | ||
| .paginate(paginate_options) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def filtered_remediation_entries | ||
| combined_search = [params[:search].presence, 'fix_type = command'].compact.join(' AND ') | ||
| entries = resource_scope.search_for(combined_search) | ||
| entries = entries.where.not(id: params[:excluded_ids]) if params[:excluded_ids].present? | ||
| entries | ||
| end | ||
|
|
||
| def target_host_ids(entries) | ||
| host_ids = entries.pluck(:host_id).uniq.compact | ||
| host_ids = [@preupgrade_report.host_id].compact if host_ids.empty? && @preupgrade_report | ||
| host_ids | ||
| end | ||
|
|
||
| def find_preupgrade_report | ||
| @preupgrade_report = PreupgradeReport | ||
| .joins(:host) | ||
| .merge(Host.authorized(:view_hosts, Host)) | ||
| .find(params[:preupgrade_report_id]) | ||
| end | ||
|
|
||
| def path_to_authenticate | ||
| auth_action = case action_name | ||
| when 'auto_complete_search' | ||
| 'index' | ||
| when 'bulk_remediate' | ||
| 'create' | ||
| else | ||
| action_name | ||
| end | ||
| path_params = params.slice(:id, :user_id) | ||
| .merge(action: auth_action, controller: 'api/v2/job_invocations') | ||
| Foreman::AccessControl.normalize_path_hash(path_params) | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| collection @preupgrade_report_entries | ||
| extends 'api/v2/preupgrade_report_entries/base' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,4 @@ | ||
| object @preupgrade_report | ||
| # frozen_string_literal: true | ||
|
|
||
| object @preupgrade_report | ||
| extends 'api/v2/preupgrade_reports/base' | ||
|
|
||
| child :preupgrade_report_entries do | ||
| extends 'api/v2/preupgrade_report_entries/base' | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.