diff --git a/app/controllers/repp/v1/domains_controller.rb b/app/controllers/repp/v1/domains_controller.rb index 283d2bf7b..0e16a90c1 100644 --- a/app/controllers/repp/v1/domains_controller.rb +++ b/app/controllers/repp/v1/domains_controller.rb @@ -3,6 +3,7 @@ module Repp module V1 class DomainsController < BaseController before_action :set_authorized_domain, only: %i[transfer_info] + before_action :forward_registrar_id, only: %i[create] before_action :set_domain, only: %i[show] def index @@ -17,6 +18,18 @@ module Repp render_success(data: { domain: Serializers::RegistrantApi::Domain.new(@domain).to_json }) end + ## POST /repp/v1/domains + def create + authorize!(:create, Epp::Domain) + puts params + @domain = Epp::Domain.new + action = Actions::DomainCreate.new(@domain, domain_create_params) + + handle_errors(@domain) and return unless action.call + + render_success(create_update_success_body) + end + def transfer_info contact_fields = %i[code name ident ident_type ident_country_code phone email street city zip country_code statuses] @@ -72,6 +85,10 @@ module Repp params.permit(:id) end + def forward_registrar_id + params[:domain][:registrar_id] = current_user.registrar.id + end + def set_domain @domain = Domain.find_by(registrar: current_user.registrar, name: params[:id]) end @@ -104,6 +121,13 @@ module Repp def index_params params.permit(:limit, :offset, :details) end + + def domain_create_params + params.require(:domain).require([:name, :registrant_id, :period, :period_unit]) + params.require(:domain).permit(:name, :registrant_id, :period, :period_unit, :registrar_id) + + end + end end end diff --git a/app/models/actions/domain_create.rb b/app/models/actions/domain_create.rb index ced9c2327..30f004ae3 100644 --- a/app/models/actions/domain_create.rb +++ b/app/models/actions/domain_create.rb @@ -64,11 +64,14 @@ module Actions end def assign_domain_attributes + puts "FOOOK" + puts params + puts "AYYYYY #{params[:name]}" domain.name = params[:name].strip.downcase domain.registrar = Registrar.find(params[:registrar_id]) assign_domain_period assign_domain_auth_codes - domain.dnskeys_attributes = params[:dnskeys_attributes] + domain.dnskeys_attributes = params[:dnskeys_attributes] if params[:dnskeys_attributes] end def assign_domain_auth_codes @@ -82,7 +85,7 @@ module Actions end def assign_nameservers - domain.nameservers_attributes = params[:nameservers_attributes] + domain.nameservers_attributes = params[:nameservers_attributes] if params[:nameservers_attributes] end def assign_contact(contact_code, admin: true) @@ -98,14 +101,16 @@ module Actions def assign_domain_contacts @admin_contacts = [] @tech_contacts = [] - params[:admin_domain_contacts_attributes].each { |c| assign_contact(c) } - params[:tech_domain_contacts_attributes].each { |c| assign_contact(c, admin: false) } + params[:admin_domain_contacts_attributes]&.each { |c| assign_contact(c) } + params[:tech_domain_contacts_attributes]&.each { |c| assign_contact(c, admin: false) } domain.admin_domain_contacts_attributes = @admin_contacts domain.tech_domain_contacts_attributes = @tech_contacts end def assign_expiry_time + return unless domain.period + period = Integer(domain.period) plural_period_unit_name = (domain.period_unit == 'm' ? 'months' : 'years').to_sym exp = (Time.zone.now.advance(plural_period_unit_name => period) + 1.day).beginning_of_day diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 99a3089a9..c4106e45a 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -31,7 +31,7 @@ class Epp::Domain < Domain # validate registrant here as well ([Contact.find_by(code: registrant.code)] + active_admins + active_techs).each do |x| unless x.valid? - add_epp_error('2304', nil, nil, I18n.t(:contact_is_not_valid, value: x.code)) + add_epp_error('2304', nil, nil, I18n.t(:contact_is_not_valid, value: x.try(:code))) ok = false end end