mirror of
https://github.com/internetee/registry.git
synced 2025-05-30 01:20:04 +02:00
Honor contacts status on epp request #2477
This commit is contained in:
parent
601592aed1
commit
54db11812b
4 changed files with 59 additions and 7 deletions
|
@ -351,4 +351,34 @@ class Contact < ActiveRecord::Base
|
||||||
def set_ok
|
def set_ok
|
||||||
statuses << OK if statuses.detect { |s| s == OK }.blank?
|
statuses << OK if statuses.detect { |s| s == OK }.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def linked?
|
||||||
|
statuses.include?(LINKED)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_prohibited?
|
||||||
|
(statuses & [
|
||||||
|
CLIENT_UPDATE_PROHIBITED,
|
||||||
|
SERVER_UPDATE_PROHIBITED,
|
||||||
|
CLIENT_TRANSFER_PROHIBITED,
|
||||||
|
SERVER_TRANSFER_PROHIBITED,
|
||||||
|
PENDING_CREATE,
|
||||||
|
PENDING_TRANSFER,
|
||||||
|
PENDING_UPDATE,
|
||||||
|
PENDING_DELETE
|
||||||
|
]).present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_prohibited?
|
||||||
|
(statuses & [
|
||||||
|
CLIENT_DELETE_PROHIBITED,
|
||||||
|
SERVER_DELETE_PROHIBITED,
|
||||||
|
CLIENT_TRANSFER_PROHIBITED,
|
||||||
|
SERVER_TRANSFER_PROHIBITED,
|
||||||
|
PENDING_CREATE,
|
||||||
|
PENDING_TRANSFER,
|
||||||
|
PENDING_UPDATE,
|
||||||
|
PENDING_DELETE
|
||||||
|
]).present?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,13 @@ class Epp::Contact < Contact
|
||||||
# disable STI, there is type column present
|
# disable STI, there is type column present
|
||||||
self.inheritance_column = :sti_disabled
|
self.inheritance_column = :sti_disabled
|
||||||
|
|
||||||
|
before_validation :manage_permissions
|
||||||
|
def manage_permissions
|
||||||
|
return unless update_prohibited? || delete_prohibited?
|
||||||
|
add_epp_error('2304', nil, nil, I18n.t(:object_status_prohibits_operation))
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
# support legacy search
|
# support legacy search
|
||||||
def find_by_epp_code(code)
|
def find_by_epp_code(code)
|
||||||
|
|
|
@ -9,6 +9,21 @@ class Epp::Domain < Domain
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
before_validation :validate_contacts
|
||||||
|
def validate_contacts
|
||||||
|
return if contacts.map {|c| c.valid? }.all?
|
||||||
|
add_epp_error('2304', nil, nil, I18n.t(:object_status_prohibits_operation))
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
before_save :update_contact_status
|
||||||
|
def update_contact_status
|
||||||
|
contacts.each do |c|
|
||||||
|
next if c.linked?
|
||||||
|
c.save(validate: false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def new_from_epp(frame, current_user)
|
def new_from_epp(frame, current_user)
|
||||||
domain = Epp::Domain.new
|
domain = Epp::Domain.new
|
||||||
|
|
|
@ -179,17 +179,17 @@ describe Contact do
|
||||||
|
|
||||||
it 'should have linked status when domain' do
|
it 'should have linked status when domain' do
|
||||||
contact = Fabricate(:contact)
|
contact = Fabricate(:contact)
|
||||||
tech_domain_contact = Fabricate(:tech_domain_contact, contact_id: @contact.id)
|
tech_domain_contact = Fabricate(:tech_domain_contact, contact_id: contact.id)
|
||||||
contact.statuses.should == %w(ok)
|
contact.statuses.should == %w(ok)
|
||||||
# domain = Fabricate(:domain, tech_domain_contacts: [@tech_domain_contact])
|
domain = Fabricate(:domain, tech_domain_contacts: [tech_domain_contact])
|
||||||
|
|
||||||
|
contact = domain.contacts.first
|
||||||
contact.save
|
contact.save
|
||||||
contact.reload.statuses.should == %w(linked ok)
|
contact.statuses.sort.should == %w(linked ok)
|
||||||
|
|
||||||
# contact = @domain.contacts.first
|
|
||||||
# contact.save
|
|
||||||
|
|
||||||
# contact.statuses.sort.should == %w(linked ok)
|
contact = domain.contacts.second
|
||||||
|
contact.save
|
||||||
|
contact.statuses.sort.should == %w(linked ok)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not have linked status when no domain' do
|
it 'should not have linked status when no domain' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue