delete.rb 636 B

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::User::Device::Delete < Service::Base
  3. attr_reader :user, :device
  4. def initialize(user:, device:)
  5. super()
  6. raise Exceptions::UnprocessableEntity, __('UserDevice could not be found.') if device.blank?
  7. @user = user
  8. @device = device
  9. end
  10. def execute
  11. Session.all.each do |session|
  12. next if session.data['user_id'] != user.id
  13. next if session.data['user_device_fingerprint'] != device.fingerprint
  14. begin
  15. session.destroy!
  16. rescue
  17. # noop
  18. end
  19. end
  20. device.destroy!
  21. end
  22. end