triggers_subscriptions.rb 973 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # Trigger GraphQL subscriptions on ticket changes.
  3. module Ticket::TriggersSubscriptions
  4. extend ActiveSupport::Concern
  5. included do
  6. after_update_commit :trigger_subscriptions
  7. after_update_commit :trigger_checklist_subscriptions
  8. end
  9. private
  10. def trigger_subscriptions
  11. Gql::Subscriptions::TicketUpdates.trigger(self, arguments: { ticket_id: Gql::ZammadSchema.id_from_object(self) })
  12. end
  13. TRIGGER_CHECKLIST_UPDATE_ON = %w[title group_id].freeze
  14. def trigger_checklist_subscriptions
  15. return if !saved_changes.keys.intersect? TRIGGER_CHECKLIST_UPDATE_ON
  16. Checklist
  17. .where(id: referencing_checklists)
  18. .includes(:ticket)
  19. .each do |elem|
  20. Gql::Subscriptions::Ticket::ChecklistUpdates.trigger(
  21. elem,
  22. arguments: {
  23. ticket_id: Gql::ZammadSchema.id_from_object(elem.ticket),
  24. }
  25. )
  26. end
  27. end
  28. end