Charge notes_create when quick actions publish a review
What does this MR do and why?
The /submit_review and /approve quick actions publish every pending draft of the current user, but only the note carrying the command counts against notes_create. The other ways to publish a review (the review drawer, the draft notes API and POST .../approve with publish_review) count each draft, capped at the limit. This MR charges the drafts in the two quick actions the same way.
- The charge runs after the existing
review_idchecks, so a review published from the review drawer is not counted twice. - The cap leaves room for the note carrying the command, which the notes endpoint has already counted. Without that, a review with as many drafts as the limit could never be published with a quick action.
notes_create_limit_allowlistapplies, as on the other publish paths.- When the user is over the limit, the command publishes nothing and shows "Too many notes have been created. Try again in 60 seconds.", the message the review drawer uses.
/approveand/submit_review approvedo not approve either, likePOST .../approvewithpublish_review, which returns 429 before approving. /approvewithout pending drafts is not charged and approves as before.
References
Relates to https://gitlab.com/gitlab-org/gitlab/-/work_items/634354
Draft note creation has its own limit in !267498 (merged). This MR only changes publishing.
How to set up and validate locally
-
Set the limit to 5 in the Rails console, then wait a minute for the settings cache:
ApplicationSetting.current.update!(notes_create_limit: 5) -
On a merge request, add 6 comments to a review (Start a review or Add to review).
-
Within one minute, post two regular comments with Add comment now, then a comment that contains only
/submit_review. The comment box shows "Too many notes have been created. Try again in 60 seconds.", and after a reload Your review still shows 6 drafts. -
Wait a minute and post
/submit_reviewagain. The review is published: the command note counts 1 and the drafts count 4, the rest of the limit. -
Restore the limit:
ApplicationSetting.current.update!(notes_create_limit: 300)
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.