Merge branch 'master' of github.com:internetee/registry

This commit is contained in:
Martin Lensment 2014-08-28 18:10:13 +03:00
commit c1b24d6b71
6 changed files with 148 additions and 147 deletions

View file

@ -35,3 +35,6 @@ Style/IndentHash:
Style/SingleLineBlockParams: Style/SingleLineBlockParams:
Enabled: false Enabled: false
# No need for nested module/class definition as far as I know
Style/ClassAndModuleChildren:
Enabled: false

View file

@ -71,7 +71,7 @@ group :development, :test do
gem 'capybara', '~> 2.4.1' gem 'capybara', '~> 2.4.1'
# For feature testing # For feature testing
# gem 'capybara-webkit', '1.2.0' # Webkit driver didn't work with turbolinks # gem 'capybara-webkit', '1.2.0' # Webkit driver didn't work with turbolinks
gem 'phantomjs', :require => 'phantomjs/poltergeist' gem 'phantomjs', require: 'phantomjs/poltergeist'
gem 'poltergeist', '~> 1.5.1' # We are using PhantomJS instead gem 'poltergeist', '~> 1.5.1' # We are using PhantomJS instead
# For cleaning db in feature and epp tests # For cleaning db in feature and epp tests

View file

@ -1,151 +1,149 @@
module Epp module Epp::ContactsHelper
module ContactsHelper def create_contact
def create_contact @contact = Contact.new(contact_and_address_attributes)
@contact = Contact.new(contact_and_address_attributes) render '/epp/contacts/create' and return if stamp(@contact) && @contact.save
render '/epp/contacts/create' and return if stamp(@contact) && @contact.save
handle_errors(@contact)
end
def update_contact
code = params_hash['epp']['command']['update']['update'][:id]
@contact = Contact.where(code: code).first
if rights? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update))
render 'epp/contacts/update'
else
contact_exists?
handle_errors(@contact) handle_errors(@contact)
end end
end
def update_contact def delete_contact
code = params_hash['epp']['command']['update']['update'][:id] Contact.transaction do
@contact = Contact.where(code: code).first
if rights? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update))
render 'epp/contacts/update'
else
contact_exists?
handle_errors(@contact)
end
end
def delete_contact
Contact.transaction do
@contact = find_contact
handle_errors(@contact) and return unless @contact
handle_errors(@contact) and return unless @contact.destroy_and_clean
render '/epp/contacts/delete'
end
end
def check_contact
ph = params_hash['epp']['command']['check']['check']
@contacts = Contact.check_availability(ph[:id])
render '/epp/contacts/check'
end
def info_contact
handle_errors and return unless rights?
@contact = find_contact @contact = find_contact
handle_errors(@contact) and return unless @contact handle_errors(@contact) and return unless @contact
render 'epp/contacts/info' handle_errors(@contact) and return unless @contact.destroy_and_clean
end
def renew_contact render '/epp/contacts/delete'
epp_errors << { code: '2101', msg: t(:'errors.messages.unimplemented_command') }
handle_errors
end
## HELPER METHODS
private
## CREATE
def validate_contact_create_request
@ph = params_hash['epp']['command']['create']['create']
xml_attrs_present?(@ph, [%w(id), %w(authInfo pw), %w(postalInfo)])
return epp_errors.empty? unless @ph['postalInfo'].is_a?(Hash) || @ph['postalInfo'].is_a?(Array)
(epp_errors << Address.validate_postal_info_types(parsed_frame)).flatten!
xml_attrs_array_present?(@ph['postalInfo'], [%w(name), %w(addr city), %w(addr cc)])
end
## UPDATE
def validate_contact_update_request
@ph = params_hash['epp']['command']['update']['update']
update_attrs_present?
xml_attrs_present?(@ph, [['id']])
end
def contact_exists?
return true if @contact.is_a?(Contact)
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'),
value: { obj: 'id', val: code } }
end
def update_attrs_present?
return true if parsed_frame.css('add').present?
return true if parsed_frame.css('rem').present?
return true if parsed_frame.css('chg').present?
epp_errors << { code: '2003', msg: I18n.t('errors.messages.required_parameter_missing', key: 'add, rem or chg') }
end
## DELETE
def validate_contact_delete_request
@ph = params_hash['epp']['command']['delete']['delete']
xml_attrs_present?(@ph, [['id']])
end
## CHECK
def validate_contact_check_request
@ph = params_hash['epp']['command']['check']['check']
xml_attrs_present?(@ph, [['id']])
end
## INFO
def validate_contact_info_request
@ph = params_hash['epp']['command']['info']['info']
xml_attrs_present?(@ph, [['id']])
end
## SHARED
def find_contact
contact = Contact.find_by(code: @ph[:id])
unless contact
epp_errors << { code: '2303',
msg: t('errors.messages.epp_obj_does_not_exist'),
value: { obj: 'id', val: @ph[:id] } }
end
contact
end
def rights?
pw = @ph.try(:[], :authInfo).try(:[], :pw) || @ph.try(:[], :chg).try(:[], :authInfo).try(:[], :pw) || []
return true if !find_contact.nil? && find_contact.auth_info_matches(pw)
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error'), value: { obj: 'pw', val: pw } }
false
end
def contact_and_address_attributes(type = :create)
case type
when :update
contact_hash = merge_attribute_hash(@ph[:chg], type)
else
contact_hash = merge_attribute_hash(@ph, type)
end
contact_hash[:ident_type] = ident_type unless ident_type.nil?
contact_hash
end
def merge_attribute_hash(prms, type)
contact_hash = Contact.extract_attributes(prms, type)
contact_hash = contact_hash.merge(
Address.extract_attributes((prms.try(:[], :postalInfo) || []))
)
contact_hash
end
def ident_type
result = params[:frame].slice(/(?<=\<ns2:ident type=)(.*)(?=<)/)
return nil unless result
Contact::IDENT_TYPES.any? { |type| return type if result.include?(type) }
nil
end end
end end
def check_contact
ph = params_hash['epp']['command']['check']['check']
@contacts = Contact.check_availability(ph[:id])
render '/epp/contacts/check'
end
def info_contact
handle_errors and return unless rights?
@contact = find_contact
handle_errors(@contact) and return unless @contact
render 'epp/contacts/info'
end
def renew_contact
epp_errors << { code: '2101', msg: t(:'errors.messages.unimplemented_command') }
handle_errors
end
## HELPER METHODS
private
## CREATE
def validate_contact_create_request
@ph = params_hash['epp']['command']['create']['create']
xml_attrs_present?(@ph, [%w(id), %w(authInfo pw), %w(postalInfo)])
return epp_errors.empty? unless @ph['postalInfo'].is_a?(Hash) || @ph['postalInfo'].is_a?(Array)
(epp_errors << Address.validate_postal_info_types(parsed_frame)).flatten!
xml_attrs_array_present?(@ph['postalInfo'], [%w(name), %w(addr city), %w(addr cc)])
end
## UPDATE
def validate_contact_update_request
@ph = params_hash['epp']['command']['update']['update']
update_attrs_present?
xml_attrs_present?(@ph, [['id']])
end
def contact_exists?
return true if @contact.is_a?(Contact)
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'),
value: { obj: 'id', val: code } }
end
def update_attrs_present?
return true if parsed_frame.css('add').present?
return true if parsed_frame.css('rem').present?
return true if parsed_frame.css('chg').present?
epp_errors << { code: '2003', msg: I18n.t('errors.messages.required_parameter_missing', key: 'add, rem or chg') }
end
## DELETE
def validate_contact_delete_request
@ph = params_hash['epp']['command']['delete']['delete']
xml_attrs_present?(@ph, [['id']])
end
## CHECK
def validate_contact_check_request
@ph = params_hash['epp']['command']['check']['check']
xml_attrs_present?(@ph, [['id']])
end
## INFO
def validate_contact_info_request
@ph = params_hash['epp']['command']['info']['info']
xml_attrs_present?(@ph, [['id']])
end
## SHARED
def find_contact
contact = Contact.find_by(code: @ph[:id])
unless contact
epp_errors << { code: '2303',
msg: t('errors.messages.epp_obj_does_not_exist'),
value: { obj: 'id', val: @ph[:id] } }
end
contact
end
def rights?
pw = @ph.try(:[], :authInfo).try(:[], :pw) || @ph.try(:[], :chg).try(:[], :authInfo).try(:[], :pw) || []
return true if !find_contact.nil? && find_contact.auth_info_matches(pw)
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error'), value: { obj: 'pw', val: pw } }
false
end
def contact_and_address_attributes(type = :create)
case type
when :update
contact_hash = merge_attribute_hash(@ph[:chg], type)
else
contact_hash = merge_attribute_hash(@ph, type)
end
contact_hash[:ident_type] = ident_type unless ident_type.nil?
contact_hash
end
def merge_attribute_hash(prms, type)
contact_hash = Contact.extract_attributes(prms, type)
contact_hash = contact_hash.merge(
Address.extract_attributes((prms.try(:[], :postalInfo) || []))
)
contact_hash
end
def ident_type
result = params[:frame].slice(/(?<=\<ns2:ident type=)(.*)(?=<)/)
return nil unless result
Contact::IDENT_TYPES.any? { |type| return type if result.include?(type) }
nil
end
end end

View file

@ -20,9 +20,9 @@ class Address < ActiveRecord::Base
parsed_frame.css('postalInfo').each do |pi| parsed_frame.css('postalInfo').each do |pi|
attr = pi.attributes['type'].try(:value) attr = pi.attributes['type'].try(:value)
errors << { code: 2003, msg: I18n.t('errors.messages.attr_missing', key: 'type')} and next unless attr errors << { code: 2003, msg: I18n.t('errors.messages.attr_missing', key: 'type') } and next unless attr
if !TYPES.include?(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 next
end end
errors << { code: 2005, msg: I18n.t('errors.messages.repeating_postal_info') } and next if used.include?(attr) errors << { code: 2005, msg: I18n.t('errors.messages.repeating_postal_info') } and next if used.include?(attr)

View file

@ -97,7 +97,7 @@ class Contact < ActiveRecord::Base
destroy destroy
end end
def epp_code_map def epp_code_map # rubocop:disable Metrics/MethodLength
{ {
'2302' => [ # Object exists '2302' => [ # Object exists
[:code, :epp_id_taken] [:code, :epp_id_taken]

View file

@ -285,7 +285,7 @@ class Domain < ActiveRecord::Base
add_epp_error('2306', 'curExpDate', cur_exp_date, I18n.t('errors.messages.epp_exp_dates_do_not_match')) add_epp_error('2306', 'curExpDate', cur_exp_date, I18n.t('errors.messages.epp_exp_dates_do_not_match'))
end end
def epp_code_map def epp_code_map # rubocop:disable Metrics/MethodLength
domain_validation_sg = SettingGroup.domain_validation domain_validation_sg = SettingGroup.domain_validation
{ {