update.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class Ticket::Update < BaseMutation
  4. include Gql::Mutations::Ticket::Concerns::HandlesGroup
  5. description 'Update a ticket.'
  6. argument :ticket_id, GraphQL::Types::ID, loads: Gql::Types::TicketType, description: 'The ticket to be updated'
  7. argument :input, Gql::Types::Input::Ticket::UpdateInputType, description: 'The ticket data'
  8. argument :meta, Gql::Types::Input::Ticket::UpdateMetaInputType, required: false, description: 'The ticket metadata'
  9. field :ticket, Gql::Types::TicketType, description: 'The updated ticket. If this is present but empty, the mutation was successful but the user has no rights to view the updated ticket.'
  10. def self.authorize(_obj, ctx)
  11. ctx.current_user.permissions?(['ticket.agent', 'ticket.customer'])
  12. end
  13. def resolve(ticket:, input:, meta: nil)
  14. return group_has_no_email_error if !group_has_email?(input: input)
  15. {
  16. ticket: Service::Ticket::Update
  17. .new(current_user: context.current_user)
  18. .execute(ticket: ticket, ticket_data: input, skip_validators: meta&.dig(:skip_validators), macro: meta&.dig(:macro))
  19. }
  20. rescue Exceptions::InvalidAttribute => e
  21. field = e.attribute == 'email_recipient' ? 'article.to' : e.attribute
  22. error_response({ field:, message: e.message })
  23. rescue => e
  24. raise e if !e.class.name.starts_with?('Service::Ticket::Update::Validator')
  25. error_response(
  26. message: e.message,
  27. exception: e.class,
  28. )
  29. end
  30. end
  31. end