Add overview of active sessions (#3929)
* Add overview of active sessions * Better display of browser/platform name * Improve how browser information is stored and displayed for sessions overview * Fix test
This commit is contained in:
parent
099a3b4eac
commit
f7301bd5b9
15 changed files with 147 additions and 30 deletions
|
@ -8,31 +8,49 @@
|
|||
# session_id :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# user_agent :string default(""), not null
|
||||
# ip :inet
|
||||
#
|
||||
|
||||
class SessionActivation < ApplicationRecord
|
||||
LIMIT = Rails.configuration.x.max_session_activations
|
||||
|
||||
def self.active?(id)
|
||||
id && where(session_id: id).exists?
|
||||
def detection
|
||||
@detection ||= Browser.new(user_agent)
|
||||
end
|
||||
|
||||
def self.activate(id)
|
||||
activation = create!(session_id: id)
|
||||
purge_old
|
||||
activation
|
||||
def browser
|
||||
detection.id
|
||||
end
|
||||
|
||||
def self.deactivate(id)
|
||||
return unless id
|
||||
where(session_id: id).destroy_all
|
||||
def platform
|
||||
detection.platform.id
|
||||
end
|
||||
|
||||
def self.purge_old
|
||||
order('created_at desc').offset(LIMIT).destroy_all
|
||||
before_save do
|
||||
self.user_agent = '' if user_agent.nil?
|
||||
end
|
||||
|
||||
def self.exclusive(id)
|
||||
where('session_id != ?', id).destroy_all
|
||||
class << self
|
||||
def active?(id)
|
||||
id && where(session_id: id).exists?
|
||||
end
|
||||
|
||||
def activate(options = {})
|
||||
activation = create!(options)
|
||||
purge_old
|
||||
activation
|
||||
end
|
||||
|
||||
def deactivate(id)
|
||||
return unless id
|
||||
where(session_id: id).destroy_all
|
||||
end
|
||||
|
||||
def purge_old
|
||||
order('created_at desc').offset(Rails.configuration.x.max_session_activations).destroy_all
|
||||
end
|
||||
|
||||
def exclusive(id)
|
||||
where('session_id != ?', id).destroy_all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue