mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Ignore empty identity for regisrar user switch #2754
This commit is contained in:
parent
85e5a17509
commit
598ab7ba63
4 changed files with 32 additions and 11 deletions
|
@ -105,7 +105,7 @@ class Epp::SessionsController < EppController
|
||||||
end
|
end
|
||||||
|
|
||||||
def connection_limit_ok?
|
def connection_limit_ok?
|
||||||
return true if Rails.env.test?
|
return true if Rails.env.test? || Rails.env.development?
|
||||||
c = EppSession.where(
|
c = EppSession.where(
|
||||||
'registrar_id = ? AND updated_at >= ?', @api_user.registrar_id, Time.zone.now - 5.minutes
|
'registrar_id = ? AND updated_at >= ?', @api_user.registrar_id, Time.zone.now - 5.minutes
|
||||||
).count
|
).count
|
||||||
|
|
|
@ -40,6 +40,20 @@ class ApiUser < User
|
||||||
self.active = true unless active_changed?
|
self.active = true unless active_changed?
|
||||||
end
|
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
|
def registrar_typeahead
|
||||||
@registrar_typeahead || registrar || nil
|
@registrar_typeahead || registrar || nil
|
||||||
end
|
end
|
||||||
|
@ -75,13 +89,4 @@ class ApiUser < User
|
||||||
md5 = OpenSSL::Digest::MD5.new(cert.to_der).to_s
|
md5 = OpenSSL::Digest::MD5.new(cert.to_der).to_s
|
||||||
certificates.api.exists?(md5: md5, common_name: cn)
|
certificates.api.exists?(md5: md5, common_name: cn)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
= "#{current_user} (#{current_user.roles.first}) - #{current_user.registrar}"
|
= "#{current_user} (#{current_user.roles.first}) - #{current_user.registrar}"
|
||||||
%span.caret
|
%span.caret
|
||||||
%ul.dropdown-menu{role: "menu"}
|
%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}"
|
%li= link_to "#{x} (#{x.roles.first}) - #{x.registrar}", "/registrar/switch_user/#{x.id}"
|
||||||
- if user_signed_in?
|
- if user_signed_in?
|
||||||
%li= link_to t(:log_out_), '/registrar/logout'
|
%li= link_to t(:log_out_), '/registrar/logout'
|
||||||
|
|
|
@ -3,6 +3,22 @@ require 'rails_helper'
|
||||||
describe ApiUser do
|
describe ApiUser do
|
||||||
it { should belong_to(:registrar) }
|
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
|
context 'with invalid attribute' do
|
||||||
before :all do
|
before :all do
|
||||||
@api_user = ApiUser.new
|
@api_user = ApiUser.new
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue