Refactor EPP session limit

#700
This commit is contained in:
Artur Beljajev 2018-02-14 04:06:13 +02:00
parent 93055acb3a
commit 9b4aa478bf
4 changed files with 90 additions and 9 deletions

View file

@ -74,7 +74,7 @@ class Epp::SessionsController < EppController
success = false
end
if success && !connection_limit_ok?
if success && EppSession.limit_reached?(@api_user.registrar)
epp_errors << {
msg: 'Authentication error; server closing connection (connection limit reached)',
code: '2501'
@ -143,12 +143,4 @@ class Epp::SessionsController < EppController
def resource
@api_user
end
def connection_limit_ok?
epp_session_count = EppSession.where(user_id: @api_user.registrar.api_users.ids)
.where('updated_at >= ?', Time.zone.now - 1.second).count
return false if epp_session_count >= 4
true
end
end