mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 18:56:05 +02:00
Refactor
This commit is contained in:
parent
4c884cce37
commit
9baa65a775
6 changed files with 159 additions and 22 deletions
|
@ -3,6 +3,11 @@ class EppSession < ApplicationRecord
|
|||
|
||||
validates :session_id, uniqueness: true, presence: true
|
||||
|
||||
class_attribute :timeout
|
||||
self.timeout = ENV['epp_session_timeout_seconds'].to_i.seconds
|
||||
|
||||
alias_attribute :last_access, :updated_at
|
||||
|
||||
def self.limit_per_registrar
|
||||
4
|
||||
end
|
||||
|
@ -11,4 +16,21 @@ class EppSession < ApplicationRecord
|
|||
count = where(user_id: registrar.api_users.ids).where('updated_at >= ?', Time.zone.now - 1.second).count
|
||||
count >= limit_per_registrar
|
||||
end
|
||||
|
||||
def self.expired
|
||||
interval = "#{timeout.parts.first.second} #{timeout.parts.first.first}"
|
||||
where(':now > (updated_at + interval :interval)', now: Time.zone.now, interval: interval)
|
||||
end
|
||||
|
||||
def update_last_access
|
||||
touch
|
||||
end
|
||||
|
||||
def timed_out?
|
||||
(updated_at + self.class.timeout).past?
|
||||
end
|
||||
|
||||
def expired?
|
||||
timed_out?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue