Skip to content

Commit

Permalink
fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Mar 14, 2024
1 parent ff8318a commit 9288e38
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/controllers/registrant/domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/estonian_tld/create_contact_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def create_contact(registrant_user)
end

def contact_payload(user)

{
id: nil,
name: user.name,
Expand Down Expand Up @@ -87,5 +86,4 @@ def transform_file_params(params)
{ body: Base64.encode64(params.read),
type: params.original_filename.split('.').last.downcase }
end

end
end
Original file line number Diff line number Diff line change
@@ -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"=>"[email protected]", "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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions app/models/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions app/services/domain_services/create_domain_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
71 changes: 67 additions & 4 deletions app/views/registrant/domains/_contact_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class='contact-item'>
<div class="space-y-4 flex items-baseline space-x-4">
<div class="flex items-center">
<%= form.radio_button :role, "priv", checked: form.object.new_record? ? true : form&.object&.role == 'priv', class: "h-4 w-4 border-gray-300 text-indigo-600 focus:ring-indigo-500" %>
<%= form.radio_button :role, "priv", checked: form&.object&.new_record? ? true : form&.object&.role == 'priv', class: "h-4 w-4 border-gray-300 text-indigo-600 focus:ring-indigo-500" %>
<%= form.label :role, t('.priv'), class: 'ml-3 block text-sm font-medium text-gray-700' %>
</div>

Expand All @@ -14,9 +14,72 @@
<div id='private_form'>
<b>Private contact field</b>

<%= form.text_field :name, placeholder: 'New Contact Name' %>
<%= form.text_field :email, placeholder: 'New Contact Email' %>
<%= form.text_field :ident, placeholder: 'New Contact Ident' %>
<%#= form.text_field :name, placeholder: 'New Contact Name' %>
<%#= form.text_field :email, placeholder: 'New Contact Email' %>
<%#= form.text_field :ident, placeholder: 'New Contact Ident' %>

<div class='flex flex-row justify-evenly items-center'>
<div class='flex flex-col space-y-4'>
<div class='w-96'>
<%= component 'form/country_select_input', form: form, attribute: :country_code, heroicon_name: 'globe-americas' %>
</div>

<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :ident, heroicon_name: 'identification', placeholder: '2323232323' %>
</div>
</div>

<div class='flex flex-col space-y-4'>
<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :name, heroicon_name: 'user', placeholder: 'John Doe' %>
</div>

<div class='w-96'>
<%#= component 'form/text_input', form: form, attribute: :phone_code, heroicon_name: 'phone', placeholder: '+372' %>
<%#= component 'form/text_input', form: form, attribute: :phone, heroicon_name: 'phone', placeholder: '56722123' %>

<%= component 'form/phone_input', form: form, phone_attribute: :phone, code_attribute: :phone_code,
code_placeholder: '372', phone_placeholder: '56722123' %>
</div>

<div class='w-96'>
<%= component 'form/email_input', form: form, attribute: :email, heroicon_name: 'envelope', placeholder: '[email protected]' %>
</div>
</div>
</div>

<% if show_address? %>
<div class='h-8'></div>

<%= component 'divider', label: t('.address') %>

<div class='flex flex-row justify-evenly items-center'>
<div class='flex flex-col space-y-4'>
<div class='w-96'>
<%= component 'form/country_select_input', form: form, attribute: :address_country_code, heroicon_name: 'globe-americas' %>
</div>

<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :state, heroicon_name: 'home-modern', placeholder: 'NY' %>
</div>

<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :city, heroicon_name: 'home-modern', placeholder: 'New York' %>
</div>
</div>

<div class='flex flex-col space-y-4'>
<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :zip, heroicon_name: 'home-modern', placeholder: '12345' %>
</div>

<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :street, heroicon_name: 'home-modern', placeholder: 'Somewhere' %>
</div>
</div>

</div>
<% end %>

<%= form.hidden_field :_destroy %>

Expand Down
18 changes: 9 additions & 9 deletions app/views/registrar/invoices/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,41 @@
</div>

<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :name, heroicon_name: 'user', placeholder: 'John Dee', data_attributes: { form__invoice_autocomplete_target: "nameInput" } %>
<%= component 'form/text_input', form: form, attribute: :name, heroicon_name: 'user', placeholder: 'John Dee', options: { data_attributes: { form__invoice_autocomplete_target: "nameInput" } } %>
</div>

<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :country_code, heroicon_name: 'user', placeholder: 'John Dee', data_attributes: { form__invoice_autocomplete_target: "countryCodeInput" } %>
<%= component 'form/text_input', form: form, attribute: :country_code, heroicon_name: 'user', placeholder: 'John Dee', options: { data_attributes: { form__invoice_autocomplete_target: "countryCodeInput" } } %>
</div>

<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :state, heroicon_name: 'user', placeholder: 'John Dee', data_attributes: { form__invoice_autocomplete_target: "stateInput" } %>
<%= component 'form/text_input', form: form, attribute: :state, heroicon_name: 'user', placeholder: 'John Dee', options: { data_attributes: { form__invoice_autocomplete_target: "stateInput" } } %>
</div>

<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :street, heroicon_name: 'user', placeholder: 'John Dee', data_attributes: { form__invoice_autocomplete_target: "streetInput" } %>
<%= component 'form/text_input', form: form, attribute: :street, heroicon_name: 'user', placeholder: 'John Dee', options: { data_attributes: { form__invoice_autocomplete_target: "streetInput" } } %>
</div>
</div>

<div class='flex flex-col space-y-4' >
<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :city, heroicon_name: 'user', placeholder: 'John Dee', data_attributes: { form__invoice_autocomplete_target: "cityInput" } %>
<%= component 'form/text_input', form: form, attribute: :city, heroicon_name: 'user', placeholder: 'John Dee', options: { data_attributes: { form__invoice_autocomplete_target: "cityInput" } } %>
</div>

<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :zip, heroicon_name: 'user', placeholder: 'John Dee', data_attributes: { form__invoice_autocomplete_target: "zipInput" } %>
<%= component 'form/text_input', form: form, attribute: :zip, heroicon_name: 'user', placeholder: 'John Dee', options: { data_attributes: { form__invoice_autocomplete_target: "zipInput" } } %>
</div>

<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :phone, heroicon_name: 'user', placeholder: 'John Dee', data_attributes: { form__invoice_autocomplete_target: "phoneInput" } %>
<%= component 'form/text_input', form: form, attribute: :phone, heroicon_name: 'user', placeholder: 'John Dee', options: { data_attributes: { form__invoice_autocomplete_target: "phoneInput" } } %>
</div>

<div class='w-96'>
<%= component 'form/text_input', form: form, attribute: :url, heroicon_name: 'user', placeholder: 'John Dee', data_attributes: { form__invoice_autocomplete_target: "urlInput" } %>
<%= component 'form/text_input', form: form, attribute: :url, heroicon_name: 'user', placeholder: 'John Dee', options: { data_attributes: { form__invoice_autocomplete_target: "urlInput" } } %>
</div>

<div class='w-96'>
<%= component 'form/email_input', form: form, attribute: :email, heroicon_name: 'user', placeholder: 'John Dee', data_attributes: { form__invoice_autocomplete_target: "emailInput" } %>
<%= component 'form/email_input', form: form, attribute: :email, heroicon_name: 'user', placeholder: 'John Dee', options: { data_attributes: { form__invoice_autocomplete_target: "emailInput" } } %>
</div>
</div>
</div>
Expand Down

0 comments on commit 9288e38

Please sign in to comment.