From 00aee547dd32e3d8042dec23b80ada5b39d924d6 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 11:47:30 +0200 Subject: [PATCH 01/16] registred company returns not exists --- app/interactions/actions/contact_create.rb | 4 ++ db/structure.sql | 70 +++++++++++++++++++--- 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index 0793abcd2d..7112bacc85 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -81,6 +81,10 @@ def validate_ident_birthday def maybe_company_is_relevant return true unless contact.org? + p '-=-------' + p contact.inspect + p '-=-------' + company_status = contact.return_company_status return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status diff --git a/db/structure.sql b/db/structure.sql index 98bd17871d..9653f454e3 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -9,13 +9,6 @@ SET xmloption = content; SET client_min_messages = warning; SET row_security = off; --- --- Name: public; Type: SCHEMA; Schema: -; Owner: - --- - --- *not* creating schema, since initdb creates it - - -- -- Name: btree_gin; Type: EXTENSION; Schema: -; Owner: - -- @@ -2636,6 +2629,40 @@ CREATE SEQUENCE public.repp_logs_id_seq ALTER SEQUENCE public.repp_logs_id_seq OWNED BY public.repp_logs.id; +-- +-- Name: reserve_domain_invoices; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.reserve_domain_invoices ( + id bigint NOT NULL, + invoice_number character varying, + domain_names character varying[] DEFAULT '{}'::character varying[], + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL, + status integer DEFAULT 0, + metainfo character varying +); + + +-- +-- Name: reserve_domain_invoices_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.reserve_domain_invoices_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: reserve_domain_invoices_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.reserve_domain_invoices_id_seq OWNED BY public.reserve_domain_invoices.id; + + -- -- Name: reserved_domains; Type: TABLE; Schema: public; Owner: - -- @@ -3417,6 +3444,13 @@ ALTER TABLE ONLY public.registrars ALTER COLUMN id SET DEFAULT nextval('public.r ALTER TABLE ONLY public.repp_logs ALTER COLUMN id SET DEFAULT nextval('public.repp_logs_id_seq'::regclass); +-- +-- Name: reserve_domain_invoices id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.reserve_domain_invoices ALTER COLUMN id SET DEFAULT nextval('public.reserve_domain_invoices_id_seq'::regclass); + + -- -- Name: reserved_domains id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3976,6 +4010,14 @@ ALTER TABLE ONLY public.repp_logs ADD CONSTRAINT repp_logs_pkey PRIMARY KEY (id); +-- +-- Name: reserve_domain_invoices reserve_domain_invoices_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.reserve_domain_invoices + ADD CONSTRAINT reserve_domain_invoices_pkey PRIMARY KEY (id); + + -- -- Name: reserved_domains reserved_domains_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -4784,6 +4826,13 @@ CREATE INDEX index_registrant_verifications_on_created_at ON public.registrant_v CREATE INDEX index_registrant_verifications_on_domain_id ON public.registrant_verifications USING btree (domain_id); +-- +-- Name: index_reserve_domain_invoices_on_invoice_number; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_reserve_domain_invoices_on_invoice_number ON public.reserve_domain_invoices USING btree (invoice_number); + + -- -- Name: index_setting_entries_on_code; Type: INDEX; Schema: public; Owner: - -- @@ -5613,8 +5662,11 @@ INSERT INTO "schema_migrations" (version) VALUES ('20230711083811'), ('20240816091049'), ('20240816092636'), -('20240903131540'), ('20240924103554'), -('20241015071505'); +('20241015071505'), +('20241030095636'), +('20241104104620'), +('20241112093540'), +('20241112124405'); From 2c1051a42700a744e2dd25ea88ca3e3da83550c5 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 11:57:15 +0200 Subject: [PATCH 02/16] lecolice constants into the local interaction --- app/interactions/actions/contact_create.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index 7112bacc85..b6b2691aa4 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -2,6 +2,11 @@ module Actions class ContactCreate attr_reader :contact, :legal_document, :ident, :result + REGISTERED = 'R'.freeze + LIQUIDATED = 'L'.freeze + BANKRUPT = 'N'.freeze + DELETED = 'K'.freeze + def initialize(contact, legal_document, ident) @contact = contact @legal_document = legal_document @@ -81,12 +86,8 @@ def validate_ident_birthday def maybe_company_is_relevant return true unless contact.org? - p '-=-------' - p contact.inspect - p '-=-------' - company_status = contact.return_company_status - return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status + return if [REGISTERED, LIQUIDATED].include? company_status contact.add_epp_error('2003', nil, 'ident', I18n.t('errors.messages.company_not_registered')) @error = true From 962037c5a05531e604ce1c6524e6e73365ae5f40 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 12:04:23 +0200 Subject: [PATCH 03/16] added test error message --- app/interactions/actions/contact_create.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index b6b2691aa4..5c81a71bf0 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -2,11 +2,6 @@ module Actions class ContactCreate attr_reader :contact, :legal_document, :ident, :result - REGISTERED = 'R'.freeze - LIQUIDATED = 'L'.freeze - BANKRUPT = 'N'.freeze - DELETED = 'K'.freeze - def initialize(contact, legal_document, ident) @contact = contact @legal_document = legal_document @@ -86,8 +81,14 @@ def validate_ident_birthday def maybe_company_is_relevant return true unless contact.org? + if contact.ident.blank? + contact.add_epp_error('2003', nil, 'ident', "#{I18n.t('errors.messages.required_ident_attribute_missing')}\n #{contact.inspect}") + @error = true + return + end + company_status = contact.return_company_status - return if [REGISTERED, LIQUIDATED].include? company_status + return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status contact.add_epp_error('2003', nil, 'ident', I18n.t('errors.messages.company_not_registered')) @error = true From 5778c5e4e9de1ad26e26eb5e54084a00bc63ead7 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 12:07:22 +0200 Subject: [PATCH 04/16] added more logs --- app/interactions/actions/contact_create.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index 5c81a71bf0..cb3c9f5be5 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -81,16 +81,20 @@ def validate_ident_birthday def maybe_company_is_relevant return true unless contact.org? - if contact.ident.blank? - contact.add_epp_error('2003', nil, 'ident', "#{I18n.t('errors.messages.required_ident_attribute_missing')}\n #{contact.inspect}") - @error = true - return - end + Rails.logger.info "======= I AM HERE" company_status = contact.return_company_status + Rails.logger.info "company_status: #{company_status}" + return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status + Rails.logger.info Contact::REGISTERED + Rails.logger.info Contact::LIQUIDATED + Rails.logger.info "======= I AM HERE 2" contact.add_epp_error('2003', nil, 'ident', I18n.t('errors.messages.company_not_registered')) + + Rails.logger.info "=======" + @error = true end From 025eb26f3baf02b0e31422700e0fa5cb1c3a8320 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 12:11:24 +0200 Subject: [PATCH 05/16] added logs to company register --- app/models/contact/company_register.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/contact/company_register.rb b/app/models/contact/company_register.rb index 1c436eff75..f453f96511 100644 --- a/app/models/contact/company_register.rb +++ b/app/models/contact/company_register.rb @@ -11,6 +11,10 @@ def company_is_relevant? end def return_company_status + Rails.logger.info "ident: #{ident}" + Rails.logger.info "org?: #{org?}" + Rails.logger.info "return_company_data: #{return_company_data.inspect}" + return if return_company_data.blank? return_company_data.first[:status] From 959ac0a9b2898e9ad4c3bb7cc3b99d14ff82b837 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 12:15:50 +0200 Subject: [PATCH 06/16] mock method --- app/models/contact/company_register.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/contact/company_register.rb b/app/models/contact/company_register.rb index f453f96511..b59fb3c21b 100644 --- a/app/models/contact/company_register.rb +++ b/app/models/contact/company_register.rb @@ -11,13 +11,15 @@ def company_is_relevant? end def return_company_status + company_register_2 = CompanyRegister::Client.new Rails.logger.info "ident: #{ident}" Rails.logger.info "org?: #{org?}" - Rails.logger.info "return_company_data: #{return_company_data.inspect}" + # Rails.logger.info "return_company_data: #{return_company_data.inspect}" + return_company_data_2 = company_register_2.simple_data(registration_number: ident) + Rails.logger.info "return_company_data_2: #{return_company_data_2.inspect}" + return if return_company_data_2.blank? - return if return_company_data.blank? - - return_company_data.first[:status] + return_company_data_2.first[:status] end def return_company_data From 748a146fe58e3455dabbd0e12c3ee0cfe6c9886d Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 12:18:56 +0200 Subject: [PATCH 07/16] added logs to exception --- app/models/contact/company_register.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/models/contact/company_register.rb b/app/models/contact/company_register.rb index b59fb3c21b..702ddd180e 100644 --- a/app/models/contact/company_register.rb +++ b/app/models/contact/company_register.rb @@ -11,15 +11,13 @@ def company_is_relevant? end def return_company_status - company_register_2 = CompanyRegister::Client.new Rails.logger.info "ident: #{ident}" Rails.logger.info "org?: #{org?}" - # Rails.logger.info "return_company_data: #{return_company_data.inspect}" - return_company_data_2 = company_register_2.simple_data(registration_number: ident) - Rails.logger.info "return_company_data_2: #{return_company_data_2.inspect}" - return if return_company_data_2.blank? + Rails.logger.info "return_company_data: #{return_company_data.inspect}" - return_company_data_2.first[:status] + return if return_company_data.blank? + + return_company_data.first[:status] end def return_company_data @@ -27,6 +25,7 @@ def return_company_data company_register.simple_data(registration_number: ident) rescue CompanyRegister::NotAvailableError + Rails.logger.info "ERROR HAPPENED: CompanyRegister::NotAvailableError" [] end From 1dd0d29635d91b432dfd5283616301522819626f Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 12:27:13 +0200 Subject: [PATCH 08/16] added retries --- app/models/contact/company_register.rb | 35 ++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/app/models/contact/company_register.rb b/app/models/contact/company_register.rb index 702ddd180e..48f660782a 100644 --- a/app/models/contact/company_register.rb +++ b/app/models/contact/company_register.rb @@ -23,18 +23,39 @@ def return_company_status def return_company_data return unless org? - company_register.simple_data(registration_number: ident) - rescue CompanyRegister::NotAvailableError - Rails.logger.info "ERROR HAPPENED: CompanyRegister::NotAvailableError" - [] + retries = 1 + begin + company_register.simple_data(registration_number: ident) + rescue CompanyRegister::NotAvailableError + Rails.logger.info "CompanyRegister::NotAvailableError occurred, attempt #{retries}" + if retries <= 3 # максимум 3 попытки + sleep 1 # ждем 1 секунду + retries += 1 + retry + else + Rails.logger.error "Failed to fetch company data after #{retries-1} retries" + [] + end + end end def return_company_details return unless org? - company_register.company_details(registration_number: ident) - rescue CompanyRegister::NotAvailableError - [] + retries = 1 + begin + company_register.company_details(registration_number: ident) + rescue CompanyRegister::NotAvailableError + Rails.logger.info "CompanyRegister::NotAvailableError occurred, attempt #{retries}" + if retries <= 3 # максимум 3 попытки + sleep 1 # ждем 1 секунду + retries += 1 + retry + else + Rails.logger.error "Failed to fetch company details after #{retries-1} retries" + [] + end + end end def company_register From cded81395548bd1ad1907c2fe48399715be86110 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 12:29:20 +0200 Subject: [PATCH 09/16] added details to error message --- app/models/contact/company_register.rb | 35 ++++++-------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/app/models/contact/company_register.rb b/app/models/contact/company_register.rb index 48f660782a..3c1c2fefb9 100644 --- a/app/models/contact/company_register.rb +++ b/app/models/contact/company_register.rb @@ -23,39 +23,18 @@ def return_company_status def return_company_data return unless org? - retries = 1 - begin - company_register.simple_data(registration_number: ident) - rescue CompanyRegister::NotAvailableError - Rails.logger.info "CompanyRegister::NotAvailableError occurred, attempt #{retries}" - if retries <= 3 # максимум 3 попытки - sleep 1 # ждем 1 секунду - retries += 1 - retry - else - Rails.logger.error "Failed to fetch company data after #{retries-1} retries" - [] - end - end + company_register.simple_data(registration_number: ident) + rescue CompanyRegister::NotAvailableError => e + Rails.logger.info "ERROR HAPPENED: CompanyRegister::NotAvailableError #{e.message}" + [] end def return_company_details return unless org? - retries = 1 - begin - company_register.company_details(registration_number: ident) - rescue CompanyRegister::NotAvailableError - Rails.logger.info "CompanyRegister::NotAvailableError occurred, attempt #{retries}" - if retries <= 3 # максимум 3 попытки - sleep 1 # ждем 1 секунду - retries += 1 - retry - else - Rails.logger.error "Failed to fetch company details after #{retries-1} retries" - [] - end - end + company_register.company_details(registration_number: ident) + rescue CompanyRegister::NotAvailableError + [] end def company_register From 95f5acb2b01531b9e528de6fe01307b701ae955f Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 12:40:09 +0200 Subject: [PATCH 10/16] change test mode directly --- app/models/contact/company_register.rb | 4 ++-- config/initializers/company_register.rb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/contact/company_register.rb b/app/models/contact/company_register.rb index 3c1c2fefb9..702ddd180e 100644 --- a/app/models/contact/company_register.rb +++ b/app/models/contact/company_register.rb @@ -24,8 +24,8 @@ def return_company_data return unless org? company_register.simple_data(registration_number: ident) - rescue CompanyRegister::NotAvailableError => e - Rails.logger.info "ERROR HAPPENED: CompanyRegister::NotAvailableError #{e.message}" + rescue CompanyRegister::NotAvailableError + Rails.logger.info "ERROR HAPPENED: CompanyRegister::NotAvailableError" [] end diff --git a/config/initializers/company_register.rb b/config/initializers/company_register.rb index 366c58ca46..8cced3dd8f 100644 --- a/config/initializers/company_register.rb +++ b/config/initializers/company_register.rb @@ -2,5 +2,6 @@ config.username = ENV['company_register_username'] config.password = ENV['company_register_password'] config.cache_period = ENV['company_register_cache_period_days'].to_i.days - config.test_mode = ENV['company_register_test_mode'] == 'true' + # config.test_mode = ENV['company_register_test_mode'] == 'true' + config.test_mode = false end \ No newline at end of file From 88d7689295fc27c47bf028511c18b3a23bea05dc Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 12:44:01 +0200 Subject: [PATCH 11/16] changed ident to string --- app/models/contact/company_register.rb | 2 +- config/initializers/company_register.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/contact/company_register.rb b/app/models/contact/company_register.rb index 702ddd180e..c27ba3e3d8 100644 --- a/app/models/contact/company_register.rb +++ b/app/models/contact/company_register.rb @@ -23,7 +23,7 @@ def return_company_status def return_company_data return unless org? - company_register.simple_data(registration_number: ident) + company_register.simple_data(registration_number: ident.to_s) rescue CompanyRegister::NotAvailableError Rails.logger.info "ERROR HAPPENED: CompanyRegister::NotAvailableError" [] diff --git a/config/initializers/company_register.rb b/config/initializers/company_register.rb index 8cced3dd8f..366c58ca46 100644 --- a/config/initializers/company_register.rb +++ b/config/initializers/company_register.rb @@ -2,6 +2,5 @@ config.username = ENV['company_register_username'] config.password = ENV['company_register_password'] config.cache_period = ENV['company_register_cache_period_days'].to_i.days - # config.test_mode = ENV['company_register_test_mode'] == 'true' - config.test_mode = false + config.test_mode = ENV['company_register_test_mode'] == 'true' end \ No newline at end of file From 7f6c4f24a62824aa627050b4c069cf2003356898 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 12:46:46 +0200 Subject: [PATCH 12/16] added more logs --- app/models/contact/company_register.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/contact/company_register.rb b/app/models/contact/company_register.rb index c27ba3e3d8..42b731fcae 100644 --- a/app/models/contact/company_register.rb +++ b/app/models/contact/company_register.rb @@ -21,9 +21,14 @@ def return_company_status end def return_company_data + Rails.logger.info "inside return_company_data" + Rails.logger.info "ident: #{ident}" + Rails.logger.info "org?: #{org?}" return unless org? - company_register.simple_data(registration_number: ident.to_s) + res = company_register.simple_data(registration_number: ident.to_s) + Rails.logger.info "res: #{res.inspect}" + res rescue CompanyRegister::NotAvailableError Rails.logger.info "ERROR HAPPENED: CompanyRegister::NotAvailableError" [] From 6d810bb604009f21fe1d63b2e1bf710970082c31 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 12:50:30 +0200 Subject: [PATCH 13/16] call company status directly --- app/interactions/actions/contact_create.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index cb3c9f5be5..ab3b73efb4 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -83,7 +83,14 @@ def maybe_company_is_relevant Rails.logger.info "======= I AM HERE" - company_status = contact.return_company_status + # company_status = contact.return_company_status + # Rails.logger.info "company_status: #{company_status}" + + company_register = CompanyRegister::Client.new + res = company_register.simple_data(registration_number: ident.to_s) + Rails.logger.info "res: #{res.inspect}" + + company_status = res.first[:status] Rails.logger.info "company_status: #{company_status}" return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status From 64d9ed4bc6e665073804e7c210247ef2e53aed3c Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 12:57:01 +0200 Subject: [PATCH 14/16] test --- app/interactions/actions/contact_create.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index ab3b73efb4..59a3ff73ef 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -86,6 +86,15 @@ def maybe_company_is_relevant # company_status = contact.return_company_status # Rails.logger.info "company_status: #{company_status}" + CompanyRegister.configure do |config| + config.username = ENV['company_register_username'] + config.password = ENV['company_register_password'] + config.cache_period = ENV['company_register_cache_period_days'].to_i.days + config.test_mode = ENV['company_register_test_mode'] == 'true' + end + + Rails.logger.info "CompanyRegister.configure: #{CompanyRegister.configuration.inspect}" + company_register = CompanyRegister::Client.new res = company_register.simple_data(registration_number: ident.to_s) Rails.logger.info "res: #{res.inspect}" From d23b66e8593b0f7aec4ae691b8e0929933b14d9b Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 13:17:07 +0200 Subject: [PATCH 15/16] added logs for company register values --- app/interactions/actions/contact_create.rb | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index 59a3ff73ef..c29b0bb84b 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -82,24 +82,12 @@ def maybe_company_is_relevant return true unless contact.org? Rails.logger.info "======= I AM HERE" + Rails.logger.info ENV['company_register_username'] + Rails.logger.info ENV['company_register_password'] + Rails.logger.info ENV['company_register_cache_period_days'] + Rails.logger.info ENV['company_register_test_mode'] - # company_status = contact.return_company_status - # Rails.logger.info "company_status: #{company_status}" - - CompanyRegister.configure do |config| - config.username = ENV['company_register_username'] - config.password = ENV['company_register_password'] - config.cache_period = ENV['company_register_cache_period_days'].to_i.days - config.test_mode = ENV['company_register_test_mode'] == 'true' - end - - Rails.logger.info "CompanyRegister.configure: #{CompanyRegister.configuration.inspect}" - - company_register = CompanyRegister::Client.new - res = company_register.simple_data(registration_number: ident.to_s) - Rails.logger.info "res: #{res.inspect}" - - company_status = res.first[:status] + company_status = contact.return_company_status Rails.logger.info "company_status: #{company_status}" return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status From d0a39bf4693d4245e5f1ed9fb66f80ba0ff1a422 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 25 Nov 2024 14:48:28 +0200 Subject: [PATCH 16/16] remove company creation validation --- app/interactions/actions/contact_create.rb | 29 +++----- app/models/contact/company_register.rb | 12 +--- .../repp/v1/contacts/create_test.rb | 66 +++++++++---------- 3 files changed, 42 insertions(+), 65 deletions(-) diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index c29b0bb84b..39fb3212d8 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -14,7 +14,7 @@ def call maybe_attach_legal_doc validate_ident maybe_change_email - maybe_company_is_relevant + # maybe_company_is_relevant commit validate_contact end @@ -78,29 +78,16 @@ def validate_ident_birthday @error = true end - def maybe_company_is_relevant - return true unless contact.org? + # def maybe_company_is_relevant + # return true unless contact.org? - Rails.logger.info "======= I AM HERE" - Rails.logger.info ENV['company_register_username'] - Rails.logger.info ENV['company_register_password'] - Rails.logger.info ENV['company_register_cache_period_days'] - Rails.logger.info ENV['company_register_test_mode'] + # company_status = contact.return_company_status - company_status = contact.return_company_status - Rails.logger.info "company_status: #{company_status}" + # return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status + # contact.add_epp_error('2003', nil, 'ident', I18n.t('errors.messages.company_not_registered')) - return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status - Rails.logger.info Contact::REGISTERED - Rails.logger.info Contact::LIQUIDATED - Rails.logger.info "======= I AM HERE 2" - - contact.add_epp_error('2003', nil, 'ident', I18n.t('errors.messages.company_not_registered')) - - Rails.logger.info "=======" - - @error = true - end + # @error = true + # end def maybe_attach_legal_doc ::Actions::BaseAction.attach_legal_doc_to_new(contact, legal_document, domain: false) diff --git a/app/models/contact/company_register.rb b/app/models/contact/company_register.rb index 42b731fcae..4f036dd973 100644 --- a/app/models/contact/company_register.rb +++ b/app/models/contact/company_register.rb @@ -11,26 +11,16 @@ def company_is_relevant? end def return_company_status - Rails.logger.info "ident: #{ident}" - Rails.logger.info "org?: #{org?}" - Rails.logger.info "return_company_data: #{return_company_data.inspect}" - return if return_company_data.blank? return_company_data.first[:status] end def return_company_data - Rails.logger.info "inside return_company_data" - Rails.logger.info "ident: #{ident}" - Rails.logger.info "org?: #{org?}" return unless org? - res = company_register.simple_data(registration_number: ident.to_s) - Rails.logger.info "res: #{res.inspect}" - res + company_register.simple_data(registration_number: ident.to_s) rescue CompanyRegister::NotAvailableError - Rails.logger.info "ERROR HAPPENED: CompanyRegister::NotAvailableError" [] end diff --git a/test/integration/repp/v1/contacts/create_test.rb b/test/integration/repp/v1/contacts/create_test.rb index aa252ddca0..e47b962651 100644 --- a/test/integration/repp/v1/contacts/create_test.rb +++ b/test/integration/repp/v1/contacts/create_test.rb @@ -188,39 +188,39 @@ def test_returns_error_response_if_throttled ENV['shunter_enabled'] = 'false' end - def test_returns_error_response_if_company_not_existed - original_new_method = CompanyRegister::Client.method(:new) - CompanyRegister::Client.define_singleton_method(:new) do - object = original_new_method.call - def object.simple_data(registration_number:) - [Company.new('1234567', 'ACME Ltd', 'K')] - end - object - end - - request_body = { - "contact": { - "name": 'Donald Trump', - "phone": '+372.51111112', - "email": 'donald@trumptower.com', - "ident": { - "ident_type": 'org', - "ident_country_code": 'EE', - "ident": '70000313', - }, - }, - } - - post '/repp/v1/contacts', headers: @auth_headers, params: request_body - json = JSON.parse(response.body, symbolize_names: true) - - assert_response :bad_request - assert_equal 2003, json[:code] - puts json[:message] - assert json[:message].include? 'Company is not registered' - - CompanyRegister::Client.define_singleton_method(:new, original_new_method) - end + # def test_returns_error_response_if_company_not_existed + # original_new_method = CompanyRegister::Client.method(:new) + # CompanyRegister::Client.define_singleton_method(:new) do + # object = original_new_method.call + # def object.simple_data(registration_number:) + # [Company.new('1234567', 'ACME Ltd', 'K')] + # end + # object + # end + + # request_body = { + # "contact": { + # "name": 'Donald Trump', + # "phone": '+372.51111112', + # "email": 'donald@trumptower.com', + # "ident": { + # "ident_type": 'org', + # "ident_country_code": 'EE', + # "ident": '70000313', + # }, + # }, + # } + + # post '/repp/v1/contacts', headers: @auth_headers, params: request_body + # json = JSON.parse(response.body, symbolize_names: true) + + # assert_response :bad_request + # assert_equal 2003, json[:code] + # puts json[:message] + # assert json[:message].include? 'Company is not registered' + + # CompanyRegister::Client.define_singleton_method(:new, original_new_method) + # end def test_contact_created_with_existed_company original_new_method = CompanyRegister::Client.method(:new)