Return 404 when a work item sub-resource read is denied

What does this MR do and why?

The work item sub-resource endpoints (/-/work_items/:iid/notes, /discussions, /children, /award_emoji, and the rest) authorize the parent work item through authorize_work_item_feature!, which used authorize! and returned 403 Forbidden when the user could not read it. The show endpoint returns 404 Work Item Not Found for the same denial since !264355 (merged), so the two disagreed, and the 403 confirmed that a work item exists at that IID even when the caller may not read it.

This changes the helper to respond with not_found!('Work Item') instead. Every sub-resource route goes through it, so one change covers them all. The issue and notes REST APIs already behave this way for an unreadable record.

References

Screenshots or screen recordings

Not applicable, API-only change.

How to set up and validate locally

  1. Enable the flag for your user in a Rails console:

    Feature.enable(:work_item_rest_api, User.find_by(username: 'root'))
  2. Create a requirement work item in a project with requirements licensed, and a personal access token with the api scope:

    project = Project.find_by_full_path('<group>/<project>')
    wi = WorkItem.create!(project: project, author: User.first, title: 'Requirement',
      work_item_type: WorkItems::TypesFramework::SystemDefined::Type.find_by(base_type: 'requirement'))
    puts wi.iid
  3. Fetch a sub-resource and expect 200:

    curl --header "PRIVATE-TOKEN: <token>" "http://gdk.test:3000/api/v4/projects/<project_id>/-/work_items/<iid>/notes"
  4. Disable requirements on the project and fetch again. On master this returns 403 Forbidden; with this change it returns 404 Work Item Not Found:

    project.project_feature.update!(requirements_access_level: ProjectFeature::DISABLED)

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports

Loading
Loading