mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Added new requires format to contacts controller
This commit is contained in:
parent
f96398ea9f
commit
b38f195af6
2 changed files with 28 additions and 58 deletions
|
@ -1,5 +1,14 @@
|
||||||
class Epp::ContactsController < EppController
|
class Epp::ContactsController < EppController
|
||||||
helper WhodunnitHelper ## Refactor this?
|
def info
|
||||||
|
handle_errors(@contact) and return unless @contact && rights?
|
||||||
|
# handle_errors(@contact) and return unless rights?
|
||||||
|
@disclosure = ContactDisclosure.default_values.merge(@contact.disclosure.try(:as_hash) || {})
|
||||||
|
@disclosure_policy = @contact.disclosure.try(:attributes_with_flag)
|
||||||
|
@owner = owner?(false)
|
||||||
|
# need to reload contact eagerly
|
||||||
|
@contact = find_contact if @owner # for clarity, could just be true
|
||||||
|
render_epp_response 'epp/contacts/info'
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@contact = Contact.new(contact_and_address_attributes)
|
@contact = Contact.new(contact_and_address_attributes)
|
||||||
|
@ -39,17 +48,6 @@ class Epp::ContactsController < EppController
|
||||||
render_epp_response '/epp/contacts/check'
|
render_epp_response '/epp/contacts/check'
|
||||||
end
|
end
|
||||||
|
|
||||||
def info
|
|
||||||
handle_errors(@contact) and return unless @contact && rights?
|
|
||||||
# handle_errors(@contact) and return unless rights?
|
|
||||||
@disclosure = ContactDisclosure.default_values.merge(@contact.disclosure.try(:as_hash) || {})
|
|
||||||
@disclosure_policy = @contact.disclosure.try(:attributes_with_flag)
|
|
||||||
@owner = owner?(false)
|
|
||||||
# need to reload contact eagerly
|
|
||||||
@contact = find_contact if @owner # for clarity, could just be true
|
|
||||||
render_epp_response 'epp/contacts/info'
|
|
||||||
end
|
|
||||||
|
|
||||||
def renew
|
def renew
|
||||||
epp_errors << { code: '2101', msg: t(:'errors.messages.unimplemented_command') }
|
epp_errors << { code: '2101', msg: t(:'errors.messages.unimplemented_command') }
|
||||||
handle_errors
|
handle_errors
|
||||||
|
@ -61,20 +59,22 @@ class Epp::ContactsController < EppController
|
||||||
|
|
||||||
## CREATE
|
## CREATE
|
||||||
def validate_create
|
def validate_create
|
||||||
@ph = params_hash['epp']['command']['create']['create']
|
@prefix = 'create > create >'
|
||||||
return false unless validate_params
|
requires 'postalInfo > name', 'postalInfo > addr > city',
|
||||||
xml_attrs_present?(@ph, [%w(postalInfo name), %w(postalInfo addr city), %w(postalInfo addr cc),
|
'postalInfo > addr > cc', 'ident', 'voice', 'email'
|
||||||
%w(ident), %w(voice), %w(email)])
|
|
||||||
|
|
||||||
epp_errors.empty?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
## UPDATE
|
## UPDATE
|
||||||
def validate_updatezz
|
def validate_update
|
||||||
@ph = params_hash['epp']['command']['update']['update']
|
@prefix = 'update > update >'
|
||||||
update_attrs_present?
|
requires 'id'
|
||||||
# xml_attrs_present?(@ph, [['id'], %w(authInfo pw)])
|
|
||||||
xml_attrs_present?(@ph, [['id']])
|
if element_count('chg') == 0 && element_count('rem') == 0 && element_count('add') == 0
|
||||||
|
epp_errors << {
|
||||||
|
code: '2003',
|
||||||
|
msg: I18n.t('errors.messages.required_parameter_missing', key: 'add, rem or chg')
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def contact_exists?(code)
|
def contact_exists?(code)
|
||||||
|
@ -83,13 +83,6 @@ class Epp::ContactsController < EppController
|
||||||
value: { obj: 'id', val: code } }
|
value: { obj: 'id', val: code } }
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_attrs_present?
|
|
||||||
return true if params[:parsed_frame].css('add').present?
|
|
||||||
return true if params[:parsed_frame].css('rem').present?
|
|
||||||
return true if params[:parsed_frame].css('chg').present?
|
|
||||||
epp_errors << { code: '2003', msg: I18n.t('errors.messages.required_parameter_missing', key: 'add, rem or chg') }
|
|
||||||
end
|
|
||||||
|
|
||||||
## DELETE
|
## DELETE
|
||||||
def validate_delete
|
def validate_delete
|
||||||
@ph = params_hash['epp']['command']['delete']['delete']
|
@ph = params_hash['epp']['command']['delete']['delete']
|
||||||
|
@ -115,11 +108,13 @@ class Epp::ContactsController < EppController
|
||||||
## SHARED
|
## SHARED
|
||||||
|
|
||||||
def find_contact
|
def find_contact
|
||||||
contact = Contact.find_by(code: @ph[:id])
|
contact_code = params[:parsed_frame].css('id').text.strip.downcase
|
||||||
unless contact
|
contact = Contact.find_by(code: contact_code)
|
||||||
|
|
||||||
|
if contact.blank?
|
||||||
epp_errors << { code: '2303',
|
epp_errors << { code: '2303',
|
||||||
msg: t('errors.messages.epp_obj_does_not_exist'),
|
msg: t('errors.messages.epp_obj_does_not_exist'),
|
||||||
value: { obj: 'id', val: @ph[:id] } }
|
value: { obj: 'id', val: contact_code } }
|
||||||
end
|
end
|
||||||
contact
|
contact
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
module WhodunnitHelper
|
|
||||||
def link_to_whodunnit(whodunnit)
|
|
||||||
return nil unless whodunnit
|
|
||||||
if whodunnit.include?('-ApiUser')
|
|
||||||
user = ApiUser.find(whodunnit)
|
|
||||||
return link_to(user.username, admin_epp_user_path(user))
|
|
||||||
end
|
|
||||||
user = AdminUser.find(whodunnit)
|
|
||||||
return link_to(user.username, admin_user_path(user))
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def whodunnit_with_protocol(whodunnit)
|
|
||||||
return nil unless whodunnit
|
|
||||||
if whodunnit.include?('-ApiUser')
|
|
||||||
user = ApiUser.find(whodunnit)
|
|
||||||
return "#{user.username} (EPP)"
|
|
||||||
end
|
|
||||||
user = AdminUser.find(whodunnit)
|
|
||||||
return user.username
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Add table
Add a link
Reference in a new issue