Let reviewers below Developer set their review state

What does this MR do and why?

Reviewers with the Guest, Planner, Reporter, or Security Manager role can comment, and sometimes approve, but their reviewer state never changes. Submitting a review publishes the comments, but the reviewer still shows as Awaiting review and gets no re-request icon. The API returns 204 and the UI 200, so nothing tells them it failed.

This MR lets any project member set their own reviewer state to reviewed, and be added as a reviewer when they submit. Approvals by eligible Planners and Reporters now show as approved. Request changes still needs Developer or higher, as it does today; letting approvers below Developer request changes is a follow-up MR. Non-members still can't set any reviewer state.

When a reviewer picks Request changes or Approve but isn't allowed to, the review is still submitted, their state is set to reviewed, and the review drawer and /submit_review say why.

Screenshots

Before After
A Reporter submits a Comment review and still shows as Awaiting review: before-sidebar-crop After a Comment review, the Reporter shows as reviewed and the author gets the re-request icon: after-sidebar-reporter-comment
Root cause, changes, and verification

Root cause

MergeRequests::UpdateReviewerStateService returned early unless the user had update_merge_request, which only Developer and above (or the author or assignee) hold. Every path into it was affected: POST .../draft_notes/bulk_publish with reviewer_state, the review drawer (DraftsController#publish), /submit_review, approvals through ApprovalService, and the review_started transition when a draft is created.

Changes

  • New create_merge_request_review permission, granted in config/authz/roles/guest.yml so every higher role inherits it. Non-members get nothing (public_authenticated has create_note but not this).
  • Prevented wherever sibling merge request permissions are: merge_requests_disabled | repository_disabled, the archived and pending-deletion permission groups, ~read_merge_request and hidden merge requests, EE namespace read_only, and import_sync_read_only.
  • UpdateReviewerStateService checks it for every state except requested_changes, which keeps update_merge_request. approved also requires approve_merge_request.
  • Review submissions fall back to reviewed when the requested state is refused for permissions: UpdateReviewerStateService takes fall_back_to_reviewed: and returns the reason as warning. The drafts controller returns it as reviewer_state_error, which the drawer shows, and /submit_review appends it to its message. An approval refused as :not_eligible also falls back, and /submit_review approve says so. bulk_publish falls back and still returns 204, so API callers get no warning; the docs say so. /request_changes, mergeRequestRequestChanges, and the REST approve endpoint still return their errors.
  • EE: members of a group in a protected-branch approval rule can approve without being project members, so merge_request_group_approver also enables create_merge_request_review. Their approvals now show as approved. role_enables_admin_merge_request does the same for custom roles with Approve merge request, which covers the Minimal Access base. All prevents still apply.
  • Granular tokens: create_merge_request_review joins the update_merge_request assignable permission, so existing tokens keep working.
  • /submit_review <state> now sets only reviewed or requested_changes directly. It previously passed any reviewer state through, so with the wider gate a Guest could have marked themselves approved without approving. /submit_review approve still goes through ApprovalService.
  • Docs: new Comment and Request changes rows in the merge request permissions table, and the reviewed fallback on bulk_publish.

Behavior changes

  • Guest, Planner, Reporter, and Security Manager members can set their own reviewer state with Comment, and their approvals now show as approved.
  • A refused Request changes or Approve now records reviewed and shows a warning, instead of silently leaving the state unchanged.
  • Non-member authors and assignees on public projects previously passed through update_merge_request and no longer can set reviewed.
  • GitLab Duo Code Review (classic and Code Review Flow) is unaffected. Both publish as duo_code_review_bot, which EE treats as a Developer on every project regardless of membership or license (lookup_access_level!), so it passes create_merge_request_review. Code Review Flow sends its output to POST /ai/duo_workflows/code_review/add_comments, and PublishCommentsWorker publishes it as the bot.
  • Other agent flows that call bulk_publish through composite identity (for example the Security Review flow's submit_mr_review tool) are checked as the human they act for, so a non-member requester no longer gets reviewed recorded for themselves. The flow's own reviewer state is still set by update_composite_identity_reviewer_state on every call, as on master: reviewed after a fallback, otherwise the requested state. It isn't skipped when the human's state is refused, because an author-triggered review has no reviewer row for the human and always returns an error.
  • Custom roles: every base role except Minimal Access inherits Guest, so none of them lose access. Minimal Access never had update_merge_request, so it loses nothing either.

Not in this MR

  • Letting approvers below Developer request changes, and the GraphQL mutations and review drawer changes that go with it.
  • The review drawer's "you'll be added as a reviewer" hint is still keyed on userPermissions.updateMergeRequest. Fixing it needs a new MergeRequestPermissions field first.

Verification

  • New specs failed before the fix, then passed: service, REST bulk_publish as a Reporter, policy prevents, and the /submit_review approved guard. Fallback specs for the service, drafts controller, bulk_publish, /submit_review, and the drawer warning.
  • Existing caller specs pass: drafts controller, draft notes API (CE and EE), quick actions, approval service, request changes mutations, and DestroyRequestedChangesService.
  • bin/rake gitlab:permissions:validate and ee/spec/lib/authz/role_definitions_spec.rb pass.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Edited by Kai Armstrong

Merge request reports

Loading
Loading