update.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  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 :skip_validator, String, required: false, description: 'The ticket update validator to skip'
  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:, skip_validator: 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_validator: skip_validator)
  19. }
  20. rescue => e
  21. raise e if !e.class.name.starts_with?('Service::Ticket::Update::Validator')
  22. error_response(
  23. message: e.message,
  24. exception: e.class.name,
  25. )
  26. end
  27. end
  28. end