Reject unavailable work item types on create

What does this MR do and why?

Rejects a new work item whose final type is disabled or archived, behind the enforce_work_item_type_availability flag. This MR adds the flag definition.

Before, an issue created without an explicit type, or with the legacy issue_type param, fell back to the default type even when that type was disabled or archived. Quick actions such as /type could also switch a new work item to a disabled type after the build-time check had passed.

With the flag on, Issues::CreateService#before_create checks the final type, after quick actions have run. If the type is unavailable, the check raises Issues::BaseService::WorkItemTypeUnavailableError, and CreateService#execute rescues it and returns the usual 422 error on work_item_type. Type changes on existing records are not covered here; that is !261249.

With the flag off, nothing changes. The flag is gitlab_com_derisk, default off.

This MR was split: it used to also cover type changes and several related fixes. Those now live in the MRs listed under References.

Details

With the flag on, BuildService no longer filters by availability. The before_create check owns explicit types, implicit types and the default type fallback. With the flag off, BuildService behaves as before. Imports stay exempt.

Issues::BaseService#check_work_item_type_availability runs for new records only. It looks the type up through the provider for the container, because issue.namespace is the parent group for new project issues. This adds a provider lookup to every create when the flag is on.

The error is a ::Issuable::Callbacks::Base::Error. It exposes attribute_message ("X is disabled or archived for this project or group.") and message ("Work item type X is disabled or archived for this project or group."). There is no model validation and no work_item_type_unavailable attribute.

The final type wins. A create with an explicit disabled type plus /promote_to_incident succeeds when it ends on an enabled type.

References

How to set up and validate locally

  1. Disable the Issue type for a project in the work item settings.
  2. Enable the flag with Feature.enable(:enforce_work_item_type_availability).
  3. Create an issue with no type, and then with the legacy issue_type param. REST returns 400 with {"work_item_type": ["Issue is disabled or archived for this project or group."]}. GraphQL returns "Work item type Issue is disabled or archived for this project or group.".
  4. Create a work item with a /type quick action that points at a disabled type. It fails the same way.
  5. Disable the flag and repeat. The issues are created with the default type as before.

Specs (the disabled-type examples run with the flag on and off):

  • spec/services/issues/base_service_spec.rb, spec/services/issues/build_service_spec.rb
  • ee/spec/services/ee/issues/create_service_spec.rb
  • ee/spec/requests/api/issues_spec.rb, ee/spec/requests/api/epics_spec.rb, ee/spec/requests/api/work_items/create_spec.rb
  • ee/spec/requests/api/graphql/mutations/issues/create_spec.rb, ee/spec/requests/api/graphql/mutations/epics/create_spec.rb, ee/spec/requests/api/graphql/mutations/work_items/create_spec.rb

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist.

Generated with Claude Code

Edited by Alexandru Croitor

Merge request reports

Loading
Loading