mirror of
https://github.com/internetee/registry.git
synced 2025-06-12 15:44:45 +02:00
REPP: Add Domain Create endpoint
This commit is contained in:
parent
c58b4fb2e9
commit
e2ff5d4506
3 changed files with 34 additions and 5 deletions
|
@ -3,6 +3,7 @@ module Repp
|
||||||
module V1
|
module V1
|
||||||
class DomainsController < BaseController
|
class DomainsController < BaseController
|
||||||
before_action :set_authorized_domain, only: %i[transfer_info]
|
before_action :set_authorized_domain, only: %i[transfer_info]
|
||||||
|
before_action :forward_registrar_id, only: %i[create]
|
||||||
before_action :set_domain, only: %i[show]
|
before_action :set_domain, only: %i[show]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@ -17,6 +18,18 @@ module Repp
|
||||||
render_success(data: { domain: Serializers::RegistrantApi::Domain.new(@domain).to_json })
|
render_success(data: { domain: Serializers::RegistrantApi::Domain.new(@domain).to_json })
|
||||||
end
|
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
|
def transfer_info
|
||||||
contact_fields = %i[code name ident ident_type ident_country_code phone email street city
|
contact_fields = %i[code name ident ident_type ident_country_code phone email street city
|
||||||
zip country_code statuses]
|
zip country_code statuses]
|
||||||
|
@ -72,6 +85,10 @@ module Repp
|
||||||
params.permit(:id)
|
params.permit(:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def forward_registrar_id
|
||||||
|
params[:domain][:registrar_id] = current_user.registrar.id
|
||||||
|
end
|
||||||
|
|
||||||
def set_domain
|
def set_domain
|
||||||
@domain = Domain.find_by(registrar: current_user.registrar, name: params[:id])
|
@domain = Domain.find_by(registrar: current_user.registrar, name: params[:id])
|
||||||
end
|
end
|
||||||
|
@ -104,6 +121,13 @@ module Repp
|
||||||
def index_params
|
def index_params
|
||||||
params.permit(:limit, :offset, :details)
|
params.permit(:limit, :offset, :details)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,11 +64,14 @@ module Actions
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_domain_attributes
|
def assign_domain_attributes
|
||||||
|
puts "FOOOK"
|
||||||
|
puts params
|
||||||
|
puts "AYYYYY #{params[:name]}"
|
||||||
domain.name = params[:name].strip.downcase
|
domain.name = params[:name].strip.downcase
|
||||||
domain.registrar = Registrar.find(params[:registrar_id])
|
domain.registrar = Registrar.find(params[:registrar_id])
|
||||||
assign_domain_period
|
assign_domain_period
|
||||||
assign_domain_auth_codes
|
assign_domain_auth_codes
|
||||||
domain.dnskeys_attributes = params[:dnskeys_attributes]
|
domain.dnskeys_attributes = params[:dnskeys_attributes] if params[:dnskeys_attributes]
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_domain_auth_codes
|
def assign_domain_auth_codes
|
||||||
|
@ -82,7 +85,7 @@ module Actions
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_nameservers
|
def assign_nameservers
|
||||||
domain.nameservers_attributes = params[:nameservers_attributes]
|
domain.nameservers_attributes = params[:nameservers_attributes] if params[:nameservers_attributes]
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_contact(contact_code, admin: true)
|
def assign_contact(contact_code, admin: true)
|
||||||
|
@ -98,14 +101,16 @@ module Actions
|
||||||
def assign_domain_contacts
|
def assign_domain_contacts
|
||||||
@admin_contacts = []
|
@admin_contacts = []
|
||||||
@tech_contacts = []
|
@tech_contacts = []
|
||||||
params[:admin_domain_contacts_attributes].each { |c| assign_contact(c) }
|
params[:admin_domain_contacts_attributes]&.each { |c| assign_contact(c) }
|
||||||
params[:tech_domain_contacts_attributes].each { |c| assign_contact(c, admin: false) }
|
params[:tech_domain_contacts_attributes]&.each { |c| assign_contact(c, admin: false) }
|
||||||
|
|
||||||
domain.admin_domain_contacts_attributes = @admin_contacts
|
domain.admin_domain_contacts_attributes = @admin_contacts
|
||||||
domain.tech_domain_contacts_attributes = @tech_contacts
|
domain.tech_domain_contacts_attributes = @tech_contacts
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_expiry_time
|
def assign_expiry_time
|
||||||
|
return unless domain.period
|
||||||
|
|
||||||
period = Integer(domain.period)
|
period = Integer(domain.period)
|
||||||
plural_period_unit_name = (domain.period_unit == 'm' ? 'months' : 'years').to_sym
|
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
|
exp = (Time.zone.now.advance(plural_period_unit_name => period) + 1.day).beginning_of_day
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Epp::Domain < Domain
|
||||||
# validate registrant here as well
|
# validate registrant here as well
|
||||||
([Contact.find_by(code: registrant.code)] + active_admins + active_techs).each do |x|
|
([Contact.find_by(code: registrant.code)] + active_admins + active_techs).each do |x|
|
||||||
unless x.valid?
|
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
|
ok = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue