mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Generate contact code manually
Generate contact's code explicitly on contact:create epp request and domain transfer. Remove callback.
This commit is contained in:
parent
cefd310cc0
commit
183c2bb82c
4 changed files with 18 additions and 21 deletions
|
@ -21,14 +21,15 @@ class Epp::ContactsController < EppController
|
||||||
@contact = Epp::Contact.new(frame, current_user.registrar)
|
@contact = Epp::Contact.new(frame, current_user.registrar)
|
||||||
|
|
||||||
@contact.add_legal_file_to_new(frame)
|
@contact.add_legal_file_to_new(frame)
|
||||||
|
@contact.generate_code
|
||||||
@response_code = if Contact.address_processing?
|
|
||||||
1000
|
|
||||||
else
|
|
||||||
frame.css('postalInfo addr').size != 0 ? 1100 : 1000
|
|
||||||
end
|
|
||||||
|
|
||||||
if @contact.save
|
if @contact.save
|
||||||
|
@response_code = if Contact.address_processing?
|
||||||
|
1000
|
||||||
|
else
|
||||||
|
frame.css('postalInfo addr').size != 0 ? 1100 : 1000
|
||||||
|
end
|
||||||
|
|
||||||
render_epp_response '/epp/contacts/create'
|
render_epp_response '/epp/contacts/create'
|
||||||
else
|
else
|
||||||
handle_errors(@contact)
|
handle_errors(@contact)
|
||||||
|
|
|
@ -45,7 +45,6 @@ class Contact < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
before_validation :to_upcase_country_code
|
before_validation :to_upcase_country_code
|
||||||
before_validation :prefix_code
|
|
||||||
before_validation :strip_email
|
before_validation :strip_email
|
||||||
before_create :generate_auth_info
|
before_create :generate_auth_info
|
||||||
|
|
||||||
|
@ -366,7 +365,7 @@ class Contact < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
# rubocop:disable Metrics/CyclomaticComplexity
|
# rubocop:disable Metrics/CyclomaticComplexity
|
||||||
def prefix_code
|
def generate_code
|
||||||
return nil unless new_record?
|
return nil unless new_record?
|
||||||
return nil if registrar.blank?
|
return nil if registrar.blank?
|
||||||
code = self[:code]
|
code = self[:code]
|
||||||
|
|
|
@ -646,7 +646,7 @@ class Epp::Domain < Domain
|
||||||
oc.code = nil
|
oc.code = nil
|
||||||
oc.registrar_id = registrar_id
|
oc.registrar_id = registrar_id
|
||||||
oc.copy_from_id = c.id
|
oc.copy_from_id = c.id
|
||||||
oc.prefix_code
|
oc.generate_code
|
||||||
oc.domain_transfer = true
|
oc.domain_transfer = true
|
||||||
oc.save!(validate: false)
|
oc.save!(validate: false)
|
||||||
oc
|
oc
|
||||||
|
|
|
@ -164,7 +164,10 @@ RSpec.describe Contact do
|
||||||
|
|
||||||
it 'should have code' do
|
it 'should have code' do
|
||||||
registrar = Fabricate.create(:registrar, code: 'registrarcode')
|
registrar = Fabricate.create(:registrar, code: 'registrarcode')
|
||||||
contact = Fabricate.create(:contact, registrar: registrar, code: 'contactcode')
|
|
||||||
|
contact = Fabricate.build(:contact, registrar: registrar, code: 'contactcode')
|
||||||
|
contact.generate_code
|
||||||
|
contact.save!
|
||||||
|
|
||||||
expect(contact.code).to eq('REGISTRARCODE:CONTACTCODE')
|
expect(contact.code).to eq('REGISTRARCODE:CONTACTCODE')
|
||||||
end
|
end
|
||||||
|
@ -252,16 +255,6 @@ RSpec.describe Contact do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'after create' do
|
context 'after create' do
|
||||||
it 'should not generate a new code when code is present' do
|
|
||||||
@contact = Fabricate.build(:contact,
|
|
||||||
registrar: Fabricate(:registrar, code: 'FIXED'),
|
|
||||||
code: 'FIXED:new-code',
|
|
||||||
auth_info: 'qwe321')
|
|
||||||
@contact.code.should == 'FIXED:new-code' # still new record
|
|
||||||
@contact.save.should == true
|
|
||||||
@contact.code.should == 'FIXED:NEW-CODE'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not allow to use same code' do
|
it 'should not allow to use same code' do
|
||||||
registrar = Fabricate.create(:registrar, code: 'FIXED')
|
registrar = Fabricate.create(:registrar, code: 'FIXED')
|
||||||
|
|
||||||
|
@ -299,12 +292,15 @@ RSpec.describe Contact do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate code if empty code is given' do
|
it 'should generate code if empty code is given' do
|
||||||
@contact = Fabricate(:contact, code: '')
|
@contact = Fabricate.build(:contact, code: '')
|
||||||
|
@contact.generate_code
|
||||||
|
@contact.save!
|
||||||
@contact.code.should_not == ''
|
@contact.code.should_not == ''
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not ignore empty spaces as code and generate new one' do
|
it 'should not ignore empty spaces as code and generate new one' do
|
||||||
@contact = Fabricate.build(:contact, code: ' ', registrar: Fabricate(:registrar, code: 'FIXED'))
|
@contact = Fabricate.build(:contact, code: ' ', registrar: Fabricate(:registrar, code: 'FIXED'))
|
||||||
|
@contact.generate_code
|
||||||
@contact.valid?.should == true
|
@contact.valid?.should == true
|
||||||
@contact.code.should =~ /FIXED:..../
|
@contact.code.should =~ /FIXED:..../
|
||||||
end
|
end
|
||||||
|
@ -316,6 +312,7 @@ RSpec.describe Contact do
|
||||||
registrar: Fabricate(:registrar, code: 'FIXED'),
|
registrar: Fabricate(:registrar, code: 'FIXED'),
|
||||||
code: '123asd',
|
code: '123asd',
|
||||||
auth_info: 'qwe321')
|
auth_info: 'qwe321')
|
||||||
|
@contact.generate_code
|
||||||
@contact.save
|
@contact.save
|
||||||
@contact.code.should == 'FIXED:123ASD'
|
@contact.code.should == 'FIXED:123ASD'
|
||||||
@auth_info = @contact.auth_info
|
@auth_info = @contact.auth_info
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue