Merge branch 'story/116761157-contact-dyn-states' into staging

This commit is contained in:
Vladimir Krylov 2016-05-27 14:31:39 +03:00
commit 223b6b8b9f
6 changed files with 25 additions and 10 deletions

View file

@ -35,7 +35,7 @@ module Repp
error! I18n.t('errors.messages.epp_authorization_error'), 401 unless domain.auth_info.eql? request.headers['Auth-Code']
contact_repp_json = proc{|contact|
contact.attributes.slice("code", "name", "ident", "ident_type", "ident_country_code", "phone", "email", "street", "city", "zip","country_code", "statuses")
contact.as_json.slice("code", "name", "ident", "ident_type", "ident_country_code", "phone", "email", "street", "city", "zip","country_code", "statuses")
}
@response = {

View file

@ -51,6 +51,7 @@ class Admin::SettingsController < AdminController
:admin_contacts_max_count,
:tech_contacts_min_count,
:tech_contacts_max_count,
:orphans_contacts_in_months,
:ds_digest_type,
:dnskeys_min_count,
:dnskeys_max_count,

View file

@ -41,7 +41,6 @@ class Contact < ActiveRecord::Base
validate :val_country_code
after_initialize do
self.statuses = [] if statuses.nil?
self.status_notes = {} if status_notes.nil?
self.ident_updated_at = Time.zone.now if new_record? && ident_updated_at.blank?
end
@ -175,20 +174,28 @@ class Contact < ActiveRecord::Base
')
end
# To leave only new ones we need to check
# if contact was at any time used in domain.
# This can be checked by domain history.
# This can be checked by saved relations in children attribute
def destroy_orphans
STDOUT << "#{Time.zone.now.utc} - Destroying orphaned contacts\n" unless Rails.env.test?
orphans = find_orphans
unless Rails.env.test?
orphans.each do |m|
STDOUT << "#{Time.zone.now.utc} Contact.destroy_orphans: ##{m.id} (#{m.name})\n"
counter = Counter.new
find_orphans.find_each do |contact|
ver_scope = []
%w(admin_contacts tech_contacts registrant).each do |type|
ver_scope << "(children->'#{type}')::jsonb <@ json_build_array(#{contact.id})::jsonb"
end
next if DomainVersion.where("created_at > ?", Time.now - Setting.orphans_contacts_in_months.to_i.months).where(ver_scope.join(" OR ")).any?
next if contact.domains_present?
contact.destroy
counter.next
STDOUT << "#{Time.zone.now.utc} Contact.destroy_orphans: ##{contact.id} (#{contact.name})\n"
end
count = orphans.destroy_all.count
STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{count} orphaned contacts\n" unless Rails.env.test?
STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{counter} orphaned contacts\n" unless Rails.env.test?
end
def privs

View file

@ -15,6 +15,7 @@
= render 'setting_row', var: :admin_contacts_max_count
= render 'setting_row', var: :tech_contacts_min_count
= render 'setting_row', var: :tech_contacts_max_count
= render 'setting_row', var: :orphans_contacts_in_months
= render 'setting_row', var: :ds_data_allowed
= render 'setting_row', var: :key_data_allowed
= render 'setting_row', var: :dnskeys_min_count

View file

@ -10,6 +10,7 @@ if con.present? && con.table_exists?('settings')
Setting.save_default(:admin_contacts_max_count, 10)
Setting.save_default(:tech_contacts_min_count, 1)
Setting.save_default(:tech_contacts_max_count, 10)
Setting.save_default(:orphans_contacts_in_months, 6)
Setting.save_default(:expire_pending_confirmation, 48)
Setting.save_default(:ds_digest_type, 2)

View file

@ -0,0 +1,5 @@
class ChangeContactStatusesDefault < ActiveRecord::Migration
def change
change_column_default :contacts, :statuses, []
end
end