mirror of
https://github.com/internetee/registry.git
synced 2025-05-28 16:39:55 +02:00
Added linked and ok statuses
This commit is contained in:
parent
1f7ef2254e
commit
4f417d22da
5 changed files with 79 additions and 9 deletions
|
@ -42,13 +42,10 @@ class Contact < ActiveRecord::Base
|
|||
before_create :generate_code
|
||||
before_create :generate_auth_info
|
||||
after_create :ensure_disclosure
|
||||
after_save :manage_automatic_statuses
|
||||
def manage_automatic_statuses
|
||||
if statuses.empty? && valid?
|
||||
statuses.create(value: ContactStatus::OK)
|
||||
elsif statuses.length > 1 || !valid?
|
||||
statuses.find_by(value: ContactStatus::OK).try(:destroy)
|
||||
end
|
||||
after_save :manage_statuses
|
||||
def manage_statuses
|
||||
ContactStatus.manage(statuses, self)
|
||||
statuses.reload
|
||||
end
|
||||
|
||||
scope :current_registrars, ->(id) { where(registrar_id: id) }
|
||||
|
|
|
@ -70,6 +70,32 @@ class ContactStatus < ActiveRecord::Base
|
|||
SERVER_UPDATE_PROHIBITED
|
||||
]
|
||||
|
||||
class << self
|
||||
def manage(statuses, contact)
|
||||
manage_linked(statuses, contact)
|
||||
manage_ok(statuses, contact)
|
||||
end
|
||||
|
||||
def manage_linked(statuses, contact)
|
||||
if contact.domains.present?
|
||||
create(value: LINKED, contact_id: contact.id) if statuses.select { |s| s.value == LINKED }.blank?
|
||||
else
|
||||
statuses.select { |s| s.value == LINKED }.each(&:destroy)
|
||||
end
|
||||
end
|
||||
|
||||
def manage_ok(statuses, contact)
|
||||
if statuses.present?
|
||||
if contact.valid?
|
||||
else
|
||||
statuses.select { |s| s.value == OK }.each(&:destroy)
|
||||
end
|
||||
else
|
||||
create(value: OK, contact_id: contact.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def epp_code_map
|
||||
{
|
||||
'2302' => [ # Object exists
|
||||
|
|
21
app/views/admin/contacts/partials/_statuses.haml
Normal file
21
app/views/admin/contacts/partials/_statuses.haml
Normal file
|
@ -0,0 +1,21 @@
|
|||
- panel_class = contact.errors.messages[:statuses] ? 'panel-danger' : 'panel-default'
|
||||
#contact_statuses.panel{class: panel_class}
|
||||
.panel-heading.clearfix
|
||||
= t(:statuses)
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-6'}= t(:status)
|
||||
%th{class: 'col-xs-6'}= t(:description)
|
||||
%tbody
|
||||
- contact.statuses.each do |s|
|
||||
%tr
|
||||
%td= s.value
|
||||
%td= s.description
|
||||
|
||||
- if contact.errors.messages[:statuses]
|
||||
%tfoot
|
||||
- @domain.errors.messages[:statuses].each do |s|
|
||||
%tr
|
||||
%td{colspan: 4}= s
|
|
@ -9,5 +9,9 @@
|
|||
.row
|
||||
.col-md-12= render 'admin/contacts/partials/domains'
|
||||
.row
|
||||
.col-md-12
|
||||
= render 'admin/domains/partials/legal_documents', legal_documents: @contact.legal_documents
|
||||
.col-md-12= render 'admin/contacts/partials/statuses', contact: @contact
|
||||
|
||||
- if @contact.legal_documents.present?
|
||||
.row
|
||||
.col-md-12
|
||||
= render 'admin/domains/partials/legal_documents', legal_documents: @contact.legal_documents
|
||||
|
|
|
@ -152,6 +152,28 @@ describe Contact do
|
|||
@contact.statuses.first.value.should == 'ok'
|
||||
end
|
||||
|
||||
it 'should have linked status when domain' do
|
||||
@domain_contact = Fabricate(:domain_contact, contact_type: 'admin', contact_id: @contact.id)
|
||||
@domain = Fabricate(:domain, domain_contacts: [@domain_contact])
|
||||
contact = @domain.contacts.first
|
||||
contact.save
|
||||
|
||||
contact.statuses.map(&:value).should == %w(ok linked)
|
||||
end
|
||||
|
||||
it 'should not have linked status when no domain' do
|
||||
@domain_contact = Fabricate(:domain_contact, contact_type: 'admin', contact_id: @contact.id)
|
||||
@domain = Fabricate(:domain, domain_contacts: [@domain_contact])
|
||||
contact = @domain.contacts.first
|
||||
contact.save
|
||||
|
||||
contact.statuses.map(&:value).should == %w(ok linked)
|
||||
|
||||
contact.domains.destroy_all
|
||||
contact.save
|
||||
contact.statuses.map(&:value).should == %w(ok)
|
||||
end
|
||||
|
||||
context 'as birthday' do
|
||||
before :all do
|
||||
@contact.ident_type = 'birthday'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue