Merge branch 'master' into alpha

This commit is contained in:
Priit Tark 2015-06-12 10:49:45 +03:00
commit e6e9d9cbf7
15 changed files with 150 additions and 41 deletions

View file

@ -28,6 +28,24 @@ class Admin::DomainsController < AdminController
end end
end end
def set_force_delete
if @domain.set_force_delete
flash[:notice] = I18n.t('domain_updated')
else
flash.now[:alert] = I18n.t('failed_to_update_domain')
end
redirect_to [:admin, @domain]
end
def unset_force_delete
if @domain.unset_force_delete
flash[:notice] = I18n.t('domain_updated')
else
flash.now[:alert] = I18n.t('failed_to_update_domain')
end
redirect_to [:admin, @domain]
end
private private
def set_domain def set_domain

View file

@ -1,4 +1,5 @@
class ContactMailer < ApplicationMailer class ContactMailer < ApplicationMailer
# rubocop: disable Metrics/CyclomaticComplexity
def email_updated(contact) def email_updated(contact)
unless Rails.env.production? unless Rails.env.production?
return unless TEST_EMAILS.include?(contact.email) || TEST_EMAILS.include?(contact.email_was) return unless TEST_EMAILS.include?(contact.email) || TEST_EMAILS.include?(contact.email_was)
@ -18,4 +19,5 @@ class ContactMailer < ApplicationMailer
mail(to: email, subject: "#{I18n.t(:contact_email_update_subject)} [#{@contact.code}]") mail(to: email, subject: "#{I18n.t(:contact_email_update_subject)} [#{@contact.code}]")
end end
end end
# rubocop: enable Metrics/CyclomaticComplexity
end end

View file

@ -230,7 +230,7 @@ module Depp
def extension_xml def extension_xml
xml = { _anonymus: [] } xml = { _anonymus: [] }
ident = ident_xml[:_anonymus].try(:first) if !persisted? ident = ident_xml[:_anonymus].try(:first) unless persisted?
legal = legal_document_xml[:_anonymus].try(:first) legal = legal_document_xml[:_anonymus].try(:first)
xml[:_anonymus] << ident if ident.present? xml[:_anonymus] << ident if ident.present?
xml[:_anonymus] << legal if legal.present? xml[:_anonymus] << legal if legal.present?

View file

@ -1,3 +1,4 @@
# rubocop: disable Metrics/ClassLength
class Domain < ActiveRecord::Base class Domain < ActiveRecord::Base
include Versions # version/domain_version.rb include Versions # version/domain_version.rb
has_paper_trail class_name: "DomainVersion", meta: { children: :children_log } has_paper_trail class_name: "DomainVersion", meta: { children: :children_log }
@ -152,7 +153,10 @@ class Domain < ActiveRecord::Base
d = Domain.where('valid_to <= ?', Time.zone.now) d = Domain.where('valid_to <= ?', Time.zone.now)
d.each do |x| d.each do |x|
x.domain_statuses.create(value: DomainStatus::EXPIRED) if x.expirable? next unless x.expirable?
x.domain_statuses.create(value: DomainStatus::EXPIRED)
# TODO: This should be managed by automatic_statuses
x.domain_statuses.where(value: DomainStatus::OK).destroy_all
end end
STDOUT << "#{Time.zone.now.utc} - Successfully expired #{d.count} domains\n" unless Rails.env.test? STDOUT << "#{Time.zone.now.utc} - Successfully expired #{d.count} domains\n" unless Rails.env.test?
@ -163,7 +167,10 @@ class Domain < ActiveRecord::Base
d = Domain.where('outzone_at <= ?', Time.zone.now) d = Domain.where('outzone_at <= ?', Time.zone.now)
d.each do |x| d.each do |x|
x.domain_statuses.create(value: DomainStatus::SERVER_HOLD) if x.server_holdable? next unless x.server_holdable?
x.domain_statuses.create(value: DomainStatus::SERVER_HOLD)
# TODO: This should be managed by automatic_statuses
x.domain_statuses.where(value: DomainStatus::OK).destroy_all
end end
STDOUT << "#{Time.zone.now.utc} - Successfully set server_hold to #{d.count} domains\n" unless Rails.env.test? STDOUT << "#{Time.zone.now.utc} - Successfully set server_hold to #{d.count} domains\n" unless Rails.env.test?
@ -175,6 +182,8 @@ class Domain < ActiveRecord::Base
d = Domain.where('delete_at <= ?', Time.zone.now) d = Domain.where('delete_at <= ?', Time.zone.now)
d.each do |x| d.each do |x|
x.domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if x.delete_candidateable? x.domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if x.delete_candidateable?
# TODO: This should be managed by automatic_statuses
x.domain_statuses.where(value: DomainStatus::OK).destroy_all
end end
return if Rails.env.test? return if Rails.env.test?
@ -190,6 +199,11 @@ class Domain < ActiveRecord::Base
c += 1 c += 1
end end
Domain.where('force_delete_at <= ?', Time.zone.now).each do |x|
x.destroy
c += 1
end
STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{c} domains\n" unless Rails.env.test? STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{c} domains\n" unless Rails.env.test?
end end
end end
@ -245,7 +259,7 @@ class Domain < ActiveRecord::Base
def renewable? def renewable?
if Setting.days_to_renew_domain_before_expire != 0 if Setting.days_to_renew_domain_before_expire != 0
if (valid_to - Time.zone.now).to_i / 1.day >= Setting.days_to_renew_domain_before_expire if ((valid_to - Time.zone.now.beginning_of_day).to_i / 1.day) + 1 > Setting.days_to_renew_domain_before_expire
return false return false
end end
end end
@ -298,6 +312,10 @@ class Domain < ActiveRecord::Base
true true
end end
def force_deletable?
domain_statuses.where(value: DomainStatus::FORCE_DELETE).empty?
end
def registrant_verification_asked? def registrant_verification_asked?
registrant_verification_asked_at.present? && registrant_verification_token.present? registrant_verification_asked_at.present? && registrant_verification_token.present?
end end
@ -399,9 +417,34 @@ class Domain < ActiveRecord::Base
self.delete_at = outzone_at + Setting.redemption_grace_period.days self.delete_at = outzone_at + Setting.redemption_grace_period.days
end end
def set_force_delete
domain_statuses.where(value: DomainStatus::FORCE_DELETE).first_or_create
domain_statuses.where(value: DomainStatus::SERVER_RENEW_PROHIBITED).first_or_create
domain_statuses.where(value: DomainStatus::SERVER_TRANSFER_PROHIBITED).first_or_create
domain_statuses.where(value: DomainStatus::SERVER_UPDATE_PROHIBITED).first_or_create
domain_statuses.where(value: DomainStatus::SERVER_MANUAL_INZONE).first_or_create
domain_statuses.where(value: DomainStatus::PENDING_DELETE).first_or_create
domain_statuses.where(value: DomainStatus::CLIENT_DELETE_PROHIBITED).destroy_all
domain_statuses.where(value: DomainStatus::SERVER_DELETE_PROHIBITED).destroy_all
domain_statuses.reload
self.force_delete_at = Time.zone.now + Setting.redemption_grace_period.days unless force_delete_at
save(validate: false)
end
def unset_force_delete
domain_statuses.where(value: DomainStatus::FORCE_DELETE).destroy_all
domain_statuses.where(value: DomainStatus::SERVER_RENEW_PROHIBITED).destroy_all
domain_statuses.where(value: DomainStatus::SERVER_TRANSFER_PROHIBITED).destroy_all
domain_statuses.where(value: DomainStatus::SERVER_UPDATE_PROHIBITED).destroy_all
domain_statuses.where(value: DomainStatus::SERVER_MANUAL_INZONE).destroy_all
domain_statuses.where(value: DomainStatus::PENDING_DELETE).destroy_all
domain_statuses.reload
self.force_delete_at = nil
save(validate: false)
end
def manage_automatic_statuses def manage_automatic_statuses
# domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if delete_candidateable? # domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if delete_candidateable?
if domain_statuses.empty? && valid? if domain_statuses.empty? && valid?
domain_statuses.create(value: DomainStatus::OK) domain_statuses.create(value: DomainStatus::OK)
elsif domain_statuses.length > 1 || !valid? elsif domain_statuses.length > 1 || !valid?
@ -437,3 +480,4 @@ class Domain < ActiveRecord::Base
whois_record.blank? ? create_whois_record : whois_record.save whois_record.blank? ? create_whois_record : whois_record.save
end end
end end
# rubocop: enable Metrics/ClassLength

View file

@ -434,6 +434,8 @@ class Epp::Domain < Domain
p = self.class.convert_period_to_time(period, unit) p = self.class.convert_period_to_time(period, unit)
self.valid_to = valid_to + p self.valid_to = valid_to + p
self.outzone_at = outzone_at + p
self.delete_at = delete_at + p
self.period = period self.period = period
self.period_unit = unit self.period_unit = unit

View file

@ -7,7 +7,7 @@ class Pricelist < ActiveRecord::Base
:valid_from, :category, :operation_category, :duration, presence: true :valid_from, :category, :operation_category, :duration, presence: true
CATEGORIES = %w(ee pri.ee fie.ee med.ee com.ee) CATEGORIES = %w(ee pri.ee fie.ee med.ee com.ee)
OPERATION_CATEGORIES = %w(new renew) OPERATION_CATEGORIES = %w(create renew)
DURATIONS = %w(1year 2years 3years) DURATIONS = %w(1year 2years 3years)
after_initialize :init_values after_initialize :init_values

View file

@ -1,6 +1,11 @@
- content_for :actions do - content_for :actions do
= link_to(t(:edit_statuses), edit_admin_domain_path(@domain), class: 'btn btn-primary') = link_to(t(:edit_statuses), edit_admin_domain_path(@domain), class: 'btn btn-primary')
= link_to(t(:history), admin_domain_domain_versions_path(@domain.id), method: :get, class: 'btn btn-primary') = link_to(t(:history), admin_domain_domain_versions_path(@domain.id), method: :get, class: 'btn btn-primary')
- if @domain.force_deletable?
= link_to(t(:set_force_delete), set_force_delete_admin_domain_path(@domain), method: :post, data: { confirm: t(:are_you_sure) }, class: 'btn btn-warning')
- else
= link_to(t(:unset_force_delete), unset_force_delete_admin_domain_path(@domain), method: :post, data: { confirm: t(:are_you_sure) }, class: 'btn btn-warning')
= render 'shared/title', name: @domain.name = render 'shared/title', name: @domain.name
.row .row

View file

@ -2,10 +2,10 @@
%title= "#{truncate(name, length: 60)}#{head_title_sufix}" %title= "#{truncate(name, length: 60)}#{head_title_sufix}"
.row .row
.col-sm-7 .col-sm-6
%h1.text-center-xs %h1.text-center-xs
= truncate(name, length: 35) = truncate(name, length: 35)
.col-sm-5 .col-sm-6
%h1.text-right.text-center-xs %h1.text-right.text-center-xs
= yield :actions = yield :actions
%hr %hr

View file

@ -818,3 +818,5 @@ en:
valid: Valid valid: Valid
category: Zone category: Zone
object_is_not_eligible_for_renewal: 'Object is not eligible for renewal' object_is_not_eligible_for_renewal: 'Object is not eligible for renewal'
set_force_delete: 'Set force delete'
unset_force_delete: 'Unset force delete'

View file

@ -175,6 +175,10 @@ Rails.application.routes.draw do
resources :domains do resources :domains do
resources :domain_versions resources :domain_versions
member do
post 'set_force_delete'
post 'unset_force_delete'
end
end end
resources :settings resources :settings

View file

@ -0,0 +1,5 @@
class AddForceDeleteAtToDomain < ActiveRecord::Migration
def change
add_column :domains, :force_delete_at, :datetime
end
end

View file

@ -19,7 +19,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
create_table "account_activities", force: :cascade do |t| create_table "account_activities", force: :cascade do |t|
t.integer "account_id" t.integer "account_id"
t.integer "invoice_id" t.integer "invoice_id"
t.decimal "sum", precision: 8, scale: 2 t.decimal "sum", precision: 10, scale: 2
t.string "currency" t.string "currency"
t.integer "bank_transaction_id" t.integer "bank_transaction_id"
t.datetime "created_at" t.datetime "created_at"
@ -36,7 +36,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
create_table "accounts", force: :cascade do |t| create_table "accounts", force: :cascade do |t|
t.integer "registrar_id" t.integer "registrar_id"
t.string "account_type" t.string "account_type"
t.decimal "balance", precision: 8, scale: 2, default: 0.0, null: false t.decimal "balance", precision: 10, scale: 2, default: 0.0, null: false
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "currency" t.string "currency"
@ -98,7 +98,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
t.string "buyer_name" t.string "buyer_name"
t.string "document_no" t.string "document_no"
t.string "description" t.string "description"
t.decimal "sum", precision: 8, scale: 2 t.decimal "sum", precision: 10, scale: 2
t.string "reference_no" t.string "reference_no"
t.datetime "paid_at" t.datetime "paid_at"
t.datetime "created_at" t.datetime "created_at"
@ -114,7 +114,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
t.string "vk_rec_id" t.string "vk_rec_id"
t.string "vk_stamp" t.string "vk_stamp"
t.string "vk_t_no" t.string "vk_t_no"
t.decimal "vk_amount", precision: 8, scale: 2 t.decimal "vk_amount", precision: 10, scale: 2
t.string "vk_curr" t.string "vk_curr"
t.string "vk_rec_acc" t.string "vk_rec_acc"
t.string "vk_rec_name" t.string "vk_rec_name"
@ -331,7 +331,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
t.string "description", null: false t.string "description", null: false
t.string "unit" t.string "unit"
t.integer "amount" t.integer "amount"
t.decimal "price", precision: 8, scale: 2 t.decimal "price", precision: 10, scale: 2
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "creator_str" t.string "creator_str"
@ -349,7 +349,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
t.string "currency", null: false t.string "currency", null: false
t.string "description" t.string "description"
t.string "reference_no" t.string "reference_no"
t.decimal "vat_prc", precision: 8, scale: 2, null: false t.decimal "vat_prc", precision: 10, scale: 2, null: false
t.datetime "paid_at" t.datetime "paid_at"
t.integer "seller_id" t.integer "seller_id"
t.string "seller_name", null: false t.string "seller_name", null: false
@ -382,7 +382,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
t.string "updator_str" t.string "updator_str"
t.integer "number" t.integer "number"
t.datetime "cancelled_at" t.datetime "cancelled_at"
t.decimal "sum_cache", precision: 8, scale: 2 t.decimal "sum_cache", precision: 10, scale: 2
end end
add_index "invoices", ["buyer_id"], name: "index_invoices_on_buyer_id", using: :btree add_index "invoices", ["buyer_id"], name: "index_invoices_on_buyer_id", using: :btree
@ -983,7 +983,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
t.text "crt" t.text "crt"
t.string "type" t.string "type"
t.string "registrant_ident" t.string "registrant_ident"
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: ""
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.integer "failed_attempts", default: 0, null: false t.integer "failed_attempts", default: 0, null: false
t.datetime "locked_at" t.datetime "locked_at"

View file

@ -1999,7 +1999,8 @@ describe 'EPP Domain', epp: true do
end end
it 'does not renew a domain unless less than 90 days till expiration' do it 'does not renew a domain unless less than 90 days till expiration' do
domain.valid_to = Time.zone.now.to_date + 91.days # both days are inclusive
domain.valid_to = Time.zone.now.to_date + 90.days
domain.save domain.save
exp_date = domain.valid_to.to_date exp_date = domain.valid_to.to_date
@ -2013,7 +2014,7 @@ describe 'EPP Domain', epp: true do
response[:results][0][:msg].should == 'Object is not eligible for renewal' response[:results][0][:msg].should == 'Object is not eligible for renewal'
response[:results][0][:result_code].should == '2105' response[:results][0][:result_code].should == '2105'
domain.valid_to = Time.zone.now.to_date + 90.days domain.valid_to = Time.zone.now.to_date + 89.days
domain.save domain.save
exp_date = domain.valid_to.to_date exp_date = domain.valid_to.to_date
@ -2069,7 +2070,10 @@ describe 'EPP Domain', epp: true do
it 'should renew a expired domain' do it 'should renew a expired domain' do
domain.valid_to = Time.zone.now - 50.days domain.valid_to = Time.zone.now - 50.days
new_valid_to = domain.valid_to + 1.year
domain.outzone_at = Time.zone.now - 50.days domain.outzone_at = Time.zone.now - 50.days
new_outzone_at = domain.outzone_at + 1.year
new_delete_at = domain.delete_at + 1.year
domain.save domain.save
Domain.start_expire_period Domain.start_expire_period
@ -2077,6 +2081,7 @@ describe 'EPP Domain', epp: true do
domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 1 domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 1
domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 1 domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 1
domain.domain_statuses.where(value: DomainStatus::OK).count.should == 0
exp_date = domain.valid_to.to_date exp_date = domain.valid_to.to_date
@ -2092,6 +2097,12 @@ describe 'EPP Domain', epp: true do
domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 0 domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 0
domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 0 domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 0
domain.domain_statuses.where(value: DomainStatus::OK).count.should == 1
domain.reload
domain.valid_to.should be_within(5).of(new_valid_to)
domain.outzone_at.should be_within(5).of(new_outzone_at)
domain.delete_at.should be_within(5).of(new_delete_at)
end end
it 'does not renew foreign domain' do it 'does not renew foreign domain' do

View file

@ -143,16 +143,32 @@ describe Domain do
end end
it 'should destroy delete candidates' do it 'should destroy delete candidates' do
Fabricate(:domain) d = Fabricate(:domain)
Domain.count.should == 2 d.force_delete_at = Time.zone.now
d.save
@domain.delete_at = Time.zone.now @domain.delete_at = Time.zone.now
@domain.save @domain.save
Domain.count.should == 2
Domain.start_delete_period Domain.start_delete_period
Domain.destroy_delete_candidates Domain.destroy_delete_candidates
Domain.count.should == 1 Domain.count.should == 0
end
it 'should set force delete time' do
@domain.set_force_delete
@domain.domain_statuses.count.should == 6
fda = Time.zone.now + Setting.redemption_grace_period
@domain.force_delete_at.should be_within(20).of(fda)
@domain.unset_force_delete
@domain.domain_statuses.count.should == 1
@domain.force_delete_at.should be_nil
end end
context 'about registrant update confirm' do context 'about registrant update confirm' do