Move pipeline schedule deletion into a service

What does this MR do and why?

Adds Ci::PipelineSchedules::DestroyService and routes the three places that delete a pipeline schedule through it: the pipelineScheduleDelete GraphQL mutation, DELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id, and Projects::PipelineSchedulesController#destroy. Each of them called destroy on the record directly, so there was no shared place for behaviour that every caller should get, such as the rate limit planned in a follow-up.

The service checks the granular delete_pipeline_schedule permission. It already had a definition but was never enabled; it is now enabled by the same rule as admin_pipeline_schedule in Ci::PipelineSchedulePolicy, and the never-enabled destroy_pipeline_schedule name is replaced by it in the builds-disabled and repository-disabled prevents, the archived and pending-deletion permission groups, and the EE read-only abilities. The REST endpoint, mutation and controller keep their existing admin_pipeline_schedule authorization; moving them to the granular permission is a follow-up.

Behaviour changes:

  • The REST endpoint returns 400 with the error message when the record cannot be destroyed. It returned 204 regardless before. Nothing is known to trigger this path, since no validation or abortable callback runs on destroy.
  • Everything else is unchanged. The mutation keeps the same error message.

Database review: the new destroy service is picked up by Gitlab::Database::TablesWithDestroyServices, so every foreign key into ci_pipeline_schedules must be declared or listed. The pipelines key is handled, because Ci::PipelineSchedule#destroy nullifies the schedule's pipelines in batches, so the service declares handles_removal_of :p_ci_pipelines. The schedule variables and inputs keys are cascade-only and predate the rule, so they are listed in spec/support/database/destroy_service_foreign_keys_todo.yml with a comment.

References

Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/636908

Screenshots or screen recordings

No UI change.

How to set up and validate locally

  1. Create a pipeline schedule in a project (Build > Pipeline schedules > New schedule).

  2. REST: the following returns 204 and the schedule is gone.

    curl --request DELETE --header "PRIVATE-TOKEN: <token>" \
      "http://gdk.test:3000/api/v4/projects/<project_id>/pipeline_schedules/<schedule_id>"
  3. UI: create another schedule and delete it from the actions menu on Build > Pipeline schedules. The page goes through the GraphQL mutation.

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.

🤖 Generated with Claude Code

Merge request reports

Loading
Loading