idoit_object_remove.rb 927 B

123456789101112131415161718192021222324252627
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class Ticket::ExternalReferences::IdoitObjectRemove < BaseMutation
  4. description 'Remove an idoit object from a ticket.'
  5. argument :ticket_id, GraphQL::Types::ID, loads: Gql::Types::TicketType, description: 'The related ticket for the idoit objects'
  6. argument :idoit_object_id, Integer, description: 'The idoit object to remove'
  7. field :success, Boolean, description: 'Was the mutation successful?'
  8. def self.authorize(_obj, _ctx)
  9. Setting.get('idoit_integration')
  10. end
  11. def authorized?(idoit_object_id:, ticket:)
  12. Pundit.authorize(context.current_user, ticket, :agent_update_access?)
  13. end
  14. def resolve(idoit_object_id:, ticket: nil)
  15. ticket.preferences.dig(:idoit, :object_ids)&.map!(&:to_i)&.delete(idoit_object_id)
  16. ticket.save!
  17. { success: true }
  18. end
  19. end
  20. end