mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 12:47:29 +02:00
WIP Add getting contacts from companies
This commit is contained in:
parent
c20be4e029
commit
735a0e1642
2 changed files with 25 additions and 0 deletions
|
@ -12,6 +12,8 @@ class Contact < ApplicationRecord
|
|||
belongs_to :registrar, required: true
|
||||
has_many :domain_contacts
|
||||
has_many :domains, through: :domain_contacts
|
||||
has_many :admin_domains, -> { merge(DomainContact.admin) }, source: :domain,
|
||||
through: :domain_contacts
|
||||
has_many :legal_documents, as: :documentable
|
||||
has_many :registrant_domains, class_name: 'Domain', foreign_key: 'registrant_id'
|
||||
has_many :actions, dependent: :destroy
|
||||
|
@ -252,6 +254,16 @@ class Contact < ApplicationRecord
|
|||
def registrant_user_contacts(registrant_user)
|
||||
registrant_user_direct_contacts(registrant_user)
|
||||
.or(registrant_user_indirect_contacts(registrant_user))
|
||||
# .or(registrant_user_indirect_admin_registrar_contacts(registrant_user))
|
||||
end
|
||||
|
||||
def registrant_user_indirect_admin_registrar_contacts(registrant_user)
|
||||
indirect_contacts = registrant_user_indirect_contacts(registrant_user)
|
||||
admin_contact_ids = admin_contact_ids(indirect_contacts)
|
||||
reg_contact_ids = registrar_contact_ids(indirect_contacts)
|
||||
|
||||
total_ids = (admin_contact_ids + reg_contact_ids).uniq
|
||||
where(id: total_ids)
|
||||
end
|
||||
|
||||
def registrant_user_direct_contacts(registrant_user)
|
||||
|
@ -263,11 +275,22 @@ class Contact < ApplicationRecord
|
|||
|
||||
def registrant_user_indirect_contacts(registrant_user)
|
||||
ident = registrant_user.companies.collect(&:registration_number)
|
||||
# ident = ['12345678']
|
||||
|
||||
where(ident_type: ORG,
|
||||
ident: ident,
|
||||
ident_country_code: registrant_user.country.alpha2)
|
||||
end
|
||||
|
||||
def admin_contact_ids(indirect_contacts)
|
||||
domains = indirect_contacts.map(&:admin_domains).flatten
|
||||
domains.map(&:contacts).flatten.collect(&:id)
|
||||
end
|
||||
|
||||
def registrar_contact_ids(indirect_contacts)
|
||||
registrar_domains = indirect_contacts.map(&:registrant_domains).flatten
|
||||
registrar_domains.map(&:contacts).flatten.collect(&:id)
|
||||
end
|
||||
end
|
||||
|
||||
def roid
|
||||
|
|
|
@ -6,6 +6,8 @@ class DomainContact < ApplicationRecord
|
|||
belongs_to :contact
|
||||
belongs_to :domain
|
||||
|
||||
scope :admin, -> { where(type: 'AdminDomainContact') }
|
||||
|
||||
attr_accessor :value_typeahead
|
||||
|
||||
self.ignored_columns = %w[legacy_domain_id legacy_contact_id]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue