From 0917cec85521539d4a7e8557217dc4162f7df7ad Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 17 Aug 2015 16:12:40 +0200 Subject: [PATCH] Init version of device logging. --- app/controllers/user_devices_controller.rb | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 app/controllers/user_devices_controller.rb diff --git a/app/controllers/user_devices_controller.rb b/app/controllers/user_devices_controller.rb new file mode 100644 index 000000000..480e9cae4 --- /dev/null +++ b/app/controllers/user_devices_controller.rb @@ -0,0 +1,27 @@ +# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ + +class UserDevicesController < ApplicationController + before_action :authentication_check + + def index + devices = UserDevice.where(user_id: current_user.id).order('updated_at DESC') + devices_full = [] + devices.each {|device| + attributes = device.attributes + if device.location_details['city'] + attributes['country'] += ", #{device.location_details['city']}" + end + attributes.delete('created_at') + attributes.delete('device_details') + attributes.delete('location_details') + devices_full.push attributes + } + model_index_render_result(devices_full) + end + + def destroy + UserDevice.where(user_id: current_user.id, id: params[:id]).destroy_all + render json: {}, status: :ok + end + +end