mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 12:08:27 +02:00
Resolve merge errors
This commit is contained in:
commit
73e9dd6870
817 changed files with 16875 additions and 17443 deletions
|
@ -1,4 +1,6 @@
|
|||
class Contact < ActiveRecord::Base
|
||||
require 'deserializers/xml/legal_document'
|
||||
|
||||
class Contact < ApplicationRecord
|
||||
include Versions # version/contact_version.rb
|
||||
include EppErrors
|
||||
include UserEvents
|
||||
|
@ -6,6 +8,7 @@ class Contact < ActiveRecord::Base
|
|||
include Concerns::Contact::Identical
|
||||
include Concerns::Contact::Disclosable
|
||||
include Concerns::Contact::Archivable
|
||||
include Concerns::EmailVerifable
|
||||
|
||||
belongs_to :original, class_name: self.name
|
||||
belongs_to :registrar, required: true
|
||||
|
@ -15,21 +18,25 @@ class Contact < ActiveRecord::Base
|
|||
has_many :registrant_domains, class_name: 'Domain', foreign_key: 'registrant_id'
|
||||
has_many :actions, dependent: :destroy
|
||||
|
||||
has_paper_trail class_name: "ContactVersion", meta: { children: :children_log }
|
||||
|
||||
attr_accessor :legal_document_id
|
||||
alias_attribute :kind, :ident_type
|
||||
alias_attribute :copy_from_id, :original_id # Old attribute name; for PaperTrail
|
||||
|
||||
accepts_nested_attributes_for :legal_documents
|
||||
|
||||
scope :email_verification_failed, lambda {
|
||||
joins('LEFT JOIN email_address_verifications emv ON contacts.email = emv.email')
|
||||
.where('success = false and verified_at IS NOT NULL')
|
||||
}
|
||||
|
||||
validates :name, :email, presence: true
|
||||
validates :street, :city, :zip, :country_code, presence: true, if: 'self.class.address_processing?'
|
||||
validates :street, :city, :zip, :country_code, presence: true, if: lambda {
|
||||
self.class.address_processing?
|
||||
}
|
||||
|
||||
validates :phone, presence: true, e164: true, phone: true
|
||||
|
||||
validates :email, format: /@/
|
||||
validates :email, email_format: { message: :invalid }, if: proc { |c| c.email_changed? }
|
||||
validate :correct_email_format, if: proc { |c| c.will_save_change_to_email? }
|
||||
|
||||
validates :code,
|
||||
uniqueness: { message: :epp_id_taken },
|
||||
|
@ -38,7 +45,7 @@ class Contact < ActiveRecord::Base
|
|||
validates_associated :identifier
|
||||
|
||||
validate :validate_html
|
||||
validate :validate_country_code, if: 'self.class.address_processing?'
|
||||
validate :validate_country_code, if: -> { self.class.address_processing? }
|
||||
|
||||
after_initialize do
|
||||
self.status_notes = {} if status_notes.nil?
|
||||
|
@ -56,6 +63,9 @@ class Contact < ActiveRecord::Base
|
|||
mapping: [%w[ident code], %w[ident_type type], %w[ident_country_code country_code]]
|
||||
|
||||
after_save :update_related_whois_records
|
||||
before_validation :clear_address_modifications, if: -> { !self.class.address_processing? }
|
||||
|
||||
self.ignored_columns = %w[legacy_id legacy_history_id]
|
||||
|
||||
ORG = 'org'
|
||||
PRIV = 'priv'
|
||||
|
@ -203,10 +213,9 @@ class Contact < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def registrant_user_contacts(registrant_user)
|
||||
# In Rails 5, can be replaced with a much simpler `or` query method and the raw SQL parts can
|
||||
# be removed.
|
||||
from("(#{registrant_user_direct_contacts(registrant_user).to_sql} UNION " \
|
||||
"#{registrant_user_indirect_contacts(registrant_user).to_sql}) AS contacts")
|
||||
registrant_user_direct_contacts(registrant_user)
|
||||
.or(registrant_user_company_contacts(registrant_user))
|
||||
.or(registrant_user_indirect_contacts(registrant_user))
|
||||
end
|
||||
|
||||
def registrant_user_direct_contacts(registrant_user)
|
||||
|
@ -233,13 +242,22 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
private
|
||||
|
||||
def registrant_user_indirect_contacts(registrant_user)
|
||||
def registrant_user_company_contacts(registrant_user)
|
||||
ident = registrant_user.companies.collect(&:registration_number)
|
||||
|
||||
where(ident_type: ORG,
|
||||
ident: ident,
|
||||
ident_country_code: registrant_user.country.alpha2)
|
||||
end
|
||||
|
||||
def registrant_user_indirect_contacts(registrant_user)
|
||||
company_domains = Domain.registrant_user_indirect_domains(registrant_user)
|
||||
company_contact_ids = company_domains.map(&:contacts).flatten.collect(&:id)
|
||||
company_ids = Contact.registrant_user_company_contacts(registrant_user).collect(&:id)
|
||||
total_ids = (company_contact_ids + company_ids).uniq
|
||||
|
||||
where(id: total_ids)
|
||||
end
|
||||
end
|
||||
|
||||
def roid
|
||||
|
@ -264,7 +282,7 @@ class Contact < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def to_s
|
||||
name || '[no name]'
|
||||
name
|
||||
end
|
||||
|
||||
def validate_html
|
||||
|
@ -325,7 +343,7 @@ class Contact < ActiveRecord::Base
|
|||
return false
|
||||
end
|
||||
|
||||
legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame)
|
||||
legal_document_data = ::Deserializers::Xml::LegalDocument.new(frame).call
|
||||
|
||||
if legal_document_data
|
||||
|
||||
|
@ -389,45 +407,65 @@ class Contact < ActiveRecord::Base
|
|||
# if total is smaller than needed, the load more
|
||||
# we also need to sort by valid_to
|
||||
# todo: extract to drapper. Then we can remove Domain#roles
|
||||
def all_domains(page: nil, per: nil, params: {})
|
||||
# compose filter sql
|
||||
filter_sql = case params[:domain_filter]
|
||||
when "Registrant".freeze
|
||||
%Q{select id from domains where registrant_id=#{id}}
|
||||
when AdminDomainContact.to_s, TechDomainContact.to_s
|
||||
%Q{select domain_id from domain_contacts where contact_id=#{id} AND type='#{params[:domain_filter]}'}
|
||||
else
|
||||
%Q{select domain_id from domain_contacts where contact_id=#{id} UNION select id from domains where registrant_id=#{id}}
|
||||
end
|
||||
def all_domains(page: nil, per: nil, params:, requester: nil)
|
||||
filter_sql = qualified_domain_ids(params[:domain_filter])
|
||||
|
||||
# get sorting rules
|
||||
sorts = params.fetch(:sort, {}).first || []
|
||||
sort = Domain.column_names.include?(sorts.first) ? sorts.first : "valid_to"
|
||||
order = {"asc"=>"desc", "desc"=>"asc"}[sorts.second] || "desc"
|
||||
|
||||
sort = %w[name registrar_name valid_to].include?(sorts.first) ? sorts.first : 'valid_to'
|
||||
order = %w[asc desc].include?(sorts.second) ? sorts.second : 'desc'
|
||||
|
||||
# fetch domains
|
||||
domains = Domain.where("domains.id IN (#{filter_sql})")
|
||||
domains = qualified_domain_name_list(requester, filter_sql)
|
||||
domains = domains.includes(:registrar).page(page).per(per)
|
||||
|
||||
if sorts.first == "registrar_name".freeze
|
||||
# using small rails hack to generate outer join
|
||||
domains = domains.includes(:registrar).where.not(registrars: {id: nil}).order("registrars.name #{order} NULLS LAST")
|
||||
else
|
||||
domains = domains.order("#{sort} #{order} NULLS LAST")
|
||||
end
|
||||
|
||||
|
||||
# using small rails hack to generate outer join
|
||||
domains = if sorts.first == 'registrar_name'.freeze
|
||||
domains.includes(:registrar).where.not(registrars: { id: nil })
|
||||
.order("registrars.name #{order} NULLS LAST")
|
||||
else
|
||||
domains.order("#{sort} #{order} NULLS LAST")
|
||||
end
|
||||
|
||||
# adding roles. Need here to make faster sqls
|
||||
domain_c = Hash.new([])
|
||||
registrant_domains.where(id: domains.map(&:id)).each{|d| domain_c[d.id] |= ["Registrant".freeze] }
|
||||
DomainContact.where(contact_id: id, domain_id: domains.map(&:id)).each{|d| domain_c[d.domain_id] |= [d.type] }
|
||||
domains.each{|d| d.roles = domain_c[d.id].uniq}
|
||||
registrant_domains.where(id: domains.map(&:id)).each do |d|
|
||||
domain_c[d.id] |= ['Registrant'.freeze]
|
||||
end
|
||||
|
||||
DomainContact.where(contact_id: id, domain_id: domains.map(&:id)).each do |d|
|
||||
domain_c[d.domain_id] |= [d.type]
|
||||
end
|
||||
|
||||
domains.each { |d| d.roles = domain_c[d.id].uniq }
|
||||
|
||||
domains
|
||||
end
|
||||
|
||||
def qualified_domain_name_list(requester, filter_sql)
|
||||
return Domain.where('domains.id IN (?)', filter_sql) if requester.blank?
|
||||
|
||||
registrant_user = RegistrantUser.find_or_initialize_by(registrant_ident:
|
||||
"#{requester.ident_country_code}-#{requester.ident}")
|
||||
begin
|
||||
registrant_user.domains.where('domains.id IN (?)', filter_sql)
|
||||
rescue CompanyRegister::NotAvailableError
|
||||
registrant_user.direct_domains.where('domains.id IN (?)', filter_sql)
|
||||
end
|
||||
end
|
||||
|
||||
def qualified_domain_ids(domain_filter)
|
||||
registrant_ids = registrant_domains.pluck(:id)
|
||||
return registrant_ids if domain_filter == 'Registrant'
|
||||
|
||||
if %w[AdminDomainContact TechDomainContact].include? domain_filter
|
||||
DomainContact.select('domain_id').where(contact_id: id, type: domain_filter)
|
||||
else
|
||||
(DomainContact.select('domain_id').where(contact_id: id).pluck(:domain_id) +
|
||||
registrant_ids).uniq
|
||||
end
|
||||
end
|
||||
|
||||
def update_prohibited?
|
||||
(statuses & [
|
||||
CLIENT_UPDATE_PROHIBITED,
|
||||
|
@ -454,9 +492,23 @@ class Contact < ActiveRecord::Base
|
|||
]).present?
|
||||
end
|
||||
|
||||
def clear_address_modifications
|
||||
return unless modifies_address?
|
||||
|
||||
remove_address
|
||||
end
|
||||
|
||||
def modifies_address?
|
||||
modified = false
|
||||
self.class.address_attribute_names.each { |field| modified = true if changes.key?(field) }
|
||||
|
||||
modified
|
||||
end
|
||||
|
||||
def update_related_whois_records
|
||||
# not doing anything if no real changes
|
||||
return if changes.slice(*(self.class.column_names - ["updated_at", "created_at", "statuses", "status_notes"])).empty?
|
||||
ignored_columns = %w[updated_at created_at statuses status_notes]
|
||||
return if saved_changes.slice(*(self.class.column_names - ignored_columns)).empty?
|
||||
|
||||
names = related_domain_descriptions.keys
|
||||
UpdateWhoisRecordJob.enqueue(names, 'domain') if names.present?
|
||||
|
@ -531,4 +583,4 @@ class Contact < ActiveRecord::Base
|
|||
def deletable?
|
||||
!linked?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue