triggers_subscriptions.rb 642 B

123456789101112131415161718
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. # Trigger GraphQL subscriptions on token changes.
  3. module Token::TriggersSubscriptions
  4. extend ActiveSupport::Concern
  5. included do
  6. # Tokens cannot be modified after creating so no need to push updates on update
  7. # Meanwhile pushing on update would be triggered when last_used_at is updated which may be an overkill
  8. after_commit :trigger_user_subscription, on: %i[create destroy]
  9. end
  10. def trigger_user_subscription
  11. return if !visible_in_frontend?
  12. Gql::Subscriptions::User::Current::AccessTokenUpdates.trigger(nil, scope: user_id)
  13. end
  14. end