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
  • Loading branch information
ianballou committed Feb 10, 2021
1 parent 5082180 commit 399f9cd
Showing 1 changed file with 14 additions and 1 deletion.
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

0 comments on commit 399f9cd

Please sign in to comment.