zammad/app/controllers/user_devices_controller.rb

44 lines
1.5 KiB
Ruby
Raw Permalink Normal View History

# Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/
2015-08-17 14:12:40 +00:00
class UserDevicesController < ApplicationController
prepend_before_action :authenticate_and_authorize!
2015-08-17 14:12:40 +00:00
def index
devices = UserDevice.where(user_id: current_user.id).reorder(updated_at: :desc, name: :asc)
2015-08-17 14:12:40 +00:00
devices_full = []
devices.each do |device|
2015-08-17 14:12:40 +00:00
attributes = device.attributes
city_name = device.location_details['city_name']
if city_name.present?
attributes['location'] = if attributes['location'].blank? || attributes['location'] == 'unknown'
city_name
else
"#{attributes['location']}, #{city_name}"
end
2015-08-17 14:12:40 +00:00
end
attributes.delete('created_at')
attributes.delete('device_details')
attributes.delete('location_details')
attributes.delete('fingerprint')
# mark current device to prevent killing own session via user preferences device management
if session[:user_device_fingerprint] == device.fingerprint && device.updated_at > 30.minutes.ago
attributes['current'] = true
end
2015-08-17 14:12:40 +00:00
devices_full.push attributes
end
2015-08-17 14:12:40 +00:00
model_index_render_result(devices_full)
end
def destroy
begin
Service::User::Device::Delete.with_current_user(current_user).execute(device: UserDevice.find_by(user_id: current_user.id, id: params[:id]))
rescue Exceptions::UnprocessableContent
# noop
end
2015-08-17 14:12:40 +00:00
render json: {}, status: :ok
end
end