diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 932c507..6580b1c 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -95,12 +95,12 @@ def domain_params tech_domain_contacts_attributes: [ :id, :_destroy, - contact: [:role, :name, :email, :ident, :_destroy] + contact: [:role, :name, :email, :ident, :country_code, :_destroy, :phone, :phone_code, :state, :street, :city, :zip, :address_country_code] ], admin_domain_contacts_attributes: [ :id, :_destroy, - contact: [:role, :name, :email, :ident, :_destroy] + contact: [:role, :name, :email, :ident, :_destroy, :country_code, :phone, :phone_code, :state, :street, :city, :zip, :address_country_code] ], nameservers_attributes: [ :id, diff --git a/app/jobs/estonian_tld/create_contact_job.rb b/app/jobs/estonian_tld/create_contact_job.rb index d64e606..e3dd2d5 100644 --- a/app/jobs/estonian_tld/create_contact_job.rb +++ b/app/jobs/estonian_tld/create_contact_job.rb @@ -50,7 +50,6 @@ def create_contact(registrant_user) end def contact_payload(user) - { id: nil, name: user.name, @@ -87,5 +86,4 @@ def transform_file_params(params) { body: Base64.encode64(params.read), type: params.original_filename.split('.').last.downcase } end - -end \ No newline at end of file +end diff --git a/app/jobs/estonian_tld/domain_creation_process/create_contacts_job.rb b/app/jobs/estonian_tld/domain_creation_process/create_contacts_job.rb new file mode 100644 index 0000000..3440dc8 --- /dev/null +++ b/app/jobs/estonian_tld/domain_creation_process/create_contacts_job.rb @@ -0,0 +1,88 @@ +module EstonianTld + module DomainCreationProcess + class CreateContactsJob < ApplicationJob + queue_as :critical + + def perform(pending_action) + return if pending_action.completed? + + @pending_action = pending_action + + contacts_what_not_exists = [] + contacts_without_code = [] + + pending_action.info['admin_domain_contacts_attributes'].each do |_k, v| + next if v['contact']['_destroy'] == 'true' + + contact = Contact.find_by(ident: v['contact']['ident']) + if contact.nil? + contacts_what_not_exists << v + elsif contact.code.blank? + contacts_without_code << v + end + end + + pending_action.info['tech_domain_contacts_attributes'].each do |_k, v| + next if v['contact']['_destroy'] == 'true' + + contact = Contact.find_by(ident: v['contact']['ident']) + if contact.nil? + contacts_what_not_exists << v + elsif contact.code.blank? + contacts_without_code << v + end + end + + contacts_what_not_exists.each do |contact| + create_contact(contact) + end + + puts '---' + puts contacts_what_not_exists + puts contacts_without_code + puts '---' + + (contacts_what_not_exists + contacts_without_code).each do |contact| + # EstonianTld::CreateContactJob.perform_later(contact) + user = Contact.find_by(ident: contact['contact']['ident']) + + puts '---- DO USER EXISTS ???' + puts contact['contact']['ident'] + puts user.inspect + puts '---- DO USER EXISTS ???' + + EstonianTld::CreateContactJob.perform_now(user) + end + end + + def create_contact(contact) + # {"contact"=>{"name"=>"sanjoik", "role"=>"priv", "email"=>"sanjok@gmail.com", "ident"=>"51501017732", "phone"=>"5433432", "_destroy"=>"false", "phone_code"=>"372", "country_code"=>"EE"}} + c = Contact.new( + ident: contact['contact']['ident'], + name: contact['contact']['name'], + email: contact['contact']['email'], + phone: contact['contact']['phone'], + phone_code: contact['contact']['phone_code'], + role: contact['contact']['role'], + country_code: contact['contact']['country_code'], + state: 'draft', + street: 'street', + city: 'city', + zip: 'zip' + ) + + puts '--- DO CONTACT VALID ?' + puts c.valid? + puts c.errors.full_messages + puts c.inspect + puts '--- DO CONTACT VALID ?' + + c.save! + end + + after_perform do |job| + EstonianTld::DomainCreationProcess::CreateDomainJob.perform_later(@pending_action) + end + end + end +end \ No newline at end of file diff --git a/app/jobs/estonian_tld/domain_creation_process/create_domain_job.rb b/app/jobs/estonian_tld/domain_creation_process/create_domain_job.rb index 2f07be1..9bb72c9 100644 --- a/app/jobs/estonian_tld/domain_creation_process/create_domain_job.rb +++ b/app/jobs/estonian_tld/domain_creation_process/create_domain_job.rb @@ -14,11 +14,6 @@ def perform(pending_action) registrant_contact = Contact.find_by(code: pending_action.user.code) domain = Domain.find_by(name: pending_action.info['name']) - - - p '------- Setting[dnssec_enabled] -----' - p Setting.dnssec_enabled - p '------- Setting[dnssec_enabled] -----' if domain.nil? domain = Domain.new( diff --git a/app/models/contact.rb b/app/models/contact.rb index b4d2ef1..3ec1b8e 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -7,6 +7,7 @@ class Contact < ApplicationRecord include Phone attr_accessor :phone_code + attr_accessor :registrar_format_phone has_many :domain_contacts has_many :domains, through: :domain_contacts diff --git a/app/services/domain_services/create_domain_service.rb b/app/services/domain_services/create_domain_service.rb index 405fbc1..6c9fa7a 100644 --- a/app/services/domain_services/create_domain_service.rb +++ b/app/services/domain_services/create_domain_service.rb @@ -7,12 +7,8 @@ def initialize(pending_action) end def call - # todo: check, do contacts exist in registry? - # crete contacts if not - # and after that run job - - - EstonianTld::DomainCreationProcess::CreateDomainJob.perform_later(pending_action) + EstonianTld::DomainCreationProcess::CreateContactsJob.perform_later(pending_action) + # EstonianTld::DomainCreationProcess::CreateDomainJob.perform_later(pending_action) end end end diff --git a/app/views/registrant/domains/_contact_fields.html.erb b/app/views/registrant/domains/_contact_fields.html.erb index ecfb387..cf753b8 100644 --- a/app/views/registrant/domains/_contact_fields.html.erb +++ b/app/views/registrant/domains/_contact_fields.html.erb @@ -1,7 +1,7 @@