access_token_updates.rb 811 B

12345678910111213141516171819202122232425
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Subscriptions
  3. class User::Current::AccessTokenUpdates < BaseSubscription
  4. argument :user_id, GraphQL::Types::ID, 'ID of the user to receive access token updates for', loads: Gql::Types::UserType
  5. description 'Updates to given user access tokens'
  6. field :tokens, [Gql::Types::TokenType], null: true, description: 'List of acess tokens for the user'
  7. # Instance method: allow subscriptions only for the current user
  8. def authorized?(user:)
  9. context.current_user.permissions?('user_preferences.access_token') && user.id == context.current_user.id
  10. end
  11. def update(user:)
  12. tokens = Service::User::AccessToken::List
  13. .new(user)
  14. .execute
  15. { tokens: }
  16. end
  17. end
  18. end