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

How to set up and validate locally

  1. Check out this branch.

  2. Make sure the instance has a third-party flow with a released version, and that root can edit it.

  3. Open a Rails console with bin/rails console.

  4. Paste this script. It calls aiCatalogItemVersionRestore 31 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
  5. 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.

Edited by Angus Ryer

Merge request reports

Loading
Loading