Check :read_work_item on the work item returned by the show endpoint

What does this MR do and why?

The single-item Work Item REST endpoint (GET .../-/work_items/:work_item_iid) authorized :read_work_item only against the container, not against the work item it found. WorkItemsFinder enforces visibility and confidentiality in SQL, but type-level rules such as requirements access live only in the policy, so a requirement-typed work item was still returned when requirements_access_level was disabled.

This runs the same per-item :read_work_item check the list endpoint already runs (!241766 (merged)) and returns 404 Work Item Not Found when it fails, matching the existing confidential and not-found responses on this endpoint.

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 create 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 it and expect 200:

    curl --header "PRIVATE-TOKEN: <token>" "http://gdk.test:3000/api/v4/projects/<project_id>/-/work_items/<iid>"
  4. Disable requirements on the project and fetch again. On master this still returns 200; 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