Merge branch 'master' into log-bounced-emails

This commit is contained in:
Karl Erik Õunapuu 2020-10-27 11:31:48 +02:00 committed by GitHub
commit 34b4a7fbeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
70 changed files with 790 additions and 4967 deletions

View file

@ -2,7 +2,7 @@ require 'open3'
class ApiUser < User
include EppErrors
devise :database_authenticatable, :trackable, :timeoutable, :id_card_authenticatable,
devise :database_authenticatable, :trackable, :timeoutable,
authentication_keys: [:username]
def epp_code_map
@ -47,12 +47,6 @@ class ApiUser < User
self.active = true unless saved_change_to_active?
end
class << self
def find_by_id_card(id_card)
find_by(identity_code: id_card.personal_code)
end
end
def to_s
username
end

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

@ -210,10 +210,13 @@ class Contact < ApplicationRecord
)
end
def registrant_user_contacts(registrant_user)
registrant_user_direct_contacts(registrant_user)
.or(registrant_user_company_contacts(registrant_user))
.or(registrant_user_indirect_contacts(registrant_user))
def registrant_user_contacts(registrant_user, representable: true)
represented_contacts = registrant_user_direct_contacts(registrant_user)
.or(registrant_user_company_contacts(registrant_user))
return represented_contacts if representable
represented_contacts.or(registrant_user_indirect_contacts(registrant_user))
end
def registrant_user_direct_contacts(registrant_user)

View file

@ -306,11 +306,7 @@ class Domain < ApplicationRecord
end
def renewable?
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 false unless renew_blocking_statuses.empty?
return true unless Setting.days_to_renew_domain_before_expire != 0
# if you can renew domain at days_to_renew before domain expiration
@ -321,6 +317,15 @@ class Domain < ApplicationRecord
true
end
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]
(statuses & disallowed)
end
def notify_registrar(message_key)
registrar.notifications.create!(
text: "#{I18n.t(message_key)}: #{name}",
@ -484,7 +489,7 @@ class Domain < ApplicationRecord
end
def pending_update?
statuses.include?(DomainStatus::PENDING_UPDATE) && !statuses.include?(DomainStatus::FORCE_DELETE)
statuses.include?(DomainStatus::PENDING_UPDATE)
end
# depricated not used, not valid

View file

@ -581,11 +581,14 @@ class Epp::Domain < Domain
save(validate: false)
end
### RENEW ###
def renew(cur_exp_date, period, unit = 'y')
@is_renewal = true
validate_exp_dates(cur_exp_date)
add_epp_error('2105', nil, nil, I18n.t('object_is_not_eligible_for_renewal')) unless renewable?
add_renew_epp_errors unless renewable?
return false if errors.any?
period = period.to_i
@ -613,6 +616,13 @@ class Epp::Domain < Domain
save
end
def add_renew_epp_errors
if renew_blocking_statuses.any? && !renewable?
add_epp_error('2304', 'status', renew_blocking_statuses,
I18n.t('object_status_prohibits_operation'))
end
end
### TRANSFER ###
def transfer(frame, action, current_user)

View file

@ -1,6 +0,0 @@
class IdCard
attr_accessor :first_name
attr_accessor :last_name
attr_accessor :personal_code
attr_accessor :country_code
end

View file

@ -1,7 +1,7 @@
class RegistrantUser < User
attr_accessor :idc_data
devise :trackable, :timeoutable, :id_card_authenticatable
devise :trackable, :timeoutable
def ability
@ability ||= Ability.new(self)
@ -22,8 +22,8 @@ class RegistrantUser < User
citizen_country_code: country.alpha3)
end
def contacts
Contact.registrant_user_contacts(self)
def contacts(representable: true)
Contact.registrant_user_contacts(self, representable: representable)
end
def direct_contacts
@ -66,23 +66,19 @@ class RegistrantUser < User
find_or_create_by_user_data(user_data)
end
def find_or_create_by_mid_data(response)
user_data = { first_name: response.user_givenname, last_name: response.user_surname,
ident: response.user_id_code, country_code: response.user_country }
def find_or_create_by_omniauth_data(omniauth_hash)
uid = omniauth_hash['uid']
identity_code = uid.slice(2..-1)
country_code = uid.slice(0..1)
first_name = omniauth_hash.dig('info', 'first_name')
last_name = omniauth_hash.dig('info', 'last_name')
user_data = { first_name: first_name, last_name: last_name,
ident: identity_code, country_code: country_code }
find_or_create_by_user_data(user_data)
end
def find_by_id_card(id_card)
registrant_ident = "#{id_card.country_code}-#{id_card.personal_code}"
username = [id_card.first_name, id_card.last_name].join("\s")
user = find_or_initialize_by(registrant_ident: registrant_ident)
user.username = username
user.save!
user
end
private
def find_or_create_by_user_data(user_data = {})

View file

@ -11,4 +11,11 @@ class User < ApplicationRecord
"#{self.id}-#{self.class}: #{self.username}"
end
def self.from_omniauth(omniauth_hash)
uid = omniauth_hash['uid']
identity_code = uid.slice(2..-1)
# country_code = uid.slice(0..1)
find_by(identity_code: identity_code)
end
end