mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Check for 4 sessions only in inexpired ones
This commit is contained in:
parent
495e1a4ae1
commit
13b0d45e25
1 changed files with 10 additions and 2 deletions
|
@ -11,13 +11,21 @@ class EppSession < ApplicationRecord
|
||||||
|
|
||||||
alias_attribute :last_access, :updated_at
|
alias_attribute :last_access, :updated_at
|
||||||
|
|
||||||
|
scope :not_expired,
|
||||||
|
lambda {
|
||||||
|
where(':now <= (updated_at + interval :interval)', now: Time.zone.now, interval: interval)
|
||||||
|
}
|
||||||
|
|
||||||
def self.limit_reached?(registrar)
|
def self.limit_reached?(registrar)
|
||||||
count = where(user_id: registrar.api_users.ids).count
|
count = where(user_id: registrar.api_users.ids).not_expired.count
|
||||||
count >= sessions_per_registrar
|
count >= sessions_per_registrar
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.interval
|
||||||
|
"#{timeout.parts.first.second} #{timeout.parts.first.first}"
|
||||||
|
end
|
||||||
|
|
||||||
def self.expired
|
def self.expired
|
||||||
interval = "#{timeout.parts.first.second} #{timeout.parts.first.first}"
|
|
||||||
where(':now > (updated_at + interval :interval)', now: Time.zone.now, interval: interval)
|
where(':now > (updated_at + interval :interval)', now: Time.zone.now, interval: interval)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue