mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 17:28:18 +02:00
Merge remote-tracking branch 'origin/master' into story/105855968-directo
# Conflicts: # Gemfile # Gemfile.lock
This commit is contained in:
commit
da7fed9577
232 changed files with 330 additions and 426083 deletions
|
@ -6,6 +6,8 @@ class AccountActivity < ActiveRecord::Base
|
|||
belongs_to :bank_transaction
|
||||
belongs_to :invoice
|
||||
|
||||
attr_accessor :registrar
|
||||
|
||||
CREATE = 'create'
|
||||
RENEW = 'renew'
|
||||
ADD_CREDIT = 'add_credit'
|
||||
|
@ -22,12 +24,13 @@ class AccountActivity < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def to_csv
|
||||
attributes = %w(description activity_type created_at sum)
|
||||
attributes = %w(registrar description activity_type created_at sum)
|
||||
|
||||
CSV.generate(headers: true) do |csv|
|
||||
csv << %w(description activity_type receipt_date sum)
|
||||
csv << %w(registrar description activity_type receipt_date sum)
|
||||
|
||||
all.each do |x| # rubocop:disable Rails/FindEach
|
||||
x.registrar = Registrar.find(x.account_id).try(:code)
|
||||
csv << attributes.map { |attr| x.send(attr) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
class BlockedDomain < ActiveRecord::Base
|
||||
include Versions
|
||||
before_save :generate_data
|
||||
before_destroy :remove_data
|
||||
validates :name, domain_name: true, uniqueness: true
|
||||
before_save :generate_data
|
||||
after_destroy :remove_data
|
||||
|
||||
validates :name, domain_name: true, uniqueness: true
|
||||
|
||||
|
||||
class << self
|
||||
|
@ -22,19 +23,14 @@ validates :name, domain_name: true, uniqueness: true
|
|||
def generate_data
|
||||
return if Domain.where(name: name).any?
|
||||
|
||||
@json = generate_json
|
||||
@body = generate_body
|
||||
update_whois_server
|
||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||
wr.json = @json = generate_json # we need @json to bind to class
|
||||
wr.body = generate_body
|
||||
wr.save
|
||||
end
|
||||
|
||||
alias_method :update_whois_record, :generate_data
|
||||
|
||||
def update_whois_server
|
||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||
wr.body = @body
|
||||
wr.json = @json
|
||||
wr.save
|
||||
end
|
||||
|
||||
def generate_body
|
||||
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
|
||||
|
@ -49,8 +45,6 @@ validates :name, domain_name: true, uniqueness: true
|
|||
end
|
||||
|
||||
def remove_data
|
||||
return if Domain.where(name: name).any?
|
||||
|
||||
Whois::Record.where(name: name).delete_all
|
||||
UpdateWhoisRecordJob.enqueue name, 'blocked'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,17 +22,26 @@ class BusinessRegistryCache < ActiveRecord::Base
|
|||
|
||||
# 1. load domains by business
|
||||
# 2. load domains by person
|
||||
def associated_domains
|
||||
domains = []
|
||||
|
||||
def associated_contacts
|
||||
contact_ids = Contact.where(ident_type: 'org', ident: associated_businesses, ident_country_code: 'EE').pluck(:id)
|
||||
contact_ids += Contact.where(ident_type: 'priv', ident: ident, ident_country_code: ident_country_code).pluck(:id)
|
||||
contact_ids
|
||||
end
|
||||
|
||||
def associated_domain_ids
|
||||
domain_ids = []
|
||||
|
||||
contact_ids = associated_contacts
|
||||
|
||||
unless contact_ids.blank?
|
||||
domains = DomainContact.distinct.where(contact_id: contact_ids).pluck(:domain_id)
|
||||
domain_ids = DomainContact.distinct.where(contact_id: contact_ids).pluck(:domain_id)
|
||||
end
|
||||
|
||||
Domain.includes(:registrar, :registrant).where(id: domains)
|
||||
domain_ids
|
||||
end
|
||||
|
||||
def associated_domains
|
||||
Domain.includes(:registrar, :registrant).where(id: associated_domain_ids)
|
||||
end
|
||||
|
||||
class << self
|
||||
|
|
|
@ -415,7 +415,10 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
|
||||
# fetch domains
|
||||
domains = Domain.where("domains.id IN (#{filter_sql})").includes(:registrar).page(page).per(per)
|
||||
domains = Domain.where("domains.id IN (#{filter_sql})")
|
||||
domains = domains.where("domains.id" => params[:leave_domains]) if params[:leave_domains]
|
||||
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")
|
||||
|
@ -434,6 +437,30 @@ class Contact < ActiveRecord::Base
|
|||
domains
|
||||
end
|
||||
|
||||
def all_registrant_domains(page: nil, per: nil, params: {}, registrant: nil)
|
||||
|
||||
if registrant
|
||||
sorts = params.fetch(:sort, {}).first || []
|
||||
sort = Domain.column_names.include?(sorts.first) ? sorts.first : "valid_to"
|
||||
order = {"asc"=>"desc", "desc"=>"asc"}[sorts.second] || "desc"
|
||||
|
||||
domain_ids = DomainContact.distinct.where(contact_id: registrant.id).pluck(:domain_id)
|
||||
|
||||
domains = Domain.where(id: domain_ids).includes(:registrar).page(page).per(per)
|
||||
if sorts.first == "registrar_name".freeze
|
||||
domains = domains.includes(:registrar).where.not(registrars: {id: nil}).order("registrars.name #{order} NULLS LAST")
|
||||
else
|
||||
domains = domains.order("#{sort} #{order} NULLS LAST")
|
||||
end
|
||||
|
||||
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}
|
||||
domains
|
||||
end
|
||||
end
|
||||
|
||||
def set_linked
|
||||
statuses << LINKED if statuses.detect { |s| s == LINKED }.blank?
|
||||
end
|
||||
|
@ -499,8 +526,8 @@ class Contact < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def update_related_whois_records
|
||||
ids = related_domain_descriptions.keys
|
||||
RegenerateWhoisRecordJob.enqueue(ids, :name) if ids.present?
|
||||
names = related_domain_descriptions.keys
|
||||
UpdateWhoisRecordJob.enqueue(names, :domain) if names.present?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -43,7 +43,7 @@ class Domain < ActiveRecord::Base
|
|||
has_many :dnskeys, dependent: :destroy
|
||||
|
||||
has_many :keyrelays
|
||||
has_one :whois_record, dependent: :destroy
|
||||
has_one :whois_record # destroyment will be done in after_commit
|
||||
|
||||
accepts_nested_attributes_for :dnskeys, allow_destroy: true
|
||||
|
||||
|
@ -87,14 +87,11 @@ class Domain < ActiveRecord::Base
|
|||
true
|
||||
end
|
||||
|
||||
after_save :update_whois_record
|
||||
after_commit :update_whois_record
|
||||
|
||||
after_create :update_reserved_domains
|
||||
def update_reserved_domains
|
||||
return unless in_reserved_list?
|
||||
rd = ReservedDomain.by_domain(name).first
|
||||
rd.password = SecureRandom.hex
|
||||
rd.save
|
||||
ReservedDomain.new_password_for(name) if in_reserved_list?
|
||||
end
|
||||
|
||||
validates :name_dirty, domain_name: true, uniqueness: true
|
||||
|
@ -279,7 +276,7 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def in_reserved_list?
|
||||
ReservedDomain.pw_for(name).present?
|
||||
@in_reserved_list ||= ReservedDomain.by_domain(name).any?
|
||||
end
|
||||
|
||||
def pending_transfer
|
||||
|
@ -734,7 +731,7 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def update_whois_record
|
||||
whois_record.blank? ? create_whois_record : whois_record.save
|
||||
UpdateWhoisRecordJob.enqueue name, 'domain'
|
||||
end
|
||||
|
||||
def status_notes_array=(notes)
|
||||
|
|
|
@ -18,12 +18,13 @@ class DomainCron
|
|||
DomainMailer.pending_update_expired_notification_for_new_registrant(domain.id).deliver
|
||||
end
|
||||
if domain.pending_delete? || domain.pending_delete_confirmation?
|
||||
DomainMailer.pending_delete_expired_notification(domain.id, deliver_emails).deliver
|
||||
DomainMailer.pending_delete_expired_notification(domain.id, true).deliver
|
||||
end
|
||||
domain.clean_pendings_lowlevel
|
||||
unless Rails.env.test?
|
||||
STDOUT << "#{Time.zone.now.utc} DomainCron.clean_expired_pendings: ##{domain.id} (#{domain.name})\n"
|
||||
end
|
||||
UpdateWhoisRecordJob.enqueue domain.name, 'domain'
|
||||
end
|
||||
STDOUT << "#{Time.zone.now.utc} - Successfully cancelled #{count} domain pendings\n" unless Rails.env.test?
|
||||
count
|
||||
|
|
|
@ -5,6 +5,7 @@ class Epp::Contact < Contact
|
|||
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))
|
||||
|
@ -174,6 +175,8 @@ class Epp::Contact < Contact
|
|||
else
|
||||
throw :epp_error, {code: '2306', msg: I18n.t(:ident_update_error)}
|
||||
end
|
||||
else
|
||||
throw :epp_error, {code: '2306', msg: I18n.t(:ident_update_error)}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ class Epp::Domain < Domain
|
|||
attr_accessor :is_renewal, :is_transfer
|
||||
|
||||
before_validation :manage_permissions
|
||||
|
||||
def manage_permissions
|
||||
return if is_admin # this bad hack for 109086524, refactor later
|
||||
return true if is_transfer || is_renewal
|
||||
|
@ -868,6 +869,7 @@ class Epp::Domain < Domain
|
|||
ld = parsed_frame.css('legalDocument').first
|
||||
return nil unless ld
|
||||
return nil if ld.text.starts_with?(ENV['legal_documents_dir']) # escape reloading
|
||||
return nil if ld.text.starts_with?('/home/') # escape reloading
|
||||
|
||||
{
|
||||
body: ld.text,
|
||||
|
|
|
@ -9,6 +9,9 @@ class LegalDocument < ActiveRecord::Base
|
|||
|
||||
belongs_to :documentable, polymorphic: true
|
||||
|
||||
|
||||
validates :body, length: { minimum: (1.37 * 8.kilobytes).ceil }, if: ->(file){ file.path.blank? && !Rails.env.staging?}
|
||||
|
||||
before_create :add_creator
|
||||
before_save :save_to_filesystem
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@ class ReservedDomain < ActiveRecord::Base
|
|||
include Versions # version/reserved_domain_version.rb
|
||||
before_save :fill_empty_passwords
|
||||
before_save :generate_data
|
||||
before_destroy :remove_data
|
||||
after_destroy :remove_data
|
||||
|
||||
validates :name, domain_name: true, uniqueness: true
|
||||
|
||||
|
||||
|
@ -21,38 +22,40 @@ class ReservedDomain < ActiveRecord::Base
|
|||
def any_of_domains names
|
||||
where(name: names)
|
||||
end
|
||||
end
|
||||
|
||||
def new_password_for name
|
||||
record = by_domain(name).first
|
||||
return unless record
|
||||
|
||||
def fill_empty_passwords
|
||||
|
||||
if self.password.empty?
|
||||
|
||||
self.password = SecureRandom.hex
|
||||
|
||||
record.regenerate_password
|
||||
record.save
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def name= val
|
||||
super SimpleIDN.to_unicode(val)
|
||||
end
|
||||
|
||||
def fill_empty_passwords
|
||||
regenerate_password if self.password.blank?
|
||||
end
|
||||
|
||||
def regenerate_password
|
||||
self.password = SecureRandom.hex
|
||||
end
|
||||
|
||||
def generate_data
|
||||
return if Domain.where(name: name).any?
|
||||
|
||||
@json = generate_json
|
||||
@body = generate_body
|
||||
update_whois_server
|
||||
end
|
||||
|
||||
alias_method :update_whois_record, :generate_data
|
||||
|
||||
def update_whois_server
|
||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||
wr.body = @body
|
||||
wr.json = @json
|
||||
wr.json = @json = generate_json # we need @json to bind to class
|
||||
wr.body = generate_body
|
||||
wr.save
|
||||
end
|
||||
alias_method :update_whois_record, :generate_data
|
||||
|
||||
|
||||
def generate_body
|
||||
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
|
||||
|
@ -67,9 +70,7 @@ class ReservedDomain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def remove_data
|
||||
return if Domain.where(name: name).any?
|
||||
|
||||
Whois::Record.where(name: name).delete_all
|
||||
UpdateWhoisRecordJob.enqueue name, 'reserved'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue