From b38f195af645af7b47040b4a15ec9a66331eb4d4 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 10 Feb 2015 14:55:21 +0200 Subject: [PATCH] Added new requires format to contacts controller --- app/controllers/epp/contacts_controller.rb | 61 ++++++++++------------ app/helpers/whodunnit_helper.rb | 25 --------- 2 files changed, 28 insertions(+), 58 deletions(-) delete mode 100644 app/helpers/whodunnit_helper.rb diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index 6aa5efce3..fefdce438 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -1,5 +1,14 @@ 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 @contact = Contact.new(contact_and_address_attributes) @@ -39,17 +48,6 @@ class Epp::ContactsController < EppController render_epp_response '/epp/contacts/check' 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 epp_errors << { code: '2101', msg: t(:'errors.messages.unimplemented_command') } handle_errors @@ -61,20 +59,22 @@ class Epp::ContactsController < EppController ## CREATE def validate_create - @ph = params_hash['epp']['command']['create']['create'] - return false unless validate_params - xml_attrs_present?(@ph, [%w(postalInfo name), %w(postalInfo addr city), %w(postalInfo addr cc), - %w(ident), %w(voice), %w(email)]) - - epp_errors.empty? + @prefix = 'create > create >' + requires 'postalInfo > name', 'postalInfo > addr > city', + 'postalInfo > addr > cc', 'ident', 'voice', 'email' end ## UPDATE - def validate_updatezz - @ph = params_hash['epp']['command']['update']['update'] - update_attrs_present? - # xml_attrs_present?(@ph, [['id'], %w(authInfo pw)]) - xml_attrs_present?(@ph, [['id']]) + def validate_update + @prefix = 'update > update >' + requires '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 def contact_exists?(code) @@ -83,13 +83,6 @@ class Epp::ContactsController < EppController value: { obj: 'id', val: code } } 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 def validate_delete @ph = params_hash['epp']['command']['delete']['delete'] @@ -115,11 +108,13 @@ class Epp::ContactsController < EppController ## SHARED def find_contact - contact = Contact.find_by(code: @ph[:id]) - unless contact + contact_code = params[:parsed_frame].css('id').text.strip.downcase + contact = Contact.find_by(code: contact_code) + + if contact.blank? epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'), - value: { obj: 'id', val: @ph[:id] } } + value: { obj: 'id', val: contact_code } } end contact end diff --git a/app/helpers/whodunnit_helper.rb b/app/helpers/whodunnit_helper.rb deleted file mode 100644 index a1d2999c6..000000000 --- a/app/helpers/whodunnit_helper.rb +++ /dev/null @@ -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