6714b5f1a4
Bumps [rubocop-rails](https://github.com/rubocop/rubocop-rails) from 2.12.4 to 2.13.0. - [Release notes](https://github.com/rubocop/rubocop-rails/releases) - [Changelog](https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop/rubocop-rails/compare/v2.12.4...v2.13.0)
47 lines
1.5 KiB
Ruby
47 lines
1.5 KiB
Ruby
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
|
|
|
class UserDevicesController < ApplicationController
|
|
prepend_before_action { authentication_check && authorize! }
|
|
|
|
def index
|
|
devices = UserDevice.where(user_id: current_user.id).order(updated_at: :desc, name: :asc)
|
|
devices_full = []
|
|
devices.each do |device|
|
|
attributes = device.attributes
|
|
if device.location_details['city_name'].present?
|
|
attributes['location'] += ", #{device.location_details['city_name']}"
|
|
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
|
|
devices_full.push attributes
|
|
end
|
|
model_index_render_result(devices_full)
|
|
end
|
|
|
|
def destroy
|
|
|
|
# find device
|
|
user_device = UserDevice.find_by(user_id: current_user.id, id: params[:id])
|
|
|
|
# delete device and session's
|
|
if user_device
|
|
SessionHelper.list.each do |session|
|
|
next if !session.data['user_id']
|
|
next if !session.data['user_device_id']
|
|
next if session.data['user_device_id'] != user_device.id
|
|
|
|
SessionHelper.destroy(session.id)
|
|
end
|
|
user_device.destroy
|
|
end
|
|
render json: {}, status: :ok
|
|
end
|
|
|
|
end
|