devices_updates.rb 717 B

1234567891011121314151617181920
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Subscriptions
  3. class User::Current::DevicesUpdates < BaseSubscription
  4. argument :user_id, GraphQL::Types::ID, 'ID of the user to receive devices updates for', loads: Gql::Types::UserType
  5. description 'Updates to account devices records'
  6. field :devices, [Gql::Types::UserDeviceType], null: true, description: 'List of devices for the user'
  7. def authorized?(user:)
  8. context.current_user.permissions?('user_preferences.device') && user.id == context.current_user.id
  9. end
  10. def update(user:)
  11. { devices: UserDevice.where(user_id: user.id).reorder(updated_at: :desc, name: :asc) }
  12. end
  13. end
  14. end