Rate limit third-party flow update and version restore
What does this MR do and why?
The AI Catalog save limit from !267093 (merged) covers agent, flow and trigger saves. It does not cover aiCatalogThirdPartyFlowUpdate or aiCatalogItemVersionRestore. One user can call these two mutations without a limit, and each call writes a new item version.
This MR adds the same per-user limit to both mutations. They share the counter and the message with the other saves.
Closes #635191
References
- !267093 (merged) adds the limit for the other saves.
- !266414 (merged) limits the size of a definition on the same mutations.
How to set up and validate locally
-
Check out this branch.
-
Make sure the instance has a third-party flow with a released version, and that
rootcan edit it. -
Open a Rails console with
bin/rails console. -
Paste this script. It calls
aiCatalogItemVersionRestore31 times:user = User.find_by_username('root') version = Ai::Catalog::ItemVersion.joins(:item).merge(Ai::Catalog::Item.third_party_flow).where.not(release_date: nil).last query = 'mutation($id: AiCatalogItemVersionID!) { aiCatalogItemVersionRestore(input: { id: $id, deprecateCurrent: false }) { errors } }' results = 31.times.map do GitlabSchema.execute(query, variables: { 'id' => version.to_global_id.to_s }, context: { current_user: user }) .to_h.dig('data', 'aiCatalogItemVersionRestore', 'errors') end p results.first, results.last -
Make sure that the last result is
["You have saved agents, flows, or triggers too many times. Try again in a minute."]. The first result is the normal restore result.
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.