Return 422 when a managed resource is not publicly accessible

What does this MR do and why?

Resolves #715 (closed)

When an issue or merge request action targets a resource that is private or does not exist, check_public! raised a bare StandardError, which surfaced as a 500.

This MR:

  • introduces GitlabRestService::NotPubliclyAccessibleError, raised by check_public! on a 403 or 404 instead of StandardError.
  • raises GitlabRestService::GitlabResponseFailure for any other unsuccessful response, so rate limits and server errors still return a 500.
  • rescues it in Api::V1::ApiApplicationController, which covers the merge request help, request_review and label actions and the issue assign, unassign, close and label actions.
  • rescues it in ManageMergeRequestController#request_help, which does not inherit from the API base controller.
  • returns a 422 with { "error": "Resource is not publicly accessible" } in both cases, without posting a note or awarding bonus points.
  • regenerates doc/openapi.yaml and types.gen.ts, as the new request specs add a 422 response to all seven affected actions.

Validation steps

  1. bundle exec rspec spec/services/gitlab_rest_service_spec.rb spec/requests/manage_merge_request_controller_spec.rb spec/requests/api/v1/api_application_controller_spec.rb spec/requests/api/v1/manage_merge_request_controller_spec.rb spec/requests/api/v1/manage_issue_controller_spec.rb
  2. bin/generate_api_types
  3. bundle exec rspec

/cc @leetickett-gitlab @mmichaux-ext

Edited by Salim Zidane

Merge request reports

Loading
Loading