Ignore empty identity for regisrar user switch #2754

This commit is contained in:
Priit Tark 2015-08-18 14:15:16 +03:00
parent 85e5a17509
commit 598ab7ba63
4 changed files with 32 additions and 11 deletions

View file

@ -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

View file

@ -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

View file

@ -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'

View file

@ -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