Skip to content

Commit

Permalink
Fixes #31836 - Unclear error message for cvv promotion with bad perrms (
Browse files Browse the repository at this point in the history
Katello#9153)

(cherry picked from commit 1bba15f)
  • Loading branch information
ianballou authored and jturel committed Mar 4, 2021
1 parent 25f978f commit a35919b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion app/controllers/katello/concerns/api/v2/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,20 @@ def find_unauthorized_katello_resource
end

def throw_resource_not_found(name: resource_name, id: params[:id])
fail HttpErrors::NotFound, _("Could not find %{name} resource with id %{id}") % {id: id, name: name}
perms_message = "Potential missing permissions: " +
missing_permissions.map(&:name).join(', ')
fail HttpErrors::NotFound, _("Could not find %{name} resource with id %{id}. %{perms_message}") % {id: id, name: name, perms_message: perms_message}
end

def missing_permissions
missing_perms = ::Foreman::AccessControl.permissions_for_controller_action(path_to_authenticate)

# 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"])
missing_perms << ::Permission.find_by(name: "promote_or_remove_content_views_to_environments")
end
missing_perms
end

def throw_resources_not_found(name:, expected_ids: [])
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v2/repository_sets_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def test_invalid_product_failure

results = JSON.parse(response.body)

error_message = "Could not find product resource with id #{fake_product_id}"
error_message = "Could not find product resource with id #{fake_product_id}. Potential missing permissions: edit_products"

assert_response :not_found
assert_includes results["errors"], error_message
Expand Down

0 comments on commit a35919b

Please sign in to comment.