delete.rb 820 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class User::Current::Device::Delete < BaseMutation
  4. description 'Delete a user (session) device.'
  5. argument :device_id, GraphQL::Types::ID, required: true, loads: Gql::Types::UserDeviceType, description: 'The identifier for the device to be deleted.'
  6. field :success, Boolean, description: 'This indicates if deleting the user (session) device was successful.'
  7. def self.authorize(_obj, ctx)
  8. ctx.current_user.permissions?('user_preferences.device')
  9. end
  10. def authorized?(device:)
  11. context.current_user.id == device.user_id
  12. end
  13. def resolve(device:)
  14. Service::User::Device::Delete.new(user: context.current_user, device:).execute
  15. { success: true }
  16. end
  17. end
  18. end