Domain History and basic whois rake

This commit is contained in:
Andres Keskküla 2014-11-07 14:50:45 +02:00
parent 660e910208
commit a6c936e18d
16 changed files with 254 additions and 128 deletions

View file

@ -1,3 +1,7 @@
.error-tab > a {
color: #a94442 !important;
}
.edit-highlight {
background-color: #E7E7E7;
}

View file

@ -1,10 +1,8 @@
module Epp::ContactsHelper
def create_contact
@contact = Contact.new(contact_and_address_attributes)
@contact.generate_code
@contact.registrar = current_epp_user.registrar
render '/epp/contacts/create' and return if stamp(@contact) && @contact.save
handle_errors(@contact)
end
@ -16,7 +14,7 @@ module Epp::ContactsHelper
render 'epp/contacts/update'
else
contact_exists?(code)
handle_errors(@contact)
handle_errors(@contact) and return
end
end
@ -38,7 +36,7 @@ module Epp::ContactsHelper
end
def info_contact
handle_errors and return unless rights?
# handle_errors and return unless rights?
@contact = find_contact
handle_errors(@contact) and return unless @contact
render 'epp/contacts/info'
@ -56,7 +54,7 @@ module Epp::ContactsHelper
## CREATE
def validate_contact_create_request
@ph = params_hash['epp']['command']['create']['create']
xml_attrs_present?(@ph, [%w(authInfo pw), %w(postalInfo)])
xml_attrs_present?(@ph, [%w(postalInfo)])
return epp_errors.empty? unless @ph['postalInfo'].is_a?(Hash) || @ph['postalInfo'].is_a?(Array)

View file

@ -17,18 +17,18 @@ class Address < ActiveRecord::Base
# errors, used = [], []
# parsed_frame.css('postalInfo').each do |pi|
# attr = pi.attributes['type'].try(:value)
# errors << {
# code: 2003, msg: I18n.t('errors.messages.attr_missing', key: 'type')
# errors << {
# code: 2003, msg: I18n.t('errors.messages.attr_missing', key: 'type')
# } and next unless attr
# unless TYPES.include?(attr)
# errors << {
# code: 2005,
# msg: I18n.t('errors.messages.invalid_type'), value: { obj: 'type', val: attr }
# errors << {
# code: 2005,
# msg: I18n.t('errors.messages.invalid_type'), value: { obj: 'type', val: attr }
# }
# next
# end
# errors << {
# code: 2005,
# errors << {
# code: 2005,
# msg: I18n.t('errors.messages.repeating_postal_info')
# } and next if used.include?(attr)
# used << attr
@ -54,11 +54,16 @@ class Address < ActiveRecord::Base
return {} unless addr[:addr].is_a?(Hash)
{ country_id: Country.find_by(iso: addr[:addr][:cc]).try(:id),
city: addr[:addr][:city],
street: addr[:addr][:street][0],
street2: addr[:addr][:street][1],
street3: addr[:addr][:street][2],
street: pretty_street(addr[:addr][:street]), # [0],
# street2: addr[:addr][:street][1],
# street3: addr[:addr][:street][2],
zip: addr[:addr][:pc]
}.delete_if { |_k, v| v.nil? }
end
def pretty_street(param_street)
return param_street.join(',') if param_street.is_a?(Array)
param_street
end
end
end

View file

@ -18,10 +18,9 @@ class Contact < ActiveRecord::Base
accepts_nested_attributes_for :address, :disclosure
validates :code, :phone, :email, :ident, :address, :registrar, presence: true
validates :phone, :email, :ident, :address, :registrar, presence: true
validate :ident_must_be_valid
# validate :presence_of_one_address
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/ # /\+\d{3}\.\d+/
validates :email, format: /@/
@ -37,6 +36,8 @@ class Contact < ActiveRecord::Base
# after_commit :domains_snapshot
after_update :domains_snapshot
after_destroy :domains_snapshot
before_create :generate_code
before_create :generate_auth_info
# scopes
scope :current_registrars, ->(id) { where(registrar_id: id) }
@ -96,6 +97,10 @@ class Contact < ActiveRecord::Base
self.code = SecureRandom.hex(4)
end
def generate_auth_info
self.auth_info = SecureRandom.hex(16)
end
# Find a way to use self.domains with contact
def domains_owned
Domain.where(owner_contact_id: id)
@ -149,16 +154,17 @@ class Contact < ActiveRecord::Base
# non-EPP
# EPP
def extract_attributes(ph, type = :create)
def extract_attributes(ph, _type = :create)
ph[:postalInfo] = ph[:postalInfo].first if ph[:postalInfo].is_a?(Array)
contact_hash = {
phone: ph[:voice],
ident: ph[:ident],
email: ph[:email],
fax: ph[:fax],
name: ph[:postalInfo].try(:[], :name),
org_name: ph[:postalInfo].try(:[], :org)
}
contact_hash[:auth_info] = ph[:authInfo][:pw] if type == :create
# contact_hash[:auth_info] = ph[:authInfo][:pw] if type == :create
contact_hash.delete_if { |_k, v| v.nil? }
end

View file

@ -9,4 +9,21 @@ class DomainVersion < PaperTrail::Version
def load_snapshot
YAML.load(snapshot)
end
def previous?
return true if previous
false
end
def changed_elements
return [] unless previous?
@changes = []
@previous_snap = previous.load_snapshot
@snap = load_snapshot
[:owner_contact, :tech_contacts, :admin_contacts, :nameservers, :domain].each do |key|
@changes << key unless @snap[key] == @previous_snap[key]
end
@changes
end
end

View file

@ -21,19 +21,21 @@
- children = YAML.load(version.snapshot)
- next unless children.is_a?(Hash)
- children = HashWithIndifferentAccess.new(children)
- changes = version.changed_elements
%tr
%td
%td{ :class => ('edit-highlight' if changes.include?(:domain)) }
- if children[:domain]
= children[:domain][:name]
= children[:domain][:status]
%td
%td{ :class => ('edit-highlight' if changes.include?(:owner_contact)) }
- if children[:owner_contact]
%p{:style => "font-size:x-small;"}
= children[:owner_contact][:name] + ","
= children[:owner_contact][:phone] + ","
= children[:owner_contact][:email] + ","
= children[:owner_contact][:code]
%td
%td{ :class => ('edit-highlight' if changes.include?(:admin_contacts)) }
- if children[:admin_contacts]
- children[:admin_contacts].each do |ac|
%p{:style => "font-size:x-small;"}
@ -41,7 +43,7 @@
= ac[:phone] + ","
= ac[:email] + ","
= ac[:code]
%td
%td{ :class => ('edit-highlight' if changes.include?(:tech_contacts)) }
- if children[:tech_contacts]
- children[:tech_contacts].each do |tc|
%p{:style => "font-size:x-small;"}
@ -49,7 +51,7 @@
= tc[:phone] + ","
= tc[:email] + ","
= tc[:code]
%td
%td{ :class => ('edit-highlight' if changes.include?(:nameservers)) }
- if children[:nameservers]
- children[:nameservers].each do |ns|
%p{:style => "font-size:x-small;"}

View file

@ -1,14 +1,15 @@
address = @contact.address
xml.tag!('contact:postalInfo', type: 'int') do # TODO instance method of defining type
xml.tag!('contact:name', @contact.name) if @contact.disclosure.int_name
xml.tag!('contact:org', @contact.org_name) if @contact.disclosure.int_org_name
if @contact.disclosure.int_addr
xml.tag!('contact:addr') do
xml.tag!('contact:street', address.street) if address.street
xml.tag!('contact:street', address.street2) if address.street2
xml.tag!('contact:street', address.street3) if address.street3
xml.tag!('contact:cc', address.try(:country).try(:iso)) unless address.try(:country).nil?
end
xml.tag!('contact:postalInfo', type: 'int') do
xml.tag!('contact:name', @contact.name)# if @contact.disclosure.try(:int_name)
xml.tag!('contact:org', @contact.org_name)# if @contact.disclosure.try(:int_org_name)
#if @contact.disclosure.try(:int_addr)
xml.tag!('contact:addr') do
xml.tag!('contact:street', address.street) if address.street
#xml.tag!('contact:street', address.street2) if address.street2
#xml.tag!('contact:street', address.street3) if address.street3
xml.tag!('contact:cc', address.try(:country).try(:iso)) unless address.try(:country).nil?
xml.tag!('contact:city', address.city)
end
#end
end

View file

@ -7,9 +7,10 @@ xml.epp_head do
xml.resData do
xml.tag!('contact:chkData', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do
xml << render('/epp/contacts/postal_info')
xml.tag!('contact:voice', @contact.phone) if @contact.disclosure.phone
xml.tag!('contact:fax', @contact.fax) if @contact.disclosure.fax
xml.tag!('contact:email', @contact.email) if @contact.disclosure.email
xml.tag!('contact:id', @contact.code)
xml.tag!('contact:voice', @contact.phone) #if @contact.disclosure.try(:phone)
xml.tag!('contact:fax', @contact.fax) #if @contact.disclosure.try(:fax)
xml.tag!('contact:email', @contact.email) #if @contact.disclosure..try(:email)
xml.tag!('contact:clID', @current_epp_user.username) if @current_epp_user
xml.tag!('contact:crID', @contact.cr_id ) if @contact.cr_id
xml.tag!('contact:crDate', @contact.created_at)