Skip to content

Commit

Permalink
Fixes #37237 - Allow repairing content view versions (Katello#10923)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 authored Mar 8, 2024
1 parent 8bedda9 commit a3651e4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/katello/concerns/api/v2/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions app/lib/actions/katello/content_view_version/verify_checksum.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions config/routes/api/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/katello/permission_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ 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',
:finder_scope => :publishable
@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
Expand Down

0 comments on commit a3651e4

Please sign in to comment.