ticket_article_updates.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Subscriptions
  3. class TicketArticleUpdates < BaseSubscription
  4. argument :ticket_id, GraphQL::Types::ID, description: 'Ticket identifier'
  5. description 'Updates to ticket records'
  6. field :created_article, Gql::Types::Ticket::ArticleType, description: 'New ticket article'
  7. field :updated_article, Gql::Types::Ticket::ArticleType, description: 'Changed ticket article'
  8. field :deleted_article_id, GraphQL::Types::ID, description: 'ID of removed ticket article'
  9. class << self
  10. # Helper methods for triggering with custom payload.
  11. def trigger_after_create(article)
  12. trigger({ created_article: article }, arguments: { ticket_id: Gql::ZammadSchema.id_from_object(article.ticket) })
  13. end
  14. def trigger_after_update(article)
  15. trigger({ updated_article: article }, arguments: { ticket_id: Gql::ZammadSchema.id_from_object(article.ticket) })
  16. end
  17. def trigger_after_destroy(article)
  18. trigger({ deleted_article_id: Gql::ZammadSchema.id_from_object(article) }, arguments: { ticket_id: Gql::ZammadSchema.id_from_object(article.ticket) })
  19. end
  20. end
  21. def authorized?(ticket_id:)
  22. Gql::ZammadSchema.authorized_object_from_id ticket_id, type: ::Ticket, user: context.current_user
  23. end
  24. # This needs to be passed a hash with the correct field name containing the article payload as root object,
  25. # as we cannot change the (graphql-ruby) function signature of update(ticket_id:).
  26. def update(ticket_id:)
  27. object
  28. end
  29. end
  30. end