Story#116761157 - contact statuses are generated value

This commit is contained in:
Vladimir Krylov 2016-05-27 09:30:48 +03:00
parent 105d7bf645
commit f2c96ba145
2 changed files with 15 additions and 74 deletions

View file

@ -62,16 +62,6 @@ class Contact < ActiveRecord::Base
end
end
before_save :manage_statuses
def manage_statuses
if domain_transfer # very ugly but need better workflow
self.statuses = statuses | [OK, LINKED]
return
end
manage_linked
manage_ok
end
after_save :update_related_whois_records
@ -174,7 +164,7 @@ class Contact < ActiveRecord::Base
end
def find_orphans
Contact.where('
where('
NOT EXISTS(
select 1 from domains d where d.registrant_id = contacts.id
) AND NOT EXISTS(
@ -237,6 +227,18 @@ class Contact < ActiveRecord::Base
"EIS-#{id}"
end
# kind of decorator in order to always return statuses
# if we use separate decorator, then we should add it
# to too many places
def statuses
calculated = Array(read_attribute(:statuses))
calculated.delete(Contact::LINKED)
calculated << Contact::OK
calculated << Contact::LINKED if domains_present?
calculated.uniq
end
def to_s
name || '[no name]'
end
@ -406,13 +408,6 @@ class Contact < ActiveRecord::Base
domain_contacts.present? || registrant_domains.present?
end
def manage_linked
if domains_present?
set_linked
else
unset_linked
end
end
def search_name
"#{code} #{name}"
@ -491,43 +486,6 @@ class Contact < ActiveRecord::Base
end
end
def set_linked
statuses << LINKED if statuses.detect { |s| s == LINKED }.blank?
end
def unset_linked
statuses.delete_if { |s| s == LINKED }
end
# rubocop:disable Metrics/CyclomaticComplexity
def manage_ok
return unset_ok unless valid?
case statuses.size
when 0
set_ok
when 1
set_ok if statuses == [LINKED]
when 2
return if statuses.sort == [LINKED, OK]
unset_ok
else
unset_ok
end
end
# rubocop:enable Metrics/CyclomaticComplexity
def unset_ok
statuses.delete_if { |s| s == OK }
end
def set_ok
statuses << OK if statuses.detect { |s| s == OK }.blank?
end
def linked?
statuses.include?(LINKED)
end
def update_prohibited?
(statuses & [

View file

@ -39,29 +39,12 @@ class Epp::Domain < Domain
before_save :link_contacts
def link_contacts
# Based on bullet report
if new_record?
# new record does not have correct instance contacts entries thanks to epp
unlinked_contacts = [registrant]
unlinked_contacts << admin_domain_contacts.map(&:contact)
unlinked_contacts << tech_domain_contacts.map(&:contact)
unlinked_contacts.flatten!
else
unlinked_contacts = contacts.select { |c| !c.linked? } # speed up a bit
end
unlinked_contacts.each do |uc|
uc.domains_present = true # no need to fetch domains again
uc.save(validate: false)
end
#TODO: cleanup cache if we think to cache dynamic statuses
end
after_destroy :unlink_contacts
def unlink_contacts
contacts.each do |c|
c.domains_present = false
c.save(validate: false)
end
#TODO: cleanup cache if we think to cache dynamic statuses
end
class << self