trabajo-afectivo/app/controllers/user_devices_controller.rb

47 lines
1.6 KiB
Ruby
Raw Normal View History

2016-10-19 03:11:36 +00:00
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
2015-08-17 14:12:40 +00:00
class UserDevicesController < ApplicationController
prepend_before_action { authentication_check(permission: 'user_preferences.device') }
2015-08-17 14:12:40 +00:00
def index
2016-03-25 07:19:59 +00:00
devices = UserDevice.where(user_id: current_user.id).order('updated_at DESC, name ASC')
2015-08-17 14:12:40 +00:00
devices_full = []
2016-06-30 20:04:48 +00:00
devices.each { |device|
2015-08-17 14:12:40 +00:00
attributes = device.attributes
2015-08-18 23:05:59 +00:00
if device.location_details['city_name'] && !device.location_details['city_name'].empty?
2015-08-18 22:36:58 +00:00
attributes['location'] += ", #{device.location_details['city_name']}"
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 > Time.zone.now - 30.minutes
attributes['current'] = true
end
2015-08-17 14:12:40 +00:00
devices_full.push attributes
}
model_index_render_result(devices_full)
end
def destroy
2015-08-18 22:36:58 +00:00
# find device
user_device = UserDevice.find_by(user_id: current_user.id, id: params[:id])
# delete device and session's
if user_device
2016-06-30 20:04:48 +00:00
SessionHelper.list.each { |session|
next if !session.data['user_id']
2015-08-18 22:36:58 +00:00
next if !session.data['user_device_id']
next if session.data['user_device_id'] != user_device.id
SessionHelper.destroy( session.id )
}
user_device.destroy
end
2015-08-17 14:12:40 +00:00
render json: {}, status: :ok
end
end