add.rb 1.1 KB

12345678910111213141516171819202122232425262728
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class Ticket::Checklist::Add < Ticket::Checklist::Base
  4. description 'Create an empty checklist or a checklist based on a template for a ticket.'
  5. argument :ticket_id, GraphQL::Types::ID, loads: Gql::Types::TicketType, description: 'Ticket to create the new checklist for.'
  6. argument :template_id, GraphQL::Types::ID, required: false, description: 'Checklist template ID to base the ticket checklist on.'
  7. field :checklist, Gql::Types::ChecklistType, null: true, description: 'Created checklist'
  8. def authorized?(ticket:, template_id: nil)
  9. Setting.get('checklist') && Pundit.authorize(context.current_user, ticket, :agent_update_access?)
  10. end
  11. def resolve(ticket:, template_id: nil)
  12. checklist = if template_id
  13. template = Gql::ZammadSchema.verified_object_from_id(template_id, type: ::ChecklistTemplate)
  14. Checklist.create_from_template!(ticket, template)
  15. else
  16. Checklist.create_fresh!(ticket)
  17. end
  18. { checklist: }
  19. end
  20. end
  21. end