ticket_updates.rb 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Subscriptions
  3. class TicketUpdates < BaseSubscription
  4. description 'Updates to ticket records'
  5. argument :ticket_id, GraphQL::Types::ID, description: 'Ticket identifier'
  6. argument :initial, Boolean, default_value: false, description: 'Return initial ticket data by subscribing'
  7. field :ticket, Gql::Types::TicketType, description: 'Updated ticket'
  8. # This is needed to ensure that the subscription is unique for each ticket and that `initial` is not considered.
  9. def self.topic_for(arguments:, field:, scope:)
  10. super(arguments: { 'ticketId' => arguments['ticketId'] }, field:, scope:)
  11. end
  12. def authorized?(ticket_id:, initial:)
  13. Gql::ZammadSchema.authorized_object_from_id ticket_id, type: ::Ticket, user: context.current_user
  14. end
  15. def subscribe(ticket_id:, initial:)
  16. return {} if !initial
  17. { ticket: Gql::ZammadSchema.object_from_id(ticket_id, type: ::Ticket) }
  18. end
  19. def update(ticket_id:, initial:)
  20. { ticket: object }
  21. end
  22. end
  23. end