Reject type changes to unavailable work item types
What does this MR do and why?
With enforce_work_item_type_availability on, changing an existing issue or work item to a disabled or archived type now fails with the same error as create.
Before, only new records were checked (!260607 (merged)). The REST API, GraphQL mutations and the /type and /promote_to quick actions could still move an item into a disabled type.
Issues::BaseService#check_work_item_type_availability now also runs when work_item_type_id changes. Issues::UpdateService#before_update calls it and raises WorkItemTypeUnavailableError. The existing rescuers of Issuable::Callbacks::Base::Error turn it into an error. Two places needed their own rescue:
Notes::QuickActionsServicerescues it for Issue noteables, whose update service does not.PUT /projects/:id/issues/:issue_iidrescues it, so the response matches create.
Changing a type away from a disabled type, editing, and deleting items of a disabled type stay allowed. With the flag off, behaviour is unchanged.
This MR also carries "Stop convert to ticket side effects on update failure". Issues::ConvertToTicketService ignored the result of the work item update. When the update failed, it still added the email participant and the "converted" internal note, and returned success. It now checks the update result first and returns its messages as an error. This fix does not depend on the flag. It moved here from !261250, so this MR alone never reports a false /convert_to_ticket success.
Known limitation: other changes in the same update request may already be applied when the type change is rejected. !261307, stacked on this MR, fixes that.
Responses with a disabled type and the flag on
Create and update return the same response on each surface.
- REST issues:
400 {"message": {"work_item_type": ["X is disabled or archived for this project or group."]}} - REST work items:
422 {"message": "Work item type X is disabled or archived for this project or group."} - GraphQL: "Work item type X is disabled or archived for this project or group."
Follow-up specs
A few examples combine this change with fixes from other MRs in the split: a rejected type change plus a move or clone (!261245), the updateIssue payload after a rejection (!261246), and legacy /promote with the Epic type disabled (!261244 (merged)). They are added once those MRs and this one are all merged.
References
- Part of the split of !260607 (merged).
- Depends on !260607 (merged) (stacked).
- Merge !261245 and !261246 first. They are not stacked, but without them a rejected type change can still go through with a move or clone, and
updateIssuereturns the rejected type. - !261250 and !261307 are stacked on this MR.
How to set up and validate locally
- Disable the Task type for a project in the work item settings.
- Enable the flag with
Feature.enable(:enforce_work_item_type_availability). - Change an existing issue to Task through REST, GraphQL and
/type Task. Each fails with "Task is disabled or archived for this project or group.", in the response shape listed above. - Change an item of a disabled type to an enabled type, edit it, and delete it. All three still work.
- Disable the flag and repeat the first change. It succeeds.
Specs:
ee/spec/services/ee/issues/update_service_spec.rb,ee/spec/services/ee/notes/quick_actions_service_spec.rbspec/services/issues/convert_to_ticket_service_spec.rb,ee/spec/services/issues/convert_to_ticket_service_spec.rbee/spec/requests/api/issues_spec.rb,ee/spec/requests/api/epics_spec.rb,ee/spec/requests/api/work_items/update_spec.rbee/spec/requests/api/graphql/mutations/issues/update_spec.rb,ee/spec/requests/api/graphql/mutations/work_items/update_spec.rb,ee/spec/requests/api/graphql/mutations/work_items/convert_spec.rb,ee/spec/requests/api/graphql/mutations/notes/create/note_spec.rb
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist.
Generated with Claude Code