user_devices_controller.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class UserDevicesController < ApplicationController
  3. prepend_before_action :authenticate_and_authorize!
  4. def index
  5. devices = UserDevice.where(user_id: current_user.id).reorder(updated_at: :desc, name: :asc)
  6. devices_full = []
  7. devices.each do |device|
  8. attributes = device.attributes
  9. if device.location_details['city_name'].present?
  10. attributes['location'] += ", #{device.location_details['city_name']}"
  11. end
  12. attributes.delete('created_at')
  13. attributes.delete('device_details')
  14. attributes.delete('location_details')
  15. attributes.delete('fingerprint')
  16. # mark current device to prevent killing own session via user preferences device management
  17. if session[:user_device_fingerprint] == device.fingerprint && device.updated_at > 30.minutes.ago
  18. attributes['current'] = true
  19. end
  20. devices_full.push attributes
  21. end
  22. model_index_render_result(devices_full)
  23. end
  24. def destroy
  25. begin
  26. Service::User::Device::Delete.new(user: current_user, device: UserDevice.find_by(user_id: current_user.id, id: params[:id])).execute
  27. rescue Exceptions::UnprocessableEntity
  28. # noop
  29. end
  30. render json: {}, status: :ok
  31. end
  32. end