mirror of
https://github.com/internetee/registry.git
synced 2025-08-02 16:02:03 +02:00
Rubocop autocorrect
This commit is contained in:
parent
f8c48a7456
commit
6c5c0b38c8
59 changed files with 533 additions and 546 deletions
|
@ -3,7 +3,7 @@ class Address < ActiveRecord::Base
|
|||
belongs_to :country
|
||||
|
||||
class << self
|
||||
def extract_attributes ah, type=:create
|
||||
def extract_attributes(ah, _type = :create)
|
||||
address_hash = {}
|
||||
address_hash = ({
|
||||
country_id: Country.find_by(iso: ah[:cc]).try(:id),
|
||||
|
@ -14,7 +14,7 @@ class Address < ActiveRecord::Base
|
|||
zip: ah[:pc]
|
||||
}) if ah.is_a?(Hash)
|
||||
|
||||
address_hash.delete_if { |k, v| v.nil? }
|
||||
address_hash.delete_if { |_k, v| v.nil? }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,21 +22,21 @@ module EppErrors
|
|||
values.each do |err|
|
||||
if err.is_a?(Hash)
|
||||
next unless code = find_epp_code(err[:msg])
|
||||
err_msg = {code: code, msg: err[:msg]}
|
||||
err_msg[:value] = {val: err[:val], obj: err[:obj]} if err[:val]
|
||||
err_msg = { code: code, msg: err[:msg] }
|
||||
err_msg[:value] = { val: err[:val], obj: err[:obj] } if err[:val]
|
||||
epp_errors << err_msg
|
||||
else
|
||||
next unless code = find_epp_code(err)
|
||||
err = {code: code, msg: err}
|
||||
err = { code: code, msg: err }
|
||||
|
||||
# If we have setting relation, then still add the value to the error message
|
||||
# If this sort of exception happens again, some other logic has to be implemented
|
||||
if self.class.reflect_on_association(key) && key == :setting
|
||||
err[:value] = {val: send(key).value, obj: self.class::EPP_ATTR_MAP[key]}
|
||||
err[:value] = { val: send(key).value, obj: self.class::EPP_ATTR_MAP[key] }
|
||||
|
||||
#if the key represents other relations, skip value
|
||||
# if the key represents other relations, skip value
|
||||
elsif !self.class.reflect_on_association(key)
|
||||
err[:value] = {val: send(key), obj: self.class::EPP_ATTR_MAP[key]}
|
||||
err[:value] = { val: send(key), obj: self.class::EPP_ATTR_MAP[key] }
|
||||
end
|
||||
|
||||
epp_errors << err
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class Contact < ActiveRecord::Base
|
||||
#TODO Foreign contact will get email with activation link/username/temp password
|
||||
#TODO Phone number validation, in first phase very minimam in order to support current registries
|
||||
# TODO Foreign contact will get email with activation link/username/temp password
|
||||
# TODO Phone number validation, in first phase very minimam in order to support current registries
|
||||
|
||||
include EppErrors
|
||||
|
||||
|
@ -19,23 +19,23 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
validate :ident_must_be_valid
|
||||
|
||||
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/ #/\+\d{3}\.\d+/
|
||||
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/ # /\+\d{3}\.\d+/
|
||||
validates :email, format: /@/
|
||||
|
||||
validates_uniqueness_of :code, message: :epp_id_taken
|
||||
|
||||
IDENT_TYPE_ICO = 'ico'
|
||||
IDENT_TYPES = [
|
||||
IDENT_TYPE_ICO, #Company registry code (or similar)
|
||||
"op", #Estonian ID
|
||||
"passport", #Passport number
|
||||
"birthday" #Birthday date
|
||||
IDENT_TYPE_ICO, # Company registry code (or similar)
|
||||
'op', # Estonian ID
|
||||
'passport', # Passport number
|
||||
'birthday' # Birthday date
|
||||
]
|
||||
|
||||
def ident_must_be_valid
|
||||
#TODO Ident can also be passport number or company registry code.
|
||||
#so have to make changes to validations (and doc/schema) accordingly
|
||||
return true unless ident.present? && ident_type.present? && ident_type == "op"
|
||||
# TODO Ident can also be passport number or company registry code.
|
||||
# so have to make changes to validations (and doc/schema) accordingly
|
||||
return true unless ident.present? && ident_type.present? && ident_type == 'op'
|
||||
code = Isikukood.new(ident)
|
||||
errors.add(:ident, 'bad format') unless code.valid?
|
||||
end
|
||||
|
@ -56,22 +56,22 @@ class Contact < ActiveRecord::Base
|
|||
updated_by ? updated_by.username : nil
|
||||
end
|
||||
|
||||
def auth_info_matches pw
|
||||
def auth_info_matches(pw)
|
||||
return true if auth_info == pw
|
||||
return false
|
||||
false
|
||||
end
|
||||
|
||||
#Find a way to use self.domains with contact
|
||||
# Find a way to use self.domains with contact
|
||||
def domains_owned
|
||||
Domain.find_by(owner_contact_id: id)
|
||||
end
|
||||
|
||||
def relations_with_domain?
|
||||
return true if domain_contacts.present? || domains_owned.present?
|
||||
return false
|
||||
false
|
||||
end
|
||||
|
||||
#should use only in transaction
|
||||
# should use only in transaction
|
||||
def destroy_and_clean
|
||||
clean_up_address
|
||||
|
||||
|
@ -84,15 +84,15 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
def epp_code_map
|
||||
{
|
||||
'2302' => [ #Object exists
|
||||
'2302' => [ # Object exists
|
||||
[:code, :epp_id_taken]
|
||||
],
|
||||
'2303' => #Object does not exist
|
||||
'2303' => # Object does not exist
|
||||
[:not_found, :epp_obj_does_not_exist],
|
||||
'2305' => [ #Association exists
|
||||
'2305' => [ # Association exists
|
||||
[:domains, :exist]
|
||||
],
|
||||
'2005' => [ #Value syntax error
|
||||
],
|
||||
'2005' => [ # Value syntax error
|
||||
[:phone, :invalid],
|
||||
[:email, :invalid]
|
||||
]
|
||||
|
@ -100,10 +100,7 @@ class Contact < ActiveRecord::Base
|
|||
end
|
||||
|
||||
class << self
|
||||
|
||||
|
||||
def extract_attributes ph, type=:create
|
||||
|
||||
def extract_attributes(ph, type = :create)
|
||||
contact_hash = {
|
||||
phone: ph[:voice],
|
||||
ident: ph[:ident],
|
||||
|
@ -117,7 +114,7 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
contact_hash[:code] = ph[:id] if type == :create
|
||||
|
||||
contact_hash.delete_if { |k, v| v.nil? }
|
||||
contact_hash.delete_if { |_k, v| v.nil? }
|
||||
end
|
||||
|
||||
def check_availability(codes)
|
||||
|
@ -126,9 +123,9 @@ class Contact < ActiveRecord::Base
|
|||
res = []
|
||||
codes.each do |x|
|
||||
if Contact.find_by(code: x)
|
||||
res << {code: x, avail: 0, reason: 'in use'}
|
||||
res << { code: x, avail: 0, reason: 'in use' }
|
||||
else
|
||||
res << {code: x, avail: 1}
|
||||
res << { code: x, avail: 1 }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -141,6 +138,4 @@ class Contact < ActiveRecord::Base
|
|||
def clean_up_address
|
||||
address.destroy if address
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
class Country < ActiveRecord::Base
|
||||
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class Domain < ActiveRecord::Base
|
||||
#TODO whois requests ip whitelist for full info for own domains and partial info for other domains
|
||||
#TODO most inputs should be trimmed before validatation, probably some global logic?
|
||||
# TODO whois requests ip whitelist for full info for own domains and partial info for other domains
|
||||
# TODO most inputs should be trimmed before validatation, probably some global logic?
|
||||
|
||||
include EppErrors
|
||||
|
||||
|
@ -15,18 +15,18 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
has_many :domain_contacts
|
||||
|
||||
has_many :tech_contacts, -> {
|
||||
where(domain_contacts: {contact_type: DomainContact::TECH})
|
||||
}, through: :domain_contacts, source: :contact
|
||||
has_many :tech_contacts, -> do
|
||||
where(domain_contacts: { contact_type: DomainContact::TECH })
|
||||
end, through: :domain_contacts, source: :contact
|
||||
|
||||
has_many :admin_contacts, -> {
|
||||
where(domain_contacts: {contact_type: DomainContact::ADMIN})
|
||||
}, through: :domain_contacts, source: :contact
|
||||
has_many :admin_contacts, -> do
|
||||
where(domain_contacts: { contact_type: DomainContact::ADMIN })
|
||||
end, through: :domain_contacts, source: :contact
|
||||
|
||||
has_and_belongs_to_many :nameservers
|
||||
|
||||
has_many :domain_statuses, -> {
|
||||
joins(:setting).where(settings: {setting_group_id: SettingGroup.domain_statuses.id})
|
||||
joins(:setting).where(settings: { setting_group_id: SettingGroup.domain_statuses.id })
|
||||
}
|
||||
|
||||
delegate :code, to: :owner_contact, prefix: true
|
||||
|
@ -123,14 +123,14 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
def attach_nameservers(ns_list)
|
||||
ns_list.each do |ns_attrs|
|
||||
self.nameservers.build(ns_attrs)
|
||||
nameservers.build(ns_attrs)
|
||||
end
|
||||
end
|
||||
|
||||
def attach_statuses(status_list)
|
||||
status_list.each do |x|
|
||||
setting = SettingGroup.domain_statuses.settings.find_by(value: x[:value])
|
||||
self.domain_statuses.build(
|
||||
domain_statuses.build(
|
||||
setting: setting,
|
||||
description: x[:description]
|
||||
)
|
||||
|
@ -139,9 +139,9 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
def detach_contacts(contact_list)
|
||||
to_delete = []
|
||||
contact_list.each do |k, v|
|
||||
contact_list.each do |_k, v|
|
||||
v.each do |x|
|
||||
contact = domain_contacts.joins(:contact).where(contacts: {code: x[:contact]})
|
||||
contact = domain_contacts.joins(:contact).where(contacts: { code: x[:contact] })
|
||||
if contact.blank?
|
||||
errors.add(:domain_contacts, {
|
||||
obj: 'contact',
|
||||
|
@ -154,13 +154,13 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
self.domain_contacts.delete(to_delete)
|
||||
domain_contacts.delete(to_delete)
|
||||
end
|
||||
|
||||
def detach_nameservers(ns_list)
|
||||
to_delete = []
|
||||
ns_list.each do |ns_attrs|
|
||||
nameserver = self.nameservers.where(ns_attrs)
|
||||
nameserver = nameservers.where(ns_attrs)
|
||||
if nameserver.blank?
|
||||
errors.add(:nameservers, {
|
||||
obj: 'hostObj',
|
||||
|
@ -172,13 +172,13 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
self.nameservers.delete(to_delete)
|
||||
nameservers.delete(to_delete)
|
||||
end
|
||||
|
||||
def detach_statuses(status_list)
|
||||
to_delete = []
|
||||
status_list.each do |x|
|
||||
status = domain_statuses.joins(:setting).where(settings: {value: x[:value]})
|
||||
status = domain_statuses.joins(:setting).where(settings: { value: x[:value] })
|
||||
if status.blank?
|
||||
errors.add(:domain_statuses, {
|
||||
obj: 'status',
|
||||
|
@ -190,19 +190,19 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
self.domain_statuses.delete(to_delete)
|
||||
domain_statuses.delete(to_delete)
|
||||
end
|
||||
|
||||
### RENEW ###
|
||||
|
||||
def renew(cur_exp_date, period, unit='y')
|
||||
def renew(cur_exp_date, period, unit = 'y')
|
||||
# TODO Check how much time before domain exp date can it be renewed
|
||||
validate_exp_dates(cur_exp_date)
|
||||
return false if errors.any?
|
||||
|
||||
p = self.class.convert_period_to_time(period, unit)
|
||||
|
||||
self.valid_to = self.valid_to + p
|
||||
self.valid_to = valid_to + p
|
||||
self.period = period
|
||||
self.period_unit = unit
|
||||
save
|
||||
|
@ -215,7 +215,7 @@ class Domain < ActiveRecord::Base
|
|||
min, max = sg.setting(:ns_min_count).value.to_i, sg.setting(:ns_max_count).value.to_i
|
||||
|
||||
unless nameservers.length.between?(min, max)
|
||||
errors.add(:nameservers, :out_of_range, {min: min, max: max})
|
||||
errors.add(:nameservers, :out_of_range, { min: min, max: max })
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -226,11 +226,11 @@ class Domain < ActiveRecord::Base
|
|||
def validate_period
|
||||
return unless period.present?
|
||||
if period_unit == 'd'
|
||||
valid_values = ['365', '366', '710', '712', '1065', '1068']
|
||||
valid_values = %w(365 366 710 712 1065 1068)
|
||||
elsif period_unit == 'm'
|
||||
valid_values = ['12', '24', '36']
|
||||
valid_values = %w(12 24 36)
|
||||
else
|
||||
valid_values = ['1', '2', '3']
|
||||
valid_values = %w(1 2 3)
|
||||
end
|
||||
|
||||
errors.add(:period, :out_of_range) unless valid_values.include?(period.to_s)
|
||||
|
@ -258,7 +258,7 @@ class Domain < ActiveRecord::Base
|
|||
[:valid_to, :epp_exp_dates_do_not_match]
|
||||
],
|
||||
'2004' => [ # Parameter value range error
|
||||
[:nameservers, :out_of_range, {min: domain_validation_sg.setting(:ns_min_count).value, max: domain_validation_sg.setting(:ns_max_count).value}],
|
||||
[:nameservers, :out_of_range, { min: domain_validation_sg.setting(:ns_min_count).value, max: domain_validation_sg.setting(:ns_max_count).value }],
|
||||
[:period, :out_of_range]
|
||||
],
|
||||
'2303' => [ # Object does not exist
|
||||
|
@ -277,7 +277,7 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
# For domain transfer
|
||||
def authenticate(pw)
|
||||
errors.add(:auth_info, {msg: errors.generate_message(:auth_info, :wrong_pw)}) if pw != auth_info
|
||||
errors.add(:auth_info, { msg: errors.generate_message(:auth_info, :wrong_pw) }) if pw != auth_info
|
||||
errors.empty?
|
||||
end
|
||||
|
||||
|
@ -351,20 +351,20 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
res = []
|
||||
domains.each do |x|
|
||||
if !DomainNameValidator.validate_format(x)
|
||||
res << {name: x, avail: 0, reason: 'invalid format'}
|
||||
unless DomainNameValidator.validate_format(x)
|
||||
res << { name: x, avail: 0, reason: 'invalid format' }
|
||||
next
|
||||
end
|
||||
|
||||
if !DomainNameValidator.validate_reservation(x)
|
||||
res << {name: x, avail: 0, reason: I18n.t('errors.messages.epp_domain_reserved')}
|
||||
unless DomainNameValidator.validate_reservation(x)
|
||||
res << { name: x, avail: 0, reason: I18n.t('errors.messages.epp_domain_reserved') }
|
||||
next
|
||||
end
|
||||
|
||||
if Domain.find_by(name: x)
|
||||
res << {name: x, avail: 0, reason: 'in use'}
|
||||
res << { name: x, avail: 0, reason: 'in use' }
|
||||
else
|
||||
res << {name: x, avail: 1}
|
||||
res << { name: x, avail: 1 }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -20,12 +20,12 @@ class EppSession < ActiveRecord::Base
|
|||
|
||||
class << self
|
||||
def marshal(data)
|
||||
::Base64.encode64(Marshal.dump(data)) if data
|
||||
::Base64.encode64(Marshal.dump(data)) if data
|
||||
end
|
||||
|
||||
def unmarshal(data)
|
||||
return data unless data.is_a? String
|
||||
Marshal.load(::Base64.decode64(data)) if data
|
||||
end
|
||||
def unmarshal(data)
|
||||
return data unless data.is_a? String
|
||||
Marshal.load(::Base64.decode64(data)) if data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class EppUser < ActiveRecord::Base
|
||||
#TODO should have max request limit per day
|
||||
# TODO should have max request limit per day
|
||||
belongs_to :registrar
|
||||
has_many :contacts
|
||||
end
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
class ReservedDomain < ActiveRecord::Base
|
||||
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class User < ActiveRecord::Base
|
||||
#TODO Foreign user will get email with activation link,email,temp-password.
|
||||
#After activisation, system should require to change temp password.
|
||||
#TODO Estonian id validation
|
||||
# TODO Foreign user will get email with activation link,email,temp-password.
|
||||
# After activisation, system should require to change temp password.
|
||||
# TODO Estonian id validation
|
||||
|
||||
belongs_to :role
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue