From a3651e4b977ad01ae249d58635ec8dfe4474aff5 Mon Sep 17 00:00:00 2001 From: Samir Jha Date: Fri, 8 Mar 2024 14:08:55 -0500 Subject: [PATCH] Fixes #37237 - Allow repairing content view versions (#10923) --- .../v2/content_view_versions_controller.rb | 11 +++++-- .../katello/concerns/api/v2/authorization.rb | 2 +- .../content_view_version/verify_checksum.rb | 29 +++++++++++++++++++ config/routes/api/v2.rb | 1 + lib/katello/permission_creator.rb | 4 +-- 5 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 app/lib/actions/katello/content_view_version/verify_checksum.rb diff --git a/app/controllers/katello/api/v2/content_view_versions_controller.rb b/app/controllers/katello/api/v2/content_view_versions_controller.rb index 851813dccbf..1a9c33f25fe 100644 --- a/app/controllers/katello/api/v2/content_view_versions_controller.rb +++ b/app/controllers/katello/api/v2/content_view_versions_controller.rb @@ -3,8 +3,8 @@ class Api::V2::ContentViewVersionsController < Api::V2::ApiController include ::Api::V2::BulkHostsExtension include Katello::Concerns::FilteredAutoCompleteSearch - before_action :find_authorized_katello_resource, :only => [:show, :update, :promote, :destroy, :republish_repositories] - before_action :find_content_view_from_version, :only => [:show, :update, :promote, :destroy, :republish_repositories] + before_action :find_authorized_katello_resource, :only => [:show, :update, :promote, :destroy, :republish_repositories, :verify_checksum] + before_action :find_content_view_from_version, :only => [:show, :update, :promote, :destroy, :republish_repositories, :verify_checksum] before_action :find_optional_readable_content_view, :only => [:index] before_action :find_environment, :only => [:index] @@ -141,6 +141,13 @@ def incremental_update respond_for_async :resource => task end + api :POST, "/content_view_versions/:id/verify_checksum", N_("Verify checksum of repository contents in the content view version") + param :id, :number, :required => true, :desc => N_("Content view version identifier") + def verify_checksum + task = async_task(::Actions::Katello::ContentViewVersion::VerifyChecksum, @content_view_version) + respond_for_async :resource => task + end + private def calculate_hosts_for_incremental(bulk_params, use_composites) diff --git a/app/controllers/katello/concerns/api/v2/authorization.rb b/app/controllers/katello/concerns/api/v2/authorization.rb index 7abdab39337..067b600d8f6 100644 --- a/app/controllers/katello/concerns/api/v2/authorization.rb +++ b/app/controllers/katello/concerns/api/v2/authorization.rb @@ -49,7 +49,7 @@ def missing_permissions # promote_or_remove_content_views_to_environments has a special relationship to promote_or_remove_content_views if path_to_authenticate["controller"] == "katello/api/v2/content_view_versions" && - path_to_authenticate["action"].in?(["promote", "remove_from_environment", "remove", "republish_repositories"]) + path_to_authenticate["action"].in?(["promote", "remove_from_environment", "remove", "republish_repositories", "verify_checksum"]) missing_perms << ::Permission.find_by(name: "promote_or_remove_content_views_to_environments") end missing_perms diff --git a/app/lib/actions/katello/content_view_version/verify_checksum.rb b/app/lib/actions/katello/content_view_version/verify_checksum.rb new file mode 100644 index 00000000000..3f2c45da54b --- /dev/null +++ b/app/lib/actions/katello/content_view_version/verify_checksum.rb @@ -0,0 +1,29 @@ +module Actions + module Katello + module ContentViewVersion + class VerifyChecksum < Actions::EntryAction + def plan(content_view_version) + action_subject(content_view_version.content_view) + plan_self(:version_id => content_view_version.id) + plan_action(::Actions::BulkAction, ::Actions::Katello::Repository::VerifyChecksum, content_view_version.repositories) if content_view_version.repositories.any? + end + + def run + #dummy run phase to save input and support humanized_name + end + + def humanized_name + if input && input[:version_id] + version = ::Katello::ContentViewVersion.find_by(:id => input[:version_id]) + end + + if version + _("Verify checksum of repositories in %{name} %{version}") % {:name => version.content_view.name, :version => version.version} + else + _("Verify checksum of version repositories") + end + end + end + end + end +end diff --git a/config/routes/api/v2.rb b/config/routes/api/v2.rb index e347c4da073..187faa1122e 100644 --- a/config/routes/api/v2.rb +++ b/config/routes/api/v2.rb @@ -149,6 +149,7 @@ class ActionDispatch::Routing::Mapper post :promote post :export put :republish_repositories + post :verify_checksum end collection do get :auto_complete_search diff --git a/lib/katello/permission_creator.rb b/lib/katello/permission_creator.rb index de7098ea43f..ff2f58fd378 100644 --- a/lib/katello/permission_creator.rb +++ b/lib/katello/permission_creator.rb @@ -134,7 +134,7 @@ def content_view_permissions @plugin.permission :publish_content_views, { 'katello/api/v2/content_views' => [:publish], - 'katello/api/v2/content_view_versions' => [:incremental_update, :republish_repositories], + 'katello/api/v2/content_view_versions' => [:incremental_update, :republish_repositories, :verify_checksum], 'katello/api/v2/content_imports' => [:version, :index] }, :resource_type => 'Katello::ContentView', @@ -142,7 +142,7 @@ def content_view_permissions @plugin.permission :promote_or_remove_content_views, { 'katello/api/v2/content_view_versions' => [:promote], - 'katello/api/v2/content_views' => [:remove_from_environment, :remove, :republish_repositories] + 'katello/api/v2/content_views' => [:remove_from_environment, :remove, :republish_repositories, :verify_checksum] }, :resource_type => 'Katello::ContentView', :finder_scope => :promotable_or_removable