item_delete.rb 1.0 KB

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class Ticket::Checklist::ItemDelete < Ticket::Checklist::Base
  4. description 'Delete a ticket checklist item.'
  5. argument :checklist_id, GraphQL::Types::ID, required: true, loads: Gql::Types::ChecklistType, description: 'ID of the ticket checklist to delete an item in.'
  6. argument :checklist_item_id, GraphQL::Types::ID, required: true, loads: Gql::Types::Checklist::ItemType, description: 'ID of the ticket checklist item to delete.'
  7. field :success, Boolean, description: 'Was the mutation succcessful?'
  8. def authorized?(checklist:, checklist_item:)
  9. Pundit.authorize(context.current_user, checklist_item, :destroy?)
  10. end
  11. def resolve(checklist:, checklist_item:)
  12. raise ActiveRecord::RecordInvalid, __('The given checklist item does not belong to the given checklist.') if !checklist_item.checklist.eql?(checklist)
  13. checklist_item.destroy!
  14. {
  15. success: true,
  16. }
  17. end
  18. end
  19. end