Merge branch 'experimental-live-schema-support'

This commit is contained in:
Martin Lensment 2015-07-27 16:24:26 +03:00
commit 48af3e77cd
65 changed files with 1346 additions and 1205 deletions

View file

@ -3,7 +3,7 @@ require 'open3'
class ApiUser < User
include EppErrors
def epp_code_map
def epp_code_map
{
'2306' => [ # Parameter policy error
[:password, :blank]
@ -16,6 +16,7 @@ class ApiUser < User
has_many :certificates
validates :username, :password, :registrar, :roles, presence: true
validates :password, length: { minimum: 6 }
validates :username, uniqueness: true
# TODO: probably cache, because it's requested on every EPP

View file

@ -4,7 +4,7 @@ module Depp
include DisableHtml5Validation
attr_accessor :id, :name, :email, :phone, :org_name,
:ident, :ident_type, :ident_country_code,
:ident, :ident_type, :ident_country_code,
:street, :city, :zip, :state, :country_code,
:password, :legal_document, :statuses, :code
@ -68,7 +68,7 @@ module Depp
zip: res.css('postalInfo addr pc').text,
state: res.css('postalInfo addr sp').text,
country_code: res.css('postalInfo addr cc').text,
# authInfo
password: res.css('authInfo pw').text,
@ -145,25 +145,26 @@ module Depp
end
def save
create_xml = Depp::Contact.epp_xml.create(
{
id: { value: code },
email: { value: email },
voice: { value: phone },
postalInfo: {
name: { value: name },
org: { value: org_name },
addr: {
street: { value: street },
city: { value: city },
pc: { value: zip },
sp: { value: state },
cc: { value: country_code }
}
hash = {
id: { value: code },
postalInfo: {
name: { value: name },
org: { value: org_name },
addr: {
street: { value: street },
city: { value: city },
sp: { value: state },
pc: { value: zip },
cc: { value: country_code }
}
},
extension_xml
)
},
voice: { value: phone },
email: { value: email }
}
hash[:id] = nil if code.blank?
create_xml = Depp::Contact.epp_xml.create(hash, extension_xml)
data = Depp::Contact.user.request(create_xml)
self.id = data.css('id').text
handle_errors(data)
@ -191,23 +192,23 @@ module Depp
{
id: { value: id },
chg: {
voice: { value: phone },
email: { value: email },
postalInfo: {
name: { value: name },
org: { value: org_name },
addr: {
street: { value: street },
city: { value: city },
pc: { value: zip },
sp: { value: state },
pc: { value: zip },
cc: { value: country_code }
}
},
voice: { value: phone },
email: { value: email },
authInfo: {
pw: { value: password }
}
},
authInfo: {
pw: { value: password }
}
},
extension_xml
)
@ -250,7 +251,7 @@ module Depp
return {} if legal_document.blank?
type = legal_document.original_filename.split('.').last.downcase
{
{
_anonymus: [
legalDocument: { value: Base64.encode64(legal_document.read), attrs: { type: type } }
]
@ -274,7 +275,7 @@ module Depp
ident_type == 'priv'
end
def persisted?
def persisted?
id.present?
end
@ -282,13 +283,13 @@ module Depp
data.css('result').each do |x|
success_codes = %(1000, 1300, 1301)
next if success_codes.include?(x['code'])
message = "#{x.css('msg').text} #{x.css('value').text}"
attr = message.split('[').last.strip.sub(']', '') if message.include?('[')
attr = :base if attr.nil?
attr = 'phone' if attr == 'voice'
attr = 'zip' if attr == 'pc'
errors.add(attr, message)
errors.add(attr, message)
end
errors.blank?
end

View file

@ -36,15 +36,17 @@ module Depp
end
def create(domain_params)
dns_hash = {}
keys = Domain.create_dnskeys_hash(domain_params)
dns_hash[:_anonymus] = keys if keys.any?
xml = epp_xml.create({
name: { value: domain_params[:name] },
registrant: { value: domain_params[:registrant] },
period: { value: domain_params[:period].to_s[0], attrs: { unit: domain_params[:period].to_s[1] } },
ns: Domain.create_nameservers_hash(domain_params),
registrant: { value: domain_params[:registrant] },
_anonymus: Domain.create_contacts_hash(domain_params)
}, {
_anonymus: Domain.create_dnskeys_hash(domain_params)
}, Domain.construct_custom_params_hash(domain_params))
}, dns_hash, Domain.construct_custom_params_hash(domain_params))
current_user.request(xml)
end
@ -205,6 +207,16 @@ module Depp
contacts = array_difference(create_contacts_hash(old_domain_params), create_contacts_hash(domain_params))
rem_anon = contacts
add_arr = []
add_ns = create_nameservers_hash(domain_params) - create_nameservers_hash(old_domain_params)
add_arr << { ns: add_ns } if add_ns.any?
add_arr << { _anonymus: add_anon } if add_anon.any?
rem_arr = []
rem_ns = create_nameservers_hash(old_domain_params) - create_nameservers_hash(domain_params)
rem_arr << { ns: rem_ns } if rem_ns.any?
rem_arr << { _anonymus: rem_anon } if rem_anon.any?
if domain_params[:registrant] != old_domain_params[:registrant]
chg = [{ registrant: { value: domain_params[:registrant] } }]
end
@ -212,22 +224,18 @@ module Depp
{
name: { value: domain_params[:name] },
chg: chg,
add: [
{ ns: create_nameservers_hash(domain_params) - create_nameservers_hash(old_domain_params) },
{ _anonymus: add_anon }
],
rem: [
{ ns: create_nameservers_hash(old_domain_params) - create_nameservers_hash(domain_params) },
{ _anonymus: rem_anon }
]
add: add_arr,
rem: rem_arr
}
end
def construct_ext_edit_hash(domain_params, old_domain_params)
{
add: create_dnskeys_hash(domain_params) - create_dnskeys_hash(old_domain_params),
rem: create_dnskeys_hash(old_domain_params) - create_dnskeys_hash(domain_params)
}
rem_keys = create_dnskeys_hash(old_domain_params) - create_dnskeys_hash(domain_params)
add_keys = create_dnskeys_hash(domain_params) - create_dnskeys_hash(old_domain_params)
hash = {}
hash[:rem] = rem_keys if rem_keys.any?
hash[:add] = add_keys if add_keys.any?
hash
end
def create_nameservers_hash(domain_params)