Merge remote-tracking branch 'origin/master' into 1580-registrar-api-contacts-endpoint

This commit is contained in:
Karl Erik Õunapuu 2020-11-17 09:55:32 +02:00
commit db50a89d85
No known key found for this signature in database
GPG key ID: C9DD647298A34764
51 changed files with 801 additions and 285 deletions

View file

@ -19,6 +19,16 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
end
end
def notification_template
if contact_emails_verification_failed.present?
'invalid_email'
elsif registrant.org?
'legal_person'
else
'private_person'
end
end
def force_delete_scheduled?
statuses.include?(DomainStatus::FORCE_DELETE)
end
@ -80,8 +90,8 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
end
def cancel_force_delete
restore_statuses_before_force_delete
remove_force_delete_statuses
restore_statuses_before_force_delete
clear_force_delete_data
self.force_delete_date = nil
self.force_delete_start = nil
@ -106,7 +116,7 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
end
def soft_delete_dates(years)
self.force_delete_start = valid_to - years.years + 1.day
self.force_delete_start = valid_to - years.years
self.force_delete_date = force_delete_start + Setting.expire_warning_period.days +
Setting.redemption_grace_period.days
end
@ -119,7 +129,7 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
end
def preserve_current_statuses_for_force_delete
self.statuses_before_force_delete = statuses.clone
update(statuses_before_force_delete: statuses)
end
def restore_statuses_before_force_delete
@ -128,9 +138,9 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
end
def add_force_delete_statuses
statuses << DomainStatus::FORCE_DELETE
statuses << DomainStatus::SERVER_RENEW_PROHIBITED
statuses << DomainStatus::SERVER_TRANSFER_PROHIBITED
self.statuses |= [DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED]
end
def remove_force_delete_statuses

View file

@ -15,6 +15,10 @@ module Concerns
domain: domain(billing_email))
end
def email_verification_failed?
email_verification&.failed?
end
class_methods do
def domain(email)
Mail::Address.new(email).domain&.downcase || 'not_found'

View file

@ -15,7 +15,7 @@ module Concerns
domain.registrar.notifications.create!(text: I18n.t('grace_period_started_domain',
domain_name: domain.name,
date: domain.force_delete_start))
send_mail(domain)
send_mail(domain) if domain.template_name.present?
domain.update(contact_notification_sent_date: Time.zone.today)
end

View file

@ -320,8 +320,8 @@ class Domain < ApplicationRecord
def renew_blocking_statuses
disallowed = [DomainStatus::DELETE_CANDIDATE, DomainStatus::PENDING_RENEW,
DomainStatus::PENDING_TRANSFER, DomainStatus::CLIENT_RENEW_PROHIBITED,
DomainStatus::PENDING_UPDATE, DomainStatus::PENDING_DELETE,
DomainStatus::PENDING_DELETE_CONFIRMATION, DomainStatus::SERVER_RENEW_PROHIBITED]
DomainStatus::PENDING_UPDATE, DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::PENDING_DELETE_CONFIRMATION]
(statuses & disallowed)
end
@ -384,7 +384,7 @@ class Domain < ApplicationRecord
end
def registrant_update_confirmable?(token)
return false if (statuses & [DomainStatus::FORCE_DELETE, DomainStatus::DELETE_CANDIDATE]).any?
return false if statuses.include? DomainStatus::DELETE_CANDIDATE
return false unless pending_update?
return false unless registrant_verification_asked?
return false unless registrant_verification_token == token
@ -642,6 +642,10 @@ class Domain < ApplicationRecord
DNS::DomainName.new(name)
end
def contact_emails_verification_failed
contacts.select(&:email_verification_failed?)&.map(&:email)&.uniq
end
def self.to_csv
CSV.generate do |csv|
csv << column_names

View file

@ -612,6 +612,7 @@ class Epp::Domain < Domain
statuses.delete(DomainStatus::SERVER_HOLD)
statuses.delete(DomainStatus::EXPIRED)
statuses.delete(DomainStatus::SERVER_UPDATE_PROHIBITED)
cancel_pending_delete
save
end

View file

@ -30,6 +30,7 @@ module Epp
data_management_policy_violation: 2308,
command_failed: 2400,
authentication_error_server_closing_connection: 2501,
session_limit_exceeded_server_closing_connection: 2502,
}.freeze
private_constant :KEY_TO_VALUE
@ -59,6 +60,7 @@ module Epp
2308 => 'Data management policy violation',
2400 => 'Command failed',
2501 => 'Authentication error; server closing connection',
2502 => 'Session limit exceeded; server closing connection',
}.freeze
private_constant :DEFAULT_DESCRIPTIONS

View file

@ -6,19 +6,26 @@ class EppSession < ApplicationRecord
class_attribute :timeout
self.timeout = (ENV['epp_session_timeout_seconds'] || 300).to_i.seconds
class_attribute :sessions_per_registrar
self.sessions_per_registrar = (ENV['epp_sessions_per_registrar'] || 4).to_i
alias_attribute :last_access, :updated_at
def self.limit_per_registrar
4
end
scope :not_expired,
lambda {
where(':now <= (updated_at + interval :interval)', now: Time.zone.now, interval: interval)
}
def self.limit_reached?(registrar)
count = where(user_id: registrar.api_users.ids).where('updated_at >= ?', Time.zone.now - 1.second).count
count >= limit_per_registrar
count = where(user_id: registrar.api_users.ids).not_expired.count
count >= sessions_per_registrar
end
def self.interval
"#{timeout.parts.first.second} #{timeout.parts.first.first}"
end
def self.expired
interval = "#{timeout.parts.first.second} #{timeout.parts.first.first}"
where(':now > (updated_at + interval :interval)', now: Time.zone.now, interval: interval)
end

View file

@ -54,14 +54,25 @@ class RegistrantUser < User
username.split.second
end
def update_related_contacts
contacts = Contact.where(ident: ident, ident_country_code: country.alpha2)
.where('UPPER(name) != UPPER(?)', username)
contacts.each do |contact|
contact.update(name: username)
action = actions.create!(contact: contact, operation: :update)
contact.registrar.notify(action)
end
end
class << self
def find_or_create_by_api_data(user_data = {})
return false unless user_data[:ident]
return false unless user_data[:first_name]
return false unless user_data[:last_name]
user_data.each_value { |v| v.upcase! if v.is_a?(String) }
user_data[:country_code] ||= 'EE'
%i[ident country_code].each { |f| user_data[f].upcase! if user_data[f].is_a?(String) }
find_or_create_by_user_data(user_data)
end
@ -91,6 +102,7 @@ class RegistrantUser < User
user.username = "#{user_data[:first_name]} #{user_data[:last_name]}"
user.save
user.update_related_contacts
user
end
end

View file

@ -141,11 +141,13 @@ class Registrar < ApplicationRecord
end
# Audit log is needed, therefore no raw SQL
def replace_nameservers(hostname, new_attributes)
def replace_nameservers(hostname, new_attributes, domains: [])
transaction do
domain_list = []
nameservers.where(hostname: hostname).find_each do |original_nameserver|
next unless domains.include?(original_nameserver.domain.name_puny) || domains.empty?
new_nameserver = Nameserver.new
new_nameserver.domain = original_nameserver.domain
new_nameserver.attributes = new_attributes