diff --git a/app/controllers/epp/sessions_controller.rb b/app/controllers/epp/sessions_controller.rb index b877c01ce..975d3cab5 100644 --- a/app/controllers/epp/sessions_controller.rb +++ b/app/controllers/epp/sessions_controller.rb @@ -105,7 +105,7 @@ class Epp::SessionsController < EppController end def connection_limit_ok? - return true if Rails.env.test? + return true if Rails.env.test? || Rails.env.development? c = EppSession.where( 'registrar_id = ? AND updated_at >= ?', @api_user.registrar_id, Time.zone.now - 5.minutes ).count diff --git a/app/models/api_user.rb b/app/models/api_user.rb index a8e0174bd..51c4da606 100644 --- a/app/models/api_user.rb +++ b/app/models/api_user.rb @@ -40,6 +40,20 @@ class ApiUser < User self.active = true unless active_changed? end + class << self + def find_by_idc_data(idc_data) + return false if idc_data.blank? + identity_code = idc_data.scan(/serialNumber=(\d+)/).flatten.first + + find_by(identity_code: identity_code) + end + + def all_by_identity_code(identity_code) + ApiUser.where(identity_code: identity_code) + .where("identity_code is NOT NULL and identity_code != ''").includes(:registrar) + end + end + def registrar_typeahead @registrar_typeahead || registrar || nil end @@ -75,13 +89,4 @@ class ApiUser < User md5 = OpenSSL::Digest::MD5.new(cert.to_der).to_s certificates.api.exists?(md5: md5, common_name: cn) end - - class << self - def find_by_idc_data(idc_data) - return false if idc_data.blank? - identity_code = idc_data.scan(/serialNumber=(\d+)/).flatten.first - - find_by(identity_code: identity_code) - end - end end diff --git a/app/views/layouts/registrar/application.haml b/app/views/layouts/registrar/application.haml index a2273de22..3754cd0bf 100644 --- a/app/views/layouts/registrar/application.haml +++ b/app/views/layouts/registrar/application.haml @@ -54,7 +54,7 @@ = "#{current_user} (#{current_user.roles.first}) - #{current_user.registrar}" %span.caret %ul.dropdown-menu{role: "menu"} - - ApiUser.where(identity_code: current_user.identity_code).includes(:registrar).each do |x| + - ApiUser.all_by_identity_code(current_user.identity_code).each do |x| %li= link_to "#{x} (#{x.roles.first}) - #{x.registrar}", "/registrar/switch_user/#{x.id}" - if user_signed_in? %li= link_to t(:log_out_), '/registrar/logout' diff --git a/spec/models/api_user_spec.rb b/spec/models/api_user_spec.rb index 8e46d0c6e..f159e5a7a 100644 --- a/spec/models/api_user_spec.rb +++ b/spec/models/api_user_spec.rb @@ -3,6 +3,22 @@ require 'rails_helper' describe ApiUser do it { should belong_to(:registrar) } + context 'class methods' do + before do + Fabricate(:api_user, identity_code: '') + Fabricate(:api_user, identity_code: 14212128025) + end + + it 'should return all api users with given identity code' do + ApiUser.all_by_identity_code('14212128025').size.should == 1 + ApiUser.all_by_identity_code(14212128025).size.should == 1 + end + + it 'should not return any api user with blank identity code' do + ApiUser.all_by_identity_code('').size.should == 0 + end + end + context 'with invalid attribute' do before :all do @api_user = ApiUser.new