mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 03:06:14 +02:00
Resolve merge errors
This commit is contained in:
commit
73e9dd6870
817 changed files with 16875 additions and 17443 deletions
|
@ -34,8 +34,6 @@ class Ability
|
|||
if @user.registrar.api_ip_white?(@ip)
|
||||
can :manage, :poll
|
||||
can :manage, Depp::Contact
|
||||
# can :manage, Depp::Keyrelay # TODO: Keyrelay is disabled for now
|
||||
# can :confirm, :keyrelay # TODO: Keyrelay is disabled for now
|
||||
can :manage, :xml_console
|
||||
can :manage, Depp::Domain
|
||||
end
|
||||
|
@ -48,13 +46,13 @@ class Ability
|
|||
# can(:create, :epp_request)
|
||||
|
||||
# Epp::Domain
|
||||
can(:info, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || pw.blank? ? true : d.transfer_code == pw }
|
||||
can(:info, Epp::Domain)
|
||||
can(:check, Epp::Domain)
|
||||
can(:create, Epp::Domain)
|
||||
can(:renew, Epp::Domain) { |d| d.registrar_id == @user.registrar_id }
|
||||
can(:remove_hold, Epp::Domain) { |d| d.registrar_id == @user.registrar_id }
|
||||
can(:update, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.transfer_code == pw }
|
||||
can(:transfer, Epp::Domain) { |d, pw| d.transfer_code == pw }
|
||||
can(:view_password, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.transfer_code == pw }
|
||||
can(:transfer, Epp::Domain)
|
||||
can(:delete, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.transfer_code == pw }
|
||||
|
||||
# Epp::Contact
|
||||
|
@ -65,6 +63,7 @@ class Ability
|
|||
can(:update, Epp::Contact) { |c, pw| c.registrar_id == @user.registrar_id || c.auth_info == pw }
|
||||
can(:delete, Epp::Contact) { |c, pw| c.registrar_id == @user.registrar_id || c.auth_info == pw }
|
||||
can(:renew, Epp::Contact)
|
||||
can(:transfer, Epp::Contact)
|
||||
can(:view_password, Epp::Contact) { |c, pw| c.registrar_id == @user.registrar_id || c.auth_info == pw }
|
||||
end
|
||||
|
||||
|
@ -95,13 +94,13 @@ class Ability
|
|||
can :manage, ApiUser
|
||||
can :manage, AdminUser
|
||||
can :manage, Certificate
|
||||
can :manage, Keyrelay
|
||||
can :manage, LegalDocument
|
||||
can :manage, BankStatement
|
||||
can :manage, BankTransaction
|
||||
can :manage, Invoice
|
||||
can :manage, WhiteIp
|
||||
can :manage, AccountActivity
|
||||
can :manage, Dispute
|
||||
can :read, ApiLog::EppLog
|
||||
can :read, ApiLog::ReppLog
|
||||
can :update, :pending
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Account < ActiveRecord::Base
|
||||
class Account < ApplicationRecord
|
||||
include Versions
|
||||
|
||||
belongs_to :registrar, required: true
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class AccountActivity < ActiveRecord::Base
|
||||
class AccountActivity < ApplicationRecord
|
||||
include Versions
|
||||
belongs_to :account, required: true
|
||||
belongs_to :bank_transaction
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Action < ActiveRecord::Base
|
||||
has_paper_trail class_name: 'ActionVersion'
|
||||
class Action < ApplicationRecord
|
||||
has_paper_trail versions: { class_name: 'ActionVersion' }
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :contact
|
||||
|
@ -16,4 +16,4 @@ class Action < ActiveRecord::Base
|
|||
raise 'Action object is missing' unless contact
|
||||
"contact_#{operation}".to_sym
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
105
app/models/actions/contact_update.rb
Normal file
105
app/models/actions/contact_update.rb
Normal file
|
@ -0,0 +1,105 @@
|
|||
module Actions
|
||||
class ContactUpdate
|
||||
attr_reader :contact
|
||||
attr_reader :new_attributes
|
||||
attr_reader :legal_document
|
||||
attr_reader :ident
|
||||
attr_reader :user
|
||||
|
||||
def initialize(contact, new_attributes, legal_document, ident, user)
|
||||
@contact = contact
|
||||
@new_attributes = new_attributes
|
||||
@legal_document = legal_document
|
||||
@ident = ident
|
||||
@user = user
|
||||
end
|
||||
|
||||
def call
|
||||
maybe_remove_address
|
||||
maybe_update_statuses
|
||||
maybe_update_ident
|
||||
maybe_attach_legal_doc
|
||||
commit
|
||||
end
|
||||
|
||||
def maybe_remove_address
|
||||
return if Contact.address_processing?
|
||||
|
||||
new_attributes.delete(:city)
|
||||
new_attributes.delete(:zip)
|
||||
new_attributes.delete(:street)
|
||||
new_attributes.delete(:state)
|
||||
new_attributes.delete(:country_code)
|
||||
end
|
||||
|
||||
def maybe_update_statuses
|
||||
return unless Setting.client_status_editing_enabled
|
||||
|
||||
new_statuses =
|
||||
contact.statuses - new_attributes[:statuses_to_remove] + new_attributes[:statuses_to_add]
|
||||
|
||||
new_attributes[:statuses] = new_statuses
|
||||
end
|
||||
|
||||
def maybe_attach_legal_doc
|
||||
return unless legal_document
|
||||
|
||||
document = contact.legal_documents.create(
|
||||
document_type: legal_document[:type],
|
||||
body: legal_document[:body]
|
||||
)
|
||||
|
||||
contact.legal_document_id = document.id
|
||||
end
|
||||
|
||||
def maybe_update_ident
|
||||
return unless ident[:ident]
|
||||
|
||||
if contact.identifier.valid?
|
||||
submitted_ident = ::Contact::Ident.new(code: ident[:ident],
|
||||
type: ident[:ident_type],
|
||||
country_code: ident[:ident_country_code])
|
||||
|
||||
if submitted_ident != contact.identifier
|
||||
contact.add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident'))
|
||||
@error = true
|
||||
end
|
||||
else
|
||||
ident_update_attempt = ident[:ident] != contact.ident
|
||||
|
||||
if ident_update_attempt
|
||||
contact.add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.ident_update'))
|
||||
@error = true
|
||||
end
|
||||
|
||||
identifier = ::Contact::Ident.new(code: ident[:ident],
|
||||
type: ident[:ident_type],
|
||||
country_code: ident[:ident_country_code])
|
||||
|
||||
identifier.validate
|
||||
|
||||
contact.identifier = identifier
|
||||
contact.ident_updated_at ||= Time.zone.now
|
||||
end
|
||||
end
|
||||
|
||||
def commit
|
||||
return false if @error
|
||||
|
||||
contact.upid = user.registrar&.id
|
||||
contact.up_date = Time.zone.now
|
||||
|
||||
contact.attributes = new_attributes
|
||||
|
||||
email_changed = contact.will_save_change_to_email?
|
||||
old_email = contact.email_was
|
||||
updated = contact.save
|
||||
|
||||
if updated && email_changed && contact.registrant?
|
||||
ContactMailer.email_changed(contact: contact, old_email: old_email).deliver_now
|
||||
end
|
||||
|
||||
updated
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@ class AdminUser < User
|
|||
validates :identity_code, presence: true, if: -> { country_code == 'EE' }
|
||||
validates :email, presence: true
|
||||
validates :password, :password_confirmation, presence: true, if: :new_record?
|
||||
validates :password_confirmation, presence: true, if: :encrypted_password_changed?
|
||||
validates :password_confirmation, presence: true, if: :will_save_change_to_encrypted_password?
|
||||
validate :validate_identity_code, if: -> { country_code == 'EE' }
|
||||
|
||||
ROLES = %w(user customer_service admin) # should not match to api_users roles
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module ApiLog
|
||||
class Db < ActiveRecord::Base
|
||||
class Db < ApplicationRecord
|
||||
self.abstract_class = true
|
||||
# to_sym is needed because passing a string to ActiveRecord::Base.establish_connection
|
||||
# for a configuration lookup is deprecated
|
||||
|
|
|
@ -26,9 +26,9 @@ class ApiUser < User
|
|||
validates :username, uniqueness: true
|
||||
|
||||
delegate :code, :name, to: :registrar, prefix: true
|
||||
delegate :legaldoc_mandatory?, to: :registrar
|
||||
|
||||
alias_attribute :login, :username
|
||||
attr_accessor :registrar_typeahead
|
||||
|
||||
SUPER = 'super'
|
||||
EPP = 'epp'
|
||||
|
@ -44,7 +44,7 @@ class ApiUser < User
|
|||
after_initialize :set_defaults
|
||||
def set_defaults
|
||||
return unless new_record?
|
||||
self.active = true unless active_changed?
|
||||
self.active = true unless saved_change_to_active?
|
||||
end
|
||||
|
||||
class << self
|
||||
|
@ -53,10 +53,6 @@ class ApiUser < User
|
|||
end
|
||||
end
|
||||
|
||||
def registrar_typeahead
|
||||
@registrar_typeahead || registrar || nil
|
||||
end
|
||||
|
||||
def to_s
|
||||
username
|
||||
end
|
||||
|
@ -69,24 +65,14 @@ class ApiUser < User
|
|||
registrar.notifications.unread
|
||||
end
|
||||
|
||||
def registrar_pki_ok?(crt, cn)
|
||||
return false if crt.blank? || cn.blank?
|
||||
crt = crt.split(' ').join("\n")
|
||||
crt.gsub!("-----BEGIN\nCERTIFICATE-----\n", "-----BEGIN CERTIFICATE-----\n")
|
||||
crt.gsub!("\n-----END\nCERTIFICATE-----", "\n-----END CERTIFICATE-----")
|
||||
cert = OpenSSL::X509::Certificate.new(crt)
|
||||
md5 = OpenSSL::Digest::MD5.new(cert.to_der).to_s
|
||||
certificates.registrar.exists?(md5: md5, common_name: cn)
|
||||
end
|
||||
def pki_ok?(crt, com, api: true)
|
||||
return false if crt.blank? || com.blank?
|
||||
|
||||
def api_pki_ok?(crt, cn)
|
||||
return false if crt.blank? || cn.blank?
|
||||
crt = crt.split(' ').join("\n")
|
||||
crt.gsub!("-----BEGIN\nCERTIFICATE-----\n", "-----BEGIN CERTIFICATE-----\n")
|
||||
crt.gsub!("\n-----END\nCERTIFICATE-----", "\n-----END CERTIFICATE-----")
|
||||
cert = OpenSSL::X509::Certificate.new(crt)
|
||||
origin = api ? certificates.api : certificates.registrar
|
||||
cert = machine_readable_certificate(crt)
|
||||
md5 = OpenSSL::Digest::MD5.new(cert.to_der).to_s
|
||||
certificates.api.exists?(md5: md5, common_name: cn)
|
||||
|
||||
origin.exists?(md5: md5, common_name: com, revoked: false)
|
||||
end
|
||||
|
||||
def linked_users
|
||||
|
@ -98,4 +84,14 @@ class ApiUser < User
|
|||
def linked_with?(another_api_user)
|
||||
another_api_user.identity_code == self.identity_code
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def machine_readable_certificate(cert)
|
||||
cert = cert.split(' ').join("\n")
|
||||
cert.gsub!("-----BEGIN\nCERTIFICATE-----\n", "-----BEGIN CERTIFICATE-----\n")
|
||||
cert.gsub!("\n-----END\nCERTIFICATE-----", "\n-----END CERTIFICATE-----")
|
||||
|
||||
OpenSSL::X509::Certificate.new(cert)
|
||||
end
|
||||
end
|
||||
|
|
3
app/models/application_record.rb
Normal file
3
app/models/application_record.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class ApplicationRecord < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
class Auction < ActiveRecord::Base
|
||||
class Auction < ApplicationRecord
|
||||
enum status: {
|
||||
started: 'started',
|
||||
awaiting_payment: 'awaiting_payment',
|
||||
|
@ -23,10 +23,19 @@ class Auction < ActiveRecord::Base
|
|||
save!
|
||||
end
|
||||
|
||||
def whois_deadline
|
||||
registration_deadline.try(:to_s, :iso8601)
|
||||
end
|
||||
|
||||
def mark_as_no_bids
|
||||
no_bids!
|
||||
end
|
||||
|
||||
def mark_deadline(registration_deadline)
|
||||
self.registration_deadline = registration_deadline
|
||||
save!
|
||||
end
|
||||
|
||||
def mark_as_payment_received
|
||||
self.status = self.class.statuses[:payment_received]
|
||||
generate_registration_code
|
||||
|
@ -69,4 +78,4 @@ class Auction < ActiveRecord::Base
|
|||
def registration_code_matches?(code)
|
||||
registration_code == code
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class BankStatement < ActiveRecord::Base
|
||||
class BankStatement < ApplicationRecord
|
||||
include Versions
|
||||
has_many :bank_transactions
|
||||
|
||||
|
@ -25,10 +25,16 @@ class BankStatement < ActiveRecord::Base
|
|||
bank_transactions.build(bt_params)
|
||||
end
|
||||
|
||||
prepare_dir
|
||||
self.import_file_path = "#{ENV['bank_statement_import_dir']}/#{Time.zone.now.to_formatted_s(:number)}.txt"
|
||||
File.open(import_file_path, 'w') { |f| f.write(th6_file.open.read) }
|
||||
end
|
||||
|
||||
def prepare_dir
|
||||
dirname = ENV['bank_statement_import_dir']
|
||||
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
||||
end
|
||||
|
||||
def parse_th6_row(row)
|
||||
return parse_th6_header(row) if row[4, 3].strip == '000'
|
||||
return if row[4, 3].strip == '999' # skip footer
|
||||
|
@ -45,7 +51,7 @@ class BankStatement < ActiveRecord::Base
|
|||
buyer_name: row[83, 35].strip,
|
||||
document_no: row[118, 8].strip,
|
||||
description: row[126, 140].strip,
|
||||
sum: BigDecimal.new(row[268, 12].strip) / BigDecimal.new('100.0'),
|
||||
sum: BigDecimal(row[268, 12].strip) / BigDecimal('100.0'),
|
||||
reference_no: row[280, 35].strip
|
||||
}
|
||||
end
|
||||
|
@ -80,7 +86,9 @@ class BankStatement < ActiveRecord::Base
|
|||
status == FULLY_BINDED
|
||||
end
|
||||
|
||||
def bind_invoices
|
||||
bank_transactions.unbinded.each(&:autobind_invoice)
|
||||
def bind_invoices(manual: false)
|
||||
bank_transactions.unbinded.each do |transaction|
|
||||
transaction.autobind_invoice(manual: manual)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class BankTransaction < ActiveRecord::Base
|
||||
class BankTransaction < ApplicationRecord
|
||||
include Versions
|
||||
belongs_to :bank_statement
|
||||
has_one :account_activity
|
||||
|
@ -13,53 +13,72 @@ class BankTransaction < ActiveRecord::Base
|
|||
|
||||
def binded_invoice
|
||||
return unless binded?
|
||||
|
||||
account_activity.invoice
|
||||
end
|
||||
|
||||
|
||||
def invoice_num
|
||||
return @invoice_no if defined?(@invoice_no)
|
||||
|
||||
match = description.match(/^[^\d]*(\d+)/)
|
||||
return unless match
|
||||
|
||||
@invoice_no = match[1].try(:to_i)
|
||||
end
|
||||
|
||||
def invoice
|
||||
@invoice ||= registrar.invoices.find_by(number: invoice_num) if registrar
|
||||
return unless registrar
|
||||
|
||||
@invoice ||= registrar.invoices
|
||||
.order(created_at: :asc)
|
||||
.unpaid
|
||||
.non_cancelled
|
||||
.find_by(total: sum)
|
||||
end
|
||||
|
||||
def registrar
|
||||
@registrar ||= Invoice.find_by(reference_no: reference_no)&.buyer
|
||||
@registrar ||= Invoice.find_by(reference_no: parsed_ref_number)&.buyer
|
||||
end
|
||||
|
||||
|
||||
# For successful binding, reference number, invoice id and sum must match with the invoice
|
||||
def autobind_invoice
|
||||
def autobind_invoice(manual: false)
|
||||
return if binded?
|
||||
return unless registrar
|
||||
return unless invoice_num
|
||||
return unless invoice
|
||||
return unless invoice.payable?
|
||||
|
||||
return if invoice.total != sum
|
||||
create_activity(registrar, invoice)
|
||||
channel = if manual
|
||||
'admin_payment'
|
||||
else
|
||||
'system_payment'
|
||||
end
|
||||
create_internal_payment_record(channel: channel, invoice: invoice,
|
||||
registrar: registrar)
|
||||
end
|
||||
|
||||
def bind_invoice(invoice_no)
|
||||
def create_internal_payment_record(channel: nil, invoice:, registrar:)
|
||||
if channel.nil?
|
||||
create_activity(invoice.buyer, invoice)
|
||||
return
|
||||
end
|
||||
|
||||
payment_order = PaymentOrder.new_with_type(type: channel, invoice: invoice)
|
||||
payment_order.save!
|
||||
|
||||
if create_activity(registrar, invoice)
|
||||
payment_order.paid!
|
||||
else
|
||||
payment_order.update(notes: 'Failed to create activity', status: 'failed')
|
||||
end
|
||||
end
|
||||
|
||||
def bind_invoice(invoice_no, manual: false)
|
||||
if binded?
|
||||
errors.add(:base, I18n.t('transaction_is_already_binded'))
|
||||
return
|
||||
end
|
||||
|
||||
invoice = Invoice.find_by(number: invoice_no)
|
||||
errors.add(:base, I18n.t('invoice_was_not_found')) unless invoice
|
||||
validate_invoice_data(invoice)
|
||||
return if errors.any?
|
||||
|
||||
unless invoice
|
||||
errors.add(:base, I18n.t('invoice_was_not_found'))
|
||||
return
|
||||
end
|
||||
create_internal_payment_record(channel: (manual ? 'admin_payment' : nil), invoice: invoice,
|
||||
registrar: invoice.buyer)
|
||||
end
|
||||
|
||||
def validate_invoice_data(invoice)
|
||||
if invoice.paid?
|
||||
errors.add(:base, I18n.t('invoice_is_already_binded'))
|
||||
return
|
||||
|
@ -70,23 +89,21 @@ class BankTransaction < ActiveRecord::Base
|
|||
return
|
||||
end
|
||||
|
||||
if invoice.total != sum
|
||||
errors.add(:base, I18n.t('invoice_and_transaction_sums_do_not_match'))
|
||||
return
|
||||
end
|
||||
|
||||
create_activity(invoice.buyer, invoice)
|
||||
errors.add(:base, I18n.t('invoice_and_transaction_sums_do_not_match')) if invoice.total != sum
|
||||
end
|
||||
|
||||
def create_activity(registrar, invoice)
|
||||
ActiveRecord::Base.transaction do
|
||||
create_account_activity!(account: registrar.cash_account,
|
||||
invoice: invoice,
|
||||
sum: invoice.subtotal,
|
||||
currency: currency,
|
||||
description: description,
|
||||
activity_type: AccountActivity::ADD_CREDIT)
|
||||
activity = AccountActivity.new(
|
||||
account: registrar.cash_account, bank_transaction: self,
|
||||
invoice: invoice, sum: invoice.subtotal,
|
||||
currency: currency, description: description,
|
||||
activity_type: AccountActivity::ADD_CREDIT
|
||||
)
|
||||
if activity.save
|
||||
reset_pending_registrar_balance_reload
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -98,4 +115,12 @@ class BankTransaction < ActiveRecord::Base
|
|||
registrar.settings['balance_auto_reload'].delete('pending')
|
||||
registrar.save!
|
||||
end
|
||||
|
||||
def parsed_ref_number
|
||||
reference_no || ref_number_from_description
|
||||
end
|
||||
|
||||
def ref_number_from_description
|
||||
/(\d{7})/.match(description)[0]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module Billing
|
||||
class Price < ActiveRecord::Base
|
||||
class Price < ApplicationRecord
|
||||
include Concerns::Billing::Price::Expirable
|
||||
|
||||
belongs_to :zone, class_name: 'DNS::Zone', required: true
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class BlockedDomain < ActiveRecord::Base
|
||||
class BlockedDomain < ApplicationRecord
|
||||
include Versions
|
||||
before_save :generate_data
|
||||
after_destroy :remove_data
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'open3'
|
||||
|
||||
class Certificate < ActiveRecord::Base
|
||||
class Certificate < ApplicationRecord
|
||||
include Versions
|
||||
|
||||
belongs_to :api_user
|
||||
|
@ -32,20 +32,21 @@ class Certificate < ActiveRecord::Base
|
|||
errors.add(:base, I18n.t(:invalid_csr_or_crt))
|
||||
end
|
||||
|
||||
before_create :parse_metadata
|
||||
def parse_metadata
|
||||
if crt
|
||||
pc = parsed_crt.try(:subject).try(:to_s) || ''
|
||||
cn = pc.scan(/\/CN=(.+)/).flatten.first
|
||||
self.common_name = cn.split('/').first
|
||||
self.md5 = OpenSSL::Digest::MD5.new(parsed_crt.to_der).to_s
|
||||
self.interface = API
|
||||
elsif csr
|
||||
pc = parsed_csr.try(:subject).try(:to_s) || ''
|
||||
cn = pc.scan(/\/CN=(.+)/).flatten.first
|
||||
self.common_name = cn.split('/').first
|
||||
self.interface = REGISTRAR
|
||||
end
|
||||
validate :assign_metadata, on: :create
|
||||
|
||||
def assign_metadata
|
||||
origin = crt ? parsed_crt : parsed_csr
|
||||
parse_metadata(origin)
|
||||
rescue NoMethodError
|
||||
errors.add(:base, I18n.t(:invalid_csr_or_crt))
|
||||
end
|
||||
|
||||
def parse_metadata(origin)
|
||||
pc = origin.subject.to_s
|
||||
cn = pc.scan(%r{\/CN=(.+)}).flatten.first
|
||||
self.common_name = cn.split('/').first
|
||||
self.md5 = OpenSSL::Digest::MD5.new(origin.to_der).to_s if crt
|
||||
self.interface = crt ? API : REGISTRAR
|
||||
end
|
||||
|
||||
def parsed_crt
|
||||
|
@ -116,6 +117,7 @@ class Certificate < ActiveRecord::Base
|
|||
-revoke #{crt_file.path} -key '#{ENV['ca_key_password']}' -batch")
|
||||
|
||||
if err.match(/Data Base Updated/) || err.match(/ERROR:Already revoked/)
|
||||
self.revoked = true
|
||||
save!
|
||||
@cached_status = REVOKED
|
||||
else
|
||||
|
|
3
app/models/certification_request.rb
Normal file
3
app/models/certification_request.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class CertificationRequest
|
||||
extend ActiveModel::Translation
|
||||
end
|
|
@ -3,7 +3,7 @@ module Concerns::Contact::Transferable
|
|||
|
||||
included do
|
||||
validates :auth_info, presence: true
|
||||
after_initialize :generate_auth_info, if: 'new_record? && auth_info.blank?'
|
||||
after_initialize :generate_auth_info, if: -> { new_record? && auth_info.blank? }
|
||||
end
|
||||
|
||||
def transfer(new_registrar)
|
||||
|
|
44
app/models/concerns/domain/disputable.rb
Normal file
44
app/models/concerns/domain/disputable.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Concerns
|
||||
module Domain
|
||||
module Disputable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
validate :validate_disputed
|
||||
end
|
||||
|
||||
def mark_as_disputed
|
||||
statuses.push(DomainStatus::DISPUTED) unless statuses.include?(DomainStatus::DISPUTED)
|
||||
save
|
||||
end
|
||||
|
||||
def unmark_as_disputed
|
||||
statuses.delete_if { |status| status == DomainStatus::DISPUTED }
|
||||
save
|
||||
end
|
||||
|
||||
def in_disputed_list?
|
||||
@in_disputed_list ||= Dispute.active.find_by(domain_name: name).present?
|
||||
end
|
||||
|
||||
def disputed?
|
||||
Dispute.active.where(domain_name: name).any?
|
||||
end
|
||||
|
||||
def validate_disputed
|
||||
return if persisted? || !in_disputed_list?
|
||||
|
||||
if reserved_pw.blank?
|
||||
errors.add(:base, :required_parameter_missing_disputed)
|
||||
return false
|
||||
end
|
||||
|
||||
return if Dispute.valid_auth?(name, reserved_pw)
|
||||
|
||||
errors.add(:base, :invalid_auth_information_reserved)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,32 +1,116 @@
|
|||
module Concerns::Domain::ForceDelete
|
||||
module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
store_accessor :force_delete_data,
|
||||
:force_delete_type,
|
||||
:contact_notification_sent_date,
|
||||
:template_name
|
||||
|
||||
scope :notification_not_sent,
|
||||
lambda {
|
||||
where("(force_delete_data->>'contact_notification_sent_date') is null")
|
||||
}
|
||||
end
|
||||
|
||||
class_methods do
|
||||
def force_delete_scheduled
|
||||
where('force_delete_start <= ?', Time.zone.now)
|
||||
end
|
||||
end
|
||||
|
||||
def force_delete_scheduled?
|
||||
statuses.include?(DomainStatus::FORCE_DELETE)
|
||||
end
|
||||
|
||||
def schedule_force_delete
|
||||
def should_notify_on_soft_force_delete?
|
||||
force_delete_scheduled? && contact_notification_sent_date.blank? &&
|
||||
force_delete_start.to_date <= Time.zone.now.to_date && force_delete_type.to_sym == :soft &&
|
||||
!statuses.include?(DomainStatus::CLIENT_HOLD)
|
||||
end
|
||||
|
||||
def client_holdable?
|
||||
force_delete_scheduled? && !statuses.include?(DomainStatus::CLIENT_HOLD) &&
|
||||
force_delete_start.present? && force_delete_lte_today && force_delete_lte_valid_date
|
||||
end
|
||||
|
||||
def force_delete_lte_today
|
||||
force_delete_start + Setting.expire_warning_period.days <= Time.zone.now
|
||||
end
|
||||
|
||||
def force_delete_lte_valid_date
|
||||
force_delete_start + Setting.expire_warning_period.days <= valid_to
|
||||
end
|
||||
|
||||
def schedule_force_delete(type: :fast_track)
|
||||
if discarded?
|
||||
raise StandardError, 'Force delete procedure cannot be scheduled while a domain is discarded'
|
||||
end
|
||||
|
||||
type == :fast_track ? force_delete_fast_track : force_delete_soft
|
||||
end
|
||||
|
||||
def add_force_delete_type(force_delete_type)
|
||||
self.force_delete_type = force_delete_type
|
||||
end
|
||||
|
||||
def force_delete_fast_track
|
||||
preserve_current_statuses_for_force_delete
|
||||
add_force_delete_statuses
|
||||
self.force_delete_date = Time.zone.today + Setting.redemption_grace_period.days + 1.day
|
||||
add_force_delete_type(:fast)
|
||||
self.force_delete_date = force_delete_fast_track_start_date + 1.day
|
||||
self.force_delete_start = Time.zone.today + 1.day
|
||||
stop_all_pending_actions
|
||||
allow_deletion
|
||||
save(validate: false)
|
||||
end
|
||||
|
||||
def cancel_force_delete
|
||||
restore_statuses_before_force_delete
|
||||
remove_force_delete_statuses
|
||||
self.force_delete_date = nil
|
||||
def force_delete_soft
|
||||
preserve_current_statuses_for_force_delete
|
||||
add_force_delete_statuses
|
||||
add_force_delete_type(:soft)
|
||||
calculate_soft_delete_date
|
||||
stop_all_pending_actions
|
||||
allow_deletion
|
||||
save(validate: false)
|
||||
end
|
||||
|
||||
def clear_force_delete_data
|
||||
self.force_delete_data = nil
|
||||
end
|
||||
|
||||
def cancel_force_delete
|
||||
restore_statuses_before_force_delete
|
||||
remove_force_delete_statuses
|
||||
clear_force_delete_data
|
||||
self.force_delete_date = nil
|
||||
self.force_delete_start = nil
|
||||
save(validate: false)
|
||||
registrar.notifications.create!(text: I18n.t('force_delete_cancelled', domain_name: name))
|
||||
end
|
||||
|
||||
def outzone_date
|
||||
(force_delete_start || valid_to) + Setting.expire_warning_period.days
|
||||
end
|
||||
|
||||
def purge_date
|
||||
(force_delete_date&.beginning_of_day || valid_to + Setting.expire_warning_period.days +
|
||||
Setting.redemption_grace_period.days)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def calculate_soft_delete_date
|
||||
years = (valid_to.to_date - Time.zone.today).to_i / 365
|
||||
soft_delete_dates(years) if years.positive?
|
||||
end
|
||||
|
||||
def soft_delete_dates(years)
|
||||
self.force_delete_start = valid_to - years.years + 1.day
|
||||
self.force_delete_date = force_delete_start + Setting.expire_warning_period.days +
|
||||
Setting.redemption_grace_period.days
|
||||
end
|
||||
|
||||
def stop_all_pending_actions
|
||||
statuses.delete(DomainStatus::PENDING_UPDATE)
|
||||
statuses.delete(DomainStatus::PENDING_TRANSFER)
|
||||
|
@ -35,7 +119,7 @@ module Concerns::Domain::ForceDelete
|
|||
end
|
||||
|
||||
def preserve_current_statuses_for_force_delete
|
||||
self.statuses_before_force_delete = statuses
|
||||
self.statuses_before_force_delete = statuses.clone
|
||||
end
|
||||
|
||||
def restore_statuses_before_force_delete
|
||||
|
@ -47,25 +131,21 @@ module Concerns::Domain::ForceDelete
|
|||
statuses << DomainStatus::FORCE_DELETE
|
||||
statuses << DomainStatus::SERVER_RENEW_PROHIBITED
|
||||
statuses << DomainStatus::SERVER_TRANSFER_PROHIBITED
|
||||
statuses << DomainStatus::SERVER_UPDATE_PROHIBITED
|
||||
statuses << DomainStatus::PENDING_DELETE
|
||||
|
||||
if (statuses & [DomainStatus::SERVER_HOLD, DomainStatus::CLIENT_HOLD]).empty?
|
||||
statuses << DomainStatus::SERVER_MANUAL_INZONE
|
||||
end
|
||||
end
|
||||
|
||||
def remove_force_delete_statuses
|
||||
statuses.delete(DomainStatus::FORCE_DELETE)
|
||||
statuses.delete(DomainStatus::SERVER_RENEW_PROHIBITED)
|
||||
statuses.delete(DomainStatus::SERVER_TRANSFER_PROHIBITED)
|
||||
statuses.delete(DomainStatus::SERVER_UPDATE_PROHIBITED)
|
||||
statuses.delete(DomainStatus::PENDING_DELETE)
|
||||
statuses.delete(DomainStatus::SERVER_MANUAL_INZONE)
|
||||
statuses.delete(DomainStatus::CLIENT_HOLD)
|
||||
end
|
||||
|
||||
def allow_deletion
|
||||
statuses.delete(DomainStatus::CLIENT_DELETE_PROHIBITED)
|
||||
statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED)
|
||||
end
|
||||
|
||||
def force_delete_fast_track_start_date
|
||||
Time.zone.today + Setting.expire_warning_period.days + Setting.redemption_grace_period.days
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,7 +57,8 @@ module Concerns::Domain::Transferable
|
|||
|
||||
def transfer_domain_contacts(new_registrar)
|
||||
copied_ids = []
|
||||
contacts.each do |contact|
|
||||
domain_contacts.each do |dc|
|
||||
contact = Contact.find(dc.contact_id)
|
||||
next if copied_ids.include?(contact.id) || contact.registrar == new_registrar
|
||||
|
||||
if registrant_id_was == contact.id # registrant was copied previously, do not copy it again
|
||||
|
@ -66,7 +67,11 @@ module Concerns::Domain::Transferable
|
|||
oc = contact.transfer(new_registrar)
|
||||
end
|
||||
|
||||
domain_contacts.where(contact_id: contact.id).update_all({ contact_id: oc.id }) # n+1 workaround
|
||||
if domain_contacts.find_by(contact_id: oc.id, domain_id: id, type: dc.type).present?
|
||||
dc.destroy
|
||||
else
|
||||
dc.update(contact_id: oc.id)
|
||||
end
|
||||
copied_ids << contact.id
|
||||
end
|
||||
end
|
||||
|
|
91
app/models/concerns/email_verifable.rb
Normal file
91
app/models/concerns/email_verifable.rb
Normal file
|
@ -0,0 +1,91 @@
|
|||
module Concerns
|
||||
module EmailVerifable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def email_verification
|
||||
@email_verification ||= EmailAddressVerification.find_or_create_by(email: unicode_email,
|
||||
domain: domain(email))
|
||||
end
|
||||
|
||||
def billing_email_verification
|
||||
return unless attribute_names.include?('billing_email')
|
||||
|
||||
@billing_email_verification ||= EmailAddressVerification
|
||||
.find_or_create_by(email: unicode_billing_email,
|
||||
domain: domain(billing_email))
|
||||
end
|
||||
|
||||
class_methods do
|
||||
def domain(email)
|
||||
Mail::Address.new(email).domain&.downcase || 'not_found'
|
||||
rescue Mail::Field::IncompleteParseError
|
||||
'not_found'
|
||||
end
|
||||
|
||||
def local(email)
|
||||
Mail::Address.new(email).local&.downcase || email
|
||||
rescue Mail::Field::IncompleteParseError
|
||||
email
|
||||
end
|
||||
|
||||
def punycode_to_unicode(email)
|
||||
return email if domain(email) == 'not_found'
|
||||
|
||||
local = local(email)
|
||||
domain = SimpleIDN.to_unicode(domain(email))
|
||||
"#{local}@#{domain}"&.downcase
|
||||
end
|
||||
|
||||
def unicode_to_punycode(email)
|
||||
return email if domain(email) == 'not_found'
|
||||
|
||||
local = local(email)
|
||||
domain = SimpleIDN.to_ascii(domain(email))
|
||||
"#{local}@#{domain}"&.downcase
|
||||
end
|
||||
end
|
||||
|
||||
def unicode_billing_email
|
||||
self.class.punycode_to_unicode(billing_email)
|
||||
end
|
||||
|
||||
def unicode_email
|
||||
self.class.punycode_to_unicode(email)
|
||||
end
|
||||
|
||||
def domain(email)
|
||||
SimpleIDN.to_unicode(self.class.domain(email))
|
||||
end
|
||||
|
||||
def punycode_to_unicode(email)
|
||||
self.class.punycode_to_unicode(email)
|
||||
end
|
||||
|
||||
def correct_email_format
|
||||
return if email.blank?
|
||||
|
||||
result = email_verification.verify
|
||||
process_result(result: result, field: :email)
|
||||
end
|
||||
|
||||
def correct_billing_email_format
|
||||
return if email.blank?
|
||||
|
||||
result = billing_email_verification.verify
|
||||
process_result(result: result, field: :billing_email)
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/LineLength
|
||||
def process_result(result:, field:)
|
||||
case result[:errors].keys.first
|
||||
when :smtp
|
||||
errors.add(field, I18n.t('activerecord.errors.models.contact.attributes.email.email_smtp_check_error'))
|
||||
when :mx
|
||||
errors.add(field, I18n.t('activerecord.errors.models.contact.attributes.email.email_mx_check_error'))
|
||||
when :regex
|
||||
errors.add(field, I18n.t('activerecord.errors.models.contact.attributes.email.email_regex_check_error'))
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/LineLength
|
||||
end
|
||||
end
|
|
@ -20,7 +20,7 @@ module EppErrors
|
|||
epp_errors << collect_parent_errors(attr, errors)
|
||||
end
|
||||
|
||||
errors[:epp_errors] = epp_errors
|
||||
errors.add(:epp_errors, epp_errors)
|
||||
errors[:epp_errors].flatten!
|
||||
end
|
||||
|
||||
|
|
34
app/models/concerns/invoice/book_keeping.rb
Normal file
34
app/models/concerns/invoice/book_keeping.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Concerns
|
||||
module Invoice
|
||||
module BookKeeping
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def as_directo_json
|
||||
invoice = ActiveSupport::JSON.decode(ActiveSupport::JSON.encode(self))
|
||||
invoice['customer'] = compose_directo_customer
|
||||
invoice['issue_date'] = issue_date.strftime('%Y-%m-%d')
|
||||
invoice['transaction_date'] = account_activity
|
||||
.bank_transaction&.paid_at&.strftime('%Y-%m-%d')
|
||||
invoice['language'] = buyer.language == 'en' ? 'ENG' : ''
|
||||
invoice['invoice_lines'] = compose_directo_product
|
||||
|
||||
invoice
|
||||
end
|
||||
|
||||
def compose_directo_product
|
||||
[{ 'product_id': Setting.directo_receipt_product_name, 'description': order,
|
||||
'quantity': 1, 'price': ActionController::Base.helpers.number_with_precision(
|
||||
subtotal, precision: 2, separator: '.'
|
||||
) }].as_json
|
||||
end
|
||||
|
||||
def compose_directo_customer
|
||||
{
|
||||
'code': buyer.accounting_customer_code,
|
||||
'destination': buyer_country_code,
|
||||
'vat_reg_no': buyer_vat_no,
|
||||
}.as_json
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
34
app/models/concerns/job/force_delete.rb
Normal file
34
app/models/concerns/job/force_delete.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Concerns
|
||||
module Job
|
||||
module ForceDelete
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def start_client_hold
|
||||
log_prepare_client_hold
|
||||
|
||||
::PaperTrail.request.whodunnit = "cron - #{__method__}"
|
||||
|
||||
::Domain.force_delete_scheduled.each do |domain|
|
||||
proceed_client_hold(domain: domain)
|
||||
end
|
||||
|
||||
log_end_end_force_delete_job
|
||||
end
|
||||
|
||||
def proceed_client_hold(domain:)
|
||||
notify_on_grace_period(domain) if domain.should_notify_on_soft_force_delete?
|
||||
return unless domain.client_holdable?
|
||||
|
||||
domain.statuses << DomainStatus::CLIENT_HOLD
|
||||
log_start_client_hold(domain)
|
||||
|
||||
domain.save(validate: false)
|
||||
notify_client_hold(domain)
|
||||
|
||||
log_end_end_client_hold(domain)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
34
app/models/concerns/job/force_delete_logging.rb
Normal file
34
app/models/concerns/job/force_delete_logging.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Concerns
|
||||
module Job
|
||||
module ForceDeleteLogging
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def log_prepare_client_hold
|
||||
return if Rails.env.test?
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} - Setting client_hold to domains\n"
|
||||
end
|
||||
|
||||
def log_start_client_hold(domain)
|
||||
return if Rails.env.test?
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} DomainCron.start_client_hold: ##{domain.id} "\
|
||||
"(#{domain.name}) #{domain.changes}\n"
|
||||
end
|
||||
|
||||
def log_end_end_client_hold(domain)
|
||||
return if Rails.env.test?
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} - Successfully set client_hold on (#{domain.name})"
|
||||
end
|
||||
|
||||
def log_end_end_force_delete_job
|
||||
return if Rails.env.test?
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} - All client_hold setting are done\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
app/models/concerns/job/force_delete_notify.rb
Normal file
31
app/models/concerns/job/force_delete_notify.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Concerns
|
||||
module Job
|
||||
module ForceDeleteNotify
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def notify_client_hold(domain)
|
||||
domain.registrar.notifications.create!(text: I18n.t('force_delete_set_on_domain',
|
||||
domain_name: domain.name,
|
||||
outzone_date: domain.outzone_date,
|
||||
purge_date: domain.purge_date))
|
||||
end
|
||||
|
||||
def notify_on_grace_period(domain)
|
||||
domain.registrar.notifications.create!(text: I18n.t('grace_period_started_domain',
|
||||
domain_name: domain.name,
|
||||
date: domain.force_delete_start))
|
||||
send_mail(domain)
|
||||
domain.update(contact_notification_sent_date: Time.zone.today)
|
||||
end
|
||||
|
||||
def send_mail(domain)
|
||||
DomainDeleteMailer.forced(domain: domain,
|
||||
registrar: domain.registrar,
|
||||
registrant: domain.registrant,
|
||||
template_name: domain.template_name).deliver_now
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
128
app/models/concerns/registrar/book_keeping.rb
Normal file
128
app/models/concerns/registrar/book_keeping.rb
Normal file
|
@ -0,0 +1,128 @@
|
|||
module Concerns
|
||||
module Registrar
|
||||
module BookKeeping
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
DOMAIN_TO_PRODUCT = { 'ee': '01EE', 'com.ee': '02COM', 'pri.ee': '03PRI',
|
||||
'fie.ee': '04FIE', 'med.ee': '05MED' }.freeze
|
||||
|
||||
def monthly_summary(month:)
|
||||
activities = monthly_activites(month)
|
||||
return unless activities.any?
|
||||
|
||||
invoice = {
|
||||
'number': 1,
|
||||
'customer': compose_directo_customer,
|
||||
'language': language == 'en' ? 'ENG' : '', 'currency': activities.first.currency,
|
||||
'date': month.end_of_month.strftime('%Y-%m-%d')
|
||||
}.as_json
|
||||
|
||||
invoice['invoice_lines'] = prepare_invoice_lines(month: month, activities: activities)
|
||||
|
||||
invoice
|
||||
end
|
||||
|
||||
def prepare_invoice_lines(month:, activities:)
|
||||
lines = []
|
||||
|
||||
lines << { 'description': title_for_summary(month) }
|
||||
activities.each do |activity|
|
||||
fetch_invoice_lines(activity, lines)
|
||||
end
|
||||
lines << prepayment_for_all(lines)
|
||||
|
||||
lines.as_json
|
||||
end
|
||||
|
||||
def title_for_summary(date)
|
||||
I18n.with_locale(language == 'en' ? 'en' : 'et') do
|
||||
I18n.t('registrar.monthly_summary_title', date: I18n.l(date, format: '%B %Y'))
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_invoice_lines(activity, lines)
|
||||
price = load_price(activity)
|
||||
if price.duration.include? 'year'
|
||||
price.duration.to_i.times do |duration|
|
||||
lines << new_monthly_invoice_line(activity: activity, duration: duration + 1).as_json
|
||||
end
|
||||
else
|
||||
lines << new_monthly_invoice_line(activity: activity).as_json
|
||||
end
|
||||
end
|
||||
|
||||
def monthly_activites(month)
|
||||
AccountActivity.where(account_id: account_ids)
|
||||
.where(created_at: month.beginning_of_month..month.end_of_month)
|
||||
.where(activity_type: [AccountActivity::CREATE, AccountActivity::RENEW])
|
||||
end
|
||||
|
||||
def new_monthly_invoice_line(activity:, duration: nil)
|
||||
price = load_price(activity)
|
||||
line = {
|
||||
'product_id': DOMAIN_TO_PRODUCT[price.zone_name.to_sym],
|
||||
'quantity': 1,
|
||||
'unit': language == 'en' ? 'pc' : 'tk',
|
||||
}
|
||||
|
||||
finalize_invoice_line(line, price: price, duration: duration, activity: activity)
|
||||
end
|
||||
|
||||
def finalize_invoice_line(line, price:, activity:, duration:)
|
||||
yearly = price.duration.include?('year')
|
||||
|
||||
line['price'] = yearly ? (price.price.amount / price.duration.to_i) : price.price.amount
|
||||
line['description'] = description_in_language(price: price, yearly: yearly)
|
||||
|
||||
if duration.present?
|
||||
add_product_timeframe(line: line, activity: activity, duration: duration) if duration > 1
|
||||
end
|
||||
|
||||
line
|
||||
end
|
||||
|
||||
def add_product_timeframe(line:, activity:, duration:)
|
||||
create_time = activity.created_at
|
||||
line['start_date'] = (create_time + (duration - 1).year).end_of_month.strftime('%Y-%m-%d')
|
||||
line['end_date'] = (create_time + (duration - 1).year + 1).end_of_month.strftime('%Y-%m-%d')
|
||||
end
|
||||
|
||||
def description_in_language(price:, yearly:)
|
||||
timeframe_string = yearly ? 'yearly' : 'monthly'
|
||||
locale_string = "registrar.invoice_#{timeframe_string}_product_description"
|
||||
|
||||
I18n.with_locale(language == 'en' ? 'en' : 'et') do
|
||||
I18n.t(locale_string, tld: ".#{price.zone_name}", length: price.duration.to_i)
|
||||
end
|
||||
end
|
||||
|
||||
def prepayment_for_all(lines)
|
||||
total = 0
|
||||
en = language == 'en'
|
||||
lines.each { |l| total += l['quantity'].to_f * l['price'].to_f }
|
||||
{
|
||||
'product_id': Setting.directo_receipt_product_name,
|
||||
'description': en ? 'Domains prepayment' : 'Domeenide ettemaks',
|
||||
'quantity': -1,
|
||||
'price': total,
|
||||
'unit': en ? 'pc' : 'tk',
|
||||
}
|
||||
end
|
||||
|
||||
def compose_directo_customer
|
||||
{
|
||||
'code': accounting_customer_code,
|
||||
'destination': address_country_code,
|
||||
'vat_reg_no': vat_no,
|
||||
}.as_json
|
||||
end
|
||||
|
||||
def load_price(account_activity)
|
||||
@pricelists ||= {}
|
||||
return @pricelists[account_activity.price_id] if @pricelists.key? account_activity.price_id
|
||||
|
||||
@pricelists[account_activity.price_id] = account_activity.price
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
16
app/models/concerns/registrar/legal_doc.rb
Normal file
16
app/models/concerns/registrar/legal_doc.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
module Concerns
|
||||
module Registrar
|
||||
module LegalDoc
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def legaldoc_mandatory?
|
||||
!legaldoc_not_mandatory?
|
||||
end
|
||||
|
||||
def legaldoc_not_mandatory?
|
||||
setting = Setting.legal_document_is_mandatory
|
||||
legaldoc_optout || !setting
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
9
app/models/concerns/remove_hold.rb
Normal file
9
app/models/concerns/remove_hold.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
module RemoveHold
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def remove_hold(params)
|
||||
xml = epp_xml.update(name: { value: params[:domain_name] },
|
||||
rem: [status: { attrs: { s: 'clientHold' }, value: '' }])
|
||||
current_user.request(xml)
|
||||
end
|
||||
end
|
|
@ -1,10 +1,17 @@
|
|||
# Papertrail concerns is mainly tested at country spec
|
||||
module Versions
|
||||
extend ActiveSupport::Concern
|
||||
WITH_CHILDREN = %w[Domain Contact].freeze
|
||||
|
||||
included do
|
||||
attr_accessor :version_loader
|
||||
has_paper_trail class_name: "#{model_name}Version"
|
||||
|
||||
if WITH_CHILDREN.include?(model_name.name)
|
||||
has_paper_trail versions: { class_name: "#{model_name}Version" },
|
||||
meta: { children: :children_log }
|
||||
else
|
||||
has_paper_trail versions: { class_name: "#{model_name}Version" }
|
||||
end
|
||||
|
||||
# add creator and updator
|
||||
before_create :add_creator
|
||||
|
@ -12,23 +19,25 @@ module Versions
|
|||
before_update :add_updator
|
||||
|
||||
def add_creator
|
||||
self.creator_str = ::PaperTrail.whodunnit
|
||||
self.creator_str = ::PaperTrail.request.whodunnit
|
||||
true
|
||||
end
|
||||
|
||||
def add_updator
|
||||
self.updator_str = ::PaperTrail.whodunnit
|
||||
self.updator_str = ::PaperTrail.request.whodunnit
|
||||
true
|
||||
end
|
||||
|
||||
def creator
|
||||
return nil if creator_str.blank?
|
||||
|
||||
creator = user_from_id_role_username creator_str
|
||||
creator.present? ? creator : creator_str
|
||||
end
|
||||
|
||||
def updator
|
||||
return nil if updator_str.blank?
|
||||
|
||||
updator = user_from_id_role_username updator_str
|
||||
updator.present? ? updator : updator_str
|
||||
end
|
||||
|
@ -45,25 +54,27 @@ module Versions
|
|||
|
||||
# callbacks
|
||||
def touch_domain_version
|
||||
domain.try(:touch_with_version)
|
||||
domain.try(:touch)
|
||||
end
|
||||
|
||||
def touch_domains_version
|
||||
domains.each(&:touch_with_version)
|
||||
domains.each(&:touch)
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def all_versions_for(ids, time)
|
||||
ver_klass = paper_trail_version_class
|
||||
ver_klass = paper_trail.version_class
|
||||
from_history = ver_klass.where(item_id: ids.to_a).
|
||||
order(:item_id).
|
||||
preceding(time + 1, true).
|
||||
select("distinct on (item_id) #{ver_klass.table_name}.*").
|
||||
map do |ver|
|
||||
o = new(ver.object)
|
||||
valid_columns = ver.item_type.constantize&.column_names
|
||||
o = new(ver.object&.slice(*valid_columns))
|
||||
o.version_loader = ver
|
||||
ver.object_changes.to_h.each { |k, v| o.public_send("#{k}=", v[-1]) }
|
||||
changes = ver.object_changes.to_h&.slice(*valid_columns)
|
||||
changes.each { |k, v| o.public_send("#{k}=", v[-1]) }
|
||||
o
|
||||
end
|
||||
not_in_history = where(id: (ids.to_a - from_history.map(&:id)))
|
||||
|
|
15
app/models/concerns/whois_status_populate.rb
Normal file
15
app/models/concerns/whois_status_populate.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module WhoisStatusPopulate
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def generate_json(record, domain_status:)
|
||||
h = HashWithIndifferentAccess.new(name: record.name, status: [domain_status])
|
||||
return h if record.json.blank?
|
||||
|
||||
status_arr = (record.json['status'] ||= [])
|
||||
return record.json if status_arr.include? domain_status
|
||||
|
||||
status_arr.push(domain_status)
|
||||
record.json['status'] = status_arr
|
||||
record.json
|
||||
end
|
||||
end
|
74
app/models/concerns/zone/whois_queryable.rb
Normal file
74
app/models/concerns/zone/whois_queryable.rb
Normal file
|
@ -0,0 +1,74 @@
|
|||
module Concerns
|
||||
module Zone
|
||||
module WhoisQueryable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_save :update_whois_record, if: :subzone?
|
||||
after_destroy :update_whois_record
|
||||
end
|
||||
|
||||
def subzone?
|
||||
origin.include? '.'
|
||||
end
|
||||
|
||||
def update_whois_record
|
||||
UpdateWhoisRecordJob.enqueue origin, 'zone'
|
||||
end
|
||||
|
||||
def generate_data
|
||||
wr = Whois::Record.find_or_initialize_by(name: origin)
|
||||
wr.json = generate_json
|
||||
wr.save
|
||||
end
|
||||
|
||||
def generate_json
|
||||
data = {}.with_indifferent_access
|
||||
[domain_vars, registrar_vars, registrant_vars].each do |h|
|
||||
data.merge!(h)
|
||||
end
|
||||
|
||||
data
|
||||
end
|
||||
|
||||
# Take note - since this concern only used to zone whois queries, dnssec keys are set to
|
||||
# empty array
|
||||
def domain_vars
|
||||
{ disclaimer: Setting.registry_whois_disclaimer, name: origin,
|
||||
registered: created_at.try(:to_s, :iso8601), status: ['ok (paid and in zone)'],
|
||||
changed: updated_at.try(:to_s, :iso8601), email: Setting.registry_email,
|
||||
admin_contacts: [contact_vars], tech_contacts: [contact_vars],
|
||||
nameservers: nameserver_vars, dnssec_keys: [], dnssec_changed: nil }
|
||||
end
|
||||
|
||||
def registrar_vars
|
||||
{ registrar: Setting.registry_juridical_name, registrar_website: Setting.registry_url,
|
||||
registrar_phone: Setting.registry_phone }
|
||||
end
|
||||
|
||||
def registrant_vars
|
||||
{ registrant: Setting.registry_juridical_name, registrant_reg_no: Setting.registry_reg_no,
|
||||
registrant_ident_country_code: Setting.registry_country_code, registrant_kind: 'org',
|
||||
registrant_disclosed_attributes: %w[name email] }
|
||||
end
|
||||
|
||||
def contact_vars
|
||||
{ name: Setting.registry_invoice_contact, email: Setting.registry_email,
|
||||
disclosed_attributes: %w[name email] }
|
||||
end
|
||||
|
||||
def nameserver_vars
|
||||
vars = []
|
||||
return vars unless ns_records
|
||||
|
||||
parsed_ns = ns_records.gsub("\r", '').gsub("\n", '')
|
||||
parsed_ns.split("#{origin}. IN NS ").each do |ns|
|
||||
ns.delete_suffix! '.'
|
||||
vars << ns if ns.match? Nameserver::HOSTNAME_REGEXP
|
||||
end
|
||||
|
||||
vars
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
class Counter
|
||||
def initialize value = 0
|
||||
@value = value
|
||||
end
|
||||
attr_accessor :value
|
||||
def method_missing *args, &blk
|
||||
@value.send(*args, &blk)
|
||||
end
|
||||
def to_s
|
||||
@value.to_s
|
||||
end
|
||||
|
||||
def now
|
||||
@value
|
||||
end
|
||||
|
||||
# pre-increment ".+" when x not present
|
||||
def next(x = 1)
|
||||
@value += x
|
||||
end
|
||||
def prev(x = 1)
|
||||
@value -= x
|
||||
end
|
||||
end
|
|
@ -1,6 +1,7 @@
|
|||
module Depp
|
||||
class Domain
|
||||
include ActiveModel::Conversion
|
||||
include RemoveHold
|
||||
extend ActiveModel::Naming
|
||||
|
||||
attr_accessor :name, :current_user, :epp_xml
|
||||
|
@ -121,16 +122,6 @@ module Depp
|
|||
}, op, Domain.construct_custom_params_hash(params)))
|
||||
end
|
||||
|
||||
def confirm_keyrelay(domain_params)
|
||||
xml = epp_xml.update({
|
||||
name: { value: domain_params[:name] }
|
||||
}, {
|
||||
add: Domain.create_dnskeys_hash(domain_params)
|
||||
})
|
||||
|
||||
current_user.request(xml)
|
||||
end
|
||||
|
||||
def confirm_transfer(domain_params)
|
||||
data = current_user.request(epp_xml.info(name: { value: domain_params[:name] }))
|
||||
pw = data.css('pw').text
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
module Depp
|
||||
class Keyrelay
|
||||
attr_accessor :current_user, :epp_xml
|
||||
|
||||
def initialize(args = {})
|
||||
self.current_user = args[:current_user]
|
||||
self.epp_xml = EppXml::Keyrelay.new(cl_trid_prefix: current_user.tag)
|
||||
end
|
||||
|
||||
def keyrelay(params)
|
||||
custom_params = {}
|
||||
if params[:legal_document].present?
|
||||
type = params[:legal_document].original_filename.split('.').last.downcase
|
||||
custom_params = {
|
||||
_anonymus: [
|
||||
legalDocument: { value: Base64.encode64(params[:legal_document].read), attrs: { type: type } }
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
xml = epp_xml.keyrelay({
|
||||
name: { value: params['domain_name'] },
|
||||
keyData: {
|
||||
flags: { value: params['key_data_flags'] },
|
||||
protocol: { value: params['key_data_protocol'] },
|
||||
alg: { value: params['key_data_alg'] },
|
||||
pubKey: { value: params['key_data_public_key'] }
|
||||
},
|
||||
authInfo: {
|
||||
pw: { value: params['password'] }
|
||||
},
|
||||
expiry: expiry(params['expiry'])
|
||||
}, custom_params)
|
||||
|
||||
current_user.request(xml)
|
||||
end
|
||||
|
||||
def expiry(value)
|
||||
ISO8601::Duration.new(value)
|
||||
{ relative: { value: value } }
|
||||
rescue => _e
|
||||
{ absolute: { value: value } }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,196 +1,3 @@
|
|||
class Directo < ActiveRecord::Base
|
||||
DOMAIN_TO_PRODUCT = {"ee" => "01EE", "com.ee" => "02COM", "pri.ee" => "03PRI", "fie.ee"=>"04FIE", "med.ee" => "05MED"}.freeze
|
||||
class Directo < ApplicationRecord
|
||||
belongs_to :item, polymorphic: true
|
||||
|
||||
def self.send_receipts
|
||||
new_trans = Invoice.where(in_directo: false).non_cancelled
|
||||
total = new_trans.count
|
||||
counter = 0
|
||||
Rails.logger.info("[DIRECTO] Will try to send #{total} invoices")
|
||||
|
||||
new_trans.find_in_batches(batch_size: 10).each do |group|
|
||||
mappers = {} # need them as no direct connection between invoice
|
||||
builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
||||
xml.invoices {
|
||||
group.each do |invoice|
|
||||
|
||||
if invoice.account_activity.nil? || invoice.account_activity.bank_transaction.nil? ||
|
||||
invoice.account_activity.bank_transaction.sum.nil? || invoice.account_activity.bank_transaction.sum != invoice.total
|
||||
Rails.logger.info("[DIRECTO] Invoice #{invoice.number} has been skipped")
|
||||
next
|
||||
end
|
||||
counter += 1
|
||||
|
||||
num = invoice.number
|
||||
mappers[num] = invoice
|
||||
xml.invoice(
|
||||
"SalesAgent" => Setting.directo_sales_agent,
|
||||
"Number" => num,
|
||||
"InvoiceDate" => invoice.issue_date.strftime("%Y-%m-%d"),
|
||||
"PaymentTerm" => Setting.directo_receipt_payment_term,
|
||||
"Currency" => invoice.currency,
|
||||
"CustomerCode"=> invoice.buyer.accounting_customer_code
|
||||
){
|
||||
xml.line(
|
||||
"ProductID" => Setting.directo_receipt_product_name,
|
||||
"Quantity" => 1,
|
||||
"UnitPriceWoVAT" => ActionController::Base.helpers.number_with_precision(invoice.subtotal, precision: 2, separator: "."),
|
||||
"ProductName" => invoice.order
|
||||
)
|
||||
}
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
data = builder.to_xml.gsub("\n",'')
|
||||
Rails.logger.info("[Directo] XML request: #{data}")
|
||||
response = RestClient::Request.execute(url: ENV['directo_invoice_url'], method: :post, payload: {put: "1", what: "invoice", xmldata: data}, verify_ssl: false)
|
||||
Rails.logger.info("[Directo] Directo responded with code: #{response.code}, body: #{response.body}")
|
||||
dump_result_to_db(mappers, response.to_s)
|
||||
end
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} - Directo receipts sending finished. #{counter} of #{total} are sent\n"
|
||||
end
|
||||
|
||||
def self.dump_result_to_db mappers, xml
|
||||
Nokogiri::XML(xml).css("Result").each do |res|
|
||||
obj = mappers[res.attributes["docid"].value.to_i]
|
||||
obj.directo_records.create!(response: res.as_json.to_h, invoice_number: obj.number)
|
||||
obj.update_columns(in_directo: true)
|
||||
Rails.logger.info("[DIRECTO] Invoice #{res.attributes["docid"].value} was pushed and return is #{res.as_json.to_h.inspect}")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.send_monthly_invoices(debug: false)
|
||||
I18n.locale = :et
|
||||
month = Time.now - 1.month
|
||||
invoices_until = month.end_of_month
|
||||
date_format = "%Y-%m-%d"
|
||||
invoice_counter= Counter.new
|
||||
|
||||
min_directo = Setting.directo_monthly_number_min.presence.try(:to_i)
|
||||
max_directo = Setting.directo_monthly_number_max.presence.try(:to_i)
|
||||
last_directo = [Setting.directo_monthly_number_last.presence.try(:to_i), min_directo].compact.max || 0
|
||||
if max_directo && max_directo <= last_directo
|
||||
raise "Directo counter is out of period (max allowed number is smaller than last counter number)"
|
||||
end
|
||||
|
||||
directo_next = last_directo
|
||||
Registrar.where.not(test_registrar: true).find_each do |registrar|
|
||||
unless registrar.cash_account
|
||||
Rails.logger.info("[DIRECTO] Monthly invoice for registrar #{registrar.id} has been skipped as it doesn't has cash_account")
|
||||
next
|
||||
end
|
||||
counter = Counter.new(1)
|
||||
items = {}
|
||||
registrar_activities = AccountActivity.where(account_id: registrar.account_ids).where("created_at BETWEEN ? AND ?",month.beginning_of_month, month.end_of_month)
|
||||
|
||||
# adding domains items
|
||||
registrar_activities.where(activity_type: [AccountActivity::CREATE, AccountActivity::RENEW]).each do |activity|
|
||||
price = load_price(activity)
|
||||
|
||||
if price.duration.include?('year')
|
||||
price.duration.to_i.times do |i|
|
||||
year = i+1
|
||||
hash = {
|
||||
"ProductID" => DOMAIN_TO_PRODUCT[price.zone_name],
|
||||
"Unit" => "tk",
|
||||
"ProductName" => ".#{price.zone_name} registreerimine: #{price.duration.to_i} aasta#{price.duration.to_i > 1 ? 't' : ''}",
|
||||
"UnitPriceWoVAT" => price.price.amount / price.duration.to_i
|
||||
}
|
||||
hash["StartDate"] = (activity.created_at + (year-1).year).end_of_month.strftime(date_format) if year > 1
|
||||
hash["EndDate"] = (activity.created_at + (year-1).year + 1).end_of_month.strftime(date_format) if year > 1
|
||||
|
||||
if items.has_key?(hash)
|
||||
items[hash]["Quantity"] += 1
|
||||
else
|
||||
items[hash] = { "RN" => counter.next, "RR" => counter.now - i, "Quantity" => 1 }
|
||||
end
|
||||
end
|
||||
else
|
||||
1.times do |i|
|
||||
quantity = price.account_activities
|
||||
.where(account_id: registrar.account_ids)
|
||||
.where(created_at: month.beginning_of_month..month.end_of_month)
|
||||
.where(activity_type: [AccountActivity::CREATE, AccountActivity::RENEW])
|
||||
.count
|
||||
|
||||
hash = {
|
||||
"ProductID" => DOMAIN_TO_PRODUCT[price.zone_name],
|
||||
"Unit" => "tk",
|
||||
"ProductName" => ".#{price.zone_name} registreerimine: #{price.duration.to_i} kuud",
|
||||
"UnitPriceWoVAT" => price.price.amount,
|
||||
}
|
||||
|
||||
if items.has_key?(hash)
|
||||
#items[hash]["Quantity"] += 1
|
||||
else
|
||||
items[hash] = { "RN" => counter.next, "RR" => counter.now - i, "Quantity" => quantity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
#adding prepaiments
|
||||
if items.any?
|
||||
total = 0
|
||||
items.each{ |key, val| total += val["Quantity"] * key["UnitPriceWoVAT"] }
|
||||
hash = {"ProductID" => Setting.directo_receipt_product_name, "Unit" => "tk", "ProductName" => "Domeenide ettemaks", "UnitPriceWoVAT"=>total}
|
||||
items[hash] = {"RN"=>counter.next, "RR" => counter.now, "Quantity"=> -1}
|
||||
end
|
||||
|
||||
# generating XML
|
||||
if items.any?
|
||||
directo_next += 1
|
||||
invoice_counter.next
|
||||
|
||||
builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
||||
xml.invoices{
|
||||
xml.invoice("Number" =>directo_next,
|
||||
"InvoiceDate" =>invoices_until.strftime(date_format),
|
||||
"PaymentTerm" =>Setting.directo_receipt_payment_term,
|
||||
"CustomerCode"=>registrar.accounting_customer_code,
|
||||
"Language" =>"",
|
||||
"Currency" =>registrar_activities.first.currency,
|
||||
"SalesAgent" =>Setting.directo_sales_agent){
|
||||
xml.line("RN" => 1, "RR"=>1, "ProductName"=> "Domeenide registreerimine - #{I18n.l(invoices_until, format: "%B %Y").titleize}")
|
||||
items.each do |line, val|
|
||||
xml.line(val.merge(line))
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
data = builder.to_xml.gsub("\n",'')
|
||||
Rails.logger.info("[Directo] XML request: #{data}")
|
||||
|
||||
if debug
|
||||
STDOUT << "#{Time.zone.now.utc} - Directo xml had to be sent #{data}\n"
|
||||
else
|
||||
response = RestClient::Request.execute(url: ENV['directo_invoice_url'], method: :post, payload: {put: "1", what: "invoice", xmldata: data}, verify_ssl: false)
|
||||
Rails.logger.info("[Directo] Directo responded with code: #{response.code}, body: #{response.body}")
|
||||
response = response.to_s
|
||||
|
||||
Setting.directo_monthly_number_last = directo_next
|
||||
Nokogiri::XML(response).css("Result").each do |res|
|
||||
Directo.create!(request: data, response: res.as_json.to_h, invoice_number: directo_next)
|
||||
Rails.logger.info("[DIRECTO] Invoice #{res.attributes["docid"].value} was pushed and return is #{res.as_json.to_h.inspect}")
|
||||
end
|
||||
end
|
||||
else
|
||||
Rails.logger.info("[DIRECTO] Registrar #{registrar.id} has nothing to be sent to Directo")
|
||||
end
|
||||
|
||||
end
|
||||
STDOUT << "#{Time.zone.now.utc} - Directo invoices sending finished. #{invoice_counter.now} are sent\n"
|
||||
end
|
||||
|
||||
def self.load_price(account_activity)
|
||||
@pricelists ||= {}
|
||||
return @pricelists[account_activity.price_id] if @pricelists.has_key?(account_activity.price_id)
|
||||
@pricelists[account_activity.price_id] = account_activity.price
|
||||
end
|
||||
end
|
||||
|
|
133
app/models/dispute.rb
Normal file
133
app/models/dispute.rb
Normal file
|
@ -0,0 +1,133 @@
|
|||
class Dispute < ApplicationRecord
|
||||
include WhoisStatusPopulate
|
||||
validates :domain_name, :password, :starts_at, :expires_at, presence: true
|
||||
before_validation :fill_empty_passwords, :set_expiry_date
|
||||
validate :validate_domain_name_format
|
||||
validate :validate_domain_name_period_uniqueness
|
||||
validate :validate_start_date
|
||||
|
||||
before_save :set_expiry_date, :sync_reserved_password, :generate_data
|
||||
after_destroy :remove_data
|
||||
|
||||
scope :expired, -> { where('expires_at < ?', Time.zone.today) }
|
||||
scope :active, lambda {
|
||||
where('starts_at <= ? AND expires_at >= ? AND closed IS NULL', Time.zone.today, Time.zone.today)
|
||||
}
|
||||
scope :closed, -> { where.not(closed: nil) }
|
||||
|
||||
attr_readonly :domain_name
|
||||
|
||||
def domain
|
||||
Domain.find_by(name: domain_name)
|
||||
end
|
||||
|
||||
def self.close_by_domain(domain_name)
|
||||
dispute = Dispute.active.find_by(domain_name: domain_name)
|
||||
return false unless dispute
|
||||
|
||||
dispute.close(initiator: 'Registrant')
|
||||
end
|
||||
|
||||
def self.valid_auth?(domain_name, password)
|
||||
Dispute.active.find_by(domain_name: domain_name, password: password).present?
|
||||
end
|
||||
|
||||
def set_expiry_date
|
||||
return if starts_at.blank?
|
||||
|
||||
self.expires_at = starts_at + Setting.dispute_period_in_months.months
|
||||
end
|
||||
|
||||
def generate_password
|
||||
self.password = SecureRandom.hex
|
||||
end
|
||||
|
||||
def generate_data
|
||||
return if starts_at > Time.zone.today || expires_at < Time.zone.today
|
||||
|
||||
domain&.mark_as_disputed
|
||||
return if domain
|
||||
|
||||
wr = Whois::Record.find_or_initialize_by(name: domain_name)
|
||||
wr.json = @json = generate_json(wr, domain_status: 'disputed')
|
||||
wr.save
|
||||
end
|
||||
|
||||
def close(initiator: 'Unknown')
|
||||
return false unless update(closed: Time.zone.now, initiator: initiator)
|
||||
return if Dispute.active.where(domain_name: domain_name).any?
|
||||
|
||||
domain&.unmark_as_disputed
|
||||
return true if domain
|
||||
|
||||
forward_to_auction_if_possible
|
||||
end
|
||||
|
||||
def forward_to_auction_if_possible
|
||||
domain = DNS::DomainName.new(domain_name)
|
||||
if domain.available? && domain.auctionable?
|
||||
domain.sell_at_auction
|
||||
return true
|
||||
end
|
||||
|
||||
whois_record = Whois::Record.find_by(name: domain_name)
|
||||
remove_whois_data(whois_record)
|
||||
end
|
||||
|
||||
def remove_whois_data(record)
|
||||
return true unless record
|
||||
|
||||
record.json['status'] = record.json['status'].delete_if { |status| status == 'disputed' }
|
||||
record.destroy && return if record.json['status'].blank?
|
||||
|
||||
record.save
|
||||
end
|
||||
|
||||
def remove_data
|
||||
UpdateWhoisRecordJob.enqueue domain_name, 'disputed'
|
||||
end
|
||||
|
||||
def fill_empty_passwords
|
||||
generate_password if password.blank?
|
||||
end
|
||||
|
||||
def sync_reserved_password
|
||||
reserved_domain = ReservedDomain.find_by(name: domain_name)
|
||||
generate_password if password.blank?
|
||||
|
||||
unless reserved_domain.nil?
|
||||
reserved_domain.password = password
|
||||
reserved_domain.save!
|
||||
end
|
||||
|
||||
generate_data
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_start_date
|
||||
return if starts_at.nil?
|
||||
|
||||
errors.add(:starts_at, :future) if starts_at.future?
|
||||
end
|
||||
|
||||
def validate_domain_name_format
|
||||
return unless domain_name
|
||||
|
||||
zone = domain_name.reverse.rpartition('.').map(&:reverse).reverse.last
|
||||
supported_zone = DNS::Zone.origins.include?(zone)
|
||||
|
||||
errors.add(:domain_name, :unsupported_zone) unless supported_zone
|
||||
end
|
||||
|
||||
def validate_domain_name_period_uniqueness
|
||||
existing_dispute = Dispute.unscoped.where(domain_name: domain_name, closed: nil)
|
||||
.where('expires_at >= ?', starts_at)
|
||||
|
||||
existing_dispute = existing_dispute.where.not(id: id) unless new_record?
|
||||
|
||||
return unless existing_dispute.any?
|
||||
|
||||
errors.add(:starts_at, 'Dispute already exists for this domain at given timeframe')
|
||||
end
|
||||
end
|
|
@ -60,13 +60,18 @@ module DNS
|
|||
end
|
||||
|
||||
def blocked?
|
||||
BlockedDomain.where(name: name).any?
|
||||
BlockedDomain.where(name: name).any? ||
|
||||
BlockedDomain.where(name: SimpleIDN.to_unicode(name)).any?
|
||||
end
|
||||
|
||||
def reserved?
|
||||
ReservedDomain.where(name: name).any?
|
||||
end
|
||||
|
||||
def disputed?
|
||||
Dispute.active.where(domain_name: name).any?
|
||||
end
|
||||
|
||||
def auctionable?
|
||||
!not_auctionable?
|
||||
end
|
||||
|
@ -80,7 +85,7 @@ module DNS
|
|||
attr_reader :name
|
||||
|
||||
def not_auctionable?
|
||||
blocked? || reserved?
|
||||
blocked? || reserved? || disputed?
|
||||
end
|
||||
|
||||
def zone_with_same_origin?
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DNS
|
||||
class Zone < ActiveRecord::Base
|
||||
class Zone < ApplicationRecord
|
||||
validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, :master_nameserver, presence: true
|
||||
validates :ttl, :refresh, :retry, :expire, :minimum_ttl, numericality: { only_integer: true }
|
||||
validates :origin, uniqueness: true
|
||||
include Concerns::Zone::WhoisQueryable
|
||||
|
||||
before_destroy do
|
||||
!used?
|
||||
throw(:abort) if used?
|
||||
end
|
||||
|
||||
def self.generate_zonefiles
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Dnskey < ActiveRecord::Base
|
||||
class Dnskey < ApplicationRecord
|
||||
include Versions # version/dnskey_version.rb
|
||||
include EppErrors
|
||||
|
||||
|
@ -9,10 +9,16 @@ class Dnskey < ActiveRecord::Base
|
|||
validate :validate_protocol
|
||||
validate :validate_flags
|
||||
|
||||
before_save -> { generate_digest if public_key_changed? && !ds_digest_changed? }
|
||||
before_save lambda {
|
||||
generate_digest if will_save_change_to_public_key? && !will_save_change_to_ds_digest?
|
||||
}
|
||||
|
||||
before_save lambda {
|
||||
if (public_key_changed? || flags_changed? || alg_changed? || protocol_changed?) && !ds_key_tag_changed?
|
||||
if (will_save_change_to_public_key? ||
|
||||
will_save_change_to_flags? ||
|
||||
will_save_change_to_alg? ||
|
||||
will_save_change_to_protocol?) &&
|
||||
!will_save_change_to_ds_key_tag?
|
||||
generate_ds_key_tag
|
||||
end
|
||||
}
|
||||
|
@ -22,6 +28,8 @@ class Dnskey < ActiveRecord::Base
|
|||
FLAGS = %w(0 256 257) # 256 = ZSK, 257 = KSK
|
||||
DS_DIGEST_TYPE = [1,2]
|
||||
|
||||
self.ignored_columns = %w[legacy_domain_id]
|
||||
|
||||
def epp_code_map
|
||||
{
|
||||
'2005' => [
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Domain < ActiveRecord::Base
|
||||
class Domain < ApplicationRecord
|
||||
include UserEvents
|
||||
include Versions # version/domain_version.rb
|
||||
include Concerns::Domain::Expirable
|
||||
|
@ -9,8 +9,7 @@ class Domain < ActiveRecord::Base
|
|||
include Concerns::Domain::Transferable
|
||||
include Concerns::Domain::RegistryLockable
|
||||
include Concerns::Domain::Releasable
|
||||
|
||||
has_paper_trail class_name: "DomainVersion", meta: { children: :children_log }
|
||||
include Concerns::Domain::Disputable
|
||||
|
||||
attr_accessor :roles
|
||||
|
||||
|
@ -51,13 +50,13 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
has_many :dnskeys, dependent: :destroy
|
||||
|
||||
has_many :keyrelays
|
||||
has_one :whois_record # destroyment will be done in after_commit
|
||||
|
||||
accepts_nested_attributes_for :dnskeys, allow_destroy: true
|
||||
|
||||
has_many :legal_documents, as: :documentable
|
||||
accepts_nested_attributes_for :legal_documents, reject_if: proc { |attrs| attrs[:body].blank? }
|
||||
has_many :registrant_verifications, dependent: :destroy
|
||||
|
||||
after_initialize do
|
||||
self.pending_json = {} if pending_json.blank?
|
||||
|
@ -73,12 +72,13 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
before_update :manage_statuses
|
||||
def manage_statuses
|
||||
return unless registrant_id_changed? # rollback has not yet happened
|
||||
return unless will_save_change_to_registrant_id? # rollback has not yet happened
|
||||
|
||||
pending_update! if registrant_verification_asked?
|
||||
true
|
||||
end
|
||||
|
||||
after_commit :update_whois_record, unless: 'domain_name.at_auction?'
|
||||
after_commit :update_whois_record, unless: -> { domain_name.at_auction? }
|
||||
|
||||
after_create :update_reserved_domains
|
||||
def update_reserved_domains
|
||||
|
@ -89,8 +89,8 @@ class Domain < ActiveRecord::Base
|
|||
validates :puny_label, length: { maximum: 63 }
|
||||
validates :period, presence: true, numericality: { only_integer: true }
|
||||
validates :transfer_code, presence: true
|
||||
|
||||
validate :validate_reservation
|
||||
|
||||
def validate_reservation
|
||||
return if persisted? || !in_reserved_list?
|
||||
|
||||
|
@ -100,6 +100,7 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
return if ReservedDomain.pw_for(name) == reserved_pw
|
||||
|
||||
errors.add(:base, :invalid_auth_information_reserved)
|
||||
end
|
||||
|
||||
|
@ -116,12 +117,15 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
attr_accessor :is_admin
|
||||
|
||||
validate :check_permissions, :unless => :is_admin
|
||||
def check_permissions
|
||||
return unless force_delete_scheduled?
|
||||
errors.add(:base, I18n.t(:object_status_prohibits_operation))
|
||||
false
|
||||
end
|
||||
# Removed to comply new ForceDelete procedure
|
||||
# at https://github.com/internetee/registry/issues/1428#issuecomment-570561967
|
||||
#
|
||||
# validate :check_permissions, :unless => :is_admin
|
||||
# def check_permissions
|
||||
# return unless force_delete_scheduled?
|
||||
# errors.add(:base, I18n.t(:object_status_prohibits_operation))
|
||||
# false
|
||||
# end
|
||||
|
||||
validates :nameservers, domain_nameserver: {
|
||||
min: -> { Setting.ns_min_count },
|
||||
|
@ -170,6 +174,8 @@ class Domain < ActiveRecord::Base
|
|||
attr_accessor :registrant_typeahead, :update_me,
|
||||
:epp_pending_update, :epp_pending_delete, :reserved_pw
|
||||
|
||||
self.ignored_columns = %w[legacy_id legacy_registrar_id legacy_registrant_id]
|
||||
|
||||
def subordinate_nameservers
|
||||
nameservers.select { |x| x.hostname.end_with?(name) }
|
||||
end
|
||||
|
@ -192,17 +198,14 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def registrant_user_domains(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_domains_by_registrant(registrant_user).to_sql} UNION " \
|
||||
"#{registrant_user_indirect_domains(registrant_user).to_sql} UNION " \
|
||||
"#{registrant_user_domains_by_contact(registrant_user).to_sql}) AS domains"
|
||||
)
|
||||
end
|
||||
|
||||
def registrant_user_direct_domains(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_domains_by_registrant(registrant_user).to_sql} UNION " \
|
||||
"#{registrant_user_direct_domains_by_contact(registrant_user).to_sql}) AS domains"
|
||||
|
@ -210,14 +213,20 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def registrant_user_administered_domains(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_domains_by_registrant(registrant_user).to_sql} UNION " \
|
||||
"#{registrant_user_domains_by_admin_contact(registrant_user).to_sql}) AS domains"
|
||||
)
|
||||
end
|
||||
|
||||
def registrant_user_indirect_domains(registrant_user)
|
||||
companies = Contact.registrant_user_company_contacts(registrant_user)
|
||||
from(
|
||||
"(#{registrant_user_company_registrant(companies).to_sql} UNION "\
|
||||
"#{registrant_user_domains_company(companies).to_sql}) AS domains"
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def registrant_user_domains_by_registrant(registrant_user)
|
||||
|
@ -230,7 +239,7 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
def registrant_user_domains_by_admin_contact(registrant_user)
|
||||
joins(:domain_contacts).where(domain_contacts: { contact_id: registrant_user.contacts,
|
||||
type: [AdminDomainContact] })
|
||||
type: [AdminDomainContact.name] })
|
||||
end
|
||||
|
||||
def registrant_user_direct_domains_by_registrant(registrant_user)
|
||||
|
@ -240,11 +249,19 @@ class Domain < ActiveRecord::Base
|
|||
def registrant_user_direct_domains_by_contact(registrant_user)
|
||||
joins(:domain_contacts).where(domain_contacts: { contact_id: registrant_user.direct_contacts })
|
||||
end
|
||||
|
||||
def registrant_user_company_registrant(companies)
|
||||
where(registrant: companies)
|
||||
end
|
||||
|
||||
def registrant_user_domains_company(companies)
|
||||
joins(:domain_contacts).where(domain_contacts: { contact: companies })
|
||||
end
|
||||
end
|
||||
|
||||
def name=(value)
|
||||
value.strip!
|
||||
value.downcase!
|
||||
value&.strip!
|
||||
value&.downcase!
|
||||
self[:name] = SimpleIDN.to_unicode(value)
|
||||
self[:name_puny] = SimpleIDN.to_ascii(value)
|
||||
self[:name_dirty] = value
|
||||
|
@ -284,20 +301,23 @@ class Domain < ActiveRecord::Base
|
|||
def server_holdable?
|
||||
return false if statuses.include?(DomainStatus::SERVER_HOLD)
|
||||
return false if statuses.include?(DomainStatus::SERVER_MANUAL_INZONE)
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def renewable?
|
||||
if Setting.days_to_renew_domain_before_expire != 0
|
||||
# if you can renew domain at days_to_renew before domain expiration
|
||||
if (expire_time.to_date - Date.today) + 1 > Setting.days_to_renew_domain_before_expire
|
||||
return false
|
||||
end
|
||||
blocking_statuses = [DomainStatus::DELETE_CANDIDATE, DomainStatus::PENDING_RENEW,
|
||||
DomainStatus::PENDING_TRANSFER, DomainStatus::DISPUTED,
|
||||
DomainStatus::PENDING_UPDATE, DomainStatus::PENDING_DELETE,
|
||||
DomainStatus::PENDING_DELETE_CONFIRMATION]
|
||||
return false if statuses.include_any? blocking_statuses
|
||||
return true unless Setting.days_to_renew_domain_before_expire != 0
|
||||
|
||||
# if you can renew domain at days_to_renew before domain expiration
|
||||
if (expire_time.to_date - Time.zone.today) + 1 > Setting.days_to_renew_domain_before_expire
|
||||
return false
|
||||
end
|
||||
|
||||
return false if statuses.include_any?(DomainStatus::DELETE_CANDIDATE, DomainStatus::PENDING_RENEW,
|
||||
DomainStatus::PENDING_TRANSFER, DomainStatus::PENDING_DELETE,
|
||||
DomainStatus::PENDING_UPDATE, DomainStatus::PENDING_DELETE_CONFIRMATION)
|
||||
true
|
||||
end
|
||||
|
||||
|
@ -487,9 +507,9 @@ class Domain < ActiveRecord::Base
|
|||
self.delete_date = nil
|
||||
when DomainStatus::SERVER_MANUAL_INZONE # removal causes server hold to set
|
||||
self.outzone_at = Time.zone.now if force_delete_scheduled?
|
||||
when DomainStatus::DomainStatus::EXPIRED # removal causes server hold to set
|
||||
when DomainStatus::EXPIRED # removal causes server hold to set
|
||||
self.outzone_at = self.expire_time + 15.day
|
||||
when DomainStatus::DomainStatus::SERVER_HOLD # removal causes server hold to set
|
||||
when DomainStatus::SERVER_HOLD # removal causes server hold to set
|
||||
self.outzone_at = nil
|
||||
end
|
||||
end
|
||||
|
@ -548,6 +568,8 @@ class Domain < ActiveRecord::Base
|
|||
activate if nameservers.reject(&:marked_for_destruction?).size >= Setting.ns_min_count
|
||||
end
|
||||
|
||||
cancel_force_delete if force_delete_scheduled? && will_save_change_to_registrant_id?
|
||||
|
||||
if statuses.empty? && valid?
|
||||
statuses << DomainStatus::OK
|
||||
elsif (statuses.length > 1 && active?) || !valid?
|
||||
|
@ -586,6 +608,15 @@ class Domain < ActiveRecord::Base
|
|||
(admin_contacts.emails + [registrant.email]).uniq
|
||||
end
|
||||
|
||||
def force_delete_contact_emails
|
||||
(primary_contact_emails + tech_contacts.pluck(:email) +
|
||||
["info@#{name}", "#{prepared_domain_name}@#{name}"]).uniq
|
||||
end
|
||||
|
||||
def prepared_domain_name
|
||||
name.split('.')&.first
|
||||
end
|
||||
|
||||
def new_registrant_email
|
||||
pending_json['new_registrant_email']
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class DomainContact < ActiveRecord::Base
|
||||
class DomainContact < ApplicationRecord
|
||||
# STI: tech_domain_contact
|
||||
# STI: admin_domain_contact
|
||||
include Versions # version/domain_contact_version.rb
|
||||
|
@ -8,6 +8,8 @@ class DomainContact < ActiveRecord::Base
|
|||
|
||||
attr_accessor :value_typeahead
|
||||
|
||||
self.ignored_columns = %w[legacy_domain_id legacy_contact_id]
|
||||
|
||||
def epp_code_map
|
||||
{
|
||||
'2302' => [
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
class DomainCron
|
||||
include Concerns::Job::ForceDelete
|
||||
include Concerns::Job::ForceDeleteLogging
|
||||
include Concerns::Job::ForceDeleteNotify
|
||||
|
||||
def self.clean_expired_pendings
|
||||
STDOUT << "#{Time.zone.now.utc} - Clean expired domain pendings\n" unless Rails.env.test?
|
||||
|
||||
::PaperTrail.whodunnit = "cron - #{__method__}"
|
||||
::PaperTrail.request.whodunnit = "cron - #{__method__}"
|
||||
expire_at = Setting.expire_pending_confirmation.hours.ago
|
||||
count = 0
|
||||
expired_pending_domains = Domain.where('registrant_verification_asked_at <= ?', expire_at)
|
||||
|
@ -35,7 +38,7 @@ class DomainCron
|
|||
end
|
||||
|
||||
def self.start_expire_period
|
||||
::PaperTrail.whodunnit = "cron - #{__method__}"
|
||||
::PaperTrail.request.whodunnit = "cron - #{__method__}"
|
||||
domains = Domain.expired
|
||||
marked = 0
|
||||
real = 0
|
||||
|
@ -61,7 +64,7 @@ class DomainCron
|
|||
def self.start_redemption_grace_period
|
||||
STDOUT << "#{Time.zone.now.utc} - Setting server_hold to domains\n" unless Rails.env.test?
|
||||
|
||||
::PaperTrail.whodunnit = "cron - #{__method__}"
|
||||
::PaperTrail.request.whodunnit = "cron - #{__method__}"
|
||||
|
||||
domains = Domain.outzone_candidates
|
||||
marked = 0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class DomainStatus < ActiveRecord::Base
|
||||
include Versions # version/domain_status_version.rb
|
||||
include EppErrors
|
||||
# frozen_string_literal: true
|
||||
|
||||
class DomainStatus < ApplicationRecord
|
||||
include EppErrors
|
||||
belongs_to :domain
|
||||
|
||||
# Requests to delete the object MUST be rejected.
|
||||
|
@ -72,6 +72,7 @@ class DomainStatus < ActiveRecord::Base
|
|||
FORCE_DELETE = 'serverForceDelete'
|
||||
DELETE_CANDIDATE = 'deleteCandidate'
|
||||
EXPIRED = 'expired'
|
||||
DISPUTED = 'disputed'
|
||||
|
||||
STATUSES = [
|
||||
CLIENT_DELETE_PROHIBITED, SERVER_DELETE_PROHIBITED, CLIENT_HOLD, SERVER_HOLD,
|
||||
|
@ -80,19 +81,19 @@ class DomainStatus < ActiveRecord::Base
|
|||
INACTIVE, OK, PENDING_CREATE, PENDING_DELETE, PENDING_DELETE_CONFIRMATION, PENDING_RENEW, PENDING_TRANSFER,
|
||||
PENDING_UPDATE, SERVER_MANUAL_INZONE, SERVER_REGISTRANT_CHANGE_PROHIBITED,
|
||||
SERVER_ADMIN_CHANGE_PROHIBITED, SERVER_TECH_CHANGE_PROHIBITED, FORCE_DELETE,
|
||||
DELETE_CANDIDATE, EXPIRED
|
||||
]
|
||||
DELETE_CANDIDATE, EXPIRED, DISPUTED
|
||||
].freeze
|
||||
|
||||
CLIENT_STATUSES = [
|
||||
CLIENT_DELETE_PROHIBITED, CLIENT_HOLD, CLIENT_RENEW_PROHIBITED, CLIENT_TRANSFER_PROHIBITED,
|
||||
CLIENT_UPDATE_PROHIBITED
|
||||
]
|
||||
].freeze
|
||||
|
||||
SERVER_STATUSES = [
|
||||
SERVER_DELETE_PROHIBITED, SERVER_HOLD, SERVER_RENEW_PROHIBITED, SERVER_TRANSFER_PROHIBITED,
|
||||
SERVER_UPDATE_PROHIBITED, SERVER_MANUAL_INZONE, SERVER_REGISTRANT_CHANGE_PROHIBITED,
|
||||
SERVER_ADMIN_CHANGE_PROHIBITED, SERVER_TECH_CHANGE_PROHIBITED
|
||||
]
|
||||
].freeze
|
||||
|
||||
UPDATE_PROHIBIT_STATES = [
|
||||
DomainStatus::PENDING_DELETE_CONFIRMATION,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class DomainTransfer < ActiveRecord::Base
|
||||
class DomainTransfer < ApplicationRecord
|
||||
belongs_to :domain
|
||||
|
||||
belongs_to :old_registrar, class_name: 'Registrar'
|
||||
|
|
56
app/models/email_address_verification.rb
Normal file
56
app/models/email_address_verification.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
class EmailAddressVerification < ApplicationRecord
|
||||
RECENTLY_VERIFIED_PERIOD = 1.month
|
||||
|
||||
scope :not_verified_recently, lambda {
|
||||
where('verified_at IS NULL or verified_at < ?', verification_period)
|
||||
}
|
||||
|
||||
scope :verified_recently, lambda {
|
||||
where('verified_at IS NOT NULL and verified_at >= ?', verification_period).where(success: true)
|
||||
}
|
||||
|
||||
scope :verification_failed, lambda {
|
||||
where.not(verified_at: nil).where(success: false)
|
||||
}
|
||||
|
||||
scope :by_domain, ->(domain_name) { where(domain: domain_name) }
|
||||
|
||||
def recently_verified?
|
||||
verified_at.present? &&
|
||||
verified_at > verification_period
|
||||
end
|
||||
|
||||
def verification_period
|
||||
self.class.verification_period
|
||||
end
|
||||
|
||||
def self.verification_period
|
||||
Time.zone.now - RECENTLY_VERIFIED_PERIOD
|
||||
end
|
||||
|
||||
def not_verified?
|
||||
verified_at.blank? && !success
|
||||
end
|
||||
|
||||
def failed?
|
||||
verified_at.present? && !success
|
||||
end
|
||||
|
||||
def verified?
|
||||
success
|
||||
end
|
||||
|
||||
def verify
|
||||
validation_request = Truemail.validate(email)
|
||||
|
||||
if validation_request.result.success
|
||||
update(verified_at: Time.zone.now,
|
||||
success: true)
|
||||
else
|
||||
update(verified_at: Time.zone.now,
|
||||
success: false)
|
||||
end
|
||||
|
||||
validation_request.result
|
||||
end
|
||||
end
|
|
@ -1,3 +1,7 @@
|
|||
require 'deserializers/xml/legal_document'
|
||||
require 'deserializers/xml/ident'
|
||||
require 'deserializers/xml/contact'
|
||||
|
||||
class Epp::Contact < Contact
|
||||
include EppErrors
|
||||
|
||||
|
@ -9,7 +13,7 @@ class Epp::Contact < Contact
|
|||
def manage_permissions
|
||||
return unless update_prohibited? || delete_prohibited?
|
||||
add_epp_error('2304', nil, nil, I18n.t(:object_status_prohibits_operation))
|
||||
false
|
||||
throw(:abort)
|
||||
end
|
||||
|
||||
class << self
|
||||
|
@ -20,26 +24,9 @@ class Epp::Contact < Contact
|
|||
end
|
||||
|
||||
def attrs_from(frame, new_record: false)
|
||||
f = frame
|
||||
at = {}.with_indifferent_access
|
||||
at[:name] = f.css('postalInfo name').text if f.css('postalInfo name').present?
|
||||
at[:org_name] = f.css('postalInfo org').text if f.css('postalInfo org').present?
|
||||
at[:email] = f.css('email').text if f.css('email').present?
|
||||
at[:fax] = f.css('fax').text if f.css('fax').present?
|
||||
at[:phone] = f.css('voice').text if f.css('voice').present?
|
||||
|
||||
if address_processing?
|
||||
at[:city] = f.css('postalInfo addr city').text if f.css('postalInfo addr city').present?
|
||||
at[:zip] = f.css('postalInfo addr pc').text if f.css('postalInfo addr pc').present?
|
||||
at[:street] = f.css('postalInfo addr street').text if f.css('postalInfo addr street').present?
|
||||
at[:state] = f.css('postalInfo addr sp').text if f.css('postalInfo addr sp').present?
|
||||
at[:country_code] = f.css('postalInfo addr cc').text if f.css('postalInfo addr cc').present?
|
||||
end
|
||||
|
||||
at[:auth_info] = f.css('authInfo pw').text if f.css('authInfo pw').present?
|
||||
|
||||
|
||||
at.merge!(ident_attrs(f.css('ident').first)) if new_record
|
||||
at = ::Deserializers::Xml::Contact.new(frame).call
|
||||
ident_attrs = ::Deserializers::Xml::Ident.new(frame).call
|
||||
at.merge!(ident_attrs) if new_record
|
||||
at
|
||||
end
|
||||
|
||||
|
@ -54,36 +41,6 @@ class Epp::Contact < Contact
|
|||
)
|
||||
end
|
||||
|
||||
def ident_attrs(ident_frame)
|
||||
return {} unless ident_attr_valid?(ident_frame)
|
||||
|
||||
{
|
||||
ident: ident_frame.text,
|
||||
ident_type: ident_frame.attr('type'),
|
||||
ident_country_code: ident_frame.attr('cc')
|
||||
}
|
||||
end
|
||||
|
||||
def ident_attr_valid?(ident_frame)
|
||||
return false if ident_frame.blank?
|
||||
return false if ident_frame.try('text').blank?
|
||||
return false if ident_frame.attr('type').blank?
|
||||
return false if ident_frame.attr('cc').blank?
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def legal_document_attrs(legal_frame)
|
||||
return [] if legal_frame.blank?
|
||||
return [] if legal_frame.try('text').blank?
|
||||
return [] if legal_frame.attr('type').blank?
|
||||
|
||||
[{
|
||||
body: legal_frame.text,
|
||||
document_type: legal_frame.attr('type')
|
||||
}]
|
||||
end
|
||||
|
||||
def check_availability(codes)
|
||||
codes = [codes] if codes.is_a?(String)
|
||||
|
||||
|
@ -99,10 +56,11 @@ class Epp::Contact < Contact
|
|||
|
||||
res
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
delegate :ident_attr_valid?, to: :class
|
||||
|
||||
# rubocop:disable Style/SymbolArray
|
||||
def epp_code_map
|
||||
{
|
||||
'2003' => [ # Required parameter missing
|
||||
|
@ -120,7 +78,10 @@ class Epp::Contact < Contact
|
|||
[:email, :invalid],
|
||||
[:country_code, :invalid],
|
||||
[:code, :invalid],
|
||||
[:code, :too_long_contact_code]
|
||||
[:code, :too_long_contact_code],
|
||||
[:email, :email_smtp_check_error],
|
||||
[:email, :email_mx_check_error],
|
||||
[:email, :email_regex_check_error],
|
||||
],
|
||||
'2302' => [ # Object exists
|
||||
[:code, :epp_id_taken]
|
||||
|
@ -130,95 +91,7 @@ class Epp::Contact < Contact
|
|||
]
|
||||
}
|
||||
end
|
||||
|
||||
def update_attributes(frame, current_user)
|
||||
return super if frame.blank?
|
||||
at = {}.with_indifferent_access
|
||||
at.deep_merge!(self.class.attrs_from(frame.css('chg'), new_record: false))
|
||||
|
||||
if Setting.client_status_editing_enabled
|
||||
at[:statuses] = statuses - statuses_attrs(frame.css('rem'), 'rem') + statuses_attrs(frame.css('add'), 'add')
|
||||
end
|
||||
|
||||
if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame))
|
||||
frame.css("legalDocument").first.content = doc.path if doc&.persisted?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
|
||||
ident_frame = frame.css('ident').first
|
||||
|
||||
# https://github.com/internetee/registry/issues/576
|
||||
if ident_frame
|
||||
if identifier.valid?
|
||||
submitted_ident = Ident.new(code: ident_frame.text,
|
||||
type: ident_frame.attr('type'),
|
||||
country_code: ident_frame.attr('cc'))
|
||||
|
||||
report_valid_ident_error if submitted_ident != identifier
|
||||
else
|
||||
ident_update_attempt = ident_frame.text.present? && (ident_frame.text != ident)
|
||||
report_ident_update_error if ident_update_attempt
|
||||
|
||||
identifier = Ident.new(code: ident,
|
||||
type: ident_frame.attr('type'),
|
||||
country_code: ident_frame.attr('cc'))
|
||||
|
||||
identifier.validate
|
||||
|
||||
self.identifier = identifier
|
||||
self.ident_updated_at ||= Time.zone.now
|
||||
end
|
||||
end
|
||||
|
||||
self.upid = current_user.registrar.id if current_user.registrar
|
||||
self.up_date = Time.zone.now
|
||||
|
||||
self.attributes = at
|
||||
|
||||
email_changed = email_changed?
|
||||
old_email = email_was
|
||||
updated = save
|
||||
|
||||
if updated && email_changed && registrant?
|
||||
ContactMailer.email_changed(contact: self, old_email: old_email).deliver_now
|
||||
end
|
||||
|
||||
updated
|
||||
end
|
||||
|
||||
def statuses_attrs(frame, action)
|
||||
status_list = status_list_from(frame)
|
||||
|
||||
if action == 'rem'
|
||||
to_destroy = []
|
||||
status_list.each do |status|
|
||||
if statuses.include?(status)
|
||||
to_destroy << status
|
||||
else
|
||||
add_epp_error('2303', 'status', status, [:contact_statuses, :not_found])
|
||||
end
|
||||
end
|
||||
|
||||
return to_destroy
|
||||
else
|
||||
return status_list
|
||||
end
|
||||
end
|
||||
|
||||
def status_list_from(frame)
|
||||
status_list = []
|
||||
|
||||
frame.css('status').each do |status|
|
||||
unless Contact::CLIENT_STATUSES.include?(status['s'])
|
||||
add_epp_error('2303', 'status', status['s'], [:domain_statuses, :not_found])
|
||||
next
|
||||
end
|
||||
|
||||
status_list << status['s']
|
||||
end
|
||||
|
||||
status_list
|
||||
end
|
||||
# rubocop:enable Style/SymbolArray
|
||||
|
||||
def attach_legal_document(legal_document_data)
|
||||
return unless legal_document_data
|
||||
|
@ -230,7 +103,7 @@ class Epp::Contact < Contact
|
|||
end
|
||||
|
||||
def add_legal_file_to_new frame
|
||||
legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame)
|
||||
legal_document_data = ::Deserializers::Xml::LegalDocument.new(frame).call
|
||||
return unless legal_document_data
|
||||
|
||||
doc = LegalDocument.create(
|
||||
|
@ -243,14 +116,4 @@ class Epp::Contact < Contact
|
|||
frame.css("legalDocument").first.content = doc.path if doc&.persisted?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def report_valid_ident_error
|
||||
throw :epp_error, { code: '2308', msg: I18n.t('epp.contacts.errors.valid_ident') }
|
||||
end
|
||||
|
||||
def report_ident_update_error
|
||||
throw :epp_error, { code: '2308', msg: I18n.t('epp.contacts.errors.ident_update') }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'deserializers/xml/legal_document'
|
||||
|
||||
class Epp::Domain < Domain
|
||||
include EppErrors
|
||||
|
||||
|
@ -9,10 +11,11 @@ class Epp::Domain < Domain
|
|||
def manage_permissions
|
||||
return if is_admin # this bad hack for 109086524, refactor later
|
||||
return true if is_transfer || is_renewal
|
||||
return unless update_prohibited? || delete_prohibited?
|
||||
return unless update_prohibited?
|
||||
|
||||
stat = (statuses & (DomainStatus::UPDATE_PROHIBIT_STATES + DomainStatus::DELETE_PROHIBIT_STATES)).first
|
||||
add_epp_error('2304', 'status', stat, I18n.t(:object_status_prohibits_operation))
|
||||
false
|
||||
throw(:abort)
|
||||
end
|
||||
|
||||
after_validation :validate_contacts
|
||||
|
@ -23,12 +26,8 @@ class Epp::Domain < Domain
|
|||
active_admins = admin_domain_contacts.select { |x| !x.marked_for_destruction? }
|
||||
active_techs = tech_domain_contacts.select { |x| !x.marked_for_destruction? }
|
||||
|
||||
# bullet workaround
|
||||
ac = active_admins.map { |x| Contact.find(x.contact_id) }
|
||||
tc = active_techs.map { |x| Contact.find(x.contact_id) }
|
||||
|
||||
# validate registrant here as well
|
||||
([registrant] + ac + tc).each do |x|
|
||||
([registrant] + active_admins + active_techs).each do |x|
|
||||
unless x.valid?
|
||||
add_epp_error('2304', nil, nil, I18n.t(:contact_is_not_valid, value: x.code))
|
||||
ok = false
|
||||
|
@ -56,12 +55,13 @@ class Epp::Domain < Domain
|
|||
def epp_code_map
|
||||
{
|
||||
'2002' => [ # Command use error
|
||||
[:base, :domain_already_belongs_to_the_querying_registrar]
|
||||
%i[base domain_already_belongs_to_the_querying_registrar],
|
||||
],
|
||||
'2003' => [ # Required parameter missing
|
||||
[:registrant, :blank],
|
||||
[:registrar, :blank],
|
||||
[:base, :required_parameter_missing_reserved]
|
||||
%i[registrant blank],
|
||||
%i[registrar blank],
|
||||
%i[base required_parameter_missing_reserved],
|
||||
%i[base required_parameter_missing_disputed],
|
||||
],
|
||||
'2004' => [ # Parameter value range error
|
||||
[:dnskeys, :out_of_range,
|
||||
|
@ -88,10 +88,11 @@ class Epp::Domain < Domain
|
|||
[:puny_label, :too_long, { obj: 'name', val: name_puny }]
|
||||
],
|
||||
'2201' => [ # Authorisation error
|
||||
[:transfer_code, :wrong_pw]
|
||||
%i[transfer_code wrong_pw],
|
||||
],
|
||||
'2202' => [
|
||||
[:base, :invalid_auth_information_reserved]
|
||||
%i[base invalid_auth_information_reserved],
|
||||
%i[base invalid_auth_information_disputed],
|
||||
],
|
||||
'2302' => [ # Object exists
|
||||
[:name_dirty, :taken, { value: { obj: 'name', val: name_dirty } }],
|
||||
|
@ -123,9 +124,8 @@ class Epp::Domain < Domain
|
|||
|
||||
def attach_default_contacts
|
||||
return if registrant.blank?
|
||||
regt = Registrant.find(registrant.id) # temp for bullet
|
||||
tech_contacts << regt if tech_domain_contacts.blank?
|
||||
admin_contacts << regt if admin_domain_contacts.blank? && !regt.org?
|
||||
tech_contacts << registrant if tech_domain_contacts.blank?
|
||||
admin_contacts << registrant if admin_domain_contacts.blank? && !registrant.org?
|
||||
end
|
||||
|
||||
def attrs_from(frame, current_user, action = nil)
|
||||
|
@ -182,14 +182,12 @@ class Epp::Domain < Domain
|
|||
# Adding legal doc to domain and
|
||||
# if something goes wrong - raise Rollback error
|
||||
def add_legal_file_to_new frame
|
||||
legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame)
|
||||
legal_document_data = ::Deserializers::Xml::LegalDocument.new(frame).call
|
||||
return unless legal_document_data
|
||||
return if legal_document_data[:body].starts_with?(ENV['legal_documents_dir'])
|
||||
|
||||
doc = LegalDocument.create(
|
||||
documentable_type: Domain,
|
||||
document_type: legal_document_data[:type],
|
||||
body: legal_document_data[:body]
|
||||
)
|
||||
doc = LegalDocument.create(documentable_type: Domain, document_type: legal_document_data[:type],
|
||||
body: legal_document_data[:body])
|
||||
self.legal_documents = [doc]
|
||||
|
||||
frame.css("legalDocument").first.content = doc.path if doc&.persisted?
|
||||
|
@ -450,13 +448,16 @@ class Epp::Domain < Domain
|
|||
def update(frame, current_user, verify = true)
|
||||
return super if frame.blank?
|
||||
|
||||
check_discarded
|
||||
if discarded?
|
||||
add_epp_error('2304', nil, nil, 'Object status prohibits operation')
|
||||
return
|
||||
end
|
||||
|
||||
at = {}.with_indifferent_access
|
||||
at.deep_merge!(attrs_from(frame.css('chg'), current_user, 'chg'))
|
||||
at.deep_merge!(attrs_from(frame.css('rem'), current_user, 'rem'))
|
||||
|
||||
if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame))
|
||||
if doc = attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
|
||||
frame.css("legalDocument").first.content = doc.path if doc&.persisted?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
|
@ -474,13 +475,36 @@ class Epp::Domain < Domain
|
|||
self.up_date = Time.zone.now
|
||||
end
|
||||
|
||||
same_registrant_as_current = (registrant.code == frame.css('registrant').text)
|
||||
registrant_verification_needed = false
|
||||
# registrant block may not be present, so we need this to rule out false positives
|
||||
if frame.css('registrant').text.present?
|
||||
registrant_verification_needed = (registrant.code != frame.css('registrant').text)
|
||||
end
|
||||
|
||||
if !same_registrant_as_current && errors.empty? && verify &&
|
||||
if registrant_verification_needed && disputed?
|
||||
disputed_pw = frame.css('reserved > pw').text
|
||||
if disputed_pw.blank?
|
||||
add_epp_error('2304', nil, nil, 'Required parameter missing; reserved' \
|
||||
'pw element required for dispute domains')
|
||||
else
|
||||
dispute = Dispute.active.find_by(domain_name: name, password: disputed_pw)
|
||||
if dispute
|
||||
Dispute.close_by_domain(name)
|
||||
registrant_verification_needed = false # Prevent asking current registrant confirmation
|
||||
else
|
||||
add_epp_error('2202', nil, nil, 'Invalid authorization information; '\
|
||||
'invalid reserved>pw value')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unverified_registrant_params = frame.css('registrant').present? &&
|
||||
frame.css('registrant').attr('verified').to_s.downcase != 'yes'
|
||||
|
||||
if registrant_verification_needed && errors.empty? && verify &&
|
||||
Setting.request_confrimation_on_registrant_change_enabled &&
|
||||
frame.css('registrant').present? &&
|
||||
frame.css('registrant').attr('verified').to_s.downcase != 'yes'
|
||||
registrant_verification_asked!(frame.to_s, current_user.id)
|
||||
unverified_registrant_params
|
||||
registrant_verification_asked!(frame.to_s, current_user.id) unless disputed?
|
||||
end
|
||||
|
||||
errors.empty? && super(at)
|
||||
|
@ -517,6 +541,7 @@ class Epp::Domain < Domain
|
|||
|
||||
def attach_legal_document(legal_document_data)
|
||||
return unless legal_document_data
|
||||
return if legal_document_data[:body].starts_with?(ENV['legal_documents_dir'])
|
||||
|
||||
legal_documents.create(
|
||||
document_type: legal_document_data[:type],
|
||||
|
@ -525,9 +550,12 @@ class Epp::Domain < Domain
|
|||
end
|
||||
|
||||
def epp_destroy(frame, user_id)
|
||||
check_discarded
|
||||
if discarded?
|
||||
add_epp_error('2304', nil, nil, 'Object status prohibits operation')
|
||||
return
|
||||
end
|
||||
|
||||
if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame))
|
||||
if doc = attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
|
||||
frame.css("legalDocument").first.content = doc.path if doc&.persisted?
|
||||
end
|
||||
|
||||
|
@ -544,10 +572,10 @@ class Epp::Domain < Domain
|
|||
end
|
||||
|
||||
def set_pending_delete!
|
||||
throw :epp_error, {
|
||||
code: '2304',
|
||||
msg: I18n.t(:object_status_prohibits_operation)
|
||||
} unless pending_deletable?
|
||||
unless pending_deletable?
|
||||
add_epp_error('2304', nil, nil, I18n.t(:object_status_prohibits_operation))
|
||||
return
|
||||
end
|
||||
|
||||
self.delete_date = Time.zone.today + Setting.redemption_grace_period.days + 1.day
|
||||
set_pending_delete
|
||||
|
@ -590,7 +618,10 @@ class Epp::Domain < Domain
|
|||
### TRANSFER ###
|
||||
|
||||
def transfer(frame, action, current_user)
|
||||
check_discarded
|
||||
if discarded?
|
||||
add_epp_error('2106', nil, nil, 'Object is not eligible for transfer')
|
||||
return
|
||||
end
|
||||
|
||||
@is_transfer = true
|
||||
|
||||
|
@ -609,10 +640,8 @@ class Epp::Domain < Domain
|
|||
|
||||
def query_transfer(frame, current_user)
|
||||
if current_user.registrar == registrar
|
||||
throw :epp_error, {
|
||||
code: '2002',
|
||||
msg: I18n.t(:domain_already_belongs_to_the_querying_registrar)
|
||||
}
|
||||
add_epp_error('2002', nil, nil, I18n.t(:domain_already_belongs_to_the_querying_registrar))
|
||||
return
|
||||
end
|
||||
|
||||
transaction do
|
||||
|
@ -637,7 +666,7 @@ class Epp::Domain < Domain
|
|||
self.registrar = current_user.registrar
|
||||
end
|
||||
|
||||
attach_legal_document(self.class.parse_legal_document_from_frame(frame))
|
||||
attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
|
||||
save!(validate: false)
|
||||
|
||||
return dt
|
||||
|
@ -646,11 +675,10 @@ class Epp::Domain < Domain
|
|||
|
||||
def approve_transfer(frame, current_user)
|
||||
pt = pending_transfer
|
||||
|
||||
if current_user.registrar != pt.old_registrar
|
||||
throw :epp_error, {
|
||||
msg: I18n.t('transfer_can_be_approved_only_by_current_registrar'),
|
||||
code: '2304'
|
||||
}
|
||||
add_epp_error('2304', nil, nil, I18n.t('transfer_can_be_approved_only_by_current_registrar'))
|
||||
return
|
||||
end
|
||||
|
||||
transaction do
|
||||
|
@ -663,7 +691,7 @@ class Epp::Domain < Domain
|
|||
regenerate_transfer_code
|
||||
self.registrar = pt.new_registrar
|
||||
|
||||
attach_legal_document(self.class.parse_legal_document_from_frame(frame))
|
||||
attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
|
||||
save!(validate: false)
|
||||
end
|
||||
|
||||
|
@ -672,11 +700,10 @@ class Epp::Domain < Domain
|
|||
|
||||
def reject_transfer(frame, current_user)
|
||||
pt = pending_transfer
|
||||
|
||||
if current_user.registrar != pt.old_registrar
|
||||
throw :epp_error, {
|
||||
msg: I18n.t('transfer_can_be_rejected_only_by_current_registrar'),
|
||||
code: '2304'
|
||||
}
|
||||
add_epp_error('2304', nil, nil, I18n.t('transfer_can_be_rejected_only_by_current_registrar'))
|
||||
return
|
||||
end
|
||||
|
||||
transaction do
|
||||
|
@ -684,59 +711,13 @@ class Epp::Domain < Domain
|
|||
status: DomainTransfer::CLIENT_REJECTED
|
||||
)
|
||||
|
||||
attach_legal_document(self.class.parse_legal_document_from_frame(frame))
|
||||
attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
|
||||
save!(validate: false)
|
||||
end
|
||||
|
||||
pt
|
||||
end
|
||||
|
||||
def keyrelay(parsed_frame, requester)
|
||||
if registrar == requester
|
||||
errors.add(:base, :domain_already_belongs_to_the_querying_registrar) and return false
|
||||
end
|
||||
|
||||
abs_datetime = parsed_frame.css('absolute').text
|
||||
abs_datetime = DateTime.zone.parse(abs_datetime) if abs_datetime.present?
|
||||
|
||||
transaction do
|
||||
kr = keyrelays.build(
|
||||
pa_date: Time.zone.now,
|
||||
key_data_flags: parsed_frame.css('flags').text,
|
||||
key_data_protocol: parsed_frame.css('protocol').text,
|
||||
key_data_alg: parsed_frame.css('alg').text,
|
||||
key_data_public_key: parsed_frame.css('pubKey').text,
|
||||
auth_info_pw: parsed_frame.css('pw').text,
|
||||
expiry_relative: parsed_frame.css('relative').text,
|
||||
expiry_absolute: abs_datetime,
|
||||
requester: requester,
|
||||
accepter: registrar
|
||||
)
|
||||
|
||||
legal_document_data = self.class.parse_legal_document_from_frame(parsed_frame)
|
||||
if legal_document_data
|
||||
kr.legal_documents.build(
|
||||
document_type: legal_document_data[:type],
|
||||
body: legal_document_data[:body]
|
||||
)
|
||||
end
|
||||
|
||||
kr.save
|
||||
|
||||
return false unless valid?
|
||||
|
||||
registrar.notifications.create!(
|
||||
text: 'Key Relay action completed successfully.',
|
||||
attached_obj_type: kr.class.to_s,
|
||||
attached_obj_id: kr.id
|
||||
)
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
### VALIDATIONS ###
|
||||
|
||||
def validate_exp_dates(cur_exp_date)
|
||||
begin
|
||||
return if cur_exp_date.to_date == valid_to.to_date
|
||||
|
@ -751,6 +732,11 @@ class Epp::Domain < Domain
|
|||
|
||||
|
||||
def can_be_deleted?
|
||||
if disputed?
|
||||
errors.add(:base, :domain_status_prohibits_operation)
|
||||
return false
|
||||
end
|
||||
|
||||
begin
|
||||
errors.add(:base, :domain_status_prohibits_operation)
|
||||
return false
|
||||
|
@ -774,18 +760,6 @@ class Epp::Domain < Domain
|
|||
p[:unit]
|
||||
end
|
||||
|
||||
def parse_legal_document_from_frame(parsed_frame)
|
||||
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,
|
||||
type: ld['type']
|
||||
}
|
||||
end
|
||||
|
||||
def check_availability(domain_names)
|
||||
domain_names = [domain_names] if domain_names.is_a?(String)
|
||||
|
||||
|
@ -814,15 +788,4 @@ class Epp::Domain < Domain
|
|||
result
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_discarded
|
||||
if discarded?
|
||||
throw :epp_error, {
|
||||
code: '2105',
|
||||
msg: I18n.t(:object_is_not_eligible_for_renewal),
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,22 +1,27 @@
|
|||
module EPP
|
||||
module Epp
|
||||
class Response
|
||||
attr_accessor :results
|
||||
attr_reader :results
|
||||
|
||||
def self.from_xml(xml)
|
||||
def self.xml(xml)
|
||||
xml_doc = Nokogiri::XML(xml)
|
||||
response = new
|
||||
|
||||
result_elements = xml_doc.css('result')
|
||||
results = []
|
||||
|
||||
result_elements.each do |result_element|
|
||||
response.results << Result.new(result_element[:code].to_s, result_element.text.strip)
|
||||
code_value = result_element[:code]
|
||||
code = Result::Code.new(code_value)
|
||||
results << Result.new(code: code)
|
||||
end
|
||||
|
||||
response
|
||||
new(results: results)
|
||||
end
|
||||
|
||||
def initialize
|
||||
@results = []
|
||||
def initialize(results:)
|
||||
@results = results
|
||||
end
|
||||
|
||||
def code?(code)
|
||||
results.any? { |result| result.code == code }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,27 +1,10 @@
|
|||
module EPP
|
||||
module Epp
|
||||
class Response
|
||||
class Result
|
||||
CODE_TO_TYPE = {
|
||||
'1000' => :success,
|
||||
'1001' => :success_pending,
|
||||
'1300' => :success_empty_queue,
|
||||
'1301' => :success_dequeue,
|
||||
'2001' => :syntax_error,
|
||||
'2003' => :required_param_missing,
|
||||
'2005' => :param_syntax_error,
|
||||
'2308' => :data_management_policy_violation
|
||||
}
|
||||
attr_reader :code
|
||||
|
||||
attr_accessor :code
|
||||
attr_accessor :message
|
||||
|
||||
def initialize(code, message)
|
||||
def initialize(code:)
|
||||
@code = code
|
||||
@message = message
|
||||
end
|
||||
|
||||
def self.codes
|
||||
CODE_TO_TYPE
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
89
app/models/epp/response/result/code.rb
Normal file
89
app/models/epp/response/result/code.rb
Normal file
|
@ -0,0 +1,89 @@
|
|||
module Epp
|
||||
class Response
|
||||
class Result
|
||||
class Code
|
||||
attr_reader :value
|
||||
|
||||
KEY_TO_VALUE = {
|
||||
completed_successfully: 1000,
|
||||
completed_successfully_action_pending: 1001,
|
||||
completed_without_address: 1100,
|
||||
completed_successfully_no_messages: 1300,
|
||||
completed_successfully_ack_to_dequeue: 1301,
|
||||
completed_successfully_ending_session: 1500,
|
||||
unknown_command: 2000,
|
||||
syntax_error: 2001,
|
||||
use_error: 2002,
|
||||
required_parameter_missing: 2003,
|
||||
parameter_value_range_error: 2004,
|
||||
parameter_value_syntax_error: 2005,
|
||||
unimplemented: 2101,
|
||||
billing_failure: 2104,
|
||||
object_is_not_eligible_for_renewal: 2105,
|
||||
object_is_not_eligible_for_transfer: 2106,
|
||||
authorization_error: 2201,
|
||||
invalid_authorization_information: 2202,
|
||||
object_does_not_exist: 2303,
|
||||
object_status_prohibits_operation: 2304,
|
||||
object_association_prohibits_operation: 2305,
|
||||
parameter_value_policy_error: 2306,
|
||||
data_management_policy_violation: 2308,
|
||||
command_failed: 2400,
|
||||
authentication_error_server_closing_connection: 2501,
|
||||
}.freeze
|
||||
private_constant :KEY_TO_VALUE
|
||||
|
||||
DEFAULT_DESCRIPTIONS = {
|
||||
1000 => 'Command completed successfully',
|
||||
1001 => 'Command completed successfully; action pending',
|
||||
1100 => 'Command completed successfully; Postal address data discarded',
|
||||
1300 => 'Command completed successfully; no messages',
|
||||
1301 => 'Command completed successfully; ack to dequeue',
|
||||
1500 => 'Command completed successfully; ending session',
|
||||
2000 => 'Unknown command',
|
||||
2001 => 'Command syntax error',
|
||||
2002 => 'Command use error',
|
||||
2003 => 'Required parameter missing',
|
||||
2004 => 'Parameter value range error',
|
||||
2005 => 'Parameter value syntax error',
|
||||
2101 => 'Unimplemented command',
|
||||
2104 => 'Billing failure',
|
||||
2105 => 'Object is not eligible for renewal',
|
||||
2106 => 'Object is not eligible for transfer',
|
||||
2201 => 'Authorization error',
|
||||
2202 => 'Invalid authorization information',
|
||||
2303 => 'Object does not exist',
|
||||
2304 => 'Object status prohibits operation',
|
||||
2305 => 'Object association prohibits operation',
|
||||
2306 => 'Parameter value policy error',
|
||||
2308 => 'Data management policy violation',
|
||||
2400 => 'Command failed',
|
||||
2501 => 'Authentication error; server closing connection',
|
||||
}.freeze
|
||||
private_constant :DEFAULT_DESCRIPTIONS
|
||||
|
||||
def self.codes
|
||||
KEY_TO_VALUE
|
||||
end
|
||||
|
||||
def self.default_descriptions
|
||||
DEFAULT_DESCRIPTIONS
|
||||
end
|
||||
|
||||
def self.key(key)
|
||||
new(KEY_TO_VALUE[key])
|
||||
end
|
||||
|
||||
def initialize(value)
|
||||
value = value.to_i
|
||||
raise ArgumentError, "Invalid value: #{value}" unless KEY_TO_VALUE.value?(value)
|
||||
@value = value
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
value == other.value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
class EppSession < ActiveRecord::Base
|
||||
class EppSession < ApplicationRecord
|
||||
belongs_to :user, required: true
|
||||
|
||||
validates :session_id, uniqueness: true, presence: true
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
class Invoice < ActiveRecord::Base
|
||||
class Invoice < ApplicationRecord
|
||||
include Versions
|
||||
include Concerns::Invoice::Cancellable
|
||||
include Concerns::Invoice::Payable
|
||||
include Concerns::Invoice::BookKeeping
|
||||
|
||||
belongs_to :seller, class_name: 'Registrar'
|
||||
belongs_to :buyer, class_name: 'Registrar'
|
||||
has_one :account_activity
|
||||
has_many :items, class_name: 'InvoiceItem', dependent: :destroy
|
||||
has_many :directo_records, as: :item, class_name: 'Directo'
|
||||
has_many :payment_orders
|
||||
|
||||
accepts_nested_attributes_for :items
|
||||
|
||||
|
@ -36,7 +37,7 @@ class Invoice < ActiveRecord::Base
|
|||
attribute :vat_rate, ::Type::VATRate.new
|
||||
|
||||
def set_invoice_number
|
||||
last_no = Invoice.order(number: :desc).where('number IS NOT NULL').limit(1).pluck(:number).first
|
||||
last_no = Invoice.order(number: :desc).limit(1).pluck(:number).first
|
||||
|
||||
if last_no && last_no >= Setting.invoice_number_min.to_i
|
||||
self.number = last_no + 1
|
||||
|
@ -48,7 +49,7 @@ class Invoice < ActiveRecord::Base
|
|||
|
||||
errors.add(:base, I18n.t('failed_to_generate_invoice_invoice_number_limit_reached'))
|
||||
logger.error('INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE')
|
||||
false
|
||||
throw(:abort)
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
@ -71,7 +72,7 @@ class Invoice < ActiveRecord::Base
|
|||
Country.new(buyer_country_code)
|
||||
end
|
||||
|
||||
# order is used for directo/banklink description
|
||||
# order is used for directo/banklink description
|
||||
def order
|
||||
"Order nr. #{number}"
|
||||
end
|
||||
|
@ -103,6 +104,14 @@ class Invoice < ActiveRecord::Base
|
|||
generator.generate
|
||||
end
|
||||
|
||||
def do_not_send_e_invoice?
|
||||
e_invoice_sent? || cancelled? || paid?
|
||||
end
|
||||
|
||||
def e_invoice_sent?
|
||||
e_invoice_sent_at.present?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def apply_default_buyer_vat_no
|
||||
|
@ -112,4 +121,4 @@ class Invoice < ActiveRecord::Base
|
|||
def calculate_total
|
||||
self.total = subtotal + vat_amount
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class InvoiceItem < ActiveRecord::Base
|
||||
class InvoiceItem < ApplicationRecord
|
||||
include Versions
|
||||
belongs_to :invoice
|
||||
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
class Keyrelay < ActiveRecord::Base
|
||||
include Versions # version/keyrelay_version.rb
|
||||
include EppErrors
|
||||
|
||||
belongs_to :domain
|
||||
|
||||
belongs_to :requester, class_name: 'Registrar'
|
||||
belongs_to :accepter, class_name: 'Registrar'
|
||||
|
||||
has_many :legal_documents, as: :documentable
|
||||
|
||||
delegate :name, to: :domain, prefix: true
|
||||
|
||||
validates :domain, :key_data_public_key, :key_data_flags, :key_data_protocol,
|
||||
:key_data_alg, :auth_info_pw, presence: true
|
||||
validates :expiry_relative, duration_iso8601: true
|
||||
|
||||
validate :validate_expiry_relative_xor_expiry_absolute
|
||||
|
||||
after_save :touch_domain_version
|
||||
|
||||
def epp_code_map
|
||||
{
|
||||
'2005' => [
|
||||
[:expiry_relative, :unknown_pattern, { value: { obj: 'relative', val: expiry_relative } }]
|
||||
],
|
||||
'2003' => [
|
||||
# TODO: Remove only_one_parameter_allowed and other params that are validated in controller?
|
||||
[:base, :only_one_parameter_allowed, { param_1: 'relative', param_2: 'absolute' }],
|
||||
[:key_data_public_key, :blank],
|
||||
[:key_data_flags, :blank],
|
||||
[:key_data_protocol, :blank],
|
||||
[:key_data_alg, :blank],
|
||||
[:auth_info_pw, :blank]
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def expiry
|
||||
if expiry_relative.present?
|
||||
pa_date + ISO8601::Duration.new(expiry_relative).to_seconds
|
||||
elsif expiry_absolute
|
||||
expiry_absolute
|
||||
end
|
||||
end
|
||||
|
||||
def status
|
||||
if Time.zone.now > expiry
|
||||
return 'expired'
|
||||
else
|
||||
return 'pending'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_expiry_relative_xor_expiry_absolute
|
||||
return if expiry_relative.blank? ^ expiry_absolute.blank?
|
||||
errors.add(:base, I18n.t(:only_one_parameter_allowed, param_1: 'relative', param_2: 'absolute'))
|
||||
end
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
module Legacy
|
||||
class Contact < Db
|
||||
self.table_name = :contact
|
||||
belongs_to :object_registry, foreign_key: :id
|
||||
belongs_to :object, foreign_key: :id
|
||||
|
||||
has_one :object_state, -> { where('valid_to IS NULL') }, foreign_key: :object_id
|
||||
end
|
||||
end
|
|
@ -1,14 +0,0 @@
|
|||
module Legacy
|
||||
class Db < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
begin
|
||||
establish_connection :fred
|
||||
rescue ActiveRecord::AdapterNotSpecified => e
|
||||
logger.info "Legacy 'fred' database support is currently disabled because #{e}"
|
||||
end
|
||||
|
||||
def readonly?
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
module Legacy
|
||||
class Dnskey < Db
|
||||
self.table_name = :dnskey
|
||||
|
||||
belongs_to :object_registry, foreign_key: :id
|
||||
belongs_to :object, foreign_key: :id
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
module Legacy
|
||||
class Domain < Db
|
||||
self.table_name = :domain
|
||||
|
||||
belongs_to :object_registry, foreign_key: :id
|
||||
belongs_to :object, foreign_key: :id
|
||||
belongs_to :nsset, foreign_key: :nsset
|
||||
# belongs_to :registrant, foreign_key: :registrant, primary_key: :legacy_id, class_name: '::Contact'
|
||||
|
||||
has_many :object_states, -> { where('valid_to IS NULL') }, foreign_key: :object_id
|
||||
has_many :dnskeys, foreign_key: :keysetid, primary_key: :keyset
|
||||
has_many :domain_contact_maps, foreign_key: :domainid
|
||||
has_many :nsset_contact_maps, foreign_key: :nssetid, primary_key: :nsset
|
||||
has_many :domain_histories, foreign_key: :id
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
module Legacy
|
||||
class DomainContactMap < Db
|
||||
self.table_name = :domain_contact_map
|
||||
|
||||
# belongs_to :contact, foreign_key: :contactid, primary_key: :legacy_id, class_name: '::Contact'
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
module Legacy
|
||||
class DomainHistory < Db
|
||||
self.table_name = :domain_history
|
||||
|
||||
belongs_to :domain, foreign_key: :id
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
module Legacy
|
||||
class EnumObjectState < Db
|
||||
self.table_name = :enum_object_states
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
module Legacy
|
||||
class Host < Db
|
||||
self.table_name = :host
|
||||
|
||||
has_many :host_ipaddr_maps, foreign_key: :hostid
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
module Legacy
|
||||
class HostIpaddrMap < Db
|
||||
self.table_name = :host_ipaddr_map
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
module Legacy
|
||||
class Invoice < Db
|
||||
self.table_name = :invoice
|
||||
end
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
module Legacy
|
||||
class Nsset < Db
|
||||
self.table_name = :nsset
|
||||
|
||||
belongs_to :object, foreign_key: :id
|
||||
belongs_to :object_registry, foreign_key: :id
|
||||
has_many :hosts, foreign_key: :nssetid
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
module Legacy
|
||||
class NssetContactMap < Db
|
||||
self.table_name = :nsset_contact_map
|
||||
end
|
||||
end
|
|
@ -1,11 +0,0 @@
|
|||
module Legacy
|
||||
class Object < Db
|
||||
self.table_name = :object
|
||||
belongs_to :registrar, foreign_key: :upid, primary_key: :legacy_id, class_name: '::Registrar'
|
||||
|
||||
def self.instance_method_already_implemented?(method_name)
|
||||
return true if method_name == 'update'
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
module Legacy
|
||||
class ObjectHistory < Db
|
||||
self.table_name = :object_history
|
||||
|
||||
belongs_to :object_registry, foreign_key: :historyid
|
||||
|
||||
def self.instance_method_already_implemented?(method_name)
|
||||
return true if method_name == 'update'
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
module Legacy
|
||||
class ObjectRegistry < Db
|
||||
self.table_name = :object_registry
|
||||
self.inheritance_column = nil
|
||||
belongs_to :registrar, foreign_key: :crid, primary_key: :legacy_id, class_name: '::Registrar'
|
||||
belongs_to :object_history, foreign_key: :historyid
|
||||
end
|
||||
end
|
|
@ -1,81 +0,0 @@
|
|||
module Legacy
|
||||
class ObjectState < Db
|
||||
self.table_name = :object_state
|
||||
|
||||
# legacy values. Just for log
|
||||
# 2 => "serverRenewProhibited",
|
||||
# 5 => "serverOutzoneManual",
|
||||
# 6 => "serverInzoneManual",
|
||||
# 7 => "serverBlocked",
|
||||
# 8 => "expirationWarning",
|
||||
# 9 => "expired",
|
||||
# 10 => "unguarded",
|
||||
# 11 => "validationWarning1",
|
||||
# 12 => "validationWarning2",
|
||||
# 13 => "notValidated",
|
||||
# 14 => "nssetMissing",
|
||||
# 15 => "outzone",
|
||||
# 18 => "serverRegistrantChangeProhibited",
|
||||
# 19 => "deleteWarning",
|
||||
# 20 => "outzoneUnguarded",
|
||||
# 1 => "serverDeleteProhibited",
|
||||
# 3 => "serverTransferProhibited",
|
||||
# 4 => "serverUpdateProhibited",
|
||||
# 16 => "linked",
|
||||
# 17 => "deleteCandidate",
|
||||
# 21 => "forceDelete"
|
||||
|
||||
# new values
|
||||
STATE_NAMES = {
|
||||
2 => "serverRenewProhibited",
|
||||
5 => "serverHold",
|
||||
6 => "serverManualInzone",
|
||||
# 7 => "serverBlocked",
|
||||
9 => "expired",
|
||||
# 11 => "validationWarning1",
|
||||
# 13 => "notValidated",
|
||||
14 => "inactive",
|
||||
15 => "serverHold",
|
||||
18 => "serverRegistrantChangeProhibited",
|
||||
1 => "serverDeleteProhibited",
|
||||
3 => "serverTransferProhibited",
|
||||
4 => "serverUpdateProhibited",
|
||||
16 => "linked",
|
||||
17 => "deleteCandidate", # grupistaatus
|
||||
21 => "serverForceDelete" # grupistaatus
|
||||
}.freeze
|
||||
|
||||
|
||||
def name
|
||||
STATE_NAMES[state_id]
|
||||
end
|
||||
|
||||
def desc
|
||||
map = {
|
||||
1 => "Delete prohibited",
|
||||
2 => "Registration renew prohibited",
|
||||
3 => "Sponsoring registrar change prohibited",
|
||||
4 => "Update prohibited",
|
||||
7 => "Domain blocked",
|
||||
8 => "Expires within 30 days",
|
||||
9 => "Expired",
|
||||
10 => "Domain is 30 days after expiration",
|
||||
11 => "Validation of domain expire in 30 days",
|
||||
12 => "Validation of domain expire in 15 days",
|
||||
13 => "Domain not validated",
|
||||
14 => "Domain has not associated nsset",
|
||||
15 => "Domain is not generated into zone",
|
||||
16 => "Has relation to other records in registry",
|
||||
17 => "Object is going to be deleted",
|
||||
18 => "Registrant change prohibited",
|
||||
19 => "Domain will be deleted in 11 days",
|
||||
20 => "Domain is out of zone after 30 days from expiration",
|
||||
21 => "Domain is forced to delete",
|
||||
5 => "Domain is administratively kept out of zone",
|
||||
6 => "Domain is administratively kept in zone"
|
||||
}
|
||||
|
||||
map[state_id]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
module Legacy
|
||||
class Registrar < Db
|
||||
self.table_name = :registrar
|
||||
|
||||
has_many :invoices, foreign_key: :registrarid
|
||||
has_many :acl, foreign_key: :registrarid, class_name: "Legacy::RegistrarAcl"
|
||||
|
||||
def account_balance
|
||||
invoices.sum(:credit)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
module Legacy
|
||||
class RegistrarAcl < Db
|
||||
self.table_name = :registraracl
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
module Legacy
|
||||
class ZoneNs < Db
|
||||
self.table_name = :zone_ns
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
class LegalDocument < ActiveRecord::Base
|
||||
class LegalDocument < ApplicationRecord
|
||||
cattr_accessor :explicitly_write_file
|
||||
include EppErrors
|
||||
MIN_BODY_SIZE = (1.37 * 3.kilobytes).ceil
|
||||
|
@ -14,8 +14,7 @@ class LegalDocument < ActiveRecord::Base
|
|||
|
||||
belongs_to :documentable, polymorphic: true
|
||||
|
||||
|
||||
validate :val_body_length, if: ->(file){ file.path.blank? && !Rails.env.staging?}
|
||||
validate :val_body_length, if: ->(file) { file.path.blank? }
|
||||
|
||||
before_create :add_creator
|
||||
before_save :save_to_filesystem, if: :body
|
||||
|
@ -32,7 +31,6 @@ class LegalDocument < ActiveRecord::Base
|
|||
errors.add(:body, :length) if body.nil? || body.size < MIN_BODY_SIZE
|
||||
end
|
||||
|
||||
|
||||
def save_to_filesystem
|
||||
binary = Base64.decode64(body)
|
||||
digest = Digest::SHA1.new.update(binary).to_s
|
||||
|
@ -58,7 +56,7 @@ class LegalDocument < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def add_creator
|
||||
self.creator_str = ::PaperTrail.whodunnit
|
||||
self.creator_str = ::PaperTrail.request.whodunnit
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Nameserver < ActiveRecord::Base
|
||||
class Nameserver < ApplicationRecord
|
||||
include Versions # version/nameserver_version.rb
|
||||
include EppErrors
|
||||
|
||||
|
@ -34,6 +34,8 @@ class Nameserver < ActiveRecord::Base
|
|||
|
||||
delegate :name, to: :domain, prefix: true
|
||||
|
||||
self.ignored_columns = %w[legacy_domain_id]
|
||||
|
||||
def epp_code_map
|
||||
{
|
||||
'2302' => [
|
||||
|
@ -46,7 +48,7 @@ class Nameserver < ActiveRecord::Base
|
|||
[:ipv6, :invalid, { value: { obj: 'hostAddr', val: ipv6 } }]
|
||||
],
|
||||
'2003' => [
|
||||
[:ipv4, :blank]
|
||||
%i[base ip_required],
|
||||
]
|
||||
}
|
||||
end
|
||||
|
@ -81,11 +83,12 @@ class Nameserver < ActiveRecord::Base
|
|||
|
||||
def glue_record_required?
|
||||
return unless hostname? && domain
|
||||
hostname.end_with?(domain.name)
|
||||
|
||||
DomainName(hostname).domain == domain.name
|
||||
end
|
||||
|
||||
def normalize_attributes
|
||||
self.hostname = hostname.try(:strip).try(:downcase)
|
||||
self.hostname = hostname.try(:strip).try(:downcase).gsub(/\.$/, '')
|
||||
self.ipv4 = Array(ipv4).reject(&:blank?).map(&:strip)
|
||||
self.ipv6 = Array(ipv6).reject(&:blank?).map(&:strip).map(&:upcase)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Notification < ActiveRecord::Base
|
||||
class Notification < ApplicationRecord
|
||||
include Versions # version/notification_version.rb
|
||||
|
||||
belongs_to :registrar
|
||||
|
|
102
app/models/payment_order.rb
Normal file
102
app/models/payment_order.rb
Normal file
|
@ -0,0 +1,102 @@
|
|||
class PaymentOrder < ApplicationRecord
|
||||
include Versions
|
||||
include ActionView::Helpers::NumberHelper
|
||||
|
||||
PAYMENT_INTERMEDIARIES = ENV['payments_intermediaries'].to_s.strip.split(', ').freeze
|
||||
PAYMENT_BANKLINK_BANKS = ENV['payments_banks'].to_s.strip.split(', ').freeze
|
||||
INTERNAL_PAYMENT_METHODS = %w[admin_payment system_payment].freeze
|
||||
PAYMENT_METHODS = [PAYMENT_INTERMEDIARIES, PAYMENT_BANKLINK_BANKS,
|
||||
INTERNAL_PAYMENT_METHODS].flatten.freeze
|
||||
CUSTOMER_PAYMENT_METHODS = [PAYMENT_INTERMEDIARIES, PAYMENT_BANKLINK_BANKS].flatten.freeze
|
||||
|
||||
belongs_to :invoice, optional: false
|
||||
|
||||
validate :invoice_cannot_be_already_paid, on: :create
|
||||
validate :supported_payment_method
|
||||
|
||||
enum status: { issued: 'issued', paid: 'paid', cancelled: 'cancelled',
|
||||
failed: 'failed' }
|
||||
|
||||
attr_accessor :return_url, :response_url
|
||||
|
||||
def self.supported_methods
|
||||
supported = []
|
||||
|
||||
PAYMENT_METHODS.each do |method|
|
||||
class_name = ('PaymentOrders::' + method.camelize).constantize
|
||||
raise(NoMethodError, class_name) unless class_name < PaymentOrder
|
||||
|
||||
supported << class_name
|
||||
end
|
||||
|
||||
supported
|
||||
end
|
||||
|
||||
def self.new_with_type(type:, invoice:)
|
||||
channel = ('PaymentOrders::' + type.camelize).constantize
|
||||
|
||||
PaymentOrder.new(type: channel, invoice: invoice)
|
||||
end
|
||||
|
||||
# Name of configuration namespace
|
||||
def self.config_namespace_name; end
|
||||
|
||||
def supported_payment_method
|
||||
return if PaymentOrder.supported_method?(type)
|
||||
|
||||
errors.add(:type, 'is not supported')
|
||||
end
|
||||
|
||||
def invoice_cannot_be_already_paid
|
||||
return unless invoice&.paid?
|
||||
|
||||
errors.add(:invoice, 'is already paid')
|
||||
end
|
||||
|
||||
def self.supported_method?(name, shortname: false)
|
||||
some_class = if shortname
|
||||
('PaymentOrders::' + name.camelize).constantize
|
||||
else
|
||||
name.constantize
|
||||
end
|
||||
supported_methods.include? some_class
|
||||
rescue NameError
|
||||
false
|
||||
end
|
||||
|
||||
def base_transaction(sum:, paid_at:, buyer_name:)
|
||||
BankTransaction.new(
|
||||
description: invoice.order,
|
||||
reference_no: invoice.reference_no,
|
||||
currency: invoice.currency,
|
||||
iban: invoice.seller_iban,
|
||||
sum: sum,
|
||||
paid_at: paid_at,
|
||||
buyer_name: buyer_name
|
||||
)
|
||||
end
|
||||
|
||||
def complete_transaction
|
||||
return NoMethodError unless payment_received?
|
||||
|
||||
paid!
|
||||
transaction = composed_transaction
|
||||
transaction.save! && transaction.bind_invoice(invoice.number)
|
||||
return unless transaction.errors.any?
|
||||
|
||||
worded_errors = 'Failed to bind. '
|
||||
transaction.errors.full_messages.each do |err|
|
||||
worded_errors << "#{err}, "
|
||||
end
|
||||
|
||||
update!(notes: worded_errors)
|
||||
end
|
||||
|
||||
def channel
|
||||
type.gsub('PaymentOrders::', '')
|
||||
end
|
||||
|
||||
def form_url
|
||||
ENV["payments_#{self.class.config_namespace_name}_url"]
|
||||
end
|
||||
end
|
|
@ -1,15 +0,0 @@
|
|||
module PaymentOrders
|
||||
PAYMENT_INTERMEDIARIES = ENV['payments_intermediaries'].to_s.strip.split(', ').freeze
|
||||
PAYMENT_BANKLINK_BANKS = ENV['payments_banks'].to_s.strip.split(', ').freeze
|
||||
PAYMENT_METHODS = [PAYMENT_INTERMEDIARIES, PAYMENT_BANKLINK_BANKS].flatten.freeze
|
||||
|
||||
def self.create_with_type(type, invoice, opts = {})
|
||||
raise ArgumentError unless PAYMENT_METHODS.include?(type)
|
||||
|
||||
if PAYMENT_BANKLINK_BANKS.include?(type)
|
||||
BankLink.new(type, invoice, opts)
|
||||
elsif type == 'every_pay'
|
||||
EveryPay.new(type, invoice, opts)
|
||||
end
|
||||
end
|
||||
end
|
9
app/models/payment_orders/admin_payment.rb
Normal file
9
app/models/payment_orders/admin_payment.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
module PaymentOrders
|
||||
class AdminPayment < PaymentOrder
|
||||
CONFIG_NAMESPACE = 'admin_payment'.freeze
|
||||
|
||||
def self.config_namespace_name
|
||||
CONFIG_NAMESPACE
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +1,44 @@
|
|||
module PaymentOrders
|
||||
class BankLink < Base
|
||||
BANK_LINK_VERSION = '008'
|
||||
class BankLink < PaymentOrder
|
||||
BANK_LINK_VERSION = '008'.freeze
|
||||
|
||||
NEW_TRANSACTION_SERVICE_NUMBER = '1012'
|
||||
SUCCESSFUL_PAYMENT_SERVICE_NUMBER = '1111'
|
||||
CANCELLED_PAYMENT_SERVICE_NUMBER = '1911'
|
||||
NEW_TRANSACTION_SERVICE_NUMBER = '1012'.freeze
|
||||
SUCCESSFUL_PAYMENT_SERVICE_NUMBER = '1111'.freeze
|
||||
CANCELLED_PAYMENT_SERVICE_NUMBER = '1911'.freeze
|
||||
|
||||
NEW_MESSAGE_KEYS = %w(VK_SERVICE VK_VERSION VK_SND_ID VK_STAMP VK_AMOUNT
|
||||
NEW_MESSAGE_KEYS = %w[VK_SERVICE VK_VERSION VK_SND_ID VK_STAMP VK_AMOUNT
|
||||
VK_CURR VK_REF VK_MSG VK_RETURN VK_CANCEL
|
||||
VK_DATETIME).freeze
|
||||
SUCCESS_MESSAGE_KEYS = %w(VK_SERVICE VK_VERSION VK_SND_ID VK_REC_ID VK_STAMP
|
||||
VK_DATETIME].freeze
|
||||
SUCCESS_MESSAGE_KEYS = %w[VK_SERVICE VK_VERSION VK_SND_ID VK_REC_ID VK_STAMP
|
||||
VK_T_NO VK_AMOUNT VK_CURR VK_REC_ACC VK_REC_NAME
|
||||
VK_SND_ACC VK_SND_NAME VK_REF VK_MSG
|
||||
VK_T_DATETIME).freeze
|
||||
CANCEL_MESSAGE_KEYS = %w(VK_SERVICE VK_VERSION VK_SND_ID VK_REC_ID VK_STAMP
|
||||
VK_REF VK_MSG).freeze
|
||||
VK_T_DATETIME].freeze
|
||||
CANCEL_MESSAGE_KEYS = %w[VK_SERVICE VK_VERSION VK_SND_ID VK_REC_ID VK_STAMP
|
||||
VK_REF VK_MSG].freeze
|
||||
|
||||
def form_fields
|
||||
hash = {}
|
||||
hash["VK_SERVICE"] = NEW_TRANSACTION_SERVICE_NUMBER
|
||||
hash["VK_VERSION"] = BANK_LINK_VERSION
|
||||
hash["VK_SND_ID"] = seller_account
|
||||
hash["VK_STAMP"] = invoice.number
|
||||
hash["VK_AMOUNT"] = number_with_precision(invoice.total, precision: 2, separator: ".")
|
||||
hash["VK_CURR"] = invoice.currency
|
||||
hash["VK_REF"] = ""
|
||||
hash["VK_MSG"] = invoice.order
|
||||
hash["VK_RETURN"] = return_url
|
||||
hash["VK_CANCEL"] = return_url
|
||||
hash["VK_DATETIME"] = Time.zone.now.strftime("%Y-%m-%dT%H:%M:%S%z")
|
||||
hash["VK_MAC"] = calc_mac(hash)
|
||||
hash["VK_ENCODING"] = "UTF-8"
|
||||
hash["VK_LANG"] = "ENG"
|
||||
hash['VK_SERVICE'] = NEW_TRANSACTION_SERVICE_NUMBER
|
||||
hash['VK_VERSION'] = BANK_LINK_VERSION
|
||||
hash['VK_SND_ID'] = seller_account
|
||||
hash['VK_STAMP'] = invoice.number
|
||||
hash['VK_AMOUNT'] = number_with_precision(invoice.total, precision: 2, separator: ".")
|
||||
hash['VK_CURR'] = invoice.currency
|
||||
hash['VK_REF'] = ''
|
||||
hash['VK_MSG'] = invoice.order
|
||||
hash['VK_RETURN'] = return_url
|
||||
hash['VK_CANCEL'] = return_url
|
||||
hash['VK_DATETIME'] = Time.zone.now.strftime('%Y-%m-%dT%H:%M:%S%z')
|
||||
hash['VK_MAC'] = calc_mac(hash)
|
||||
hash['VK_ENCODING'] = 'UTF-8'
|
||||
hash['VK_LANG'] = 'ENG'
|
||||
hash
|
||||
end
|
||||
|
||||
def valid_response_from_intermediary?
|
||||
return false unless response
|
||||
|
||||
case response["VK_SERVICE"]
|
||||
case response['VK_SERVICE']
|
||||
when SUCCESSFUL_PAYMENT_SERVICE_NUMBER
|
||||
valid_successful_transaction?
|
||||
when CANCELLED_PAYMENT_SERVICE_NUMBER
|
||||
|
@ -48,28 +48,31 @@ module PaymentOrders
|
|||
end
|
||||
end
|
||||
|
||||
def complete_transaction
|
||||
return unless valid_successful_transaction?
|
||||
def payment_received?
|
||||
valid_response_from_intermediary? && settled_payment?
|
||||
end
|
||||
|
||||
transaction = BankTransaction.find_by(
|
||||
description: invoice.order,
|
||||
currency: invoice.currency,
|
||||
iban: invoice.seller_iban
|
||||
)
|
||||
def create_failure_report
|
||||
notes = "User failed to make payment. Bank responded with code #{response['VK_SERVICE']}"
|
||||
status = 'cancelled'
|
||||
update!(notes: notes, status: status)
|
||||
end
|
||||
|
||||
transaction.sum = response['VK_AMOUNT']
|
||||
transaction.bank_reference = response['VK_T_NO']
|
||||
transaction.buyer_bank_code = response["VK_SND_ID"]
|
||||
transaction.buyer_iban = response["VK_SND_ACC"]
|
||||
transaction.buyer_name = response["VK_SND_NAME"]
|
||||
transaction.paid_at = Time.parse(response["VK_T_DATETIME"])
|
||||
def composed_transaction
|
||||
paid_at = Time.parse(response['VK_T_DATETIME'])
|
||||
transaction = base_transaction(sum: response['VK_AMOUNT'],
|
||||
paid_at: paid_at,
|
||||
buyer_name: response['VK_SND_NAME'])
|
||||
|
||||
transaction.save!
|
||||
transaction.autobind_invoice
|
||||
transaction.bank_reference = response['VK_T_NO']
|
||||
transaction.buyer_bank_code = response['VK_SND_ID']
|
||||
transaction.buyer_iban = response['VK_SND_ACC']
|
||||
|
||||
transaction
|
||||
end
|
||||
|
||||
def settled_payment?
|
||||
response["VK_SERVICE"] == SUCCESSFUL_PAYMENT_SERVICE_NUMBER
|
||||
response['VK_SERVICE'] == SUCCESSFUL_PAYMENT_SERVICE_NUMBER
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -88,17 +91,15 @@ module PaymentOrders
|
|||
|
||||
def valid_amount?
|
||||
source = number_with_precision(
|
||||
BigDecimal.new(response["VK_AMOUNT"]), precision: 2, separator: "."
|
||||
)
|
||||
target = number_with_precision(
|
||||
invoice.total, precision: 2, separator: "."
|
||||
BigDecimal(response['VK_AMOUNT']), precision: 2, separator: '.'
|
||||
)
|
||||
target = number_with_precision(invoice.total, precision: 2, separator: '.')
|
||||
|
||||
source == target
|
||||
end
|
||||
|
||||
def valid_currency?
|
||||
invoice.currency == response["VK_CURR"]
|
||||
invoice.currency == response['VK_CURR']
|
||||
end
|
||||
|
||||
def sign(data)
|
||||
|
@ -116,7 +117,7 @@ module PaymentOrders
|
|||
|
||||
def valid_mac?(hash, keys)
|
||||
data = keys.map { |element| prepend_size(hash[element]) }.join
|
||||
verify_mac(data, hash["VK_MAC"])
|
||||
verify_mac(data, hash['VK_MAC'])
|
||||
end
|
||||
|
||||
def verify_mac(data, mac)
|
||||
|
@ -125,22 +126,22 @@ module PaymentOrders
|
|||
end
|
||||
|
||||
def prepend_size(value)
|
||||
value = (value || "").to_s.strip
|
||||
string = ""
|
||||
value = (value || '').to_s.strip
|
||||
string = ''
|
||||
string << format("%03i", value.size)
|
||||
string << value
|
||||
end
|
||||
|
||||
def seller_account
|
||||
ENV["payments_#{type}_seller_account"]
|
||||
ENV["payments_#{self.class.config_namespace_name}_seller_account"]
|
||||
end
|
||||
|
||||
def seller_certificate
|
||||
ENV["payments_#{type}_seller_private"]
|
||||
ENV["payments_#{self.class.config_namespace_name}_seller_private"]
|
||||
end
|
||||
|
||||
def bank_certificate
|
||||
ENV["payments_#{type}_bank_certificate"]
|
||||
ENV["payments_#{self.class.config_namespace_name}_bank_certificate"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
module PaymentOrders
|
||||
class Base
|
||||
include ActionView::Helpers::NumberHelper
|
||||
|
||||
attr_reader :type,
|
||||
:invoice,
|
||||
:return_url,
|
||||
:response_url,
|
||||
:response
|
||||
|
||||
def initialize(type, invoice, opts = {})
|
||||
@type = type
|
||||
@invoice = invoice
|
||||
@return_url = opts[:return_url]
|
||||
@response_url = opts[:response_url]
|
||||
@response = opts[:response]
|
||||
end
|
||||
|
||||
def create_transaction
|
||||
transaction = BankTransaction.where(description: invoice.order).first_or_initialize(
|
||||
reference_no: invoice.reference_no,
|
||||
currency: invoice.currency,
|
||||
iban: invoice.seller_iban
|
||||
)
|
||||
|
||||
transaction.save!
|
||||
end
|
||||
|
||||
def form_url
|
||||
ENV["payments_#{type}_url"]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +1,15 @@
|
|||
module PaymentOrders
|
||||
class EveryPay < Base
|
||||
USER = ENV['payments_every_pay_api_user'].freeze
|
||||
KEY = ENV['payments_every_pay_api_key'].freeze
|
||||
ACCOUNT_ID = ENV['payments_every_pay_seller_account'].freeze
|
||||
SUCCESSFUL_PAYMENT = %w(settled authorized).freeze
|
||||
class EveryPay < PaymentOrder
|
||||
USER = ENV['payments_every_pay_api_user']
|
||||
KEY = ENV['payments_every_pay_api_key']
|
||||
ACCOUNT_ID = ENV['payments_every_pay_seller_account']
|
||||
SUCCESSFUL_PAYMENT = %w[settled authorized].freeze
|
||||
|
||||
CONFIG_NAMESPACE = 'every_pay'.freeze
|
||||
|
||||
def self.config_namespace_name
|
||||
CONFIG_NAMESPACE
|
||||
end
|
||||
|
||||
def form_fields
|
||||
base_json = base_params
|
||||
|
@ -20,28 +26,28 @@ module PaymentOrders
|
|||
|
||||
def valid_response_from_intermediary?
|
||||
return false unless response
|
||||
|
||||
valid_hmac? && valid_amount? && valid_account?
|
||||
end
|
||||
|
||||
def settled_payment?
|
||||
SUCCESSFUL_PAYMENT.include?(response[:payment_state])
|
||||
SUCCESSFUL_PAYMENT.include?(response['payment_state'])
|
||||
end
|
||||
|
||||
def complete_transaction
|
||||
return unless valid_response_from_intermediary? && settled_payment?
|
||||
def payment_received?
|
||||
valid_response_from_intermediary? && settled_payment?
|
||||
end
|
||||
|
||||
transaction = BankTransaction.find_by(
|
||||
description: invoice.order,
|
||||
currency: invoice.currency,
|
||||
iban: invoice.seller_iban
|
||||
)
|
||||
def composed_transaction
|
||||
base_transaction(sum: response['amount'],
|
||||
paid_at: Date.strptime(response['timestamp'], '%s'),
|
||||
buyer_name: response['cc_holder_name'])
|
||||
end
|
||||
|
||||
transaction.sum = response[:amount]
|
||||
transaction.paid_at = Date.strptime(response[:timestamp], '%s')
|
||||
transaction.buyer_name = response[:cc_holder_name]
|
||||
|
||||
transaction.save!
|
||||
transaction.autobind_invoice
|
||||
def create_failure_report
|
||||
notes = "User failed to make valid payment. Payment state: #{response['payment_state']}"
|
||||
status = 'cancelled'
|
||||
update!(notes: notes, status: status)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -61,24 +67,27 @@ module PaymentOrders
|
|||
end
|
||||
|
||||
def valid_hmac?
|
||||
hmac_fields = response[:hmac_fields].split(',')
|
||||
hmac_fields = response['hmac_fields'].split(',')
|
||||
hmac_hash = {}
|
||||
hmac_fields.map do |field|
|
||||
symbol = field.to_sym
|
||||
hmac_hash[symbol] = response[symbol]
|
||||
hmac_hash[field] = response[field]
|
||||
end
|
||||
|
||||
hmac_string = hmac_hash.map { |key, _v| "#{key}=#{hmac_hash[key]}" }.join('&')
|
||||
expected_hmac = OpenSSL::HMAC.hexdigest('sha1', KEY, hmac_string)
|
||||
expected_hmac == response[:hmac]
|
||||
expected_hmac == response['hmac']
|
||||
rescue NoMethodError
|
||||
false
|
||||
end
|
||||
|
||||
def valid_amount?
|
||||
invoice.total == BigDecimal.new(response[:amount])
|
||||
return false unless response.key? 'amount'
|
||||
|
||||
invoice.total == BigDecimal(response['amount'])
|
||||
end
|
||||
|
||||
def valid_account?
|
||||
response[:account_id] == ACCOUNT_ID
|
||||
response['account_id'] == ACCOUNT_ID
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
7
app/models/payment_orders/lhv.rb
Normal file
7
app/models/payment_orders/lhv.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
module PaymentOrders
|
||||
class Lhv < BankLink
|
||||
def self.config_namespace_name
|
||||
'lhv'
|
||||
end
|
||||
end
|
||||
end
|
7
app/models/payment_orders/seb.rb
Normal file
7
app/models/payment_orders/seb.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
module PaymentOrders
|
||||
class Seb < BankLink
|
||||
def self.config_namespace_name
|
||||
'seb'
|
||||
end
|
||||
end
|
||||
end
|
7
app/models/payment_orders/swed.rb
Normal file
7
app/models/payment_orders/swed.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
module PaymentOrders
|
||||
class Swed < BankLink
|
||||
def self.config_namespace_name
|
||||
'swed'
|
||||
end
|
||||
end
|
||||
end
|
9
app/models/payment_orders/system_payment.rb
Normal file
9
app/models/payment_orders/system_payment.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
module PaymentOrders
|
||||
class SystemPayment < PaymentOrder
|
||||
CONFIG_NAMESPACE = 'system_payment'.freeze
|
||||
|
||||
def self.config_namespace_name
|
||||
CONFIG_NAMESPACE
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
# To be able to remove existing jobs
|
||||
class QueJob < ActiveRecord::Base
|
||||
class QueJob < ApplicationRecord
|
||||
self.primary_key = 'job_id'
|
||||
end
|
||||
|
|
|
@ -98,4 +98,4 @@ class RegistrantUser < User
|
|||
user
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
# Used in Registrant portal to collect registrant verifications
|
||||
# Registrant postgres user can access this table directly.
|
||||
class RegistrantVerification < ActiveRecord::Base
|
||||
class RegistrantVerification < ApplicationRecord
|
||||
include Versions # version/domain_version.rb
|
||||
|
||||
# actions
|
||||
CONFIRMED = 'confirmed'
|
||||
REJECTED = 'rejected'
|
||||
|
||||
|
||||
# action types
|
||||
DOMAIN_REGISTRANT_CHANGE = 'domain_registrant_change'
|
||||
DOMAIN_DELETE = 'domain_delete'
|
||||
|
||||
belongs_to :domain
|
||||
|
||||
validates :verification_token, :domain_name, :domain, :action, :action_type, presence: true
|
||||
validates :verification_token, :domain, :action, :action_type, presence: true
|
||||
|
||||
def domain_registrant_change_confirm!(initiator)
|
||||
self.action_type = DOMAIN_REGISTRANT_CHANGE
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
class Registrar < ActiveRecord::Base
|
||||
class Registrar < ApplicationRecord
|
||||
include Versions # version/registrar_version.rb
|
||||
include Concerns::Registrar::BookKeeping
|
||||
include Concerns::EmailVerifable
|
||||
include Concerns::Registrar::LegalDoc
|
||||
|
||||
has_many :domains, dependent: :restrict_with_error
|
||||
has_many :contacts, dependent: :restrict_with_error
|
||||
|
@ -21,20 +24,19 @@ class Registrar < ActiveRecord::Base
|
|||
validates :reference_no, format: Billing::ReferenceNo::REGEXP
|
||||
validate :forbid_special_code
|
||||
|
||||
validates :vat_rate, presence: true, if: 'vat_liable_in_foreign_country? && vat_no.blank?'
|
||||
validates :vat_rate, presence: true, if: -> { vat_liable_in_foreign_country? && vat_no.blank? }
|
||||
validates :vat_rate, absence: true, if: :vat_liable_locally?
|
||||
validates :vat_rate, absence: true, if: 'vat_liable_in_foreign_country? && vat_no?'
|
||||
validates :vat_rate, absence: true, if: -> { vat_liable_in_foreign_country? && vat_no? }
|
||||
validates :vat_rate, numericality: { greater_than_or_equal_to: 0, less_than: 100 },
|
||||
allow_nil: true
|
||||
|
||||
validate :forbid_special_code
|
||||
|
||||
attribute :vat_rate, ::Type::VATRate.new
|
||||
after_initialize :set_defaults
|
||||
|
||||
validates :email, :billing_email,
|
||||
email_format: { message: :invalid },
|
||||
allow_blank: true, if: proc { |c| c.email_changed? }
|
||||
validate :correct_email_format, if: proc { |c| c.will_save_change_to_email? }
|
||||
validate :correct_billing_email_format
|
||||
|
||||
alias_attribute :contact_email, :email
|
||||
|
||||
WHOIS_TRIGGERS = %w(name email phone street city state zip)
|
||||
|
||||
|
@ -44,6 +46,8 @@ class Registrar < ActiveRecord::Base
|
|||
RegenerateRegistrarWhoisesJob.enqueue id
|
||||
end
|
||||
|
||||
self.ignored_columns = %w[legacy_id]
|
||||
|
||||
class << self
|
||||
def ordered
|
||||
order(name: :asc)
|
||||
|
@ -95,9 +99,7 @@ class Registrar < ActiveRecord::Base
|
|||
}
|
||||
]
|
||||
)
|
||||
|
||||
e_invoice = invoice.to_e_invoice
|
||||
e_invoice.deliver
|
||||
SendEInvoiceJob.enqueue(invoice.id)
|
||||
|
||||
invoice
|
||||
end
|
||||
|
@ -174,6 +176,11 @@ class Registrar < ActiveRecord::Base
|
|||
iban
|
||||
end
|
||||
|
||||
def billing_email
|
||||
return contact_email if self[:billing_email].blank?
|
||||
self[:billing_email]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_defaults
|
||||
|
@ -187,4 +194,4 @@ class Registrar < ActiveRecord::Base
|
|||
def vat_liable_in_foreign_country?
|
||||
!vat_liable_locally?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
class ReservedDomain < ActiveRecord::Base
|
||||
class ReservedDomain < ApplicationRecord
|
||||
include Versions # version/reserved_domain_version.rb
|
||||
include WhoisStatusPopulate
|
||||
before_save :fill_empty_passwords
|
||||
before_save :generate_data
|
||||
before_save :sync_dispute_password
|
||||
after_destroy :remove_data
|
||||
|
||||
validates :name, domain_name: true, uniqueness: true
|
||||
|
||||
alias_attribute :registration_code, :password
|
||||
|
||||
self.ignored_columns = %w[legacy_id]
|
||||
|
||||
class << self
|
||||
def pw_for(domain_name)
|
||||
name_in_ascii = SimpleIDN.to_ascii(domain_name)
|
||||
|
@ -39,23 +43,21 @@ class ReservedDomain < ActiveRecord::Base
|
|||
self.password = SecureRandom.hex
|
||||
end
|
||||
|
||||
def sync_dispute_password
|
||||
dispute = Dispute.active.find_by(domain_name: name)
|
||||
self.password = dispute.password if dispute.present?
|
||||
end
|
||||
|
||||
def generate_data
|
||||
return if Domain.where(name: name).any?
|
||||
|
||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||
wr.json = @json = generate_json # we need @json to bind to class
|
||||
wr.json = @json = generate_json(wr, domain_status: 'Reserved') # we need @json to bind to class
|
||||
wr.save
|
||||
end
|
||||
|
||||
alias_method :update_whois_record, :generate_data
|
||||
|
||||
def generate_json
|
||||
h = HashWithIndifferentAccess.new
|
||||
h[:name] = self.name
|
||||
h[:status] = ['Reserved']
|
||||
h
|
||||
end
|
||||
|
||||
def remove_data
|
||||
UpdateWhoisRecordJob.enqueue name, 'reserved'
|
||||
end
|
||||
|
|
91
app/models/retained_domains.rb
Normal file
91
app/models/retained_domains.rb
Normal file
|
@ -0,0 +1,91 @@
|
|||
# Hiding the queries behind its own class will allow us to include disputed or
|
||||
# auctioned domains without meddling up with controller logic.
|
||||
class RetainedDomains
|
||||
RESERVED = 'reserved'.freeze
|
||||
BLOCKED = 'blocked'.freeze
|
||||
DISPUTED = 'disputed'.freeze
|
||||
|
||||
attr_reader :domains,
|
||||
:type
|
||||
|
||||
def initialize(params)
|
||||
@type = establish_type(params)
|
||||
@domains = gather_domains
|
||||
end
|
||||
|
||||
delegate :count, to: :domains
|
||||
|
||||
def to_jsonable
|
||||
domains.map { |el| domain_to_jsonable(el) }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def establish_type(params)
|
||||
type = params[:type]
|
||||
|
||||
case type
|
||||
when RESERVED then :reserved
|
||||
when BLOCKED then :blocked
|
||||
when DISPUTED then :disputed
|
||||
else :all
|
||||
end
|
||||
end
|
||||
|
||||
def gather_domains
|
||||
blocked_domains.to_a
|
||||
.union(reserved_domains.to_a)
|
||||
.union(disputed_domains.to_a)
|
||||
end
|
||||
|
||||
def blocked_domains
|
||||
if %i[all blocked].include?(type)
|
||||
BlockedDomain.order(name: :desc).all
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def reserved_domains
|
||||
if %i[all reserved].include?(type)
|
||||
ReservedDomain.order(name: :desc).all
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def disputed_domains
|
||||
if %i[all disputed].include?(type)
|
||||
Dispute.order(domain_name: :desc).active
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def domain_to_jsonable(domain)
|
||||
status = get_status(domain)
|
||||
domain_name = get_domain_name(domain)
|
||||
punycode = SimpleIDN.to_ascii(domain_name)
|
||||
|
||||
{
|
||||
name: domain_name,
|
||||
status: status,
|
||||
punycode_name: punycode,
|
||||
}
|
||||
end
|
||||
|
||||
def get_status(domain)
|
||||
case domain
|
||||
when ReservedDomain then RESERVED
|
||||
when BlockedDomain then BLOCKED
|
||||
when Dispute then DISPUTED
|
||||
end
|
||||
end
|
||||
|
||||
def get_domain_name(domain)
|
||||
case domain
|
||||
when Dispute then domain.domain_name
|
||||
else domain.name
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,72 +1,5 @@
|
|||
class Setting < RailsSettings::Base
|
||||
include Versions # version/setting_version.rb
|
||||
source Rails.root.join('config', 'app.yml')
|
||||
# frozen_string_literal: true
|
||||
|
||||
# When config/app.yml has changed, you need change this prefix to v2, v3 ... to expires caches
|
||||
# cache_prefix { "v1" }
|
||||
|
||||
def self.reload_settings!
|
||||
STDOUT << "#{Time.zone.now.utc} - Clearing settings cache\n"
|
||||
Rails.cache.delete_matched('settings:.*')
|
||||
STDOUT << "#{Time.zone.now.utc} - Settings cache cleared\n"
|
||||
end
|
||||
|
||||
|
||||
# cannot do instance validation because CachedSetting use save!
|
||||
def self.params_errors(params)
|
||||
errors = {}
|
||||
# DS data allowed and Allow key data cannot be both true
|
||||
if !!params["key_data_allowed"] && params["key_data_allowed"] == params["ds_data_allowed"]
|
||||
msg = "#{I18n.t(:key_data_allowed)} and #{I18n.t(:ds_data_with_key_allowed)} cannot be both true"
|
||||
errors["key_data_allowed"] = msg
|
||||
errors["ds_data_allowed"] = msg
|
||||
end
|
||||
|
||||
return errors
|
||||
end
|
||||
|
||||
def self.integer_settings
|
||||
%i[
|
||||
admin_contacts_min_count
|
||||
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
|
||||
ns_min_count
|
||||
ns_max_count
|
||||
transfer_wait_time
|
||||
invoice_number_min
|
||||
invoice_number_max
|
||||
days_to_keep_invoices_active
|
||||
days_to_keep_overdue_invoices_active
|
||||
days_to_renew_domain_before_expire
|
||||
expire_warning_period
|
||||
redemption_grace_period
|
||||
expire_pending_confirmation
|
||||
]
|
||||
end
|
||||
|
||||
def self.float_settings
|
||||
%i[
|
||||
registry_vat_prc
|
||||
minimum_deposit
|
||||
]
|
||||
end
|
||||
|
||||
def self.boolean_settings
|
||||
%i[
|
||||
ds_data_allowed
|
||||
key_data_allowed
|
||||
client_side_status_editing_enabled
|
||||
registrar_ip_whitelist_enabled
|
||||
api_ip_whitelist_enabled
|
||||
request_confrimation_on_registrant_change_enabled
|
||||
request_confirmation_on_domain_deletion_enabled
|
||||
nameserver_required
|
||||
address_processing
|
||||
]
|
||||
end
|
||||
class Setting < SettingEntry
|
||||
# Bridge Setting calls to SettingEntry, so we don't have to drop legacy settings yet
|
||||
end
|
||||
|
|
92
app/models/setting_entry.rb
Normal file
92
app/models/setting_entry.rb
Normal file
|
@ -0,0 +1,92 @@
|
|||
class SettingEntry < ApplicationRecord
|
||||
include Versions
|
||||
validates :code, presence: true, uniqueness: true, format: { with: /\A([a-z])[a-z|_]+[a-z]\z/ }
|
||||
validates :format, presence: true
|
||||
validates :group, presence: true
|
||||
validate :validate_value_format
|
||||
validate :validate_code_is_not_using_reserved_name
|
||||
before_update :replace_boolean_nil_with_false
|
||||
|
||||
VALUE_FORMATS = {
|
||||
string: :string_format,
|
||||
integer: :integer_format,
|
||||
float: :float_format,
|
||||
boolean: :boolean_format,
|
||||
hash: :hash_format,
|
||||
array: :array_format,
|
||||
}.with_indifferent_access.freeze
|
||||
|
||||
def retrieve
|
||||
method = VALUE_FORMATS[format]
|
||||
return false if self.format == 'boolean' && value.blank?
|
||||
return if value.blank?
|
||||
|
||||
send(method)
|
||||
end
|
||||
|
||||
def self.with_group(group_name)
|
||||
SettingEntry.order(id: :asc).where(group: group_name)
|
||||
end
|
||||
|
||||
# rubocop:disable Style/MethodMissingSuper
|
||||
# rubocop:disable Style/MissingRespondToMissing
|
||||
def self.method_missing(method, *args)
|
||||
super(method, *args)
|
||||
rescue NoMethodError
|
||||
get_or_set(method.to_s, args[0])
|
||||
end
|
||||
# rubocop:enable Style/MissingRespondToMissing
|
||||
# rubocop:enable Style/MethodMissingSuper
|
||||
|
||||
def self.get_or_set(method_name, arg)
|
||||
if method_name[-1] == '='
|
||||
SettingEntry.find_by!(code: method_name.sub('=', '')).update(value: arg.to_s)
|
||||
else
|
||||
stg = SettingEntry.find_by(code: method_name)
|
||||
stg ? stg.retrieve : nil
|
||||
end
|
||||
end
|
||||
|
||||
# Hooks
|
||||
def replace_boolean_nil_with_false
|
||||
return unless self.format == 'boolean'
|
||||
return if value == 'true'
|
||||
|
||||
self.value = 'false'
|
||||
end
|
||||
|
||||
def validate_code_is_not_using_reserved_name
|
||||
disallowed = []
|
||||
ActiveRecord::Base.instance_methods.sort.each { |m| disallowed << m.to_s }
|
||||
errors.add(:code, :invalid) if disallowed.include? code
|
||||
end
|
||||
|
||||
def validate_value_format
|
||||
formats = VALUE_FORMATS.with_indifferent_access
|
||||
errors.add(:format, :invalid) unless formats.keys.any? format
|
||||
end
|
||||
|
||||
def string_format
|
||||
value
|
||||
end
|
||||
|
||||
def integer_format
|
||||
value.to_i
|
||||
end
|
||||
|
||||
def float_format
|
||||
value.to_f
|
||||
end
|
||||
|
||||
def boolean_format
|
||||
value == 'true'
|
||||
end
|
||||
|
||||
def hash_format
|
||||
JSON.parse(value)
|
||||
end
|
||||
|
||||
def array_format
|
||||
JSON.parse(value).to_a
|
||||
end
|
||||
end
|
|
@ -1,10 +1,10 @@
|
|||
module Type
|
||||
class VATRate < ActiveRecord::Type::Decimal
|
||||
def type_cast_from_database(value)
|
||||
def deserialize(value)
|
||||
super * 100 if value
|
||||
end
|
||||
|
||||
def type_cast_for_database(value)
|
||||
def serialize(value)
|
||||
super / 100.0 if value
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
class User < ActiveRecord::Base
|
||||
class User < ApplicationRecord
|
||||
include Versions # version/user_version.rb
|
||||
|
||||
has_many :actions, dependent: :restrict_with_exception
|
||||
|
||||
attr_accessor :phone
|
||||
|
||||
self.ignored_columns = %w[legacy_id]
|
||||
|
||||
def id_role_username
|
||||
"#{self.id}-#{self.class}: #{self.username}"
|
||||
end
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
class KeyrelayVersion < PaperTrail::Version
|
||||
include VersionSession
|
||||
self.table_name = :log_keyrelays
|
||||
self.sequence_name = :log_keyrelays_id_seq
|
||||
end
|
4
app/models/version/payment_order_version.rb
Normal file
4
app/models/version/payment_order_version.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
class PaymentOrderVersion < PaperTrail::Version
|
||||
self.table_name = :log_payment_orders
|
||||
self.sequence_name = :log_payment_orders_id_seq
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue