triggers_subscriptions.rb 738 B

1234567891011121314151617181920212223
  1. # Copyright (C) 2012-2024 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(
  13. nil,
  14. arguments: {
  15. user_id: Gql::ZammadSchema.id_from_internal_id('User', user_id)
  16. }
  17. )
  18. end
  19. end