From c47b093a451adae768f1a905d99676104f8bf5d8 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 14 Jan 2022 00:39:31 +0300 Subject: [PATCH 001/172] Implement FD notes updating --- app/interactions/actions/contact_create.rb | 1 + app/interactions/actions/contact_update.rb | 1 + app/models/depp/contact.rb | 3 +- app/models/validation_event.rb | 18 +++++++ ...113201642_add_email_history_to_contacts.rb | 9 ++++ test/models/domain/force_delete_test.rb | 53 ++++++++++++++++++- 6 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20220113201642_add_email_history_to_contacts.rb diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index d31af2e38..84ed10caf 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -84,6 +84,7 @@ module Actions return false if @error contact.generate_code + contact.email_history = contact.email contact.save end end diff --git a/app/interactions/actions/contact_update.rb b/app/interactions/actions/contact_update.rb index 0cf76d116..1a5b0cd16 100644 --- a/app/interactions/actions/contact_update.rb +++ b/app/interactions/actions/contact_update.rb @@ -112,6 +112,7 @@ module Actions email_changed = contact.will_save_change_to_email? old_email = contact.email_was + contact.email_history = old_email updated = contact.save if updated && email_changed && contact.registrant? diff --git a/app/models/depp/contact.rb b/app/models/depp/contact.rb index 7deb36562..32e7f1eab 100644 --- a/app/models/depp/contact.rb +++ b/app/models/depp/contact.rb @@ -5,7 +5,8 @@ module Depp attr_accessor :id, :name, :email, :phone, :org_name, :ident, :ident_type, :ident_country_code, :street, :city, :zip, :state, :country_code, - :password, :legal_document, :statuses, :code + :password, :legal_document, :statuses, :code, + :email_history DISABLED = 'Disabled' DISCLOSURE_TYPES = [DISABLED, '1', '0'] diff --git a/app/models/validation_event.rb b/app/models/validation_event.rb index 621fec030..77facf4db 100644 --- a/app/models/validation_event.rb +++ b/app/models/validation_event.rb @@ -62,6 +62,7 @@ class ValidationEvent < ApplicationRecord if object.need_to_start_force_delete? start_force_delete elsif object.need_to_lift_force_delete? + refresh_status_notes lift_force_delete end end @@ -70,6 +71,23 @@ class ValidationEvent < ApplicationRecord Domains::ForceDeleteEmail::Base.run(email: email) end + def refresh_status_notes + old_email = object.email_history + domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten + registrant_ids = Registrant.where(email: email).pluck(:id) + + domains = domain_contacts.map(&:domain).flatten + + Domain.where(registrant_id: registrant_ids) + + domains.uniq.each do |domain| + next unless domain.status_notes[DomainStatus::FORCE_DELETE] + + domain.status_notes[DomainStatus::FORCE_DELETE].slice!(old_email) + domain.status_notes[DomainStatus::FORCE_DELETE].lstrip! + domain.save(validate: false) + end + end + def lift_force_delete # domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten # registrant_ids = Registrant.where(email: email).pluck(:id) diff --git a/db/migrate/20220113201642_add_email_history_to_contacts.rb b/db/migrate/20220113201642_add_email_history_to_contacts.rb new file mode 100644 index 000000000..2a5f59953 --- /dev/null +++ b/db/migrate/20220113201642_add_email_history_to_contacts.rb @@ -0,0 +1,9 @@ +class AddEmailHistoryToContacts < ActiveRecord::Migration[6.1] + def change + add_column :contacts, :email_history, :string + + reversible do |dir| + dir.up { Contact.update_all('email_history = email') } + end + end +end diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index f3294f034..6cae1c3a5 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -411,6 +411,57 @@ class ForceDeleteTest < ActionMailer::TestCase assert notification.text.include? asserted_text end + def test_force_delete_notes + domain = domains(:airport) + domain.update(valid_to: Time.zone.parse('2012-08-05')) + assert_not domain.force_delete_scheduled? + travel_to Time.zone.parse('2010-07-05') + email_1 = '`@internet.ee' + asserted_text = "Invalid email: #{email_1}" + + Truemail.configure.default_validation_type = :regex + + contact_first = domain.admin_contacts.first + contact_first.update_attribute(:email, email_1) + + ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do + contact_first.verify_email + end + + assert contact_first.email_verification_failed? + + domain.reload + email_2 = '`@internet2.ee' + contact_second = domain.admin_contacts.last + contact_second.update_attribute(:email, email_2) + + ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do + contact_second.verify_email + end + + assert contact_second.email_verification_failed? + + domain.reload + contact_first.update( + email: 'correct_email@internet2.ee', + email_history: email_1 + ) + + + contact_first.verify_email + + + domain.reload + assert domain.force_delete_scheduled? + assert_equal 'invalid_email', domain.template_name + assert_equal Date.parse('2010-09-19'), domain.force_delete_date.to_date + assert_equal Date.parse('2010-08-05'), domain.force_delete_start.to_date + + assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], email_2 + notification = domain.registrar.notifications.last + assert notification.text.include? asserted_text + end + def test_domain_should_have_several_bounced_emails @domain.update(valid_to: Time.zone.parse('2012-08-05')) assert_not @domain.force_delete_scheduled? @@ -458,7 +509,7 @@ class ForceDeleteTest < ActionMailer::TestCase notification = @domain.registrar.notifications.last assert notification.text.include? asserted_text - @domain.registrant.update(email: 'aaa@bbb.com') + @domain.registrant.update(email: 'aaa@bbb.com', email_history: email) @domain.registrant.verify_email assert @domain.registrant.need_to_lift_force_delete? CheckForceDeleteLift.perform_now From f7cc5a896579ad2d1d21250fe8a9fcb254a7be7f Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 14 Jan 2022 01:00:20 +0300 Subject: [PATCH 002/172] Fix structure.sql --- db/structure.sql | 158 ++++++----------------------------------------- 1 file changed, 18 insertions(+), 140 deletions(-) diff --git a/db/structure.sql b/db/structure.sql index 9afc1742f..508617362 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -51,20 +51,6 @@ CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA public; COMMENT ON EXTENSION hstore IS 'data type for storing sets of (key, value) pairs'; --- --- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public; - - --- --- Name: EXTENSION pg_stat_statements; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON EXTENSION pg_stat_statements IS 'track execution statistics of all SQL statements executed'; - - -- -- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: - -- @@ -216,8 +202,6 @@ CREATE FUNCTION public.generate_zonefile(i_origin character varying) RETURNS tex SET default_tablespace = ''; -SET default_with_oids = false; - -- -- Name: account_activities; Type: TABLE; Schema: public; Owner: - -- @@ -667,7 +651,8 @@ CREATE TABLE public.contacts ( upid integer, up_date timestamp without time zone, uuid uuid DEFAULT public.gen_random_uuid() NOT NULL, - disclosed_attributes character varying[] DEFAULT '{}'::character varying[] NOT NULL + disclosed_attributes character varying[] DEFAULT '{}'::character varying[] NOT NULL, + email_history character varying ); @@ -824,8 +809,7 @@ CREATE TABLE public.dnskeys ( creator_str character varying, updator_str character varying, legacy_domain_id integer, - updated_at timestamp without time zone, - validation_datetime timestamp without time zone + updated_at timestamp without time zone ); @@ -952,7 +936,6 @@ CREATE TABLE public.domains ( pending_json jsonb, force_delete_date date, statuses character varying[], - status_notes public.hstore, statuses_before_force_delete character varying[] DEFAULT '{}'::character varying[], upid integer, up_date timestamp without time zone, @@ -960,7 +943,8 @@ CREATE TABLE public.domains ( locked_by_registrant_at timestamp without time zone, force_delete_start timestamp without time zone, force_delete_data public.hstore, - json_statuses_history jsonb + json_statuses_history jsonb, + status_notes public.hstore ); @@ -2279,74 +2263,6 @@ CREATE SEQUENCE public.payment_orders_id_seq ALTER SEQUENCE public.payment_orders_id_seq OWNED BY public.payment_orders.id; --- --- Name: pghero_query_stats; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.pghero_query_stats ( - id bigint NOT NULL, - database text, - "user" text, - query text, - query_hash bigint, - total_time double precision, - calls bigint, - captured_at timestamp without time zone -); - - --- --- Name: pghero_query_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.pghero_query_stats_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: pghero_query_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.pghero_query_stats_id_seq OWNED BY public.pghero_query_stats.id; - - --- --- Name: pghero_space_stats; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.pghero_space_stats ( - id bigint NOT NULL, - database text, - schema text, - relation text, - size bigint, - captured_at timestamp without time zone -); - - --- --- Name: pghero_space_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.pghero_space_stats_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: pghero_space_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.pghero_space_stats_id_seq OWNED BY public.pghero_space_stats.id; - - -- -- Name: prices; Type: TABLE; Schema: public; Owner: - -- @@ -2706,7 +2622,8 @@ CREATE TABLE public.validation_events ( validation_eventable_type character varying, validation_eventable_id bigint, created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL + updated_at timestamp(6) without time zone NOT NULL, + event_type public.validation_type ); @@ -3248,20 +3165,6 @@ ALTER TABLE ONLY public.notifications ALTER COLUMN id SET DEFAULT nextval('publi ALTER TABLE ONLY public.payment_orders ALTER COLUMN id SET DEFAULT nextval('public.payment_orders_id_seq'::regclass); --- --- Name: pghero_query_stats id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pghero_query_stats ALTER COLUMN id SET DEFAULT nextval('public.pghero_query_stats_id_seq'::regclass); - - --- --- Name: pghero_space_stats id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pghero_space_stats ALTER COLUMN id SET DEFAULT nextval('public.pghero_space_stats_id_seq'::regclass); - - -- -- Name: prices id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3785,22 +3688,6 @@ ALTER TABLE ONLY public.payment_orders ADD CONSTRAINT payment_orders_pkey PRIMARY KEY (id); --- --- Name: pghero_query_stats pghero_query_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pghero_query_stats - ADD CONSTRAINT pghero_query_stats_pkey PRIMARY KEY (id); - - --- --- Name: pghero_space_stats pghero_space_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pghero_space_stats - ADD CONSTRAINT pghero_space_stats_pkey PRIMARY KEY (id); - - -- -- Name: prices prices_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -4571,20 +4458,6 @@ CREATE INDEX index_notifications_on_registrar_id ON public.notifications USING b CREATE INDEX index_payment_orders_on_invoice_id ON public.payment_orders USING btree (invoice_id); --- --- Name: index_pghero_query_stats_on_database_and_captured_at; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_pghero_query_stats_on_database_and_captured_at ON public.pghero_query_stats USING btree (database, captured_at); - - --- --- Name: index_pghero_space_stats_on_database_and_captured_at; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_pghero_space_stats_on_database_and_captured_at ON public.pghero_space_stats USING btree (database, captured_at); - - -- -- Name: index_prices_on_zone_id; Type: INDEX; Schema: public; Owner: - -- @@ -4641,6 +4514,13 @@ CREATE INDEX index_users_on_registrar_id ON public.users USING btree (registrar_ CREATE INDEX index_validation_events_on_event_data ON public.validation_events USING gin (event_data); +-- +-- Name: index_validation_events_on_event_type; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_validation_events_on_event_type ON public.validation_events USING btree (event_type); + + -- -- Name: index_validation_events_on_validation_eventable; Type: INDEX; Schema: public; Owner: - -- @@ -5386,15 +5266,13 @@ INSERT INTO "schema_migrations" (version) VALUES ('20210708131814'), ('20210729131100'), ('20210729134625'), -('20211028122103'), -('20211028125245'), -('20211029082225'), +('20210827185249'), +('20211029073644'), ('20211124071418'), -('20211124084308'), ('20211125181033'), ('20211125184334'), ('20211126085139'), -('20211231113934'), -('20220106123143'); +('20220106123143'), +('20220113201642'); From 57e156e407867ba4f303f199f1a7644950a8db9a Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 14 Jan 2022 01:17:51 +0300 Subject: [PATCH 003/172] Add email_history to registrar --- .../20220113220809_add_email_history_to_registrars.rb | 9 +++++++++ db/structure.sql | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20220113220809_add_email_history_to_registrars.rb diff --git a/db/migrate/20220113220809_add_email_history_to_registrars.rb b/db/migrate/20220113220809_add_email_history_to_registrars.rb new file mode 100644 index 000000000..1f89353a1 --- /dev/null +++ b/db/migrate/20220113220809_add_email_history_to_registrars.rb @@ -0,0 +1,9 @@ +class AddEmailHistoryToRegistrars < ActiveRecord::Migration[6.1] + def change + add_column :registrars, :email_history, :string + + reversible do |dir| + dir.up { Registrar.update_all('email_history = email') } + end + end +end diff --git a/db/structure.sql b/db/structure.sql index 508617362..c7a592295 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2417,7 +2417,8 @@ CREATE TABLE public.registrars ( iban character varying, settings jsonb DEFAULT '{}'::jsonb NOT NULL, legaldoc_optout boolean DEFAULT false NOT NULL, - legaldoc_optout_comment text + legaldoc_optout_comment text, + email_history character varying ); @@ -5273,6 +5274,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20211125184334'), ('20211126085139'), ('20220106123143'), -('20220113201642'); +('20220113201642'), +('20220113220809'); From f63a51a5d65732d9afea331701e3c4f86e256ddc Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 14 Jan 2022 09:44:06 +0300 Subject: [PATCH 004/172] Style fix --- test/models/domain/force_delete_test.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 6cae1c3a5..e403ab65a 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -447,9 +447,7 @@ class ForceDeleteTest < ActionMailer::TestCase email_history: email_1 ) - - contact_first.verify_email - + contact_first.verify_email domain.reload assert domain.force_delete_scheduled? From ee4f3401281725cf0f0161daf1456f98f02b14e0 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 14 Jan 2022 09:57:37 +0300 Subject: [PATCH 005/172] Fix test --- test/models/domain/force_delete_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index e403ab65a..3233ca68e 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -447,7 +447,9 @@ class ForceDeleteTest < ActionMailer::TestCase email_history: email_1 ) - contact_first.verify_email + ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do + contact_first.verify_email + end domain.reload assert domain.force_delete_scheduled? From 9f9606aba0833b709370c498a79b26642b64a178 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 14 Jan 2022 10:34:13 +0300 Subject: [PATCH 006/172] Fix tests --- test/models/domain/force_delete_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 3233ca68e..b57367d49 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -443,7 +443,7 @@ class ForceDeleteTest < ActionMailer::TestCase domain.reload contact_first.update( - email: 'correct_email@internet2.ee', + email: 'aaa@bbb.com', email_history: email_1 ) From 7c7213c3374ef069a4bf1a2953d4c112a38ec70a Mon Sep 17 00:00:00 2001 From: dinsmol Date: Sat, 15 Jan 2022 23:09:31 +0300 Subject: [PATCH 007/172] Fix tests --- test/fixtures/contacts.yml | 2 ++ test/models/domain/force_delete_test.rb | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/test/fixtures/contacts.yml b/test/fixtures/contacts.yml index 4d45738bd..6e362d7a6 100644 --- a/test/fixtures/contacts.yml +++ b/test/fixtures/contacts.yml @@ -1,6 +1,7 @@ john: name: John email: john@inbox.test + email_history: john@inbox.test phone: '+555.555' ident: 1234 ident_type: priv @@ -18,6 +19,7 @@ john: william: &william name: William email: william@inbox.test + email_history: william@inbox.test phone: '+555.555' fax: '+666.6' ident: 12345 diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index b57367d49..b55fd2249 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -417,12 +417,16 @@ class ForceDeleteTest < ActionMailer::TestCase assert_not domain.force_delete_scheduled? travel_to Time.zone.parse('2010-07-05') email_1 = '`@internet.ee' - asserted_text = "Invalid email: #{email_1}" + email_2 = '`@internet2.ee' + asserted_text = "Invalid email: #{email_2}" Truemail.configure.default_validation_type = :regex contact_first = domain.admin_contacts.first - contact_first.update_attribute(:email, email_1) + old_email = contact_first.email + contact_first.update( + email: email_1, + email_history: old_email) ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do contact_first.verify_email @@ -431,7 +435,6 @@ class ForceDeleteTest < ActionMailer::TestCase assert contact_first.email_verification_failed? domain.reload - email_2 = '`@internet2.ee' contact_second = domain.admin_contacts.last contact_second.update_attribute(:email, email_2) @@ -447,9 +450,8 @@ class ForceDeleteTest < ActionMailer::TestCase email_history: email_1 ) - ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do - contact_first.verify_email - end + contact_first.verify_email + assert contact_first.need_to_lift_force_delete? domain.reload assert domain.force_delete_scheduled? From 17be0908cdeeb4a7fea80308f6290394f6b34bda Mon Sep 17 00:00:00 2001 From: dinsmol Date: Sat, 15 Jan 2022 23:36:24 +0300 Subject: [PATCH 008/172] Fix tests --- test/models/domain/force_delete_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index b55fd2249..8248ebaf1 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -451,7 +451,6 @@ class ForceDeleteTest < ActionMailer::TestCase ) contact_first.verify_email - assert contact_first.need_to_lift_force_delete? domain.reload assert domain.force_delete_scheduled? From c93a35ef5253564c1f1f334f6d35ef253011f571 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Sat, 15 Jan 2022 23:56:10 +0300 Subject: [PATCH 009/172] Add test logging --- app/models/concerns/email_verifable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/email_verifable.rb b/app/models/concerns/email_verifable.rb index 4f9b4ffeb..0caad7a5c 100644 --- a/app/models/concerns/email_verifable.rb +++ b/app/models/concerns/email_verifable.rb @@ -22,7 +22,7 @@ module EmailVerifable flag = true end end - + puts "test output: #{self.email} - #{flag}" flag end From d5e6ba1e694970d814ae41c809dc89a3aa557383 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Sun, 16 Jan 2022 00:14:14 +0300 Subject: [PATCH 010/172] Fix tests --- app/models/concerns/email_verifable.rb | 2 +- test/models/domain/force_delete_test.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/email_verifable.rb b/app/models/concerns/email_verifable.rb index 0caad7a5c..4f9b4ffeb 100644 --- a/app/models/concerns/email_verifable.rb +++ b/app/models/concerns/email_verifable.rb @@ -22,7 +22,7 @@ module EmailVerifable flag = true end end - puts "test output: #{self.email} - #{flag}" + flag end diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 8248ebaf1..fd3d226ef 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -426,7 +426,8 @@ class ForceDeleteTest < ActionMailer::TestCase old_email = contact_first.email contact_first.update( email: email_1, - email_history: old_email) + email_history: old_email + ) ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do contact_first.verify_email @@ -446,7 +447,7 @@ class ForceDeleteTest < ActionMailer::TestCase domain.reload contact_first.update( - email: 'aaa@bbb.com', + email: old_email, email_history: email_1 ) From 8cab4f6df452b11cdc3d44d88e136d0b6cb5f2c0 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Mon, 17 Jan 2022 17:16:05 +0300 Subject: [PATCH 011/172] Fix tests and errors --- .../domains/force_delete_email/base.rb | 9 +++++++++ app/models/validation_event.rb | 10 ++++++++++ test/models/domain/force_delete_test.rb | 18 +++++++++--------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/interactions/domains/force_delete_email/base.rb b/app/interactions/domains/force_delete_email/base.rb index f22244045..8b3ec9965 100644 --- a/app/interactions/domains/force_delete_email/base.rb +++ b/app/interactions/domains/force_delete_email/base.rb @@ -23,11 +23,20 @@ module Domains def before_execute_force_delete(domain) if domain.force_delete_scheduled? && !domain.status_notes[DomainStatus::FORCE_DELETE].nil? added_additional_email_into_notes(domain) + notify_registrar(domain) else process_force_delete(domain) end end + def notify_registrar(domain) + domain.registrar.notifications.create!(text: I18n.t('force_delete_auto_email', + domain_name: domain.name, + outzone_date: domain.outzone_date, + purge_date: domain.purge_date, + email: domain.status_notes[DomainStatus::FORCE_DELETE])) + end + def process_force_delete(domain) domain.schedule_force_delete(type: :soft, notify_by_email: true, diff --git a/app/models/validation_event.rb b/app/models/validation_event.rb index 77facf4db..6af2daa2f 100644 --- a/app/models/validation_event.rb +++ b/app/models/validation_event.rb @@ -85,9 +85,19 @@ class ValidationEvent < ApplicationRecord domain.status_notes[DomainStatus::FORCE_DELETE].slice!(old_email) domain.status_notes[DomainStatus::FORCE_DELETE].lstrip! domain.save(validate: false) + + notify_registrar(domain) unless domain.status_notes[DomainStatus::FORCE_DELETE].empty? end end + def notify_registrar(domain) + domain.registrar.notifications.create!(text: I18n.t('force_delete_auto_email', + domain_name: domain.name, + outzone_date: domain.outzone_date, + purge_date: domain.purge_date, + email: domain.status_notes[DomainStatus::FORCE_DELETE])) + end + def lift_force_delete # domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten # registrant_ids = Registrant.where(email: email).pluck(:id) diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index fd3d226ef..7498f41d7 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -424,10 +424,8 @@ class ForceDeleteTest < ActionMailer::TestCase contact_first = domain.admin_contacts.first old_email = contact_first.email - contact_first.update( - email: email_1, - email_history: old_email - ) + contact_first.update_attribute(:email_history, old_email) + contact_first.update_attribute(:email, email_1) ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do contact_first.verify_email @@ -439,6 +437,7 @@ class ForceDeleteTest < ActionMailer::TestCase contact_second = domain.admin_contacts.last contact_second.update_attribute(:email, email_2) + travel_to Time.zone.parse('2010-07-05 0:00:03') ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do contact_second.verify_email end @@ -446,14 +445,15 @@ class ForceDeleteTest < ActionMailer::TestCase assert contact_second.email_verification_failed? domain.reload - contact_first.update( - email: old_email, - email_history: email_1 - ) + contact_first.update_attribute(:email_history, email_1) + contact_first.update_attribute(:email, 'correct_email@internet.ee') + travel_to Time.zone.parse('2010-07-05 0:00:06') contact_first.verify_email - domain.reload + + assert contact_first.need_to_lift_force_delete? + assert domain.force_delete_scheduled? assert_equal 'invalid_email', domain.template_name assert_equal Date.parse('2010-09-19'), domain.force_delete_date.to_date From a5b0b289e01af842d9c32622e347f82a525f3170 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Mon, 17 Jan 2022 17:26:01 +0300 Subject: [PATCH 012/172] Refactoring --- app/models/validation_event.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/models/validation_event.rb b/app/models/validation_event.rb index 6af2daa2f..7585eb676 100644 --- a/app/models/validation_event.rb +++ b/app/models/validation_event.rb @@ -73,13 +73,8 @@ class ValidationEvent < ApplicationRecord def refresh_status_notes old_email = object.email_history - domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten - registrant_ids = Registrant.where(email: email).pluck(:id) - domains = domain_contacts.map(&:domain).flatten + - Domain.where(registrant_id: registrant_ids) - - domains.uniq.each do |domain| + domain_list.uniq.each do |domain| next unless domain.status_notes[DomainStatus::FORCE_DELETE] domain.status_notes[DomainStatus::FORCE_DELETE].slice!(old_email) @@ -90,6 +85,13 @@ class ValidationEvent < ApplicationRecord end end + def domain_list + domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten + registrant_ids = Registrant.where(email: email).pluck(:id) + + domain_contacts.map(&:domain).flatten + Domain.where(registrant_id: registrant_ids) + end + def notify_registrar(domain) domain.registrar.notifications.create!(text: I18n.t('force_delete_auto_email', domain_name: domain.name, From 8e977da1e50da11a634014a7f3707a6ce63ac2d0 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Mon, 17 Jan 2022 17:34:57 +0300 Subject: [PATCH 013/172] Style fixes --- app/models/validation_event.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/models/validation_event.rb b/app/models/validation_event.rb index 7585eb676..49bf4325a 100644 --- a/app/models/validation_event.rb +++ b/app/models/validation_event.rb @@ -72,12 +72,10 @@ class ValidationEvent < ApplicationRecord end def refresh_status_notes - old_email = object.email_history - - domain_list.uniq.each do |domain| + domain_list.each do |domain| next unless domain.status_notes[DomainStatus::FORCE_DELETE] - domain.status_notes[DomainStatus::FORCE_DELETE].slice!(old_email) + domain.status_notes[DomainStatus::FORCE_DELETE].slice!(object.email_history) domain.status_notes[DomainStatus::FORCE_DELETE].lstrip! domain.save(validate: false) @@ -89,7 +87,7 @@ class ValidationEvent < ApplicationRecord domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten registrant_ids = Registrant.where(email: email).pluck(:id) - domain_contacts.map(&:domain).flatten + Domain.where(registrant_id: registrant_ids) + (domain_contacts.map(&:domain).flatten + Domain.where(registrant_id: registrant_ids)).uniq end def notify_registrar(domain) From 68999a4099b4a26af62d372b4e7c4d9666f813f1 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Mon, 17 Jan 2022 17:46:41 +0300 Subject: [PATCH 014/172] Refactoring --- app/interactions/actions/contact_update.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/interactions/actions/contact_update.rb b/app/interactions/actions/contact_update.rb index 1a5b0cd16..910e4f0a2 100644 --- a/app/interactions/actions/contact_update.rb +++ b/app/interactions/actions/contact_update.rb @@ -111,8 +111,7 @@ module Actions contact.attributes = new_attributes email_changed = contact.will_save_change_to_email? - old_email = contact.email_was - contact.email_history = old_email + contact.email_history = contact.email_was updated = contact.save if updated && email_changed && contact.registrant? From c72f4831cc4242ac36ea25b38bbed5091d62bb5a Mon Sep 17 00:00:00 2001 From: dinsmol Date: Mon, 17 Jan 2022 17:53:39 +0300 Subject: [PATCH 015/172] Fix error --- app/interactions/actions/contact_update.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/interactions/actions/contact_update.rb b/app/interactions/actions/contact_update.rb index 910e4f0a2..1a5b0cd16 100644 --- a/app/interactions/actions/contact_update.rb +++ b/app/interactions/actions/contact_update.rb @@ -111,7 +111,8 @@ module Actions contact.attributes = new_attributes email_changed = contact.will_save_change_to_email? - contact.email_history = contact.email_was + old_email = contact.email_was + contact.email_history = old_email updated = contact.save if updated && email_changed && contact.registrant? From 04ade0cab2b605e163af474e4557ce44c8141c12 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 21 Jan 2022 01:55:04 +0300 Subject: [PATCH 016/172] Fix tests --- test/models/domain/force_delete_test.rb | 67 +++++++++++++------------ 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 7498f41d7..974c445e6 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -411,55 +411,58 @@ class ForceDeleteTest < ActionMailer::TestCase assert notification.text.include? asserted_text end - def test_force_delete_notes + def test_add_invalid_email_to_domain_status_notes domain = domains(:airport) - domain.update(valid_to: Time.zone.parse('2012-08-05')) - assert_not domain.force_delete_scheduled? + domain.update(valid_to: Time.zone.parse('2012-08-05'), + statuses: %w[serverForceDelete serverRenewProhibited serverTransferProhibited], + force_delete_data: { 'template_name': 'invalid_email', 'force_delete_type': 'soft' }, + status_notes: { "serverForceDelete": '`@internet2.ee' }) + travel_to Time.zone.parse('2010-07-05') - email_1 = '`@internet.ee' - email_2 = '`@internet2.ee' - asserted_text = "Invalid email: #{email_2}" + email = '`@internet.ee' + invalid_emails = '`@internet2.ee `@internet.ee' + asserted_text = "Invalid email: #{invalid_emails}" Truemail.configure.default_validation_type = :regex contact_first = domain.admin_contacts.first - old_email = contact_first.email - contact_first.update_attribute(:email_history, old_email) - contact_first.update_attribute(:email, email_1) + contact_first.update_attribute(:email_history, 'john@inbox.test') + contact_first.update_attribute(:email, email) ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do contact_first.verify_email end - assert contact_first.email_verification_failed? - domain.reload - contact_second = domain.admin_contacts.last - contact_second.update_attribute(:email, email_2) + + assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_emails + notification = domain.registrar.notifications.last + assert notification.text.include? asserted_text + end + + def test_remove_invalid_email_from_domain_status_notes + domain = domains(:airport) + domain.update(valid_to: Time.zone.parse('2012-08-05'), + statuses: %w[serverForceDelete serverRenewProhibited serverTransferProhibited], + force_delete_data: { 'template_name': 'invalid_email', 'force_delete_type': 'soft' }, + status_notes: { "serverForceDelete": '`@internet2.ee `@internet.ee' }) + + travel_to Time.zone.parse('2010-07-05') + email = '`@internet2.ee' + invalid_email = '`@internet.ee' + asserted_text = "Invalid email: #{invalid_email}" + + Truemail.configure.default_validation_type = :regex + + contact_first = domain.admin_contacts.first + contact_first.update_attribute(:email_history, email) + contact_first.update_attribute(:email, 'john@inbox.test') travel_to Time.zone.parse('2010-07-05 0:00:03') - ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do - contact_second.verify_email - end - - assert contact_second.email_verification_failed? - - domain.reload - contact_first.update_attribute(:email_history, email_1) - contact_first.update_attribute(:email, 'correct_email@internet.ee') - - travel_to Time.zone.parse('2010-07-05 0:00:06') contact_first.verify_email domain.reload - assert contact_first.need_to_lift_force_delete? - - assert domain.force_delete_scheduled? - assert_equal 'invalid_email', domain.template_name - assert_equal Date.parse('2010-09-19'), domain.force_delete_date.to_date - assert_equal Date.parse('2010-08-05'), domain.force_delete_start.to_date - - assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], email_2 + assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_email notification = domain.registrar.notifications.last assert notification.text.include? asserted_text end From 1944e462c3c42a60a62429ea29ea3cc9d2780159 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Sat, 22 Jan 2022 01:06:20 +0300 Subject: [PATCH 017/172] Fix domain_history filtration --- app/controllers/admin/domain_versions_controller.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/domain_versions_controller.rb b/app/controllers/admin/domain_versions_controller.rb index bdff4b085..c6bba6d51 100644 --- a/app/controllers/admin/domain_versions_controller.rb +++ b/app/controllers/admin/domain_versions_controller.rb @@ -44,7 +44,7 @@ module Admin where_s += ' AND 1=0' if registrars == [] versions = Version::DomainVersion.includes(:item).where(where_s).order(created_at: :desc, id: :desc) - @q = versions.ransack(params[:q]) + @q = versions.ransack(fix_date_params) @versions = @q.result.page(params[:page]) @versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? @@ -77,5 +77,16 @@ module Admin def create_where_string(key, value) " AND object->>'#{key}' ~* '#{value}'" end + + private + + def fix_date_params + params_copy = params[:q].deep_dup + if params_copy['created_at_lteq'].present? + params_copy['created_at_lteq'] = Date.parse(params_copy['created_at_lteq']) + 1.day + end + + params_copy + end end end From 04de5da1935a0037be767b28a2a1fab7f44ce739 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 3 Feb 2022 00:33:38 +0300 Subject: [PATCH 018/172] Add condition for start force delete --- app/interactions/domains/force_delete_email/base.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/interactions/domains/force_delete_email/base.rb b/app/interactions/domains/force_delete_email/base.rb index f22244045..0c3ceb579 100644 --- a/app/interactions/domains/force_delete_email/base.rb +++ b/app/interactions/domains/force_delete_email/base.rb @@ -11,6 +11,8 @@ module Domains domains = domain_contacts.map(&:domain).flatten + Domain.where(registrant_id: registrant_ids) + return if expired_or_hold_domains_exists?(domains) + domains.each do |domain| next if domain.expired? @@ -20,6 +22,12 @@ module Domains private + def expired_or_hold_domains_exists?(domains) + domains.any? do |domain| + domain.statuses.include?(DomainStatus::SERVER_HOLD) && email.include?(domain.name) + end + end + def before_execute_force_delete(domain) if domain.force_delete_scheduled? && !domain.status_notes[DomainStatus::FORCE_DELETE].nil? added_additional_email_into_notes(domain) From 60de343cb890479b3138eec1eaab0cb055ec82d5 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 8 Feb 2022 01:53:54 +0300 Subject: [PATCH 019/172] Add checking for closed disputes --- app/jobs/dispute_status_update_job.rb | 9 +++++++-- lib/tasks/check_closed_disputes.rake | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 lib/tasks/check_closed_disputes.rake diff --git a/app/jobs/dispute_status_update_job.rb b/app/jobs/dispute_status_update_job.rb index 5e42f29e1..3051b0ce3 100644 --- a/app/jobs/dispute_status_update_job.rb +++ b/app/jobs/dispute_status_update_job.rb @@ -1,6 +1,7 @@ class DisputeStatusUpdateJob < ApplicationJob - def perform(logger: Logger.new($stdout)) + def perform(logger: Logger.new($stdout), include_closed: false) @logger = logger + @include_closed = include_closed @backlog = { 'activated': 0, 'closed': 0, 'activate_fail': [], 'close_fail': [] } .with_indifferent_access @@ -15,7 +16,11 @@ class DisputeStatusUpdateJob < ApplicationJob end def close_disputes - disputes = Dispute.where(closed: nil).where('expires_at < ?', Time.zone.today).all + disputes = if @include_closed + Dispute.where('expires_at < ?', Time.zone.today).all + else + Dispute.where(closed: nil).where('expires_at < ?', Time.zone.today).all + end @logger.info "DisputeStatusUpdateJob - Found #{disputes.count} closable disputes" disputes.each do |dispute| process_dispute(dispute, closing: true) diff --git a/lib/tasks/check_closed_disputes.rake b/lib/tasks/check_closed_disputes.rake new file mode 100644 index 000000000..52f863c69 --- /dev/null +++ b/lib/tasks/check_closed_disputes.rake @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +namespace :disputes do + desc 'Check closed disputes with expired_at in the Past' + task check_closed: :environment do + DisputeStatusUpdateJob.perform_now(include_closed: true) + end +end From 0b1dbe1044084a601b013ecfe5b6d3a0728a3900 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Fri, 18 Feb 2022 12:11:23 -0300 Subject: [PATCH 020/172] Fix EPP examples link on doc --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d0766bd15..2d5b058cc 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Documentation ------------- * [EPP documentation](/doc/epp) -* [EPP request-response examples](/doc/epp-examples.md) +* [EPP request-response examples](/doc/epp_examples.md) * [REPP documentation](https://internetee.github.io/repp-apidoc/) Installation From 5dd85fb2b33333cf05fd51bafddff79fd9ab97e0 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sun, 20 Feb 2022 01:12:43 +0000 Subject: [PATCH 021/172] Update dependency ruby to v3.1.1 --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 75a22a26a..94ff29cc4 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.3 +3.1.1 From 5652aa0722d28db72105fb580cbf87c6ce1a9329 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 23 Feb 2022 01:31:40 +0000 Subject: [PATCH 022/172] Update dependency pg to v1.3.3 --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index b5ae07f77..6fb2562b0 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,7 @@ gem 'figaro', '~> 1.2' # model related gem 'paper_trail', '~> 12.1' -gem 'pg', '1.3.2' +gem 'pg', '1.3.3' # 1.8 is for Rails < 5.0 gem 'ransack', '~> 2.5.0' gem 'truemail', '~> 2.4' # validates email by regexp, mail server existence and address existence diff --git a/Gemfile.lock b/Gemfile.lock index 5eaba3a62..ceb070f5a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -351,7 +351,7 @@ GEM activerecord (>= 5.2) request_store (~> 1.1) pdfkit (0.8.5) - pg (1.3.2) + pg (1.3.3) pg_query (2.1.2) google-protobuf (>= 3.17.1) pghero (2.8.1) @@ -574,7 +574,7 @@ DEPENDENCIES omniauth-tara! paper_trail (~> 12.1) pdfkit - pg (= 1.3.2) + pg (= 1.3.3) pg_query (>= 0.9.0) pghero pry (= 0.14.1) From 72a5e778a503bd2f4b8bdcc358ed3ff583418a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Wed, 23 Feb 2022 17:19:12 +0200 Subject: [PATCH 023/172] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 893557f80..8104ca662 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +23.02.2022 +* FD notes are updated when basis for FD changes [#2216](https://github.com/internetee/registry/issues/2216) + 09.02.2022 * DNSSEC key validation [#1897](https://github.com/internetee/registry/issues/1897) From f3c2daddf4d5987905753faf0d50e98e8a3cf6cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Wed, 23 Feb 2022 17:27:09 +0200 Subject: [PATCH 024/172] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8104ca662..16cb9335e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ 23.02.2022 * FD notes are updated when basis for FD changes [#2216](https://github.com/internetee/registry/issues/2216) +* Admin: date filter end date in domain hostory is now inclusive [#2274](https://github.com/internetee/registry/issues/2274) 09.02.2022 * DNSSEC key validation [#1897](https://github.com/internetee/registry/issues/1897) From b18ad6283424a9382a926067a3988fa0c5ec05f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Wed, 23 Feb 2022 19:02:25 +0200 Subject: [PATCH 025/172] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16cb9335e..0305aff95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ 23.02.2022 * FD notes are updated when basis for FD changes [#2216](https://github.com/internetee/registry/issues/2216) * Admin: date filter end date in domain hostory is now inclusive [#2274](https://github.com/internetee/registry/issues/2274) +* Job for finding and removing disputed statuses from the domains that should not have it [#2281](https://github.com/internetee/registry/issues/2281) 09.02.2022 * DNSSEC key validation [#1897](https://github.com/internetee/registry/issues/1897) From a9b942dac02247de27ff82152753f4ca0b8ed5a3 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Mon, 24 Jan 2022 23:29:18 +0300 Subject: [PATCH 026/172] Fix domain history csv --- .../admin/domain_versions_controller.rb | 12 ++++++ app/helpers/object_versions_helper.rb | 38 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/app/controllers/admin/domain_versions_controller.rb b/app/controllers/admin/domain_versions_controller.rb index c6bba6d51..8cc69d619 100644 --- a/app/controllers/admin/domain_versions_controller.rb +++ b/app/controllers/admin/domain_versions_controller.rb @@ -88,5 +88,17 @@ module Admin params_copy end + + def render_by_format(page, filename) + respond_to do |format| + format.html { render page } + format.csv do + raw_csv = csv_generate + send_data raw_csv, + filename: "#{filename}_#{Time.zone.now.to_formatted_s(:number)}.csv", + type: "#{Mime[:csv]}; charset=utf-8" + end + end + end end end diff --git a/app/helpers/object_versions_helper.rb b/app/helpers/object_versions_helper.rb index dae357cf6..d4baadd45 100644 --- a/app/helpers/object_versions_helper.rb +++ b/app/helpers/object_versions_helper.rb @@ -1,4 +1,6 @@ module ObjectVersionsHelper + CSV_HEADER = ['Name', 'Registrant', 'Registrar', 'Action', 'Created at'].freeze + def attach_existing_fields(version, new_object) version.object_changes.to_h.each do |key, value| method_name = "#{key}=".to_sym @@ -11,9 +13,45 @@ module ObjectVersionsHelper version.object.to_h.select { |key, _value| field_names.include?(key) } end + def csv_generate + CSV.generate do |csv| + csv << CSV_HEADER + @versions.each do |version| + attributes = only_present_fields(version, Domain) + domain = Domain.new(attributes) + attach_existing_fields(version, domain) unless version.event == 'destroy' + + csv << create_row(domain, version) + end + end + end + private def event_value(version, val) version.event == 'destroy' ? val.first : val.last end + + def registrant_name(domain, version) + if domain.registrant + domain.registrant.name + else + contact = Contact.all_versions_for([domain.registrant_id], version.created_at).first + if contact.nil? && ver = Version::ContactVersion.where(item_id: domain.registrant_id).last + merged_obj = ver.object_changes.to_h.each_with_object({}) {|(k,v), o| o[k] = v.last } + result = ver.object.to_h.merge(merged_obj)&.slice(*Contact&.column_names) + contact = Contact.new(result) + end + contact.try(:name) || 'Deleted' + end + end + + def create_row(domain, version) + name = domain.name + registrant = registrant_name(domain, version) + registrar = domain.registrar + event = version.event + created_at = version.created_at.to_formatted_s(:db) + [name, registrant, registrar, event, created_at] + end end From 578b75da2014a72242a94e6b1c45e15b0ab9e6f8 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 25 Jan 2022 01:08:01 +0300 Subject: [PATCH 027/172] Fix contact history csv --- .../admin/contact_versions_controller.rb | 18 +++++++++ .../admin/domain_versions_controller.rb | 5 ++- app/helpers/object_versions_helper.rb | 38 ++++++++++++++----- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/contact_versions_controller.rb b/app/controllers/admin/contact_versions_controller.rb index 8ded131c0..2bfb6dbff 100644 --- a/app/controllers/admin/contact_versions_controller.rb +++ b/app/controllers/admin/contact_versions_controller.rb @@ -1,9 +1,13 @@ module Admin class ContactVersionsController < BaseController + include ApplicationHelper include ObjectVersionsHelper load_and_authorize_resource class: Version::ContactVersion + MODEL = Contact + CSV_HEADER = ['Name', 'ID', 'Ident', 'Registrar', 'Action', 'Created at'].freeze + def index params[:q] ||= {} @@ -56,5 +60,19 @@ module Admin def create_where_string(key, value) " AND object->>'#{key}' ~* '#{value}'" end + + private + + def render_by_format(page, filename) + respond_to do |format| + format.html { render page } + format.csv do + raw_csv = csv_generate(MODEL, CSV_HEADER) + send_data raw_csv, + filename: "#{filename}_#{Time.zone.now.to_formatted_s(:number)}.csv", + type: "#{Mime[:csv]}; charset=utf-8" + end + end + end end end diff --git a/app/controllers/admin/domain_versions_controller.rb b/app/controllers/admin/domain_versions_controller.rb index 8cc69d619..7dacecb8f 100644 --- a/app/controllers/admin/domain_versions_controller.rb +++ b/app/controllers/admin/domain_versions_controller.rb @@ -4,6 +4,9 @@ module Admin load_and_authorize_resource class: Version::DomainVersion + MODEL = Domain + CSV_HEADER = ['Name', 'Registrant', 'Registrar', 'Action', 'Created at'].freeze + def index params[:q] ||= {} @@ -93,7 +96,7 @@ module Admin respond_to do |format| format.html { render page } format.csv do - raw_csv = csv_generate + raw_csv = csv_generate(MODEL, CSV_HEADER) send_data raw_csv, filename: "#{filename}_#{Time.zone.now.to_formatted_s(:number)}.csv", type: "#{Mime[:csv]}; charset=utf-8" diff --git a/app/helpers/object_versions_helper.rb b/app/helpers/object_versions_helper.rb index d4baadd45..65b54f71e 100644 --- a/app/helpers/object_versions_helper.rb +++ b/app/helpers/object_versions_helper.rb @@ -13,15 +13,15 @@ module ObjectVersionsHelper version.object.to_h.select { |key, _value| field_names.include?(key) } end - def csv_generate + def csv_generate(model, header) CSV.generate do |csv| - csv << CSV_HEADER + csv << header @versions.each do |version| - attributes = only_present_fields(version, Domain) - domain = Domain.new(attributes) - attach_existing_fields(version, domain) unless version.event == 'destroy' + attributes = only_present_fields(version, model) + history_object = model.new(attributes) + attach_existing_fields(version, history_object) unless version.event == 'destroy' - csv << create_row(domain, version) + csv << create_row(history_object, version) end end end @@ -46,10 +46,28 @@ module ObjectVersionsHelper end end - def create_row(domain, version) - name = domain.name - registrant = registrant_name(domain, version) - registrar = domain.registrar + def create_row(history_object, version) + if history_object.is_a?(Domain) + domain_history_row(history_object, version) + else + contact_history_row(history_object, version) + end + end + + def contact_history_row(history_object, version) + name = history_object.name + code = history_object.code + ident = ident_for(history_object) + registrar = history_object.registrar + event = version.event + created_at = version.created_at.to_formatted_s(:db) + [name, code, ident, registrar, event, created_at] + end + + def domain_history_row(history_object, version) + name = history_object.name + registrant = registrant_name(history_object, version) + registrar = history_object.registrar event = version.event created_at = version.created_at.to_formatted_s(:db) [name, registrant, registrar, event, created_at] From b9992177ca5e6c6523aa9cf27e2f2619138daf51 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 25 Jan 2022 01:14:03 +0300 Subject: [PATCH 028/172] Fix contact history filtration --- app/controllers/admin/contact_versions_controller.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/contact_versions_controller.rb b/app/controllers/admin/contact_versions_controller.rb index 2bfb6dbff..6555f61ac 100644 --- a/app/controllers/admin/contact_versions_controller.rb +++ b/app/controllers/admin/contact_versions_controller.rb @@ -27,7 +27,7 @@ module Admin end versions = Version::ContactVersion.includes(:item).where(where_s).order(created_at: :desc, id: :desc) - @q = versions.ransack(params[:q]) + @q = versions.ransack(fix_date_params) @versions = @q.result.page(params[:page]) @versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? @@ -63,6 +63,15 @@ module Admin private + def fix_date_params + params_copy = params[:q].deep_dup + if params_copy['created_at_lteq'].present? + params_copy['created_at_lteq'] = Date.parse(params_copy['created_at_lteq']) + 1.day + end + + params_copy + end + def render_by_format(page, filename) respond_to do |format| format.html { render page } From 20ace22d678fcd78da43b28ace4adc1673612a94 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 25 Jan 2022 16:05:56 +0300 Subject: [PATCH 029/172] Fix codeclimate errors --- .../admin/contact_versions_controller.rb | 2 +- .../admin/domain_versions_controller.rb | 2 +- app/helpers/object_versions_helper.rb | 25 ++++++++++--------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/controllers/admin/contact_versions_controller.rb b/app/controllers/admin/contact_versions_controller.rb index 6555f61ac..b92d8b90b 100644 --- a/app/controllers/admin/contact_versions_controller.rb +++ b/app/controllers/admin/contact_versions_controller.rb @@ -76,7 +76,7 @@ module Admin respond_to do |format| format.html { render page } format.csv do - raw_csv = csv_generate(MODEL, CSV_HEADER) + raw_csv = csv_generate(MODEL, CSV_HEADER, @versions) send_data raw_csv, filename: "#{filename}_#{Time.zone.now.to_formatted_s(:number)}.csv", type: "#{Mime[:csv]}; charset=utf-8" diff --git a/app/controllers/admin/domain_versions_controller.rb b/app/controllers/admin/domain_versions_controller.rb index 7dacecb8f..d26616375 100644 --- a/app/controllers/admin/domain_versions_controller.rb +++ b/app/controllers/admin/domain_versions_controller.rb @@ -96,7 +96,7 @@ module Admin respond_to do |format| format.html { render page } format.csv do - raw_csv = csv_generate(MODEL, CSV_HEADER) + raw_csv = csv_generate(MODEL, CSV_HEADER, @versions) send_data raw_csv, filename: "#{filename}_#{Time.zone.now.to_formatted_s(:number)}.csv", type: "#{Mime[:csv]}; charset=utf-8" diff --git a/app/helpers/object_versions_helper.rb b/app/helpers/object_versions_helper.rb index 65b54f71e..68185c442 100644 --- a/app/helpers/object_versions_helper.rb +++ b/app/helpers/object_versions_helper.rb @@ -13,10 +13,10 @@ module ObjectVersionsHelper version.object.to_h.select { |key, _value| field_names.include?(key) } end - def csv_generate(model, header) + def csv_generate(model, header, versions) CSV.generate do |csv| csv << header - @versions.each do |version| + versions.each do |version| attributes = only_present_fields(version, model) history_object = model.new(attributes) attach_existing_fields(version, history_object) unless version.event == 'destroy' @@ -33,17 +33,18 @@ module ObjectVersionsHelper end def registrant_name(domain, version) - if domain.registrant - domain.registrant.name - else - contact = Contact.all_versions_for([domain.registrant_id], version.created_at).first - if contact.nil? && ver = Version::ContactVersion.where(item_id: domain.registrant_id).last - merged_obj = ver.object_changes.to_h.each_with_object({}) {|(k,v), o| o[k] = v.last } - result = ver.object.to_h.merge(merged_obj)&.slice(*Contact&.column_names) - contact = Contact.new(result) - end - contact.try(:name) || 'Deleted' + return domain.registrant.name if domain.registrant + + ver = Version::ContactVersion.where(item_id: domain.registrant_id).last + contact = Contact.all_versions_for([domain.registrant_id], version.created_at).first + + if contact.nil? && ver + merged_obj = ver.object_changes.to_h.transform_values(&:last) + result = ver.object.to_h.merge(merged_obj)&.slice(*Contact&.column_names) + contact = Contact.new(result) end + + contact.try(:name) || 'Deleted' end def create_row(history_object, version) From b78f3e846d3b836b92ff17f6131c5edf888af13a Mon Sep 17 00:00:00 2001 From: dinsmol Date: Sat, 26 Feb 2022 12:46:23 +0300 Subject: [PATCH 030/172] Fix data for csv --- .../admin/contact_versions_controller.rb | 2 +- .../admin/domain_versions_controller.rb | 2 +- db/structure.sql | 160 ++++++++++++++++-- 3 files changed, 146 insertions(+), 18 deletions(-) diff --git a/app/controllers/admin/contact_versions_controller.rb b/app/controllers/admin/contact_versions_controller.rb index b92d8b90b..534a4192c 100644 --- a/app/controllers/admin/contact_versions_controller.rb +++ b/app/controllers/admin/contact_versions_controller.rb @@ -76,7 +76,7 @@ module Admin respond_to do |format| format.html { render page } format.csv do - raw_csv = csv_generate(MODEL, CSV_HEADER, @versions) + raw_csv = csv_generate(MODEL, CSV_HEADER, @q.result) send_data raw_csv, filename: "#{filename}_#{Time.zone.now.to_formatted_s(:number)}.csv", type: "#{Mime[:csv]}; charset=utf-8" diff --git a/app/controllers/admin/domain_versions_controller.rb b/app/controllers/admin/domain_versions_controller.rb index d26616375..a7741130f 100644 --- a/app/controllers/admin/domain_versions_controller.rb +++ b/app/controllers/admin/domain_versions_controller.rb @@ -96,7 +96,7 @@ module Admin respond_to do |format| format.html { render page } format.csv do - raw_csv = csv_generate(MODEL, CSV_HEADER, @versions) + raw_csv = csv_generate(MODEL, CSV_HEADER, @q.result) send_data raw_csv, filename: "#{filename}_#{Time.zone.now.to_formatted_s(:number)}.csv", type: "#{Mime[:csv]}; charset=utf-8" diff --git a/db/structure.sql b/db/structure.sql index 5b842d4a4..0c8420f43 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -51,6 +51,20 @@ CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA public; COMMENT ON EXTENSION hstore IS 'data type for storing sets of (key, value) pairs'; +-- +-- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public; + + +-- +-- Name: EXTENSION pg_stat_statements; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION pg_stat_statements IS 'track execution statistics of all SQL statements executed'; + + -- -- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: - -- @@ -202,6 +216,8 @@ CREATE FUNCTION public.generate_zonefile(i_origin character varying) RETURNS tex SET default_tablespace = ''; +SET default_with_oids = false; + -- -- Name: account_activities; Type: TABLE; Schema: public; Owner: - -- @@ -809,7 +825,9 @@ CREATE TABLE public.dnskeys ( creator_str character varying, updator_str character varying, legacy_domain_id integer, - updated_at timestamp without time zone + updated_at timestamp without time zone, + validation_datetime timestamp without time zone, + failed_validation_reason character varying ); @@ -936,6 +954,7 @@ CREATE TABLE public.domains ( pending_json jsonb, force_delete_date date, statuses character varying[], + status_notes public.hstore, statuses_before_force_delete character varying[] DEFAULT '{}'::character varying[], upid integer, up_date timestamp without time zone, @@ -943,8 +962,7 @@ CREATE TABLE public.domains ( locked_by_registrant_at timestamp without time zone, force_delete_start timestamp without time zone, force_delete_data public.hstore, - json_statuses_history jsonb, - status_notes public.hstore + json_statuses_history jsonb ); @@ -1177,6 +1195,7 @@ CREATE TABLE public.invoices ( buyer_vat_no character varying, issue_date date NOT NULL, e_invoice_sent_at timestamp without time zone, + payment_link character varying, CONSTRAINT invoices_due_date_is_not_before_issue_date CHECK ((due_date >= issue_date)) ); @@ -2263,6 +2282,74 @@ CREATE SEQUENCE public.payment_orders_id_seq ALTER SEQUENCE public.payment_orders_id_seq OWNED BY public.payment_orders.id; +-- +-- Name: pghero_query_stats; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.pghero_query_stats ( + id bigint NOT NULL, + database text, + "user" text, + query text, + query_hash bigint, + total_time double precision, + calls bigint, + captured_at timestamp without time zone +); + + +-- +-- Name: pghero_query_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.pghero_query_stats_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: pghero_query_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.pghero_query_stats_id_seq OWNED BY public.pghero_query_stats.id; + + +-- +-- Name: pghero_space_stats; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.pghero_space_stats ( + id bigint NOT NULL, + database text, + schema text, + relation text, + size bigint, + captured_at timestamp without time zone +); + + +-- +-- Name: pghero_space_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.pghero_space_stats_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: pghero_space_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.pghero_space_stats_id_seq OWNED BY public.pghero_space_stats.id; + + -- -- Name: prices; Type: TABLE; Schema: public; Owner: - -- @@ -2623,8 +2710,7 @@ CREATE TABLE public.validation_events ( validation_eventable_type character varying, validation_eventable_id bigint, created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL, - event_type public.validation_type + updated_at timestamp(6) without time zone NOT NULL ); @@ -3166,6 +3252,20 @@ ALTER TABLE ONLY public.notifications ALTER COLUMN id SET DEFAULT nextval('publi ALTER TABLE ONLY public.payment_orders ALTER COLUMN id SET DEFAULT nextval('public.payment_orders_id_seq'::regclass); +-- +-- Name: pghero_query_stats id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.pghero_query_stats ALTER COLUMN id SET DEFAULT nextval('public.pghero_query_stats_id_seq'::regclass); + + +-- +-- Name: pghero_space_stats id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.pghero_space_stats ALTER COLUMN id SET DEFAULT nextval('public.pghero_space_stats_id_seq'::regclass); + + -- -- Name: prices id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3689,6 +3789,22 @@ ALTER TABLE ONLY public.payment_orders ADD CONSTRAINT payment_orders_pkey PRIMARY KEY (id); +-- +-- Name: pghero_query_stats pghero_query_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.pghero_query_stats + ADD CONSTRAINT pghero_query_stats_pkey PRIMARY KEY (id); + + +-- +-- Name: pghero_space_stats pghero_space_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.pghero_space_stats + ADD CONSTRAINT pghero_space_stats_pkey PRIMARY KEY (id); + + -- -- Name: prices prices_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -4459,6 +4575,20 @@ CREATE INDEX index_notifications_on_registrar_id ON public.notifications USING b CREATE INDEX index_payment_orders_on_invoice_id ON public.payment_orders USING btree (invoice_id); +-- +-- Name: index_pghero_query_stats_on_database_and_captured_at; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_pghero_query_stats_on_database_and_captured_at ON public.pghero_query_stats USING btree (database, captured_at); + + +-- +-- Name: index_pghero_space_stats_on_database_and_captured_at; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_pghero_space_stats_on_database_and_captured_at ON public.pghero_space_stats USING btree (database, captured_at); + + -- -- Name: index_prices_on_zone_id; Type: INDEX; Schema: public; Owner: - -- @@ -4515,13 +4645,6 @@ CREATE INDEX index_users_on_registrar_id ON public.users USING btree (registrar_ CREATE INDEX index_validation_events_on_event_data ON public.validation_events USING gin (event_data); --- --- Name: index_validation_events_on_event_type; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_validation_events_on_event_type ON public.validation_events USING btree (event_type); - - -- -- Name: index_validation_events_on_validation_eventable; Type: INDEX; Schema: public; Owner: - -- @@ -5267,15 +5390,20 @@ INSERT INTO "schema_migrations" (version) VALUES ('20210708131814'), ('20210729131100'), ('20210729134625'), -('20210827185249'), -('20211029073644'), +('20211028122103'), +('20211028125245'), +('20211029082225'), ('20211124071418'), +('20211124084308'), ('20211125181033'), ('20211125184334'), ('20211126085139'), +('20211231113934'), ('20220106123143'), ('20220113201642'), -('20220113220809'); - +('20220113220809'), +('20220124105717'), +('20220216113112'), +('20220228093211'); From f6df99237f3da1407f7fbe0c15d0a98669f1e139 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 8 Mar 2022 12:33:50 +0200 Subject: [PATCH 031/172] Add tests for force delete email from hold domains --- .../force_delete_email/base_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/interactions/force_delete_email/base_test.rb diff --git a/test/interactions/force_delete_email/base_test.rb b/test/interactions/force_delete_email/base_test.rb new file mode 100644 index 000000000..c3f688678 --- /dev/null +++ b/test/interactions/force_delete_email/base_test.rb @@ -0,0 +1,18 @@ +require 'test_helper' + +class BaseTest < ActiveSupport::TestCase + def test_hold_domains_force_delete_email + domain = domains(:shop) + domain.update!(statuses: [DomainStatus::SERVER_HOLD]) + domain.update!(expire_time: Time.zone.now + 1.year) + + registrant = domain.registrant + registrant.update!(email: "#{registrant.email.split('@').first}@#{domain.name}") + + Domains::ForceDeleteEmail::Base.run(email: registrant.email) + + domain.reload + + assert_not domain.force_delete_scheduled? + end +end From 71001ce05639dfca185f8fb60a09a8cba8d4413c Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 8 Mar 2022 17:31:00 +0200 Subject: [PATCH 032/172] Add file fixture to download history tests --- test/fixtures/files/contact_versions.csv | 3 +++ test/fixtures/files/domain_versions.csv | 3 +++ test/system/admin_area/contact_versions_test.rb | 3 +-- test/system/admin_area/domain_versions_test.rb | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/files/contact_versions.csv create mode 100644 test/fixtures/files/domain_versions.csv diff --git a/test/fixtures/files/contact_versions.csv b/test/fixtures/files/contact_versions.csv new file mode 100644 index 000000000..c794026c2 --- /dev/null +++ b/test/fixtures/files/contact_versions.csv @@ -0,0 +1,3 @@ +Name,ID,Ident,Registrar,Action,Created at +,test_code,[ ],Best Names,update,2018-04-23 15:50:48 +,,[ ],,update,2010-07-04 21:00:00 diff --git a/test/fixtures/files/domain_versions.csv b/test/fixtures/files/domain_versions.csv new file mode 100644 index 000000000..8fa7fa9fe --- /dev/null +++ b/test/fixtures/files/domain_versions.csv @@ -0,0 +1,3 @@ +Name,Registrant,Registrar,Action,Created at +,test_code,Best Names,update,2018-04-23 15:50:48 +,John,,update,2010-07-04 21:00:00 diff --git a/test/system/admin_area/contact_versions_test.rb b/test/system/admin_area/contact_versions_test.rb index f040646bb..e199f5768 100644 --- a/test/system/admin_area/contact_versions_test.rb +++ b/test/system/admin_area/contact_versions_test.rb @@ -62,11 +62,10 @@ class ContactVersionsTest < ApplicationSystemTestCase travel_to now get admin_contact_versions_path(format: :csv) - assert_response :ok assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type'] assert_equal %(attachment; filename="contact_history_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''contact_history_#{Time.zone.now.to_formatted_s(:number)}.csv), response.headers['Content-Disposition'] - assert_not_empty response.body + assert_equal file_fixture('contact_versions.csv').read, response.body end end diff --git a/test/system/admin_area/domain_versions_test.rb b/test/system/admin_area/domain_versions_test.rb index a8aeb0cd4..75b66b1bb 100644 --- a/test/system/admin_area/domain_versions_test.rb +++ b/test/system/admin_area/domain_versions_test.rb @@ -98,7 +98,7 @@ class DomainVersionsTest < ApplicationSystemTestCase assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type'] assert_equal %(attachment; filename="domain_history_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''domain_history_#{Time.zone.now.to_formatted_s(:number)}.csv), response.headers['Content-Disposition'] - assert_not_empty response.body + assert_equal file_fixture('domain_versions.csv').read, response.body end def test_search_event_param From 807419bc3a628116f55c15119db331b688623490 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Wed, 9 Mar 2022 15:37:30 +0200 Subject: [PATCH 033/172] Tests for domains csv download at admin --- test/fixtures/files/domains.csv | 2 ++ test/system/admin_area/domains/csv_test.rb | 10 +++------- 2 files changed, 5 insertions(+), 7 deletions(-) create mode 100644 test/fixtures/files/domains.csv diff --git a/test/fixtures/files/domains.csv b/test/fixtures/files/domains.csv new file mode 100644 index 000000000..10a6e2b65 --- /dev/null +++ b/test/fixtures/files/domains.csv @@ -0,0 +1,2 @@ +Domain,Registrant,Valid to,Registrar,Created at,Statuses,Contacts code,Force delete date,Force delete data +hospital.test,Thiago,05/07/2010 03:00,Good Names,05/07/2009 03:00,[],[john-001, william-001, william-001],08/03/2022 00:00, diff --git a/test/system/admin_area/domains/csv_test.rb b/test/system/admin_area/domains/csv_test.rb index c84e2cf0e..cae01b884 100644 --- a/test/system/admin_area/domains/csv_test.rb +++ b/test/system/admin_area/domains/csv_test.rb @@ -1,18 +1,14 @@ require 'application_system_test_case' class AdminAreaCsvTest < ApplicationSystemTestCase - setup do - sign_in users(:admin) - end + setup { sign_in users(:admin) } def test_downloads_domain_list_as_csv - search_params = {"valid_to_lteq"=>nil} - expected_csv = Domain.includes(:registrar, :registrant).search(search_params).result.to_csv - travel_to Time.zone.parse('2010-07-05 10:30') visit admin_domains_url click_link('CSV') + assert_equal "attachment; filename=\"domains_#{Time.zone.now.to_formatted_s(:number)}.csv\"; filename*=UTF-8''domains_#{Time.zone.now.to_formatted_s(:number)}.csv", response_headers['Content-Disposition'] - assert_equal expected_csv, page.body + assert_equal file_fixture('domains.csv').read, page.body end end From 9fb4a6d7e6b19f7ba8647b69f0cd378d7a663a52 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Thu, 10 Mar 2022 16:03:53 +0200 Subject: [PATCH 034/172] Refactor `admin/contact_version` and `admin/domain_version` csv generation logic --- app/controllers/admin/base_controller.rb | 2 +- .../admin/contact_versions_controller.rb | 16 ---- .../admin/domain_versions_controller.rb | 22 +----- app/helpers/application_helper.rb | 24 ------ app/helpers/object_versions_helper.rb | 76 ------------------- app/models/contact.rb | 7 ++ app/models/version/contact_version.rb | 17 +++++ app/models/version/domain_version.rb | 33 ++++++++ app/services/csv_generator.rb | 17 +++++ app/services/object_versions_parser.rb | 28 +++++++ app/views/admin/contact_versions/index.haml | 6 +- app/views/admin/contact_versions/show.haml | 7 +- app/views/admin/contacts/index.haml | 2 +- .../admin/contacts/partials/_general.haml | 2 +- app/views/admin/domain_versions/archive.haml | 4 +- app/views/admin/domain_versions/show.haml | 4 +- app/views/registrar/contacts/index.html.erb | 2 +- .../registrar/contacts/list_pdf.html.erb | 2 +- .../registrar/contacts/partials/_general.haml | 2 +- 19 files changed, 117 insertions(+), 156 deletions(-) delete mode 100644 app/helpers/object_versions_helper.rb create mode 100644 app/services/csv_generator.rb create mode 100644 app/services/object_versions_parser.rb diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index 016c0a750..56806ba3e 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -26,7 +26,7 @@ module Admin respond_to do |format| format.html { render page } format.csv do - raw_csv = @q.result.to_csv + raw_csv = CsvGenerator.generate_csv(@q.result) send_data raw_csv, filename: "#{filename}_#{Time.zone.now.to_formatted_s(:number)}.csv", type: "#{Mime[:csv]}; charset=utf-8" diff --git a/app/controllers/admin/contact_versions_controller.rb b/app/controllers/admin/contact_versions_controller.rb index 534a4192c..2a26035c9 100644 --- a/app/controllers/admin/contact_versions_controller.rb +++ b/app/controllers/admin/contact_versions_controller.rb @@ -1,13 +1,9 @@ module Admin class ContactVersionsController < BaseController include ApplicationHelper - include ObjectVersionsHelper load_and_authorize_resource class: Version::ContactVersion - MODEL = Contact - CSV_HEADER = ['Name', 'ID', 'Ident', 'Registrar', 'Action', 'Created at'].freeze - def index params[:q] ||= {} @@ -71,17 +67,5 @@ module Admin params_copy end - - def render_by_format(page, filename) - respond_to do |format| - format.html { render page } - format.csv do - raw_csv = csv_generate(MODEL, CSV_HEADER, @q.result) - send_data raw_csv, - filename: "#{filename}_#{Time.zone.now.to_formatted_s(:number)}.csv", - type: "#{Mime[:csv]}; charset=utf-8" - end - end - end end end diff --git a/app/controllers/admin/domain_versions_controller.rb b/app/controllers/admin/domain_versions_controller.rb index a7741130f..c82347ff9 100644 --- a/app/controllers/admin/domain_versions_controller.rb +++ b/app/controllers/admin/domain_versions_controller.rb @@ -1,12 +1,7 @@ module Admin class DomainVersionsController < BaseController - include ObjectVersionsHelper - load_and_authorize_resource class: Version::DomainVersion - MODEL = Domain - CSV_HEADER = ['Name', 'Registrant', 'Registrar', 'Action', 'Created at'].freeze - def index params[:q] ||= {} @@ -85,23 +80,10 @@ module Admin def fix_date_params params_copy = params[:q].deep_dup - if params_copy['created_at_lteq'].present? - params_copy['created_at_lteq'] = Date.parse(params_copy['created_at_lteq']) + 1.day - end + created_at = params_copy['created_at_lteq'] + params_copy['created_at_lteq'] = Date.parse(created_at) + 1.day if created_at.present? params_copy end - - def render_by_format(page, filename) - respond_to do |format| - format.html { render page } - format.csv do - raw_csv = csv_generate(MODEL, CSV_HEADER, @q.result) - send_data raw_csv, - filename: "#{filename}_#{Time.zone.now.to_formatted_s(:number)}.csv", - type: "#{Mime[:csv]}; charset=utf-8" - end - end - end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3de98b88c..6829040c2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -9,30 +9,6 @@ module ApplicationHelper "background-image: url(#{image_path("#{unstable_env}.png")});" end - def ident_for(contact) - if contact.is_a? Hash - ident_country_code = contact[:ident_country_code] - ident_type = contact[:ident_type] - ident = contact[:ident] - else - ident_country_code = contact.ident_country_code - ident_type = contact.ident_type - ident = contact.ident - end - - case ident_type - when 'birthday' - "#{ident} [#{ident_country_code} #{ident_type}]" - else - if ident.present? - "#{ident} [#{ident_country_code} #{ident_type}]" - else - "[#{ident_country_code} #{ident_type}]" - end - - end - end - def current_commit_link hash = `git rev-parse --short HEAD` current_repo = `git remote get-url origin`.gsub('com:', 'com/') diff --git a/app/helpers/object_versions_helper.rb b/app/helpers/object_versions_helper.rb deleted file mode 100644 index 68185c442..000000000 --- a/app/helpers/object_versions_helper.rb +++ /dev/null @@ -1,76 +0,0 @@ -module ObjectVersionsHelper - CSV_HEADER = ['Name', 'Registrant', 'Registrar', 'Action', 'Created at'].freeze - - def attach_existing_fields(version, new_object) - version.object_changes.to_h.each do |key, value| - method_name = "#{key}=".to_sym - new_object.public_send(method_name, event_value(version, value)) if new_object.respond_to?(method_name) - end - end - - def only_present_fields(version, model) - field_names = model.column_names - version.object.to_h.select { |key, _value| field_names.include?(key) } - end - - def csv_generate(model, header, versions) - CSV.generate do |csv| - csv << header - versions.each do |version| - attributes = only_present_fields(version, model) - history_object = model.new(attributes) - attach_existing_fields(version, history_object) unless version.event == 'destroy' - - csv << create_row(history_object, version) - end - end - end - - private - - def event_value(version, val) - version.event == 'destroy' ? val.first : val.last - end - - def registrant_name(domain, version) - return domain.registrant.name if domain.registrant - - ver = Version::ContactVersion.where(item_id: domain.registrant_id).last - contact = Contact.all_versions_for([domain.registrant_id], version.created_at).first - - if contact.nil? && ver - merged_obj = ver.object_changes.to_h.transform_values(&:last) - result = ver.object.to_h.merge(merged_obj)&.slice(*Contact&.column_names) - contact = Contact.new(result) - end - - contact.try(:name) || 'Deleted' - end - - def create_row(history_object, version) - if history_object.is_a?(Domain) - domain_history_row(history_object, version) - else - contact_history_row(history_object, version) - end - end - - def contact_history_row(history_object, version) - name = history_object.name - code = history_object.code - ident = ident_for(history_object) - registrar = history_object.registrar - event = version.event - created_at = version.created_at.to_formatted_s(:db) - [name, code, ident, registrar, event, created_at] - end - - def domain_history_row(history_object, version) - name = history_object.name - registrant = registrant_name(history_object, version) - registrar = history_object.registrar - event = version.event - created_at = version.created_at.to_formatted_s(:db) - [name, registrant, registrar, event, created_at] - end -end diff --git a/app/models/contact.rb b/app/models/contact.rb index 84d4ba962..f15637f6f 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -569,4 +569,11 @@ class Contact < ApplicationRecord def deletable? !linked? end + + def ident_human_description + description = "[#{ident_country_code} #{ident_type}]" + description.prepend("#{ident} ") if ident.present? + + description + end end diff --git a/app/models/version/contact_version.rb b/app/models/version/contact_version.rb index 95bd4b677..498e6d468 100644 --- a/app/models/version/contact_version.rb +++ b/app/models/version/contact_version.rb @@ -4,4 +4,21 @@ class Version::ContactVersion < PaperTrail::Version self.table_name = :log_contacts self.sequence_name = :log_contacts_id_seq + + def as_csv_row + contact = ObjectVersionsParser.new(self).parse + + [ + contact.name, + contact.code, + contact.ident_human_description, + contact.registrar, + event, + created_at.to_formatted_s(:db) + ] + end + + def self.csv_header + ['Name', 'ID', 'Ident', 'Registrar', 'Action', 'Created at'].freeze + end end diff --git a/app/models/version/domain_version.rb b/app/models/version/domain_version.rb index 2c6848d4b..240adc866 100644 --- a/app/models/version/domain_version.rb +++ b/app/models/version/domain_version.rb @@ -7,6 +7,18 @@ class Version::DomainVersion < PaperTrail::Version scope :deleted, -> { where(event: 'destroy') } + def as_csv_row + domain = ObjectVersionsParser.new(self).parse + + [ + domain.name, + registrant_name(domain), + domain.registrar, + event, + created_at.to_formatted_s(:db) + ] + end + def self.was_contact_linked?(contact_id) sql = <<-SQL SELECT @@ -43,4 +55,25 @@ class Version::DomainVersion < PaperTrail::Version count_by_sql(sql).nonzero? end + + def self.csv_header + ['Name', 'Registrant', 'Registrar', 'Action', 'Created at'].freeze + end + + private + + def registrant_name(domain) + return domain.registrant.name if domain.registrant + + ver = Version::ContactVersion.where(item_id: domain.registrant_id).last + contact = Contact.all_versions_for([domain.registrant_id], created_at).first + + if contact.nil? && ver + merged_obj = ver.object_changes.to_h.transform_values(&:last) + result = ver.object.to_h.merge(merged_obj)&.slice(*Contact&.column_names) + contact = Contact.new(result) + end + + contact.try(:name) || 'Deleted' + end end diff --git a/app/services/csv_generator.rb b/app/services/csv_generator.rb new file mode 100644 index 000000000..43c116b7e --- /dev/null +++ b/app/services/csv_generator.rb @@ -0,0 +1,17 @@ +class CsvGenerator + def self.generate_csv(objects) + class_name = objects.first.class + return objects.to_csv unless custom_csv(class_name) + + CSV.generate do |csv| + csv << class_name.csv_header + objects.each { |object| csv << object.as_csv_row } + end + end + + private + + def self.custom_csv(class_name) + [Version::DomainVersion, Version::ContactVersion].include?(class_name) + end +end diff --git a/app/services/object_versions_parser.rb b/app/services/object_versions_parser.rb new file mode 100644 index 000000000..5871a6bd6 --- /dev/null +++ b/app/services/object_versions_parser.rb @@ -0,0 +1,28 @@ +class ObjectVersionsParser + def initialize(version) + @version = version + end + + def parse + model = @version.item_type.constantize + attributes = only_present_fields(model) + history_object = model.new(attributes) + attach_existing_fields(history_object) unless @version.event == 'destroy' + + history_object + end + + private + + def attach_existing_fields(history_object) + @version.object_changes.to_h.each do |key, value| + method_name = "#{key}=".to_sym + history_object.public_send(method_name, value.last) if history_object.respond_to?(method_name) + end + end + + def only_present_fields(model) + field_names = model.column_names + @version.object.to_h.select { |key, _value| field_names.include?(key) } + end +end diff --git a/app/views/admin/contact_versions/index.haml b/app/views/admin/contact_versions/index.haml index 4d7a9948d..97c267d30 100644 --- a/app/views/admin/contact_versions/index.haml +++ b/app/views/admin/contact_versions/index.haml @@ -64,14 +64,12 @@ %tbody - @versions.each do |version| - if version - - attributes = only_present_fields(version, Contact) - - contact = Contact.new(attributes) - - attach_existing_fields(version, contact) + - contact = ObjectVersionsParser.new(version).parse %tr %td= link_to(contact.name, admin_contact_version_path(version.id)) %td= contact.code - %td= ident_for(contact) + %td= contact.ident_human_description %td - if contact.registrar = link_to(contact.registrar, admin_registrar_path(contact.registrar)) diff --git a/app/views/admin/contact_versions/show.haml b/app/views/admin/contact_versions/show.haml index 901f5ee1a..57c8c3ccc 100644 --- a/app/views/admin/contact_versions/show.haml +++ b/app/views/admin/contact_versions/show.haml @@ -1,6 +1,5 @@ -- attributes = only_present_fields(@version, Contact) -- contact = Contact.new(attributes) -- attach_existing_fields(@version, contact) +- contact = ObjectVersionsParser.new(@version).parse + = render 'shared/title', name: contact.name .row @@ -23,7 +22,7 @@ %dt= t(:ident) %dd{class: changing_css_class(@version,"ident_country_code", "ident_type", "ident")} - = ident_for(contact) + = contact.ident_human_description - if contact.email.present? %dt= t(:email) diff --git a/app/views/admin/contacts/index.haml b/app/views/admin/contacts/index.haml index 0812913a1..b4198b8cc 100644 --- a/app/views/admin/contacts/index.haml +++ b/app/views/admin/contacts/index.haml @@ -100,7 +100,7 @@ %tr %td= link_to(contact, admin_contact_path(contact)) %td= contact.code - %td= ident_for(contact) + %td= contact.ident_human_description %td= contact.email %td= l(contact.created_at, format: :short) %td diff --git a/app/views/admin/contacts/partials/_general.haml b/app/views/admin/contacts/partials/_general.haml index 2396861fb..4b8d4ec32 100644 --- a/app/views/admin/contacts/partials/_general.haml +++ b/app/views/admin/contacts/partials/_general.haml @@ -14,7 +14,7 @@ %br %dt.left_25= t(:ident) - %dd.left_25= ident_for(@contact) + %dd.left_25= @contact.ident_human_description %dt.left_25= t(:email) %dd.left_25= @contact.email diff --git a/app/views/admin/domain_versions/archive.haml b/app/views/admin/domain_versions/archive.haml index ec2034ed1..85105b9f0 100644 --- a/app/views/admin/domain_versions/archive.haml +++ b/app/views/admin/domain_versions/archive.haml @@ -62,9 +62,7 @@ %tbody - @versions.each do |version| - if version - - attributes = only_present_fields(version, Domain) - - domain = Domain.new(attributes) - - attach_existing_fields(version, domain) unless version.event == 'destroy' + - domain = ObjectVersionsParser.new(version).parse %tr %td= link_to(domain.name, admin_domain_version_path(version.id)) diff --git a/app/views/admin/domain_versions/show.haml b/app/views/admin/domain_versions/show.haml index 11f70599f..ab49dffee 100644 --- a/app/views/admin/domain_versions/show.haml +++ b/app/views/admin/domain_versions/show.haml @@ -1,6 +1,4 @@ -- present_fields = only_present_fields(@version, Domain) -- domain = Domain.new(present_fields) -- attach_existing_fields(@version, domain) unless @version.event == 'destroy' +- domain = ObjectVersionsParser.new(@version).parse - if @version - children = HashWithIndifferentAccess.new(@version.children) diff --git a/app/views/registrar/contacts/index.html.erb b/app/views/registrar/contacts/index.html.erb index 4a7e8759a..35683360e 100644 --- a/app/views/registrar/contacts/index.html.erb +++ b/app/views/registrar/contacts/index.html.erb @@ -44,7 +44,7 @@ <%= contact.code %> - <%= ident_for(contact) %> + <%= contact.ident_human_description %> <%= l(contact.created_at, format: :short) %> diff --git a/app/views/registrar/contacts/list_pdf.html.erb b/app/views/registrar/contacts/list_pdf.html.erb index b9bbb1c0e..52e5956dd 100644 --- a/app/views/registrar/contacts/list_pdf.html.erb +++ b/app/views/registrar/contacts/list_pdf.html.erb @@ -20,7 +20,7 @@ <%= contact %> <%= contact.code %> - <%= ident_for(contact) %> + <%= contact.ident_human_description %> <%= l(contact.created_at, format: :short) %> <%= contact.registrar %> diff --git a/app/views/registrar/contacts/partials/_general.haml b/app/views/registrar/contacts/partials/_general.haml index 5fc8ec027..4e2a92621 100644 --- a/app/views/registrar/contacts/partials/_general.haml +++ b/app/views/registrar/contacts/partials/_general.haml @@ -14,7 +14,7 @@ %br %dt= t(:ident) - %dd= ident_for(@contact) + %dd= @contact.ident_human_description %dt= t(:email) %dd= @contact.email From 6263ded68ff1d3fbc4116a876b628b1d0971b9f2 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Fri, 11 Mar 2022 14:37:46 +0200 Subject: [PATCH 035/172] Fix admin domains CSV output --- app/models/domain.rb | 29 ++++++++++++++++++++++ app/models/version/domain_version.rb | 19 +------------- app/services/csv_generator.rb | 2 +- test/fixtures/files/domains.csv | 9 +++++-- test/system/admin_area/domains/csv_test.rb | 5 ++++ 5 files changed, 43 insertions(+), 21 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 873216cf1..2f084ed4d 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -753,6 +753,35 @@ class Domain < ApplicationRecord contacts.select(&:email_verification_failed?)&.map(&:email)&.uniq end + def as_csv_row + [ + name, + registrant_name, + valid_to.to_formatted_s(:db), + registrar, + created_at.to_formatted_s(:db), + statuses, + contacts.pluck(:code), + force_delete_date, + force_delete_data + ] + end + + def registrant_name + return registrant.name if registrant + + ver = Version::ContactVersion.where(item_id: registrant_id).last + contact = Contact.all_versions_for([registrant_id], created_at).first + + contact = ObjectVersionsParser.new(ver).parse if contact.nil? && ver + + contact.try(:name) || 'Deleted' + end + + def self.csv_header + ['Domain', 'Registrant', 'Valid to', 'Registrar', 'Created at', 'Statuses', 'Contacts code', 'Force delete date', 'Force delete data'].freeze + end + def self.pdf(html) kit = PDFKit.new(html) kit.to_pdf diff --git a/app/models/version/domain_version.rb b/app/models/version/domain_version.rb index 240adc866..52b10fc53 100644 --- a/app/models/version/domain_version.rb +++ b/app/models/version/domain_version.rb @@ -12,7 +12,7 @@ class Version::DomainVersion < PaperTrail::Version [ domain.name, - registrant_name(domain), + domain.registrant_name, domain.registrar, event, created_at.to_formatted_s(:db) @@ -59,21 +59,4 @@ class Version::DomainVersion < PaperTrail::Version def self.csv_header ['Name', 'Registrant', 'Registrar', 'Action', 'Created at'].freeze end - - private - - def registrant_name(domain) - return domain.registrant.name if domain.registrant - - ver = Version::ContactVersion.where(item_id: domain.registrant_id).last - contact = Contact.all_versions_for([domain.registrant_id], created_at).first - - if contact.nil? && ver - merged_obj = ver.object_changes.to_h.transform_values(&:last) - result = ver.object.to_h.merge(merged_obj)&.slice(*Contact&.column_names) - contact = Contact.new(result) - end - - contact.try(:name) || 'Deleted' - end end diff --git a/app/services/csv_generator.rb b/app/services/csv_generator.rb index 43c116b7e..c0d21ad62 100644 --- a/app/services/csv_generator.rb +++ b/app/services/csv_generator.rb @@ -12,6 +12,6 @@ class CsvGenerator private def self.custom_csv(class_name) - [Version::DomainVersion, Version::ContactVersion].include?(class_name) + [Version::DomainVersion, Version::ContactVersion, Domain].include?(class_name) end end diff --git a/test/fixtures/files/domains.csv b/test/fixtures/files/domains.csv index 10a6e2b65..69e9df8a8 100644 --- a/test/fixtures/files/domains.csv +++ b/test/fixtures/files/domains.csv @@ -1,2 +1,7 @@ -Domain,Registrant,Valid to,Registrar,Created at,Statuses,Contacts code,Force delete date,Force delete data -hospital.test,Thiago,05/07/2010 03:00,Good Names,05/07/2009 03:00,[],[john-001, william-001, william-001],08/03/2022 00:00, +Domain,Registrant,Valid to,Registrar,Created at,Statuses,Contacts code,Force delete date,Force delete data +shop.test,John,2010-07-04 21:00:00,Best Names,2010-07-05 07:30:00,"[""ok""]","[""william-001"", ""jane-001"", ""acme-ltd-001""]",2010-07-08, +airport.test,John,2010-07-05 00:00:00,Best Names,2010-07-05 07:30:00,"[""ok""]","[""john-001"", ""william-001"", ""william-001""]",, +library.test,Acme Ltd,2010-07-05 00:00:00,Best Names,2010-07-05 07:30:00,"[""inactive""]","[""john-001"", ""acme-ltd-001""]",, +metro.test,Jack,2010-07-05 00:00:00,Good Names,2010-07-05 07:30:00,[],"[""jack-001"", ""jack-001""]",, +hospital.test,John,2010-07-05 00:00:00,Good Names,2010-07-05 07:30:00,"[""inactive""]","[""john-001"", ""john-001""]",, +invalid.test,any,2010-07-04 21:00:00,Best Names,2010-07-05 07:30:00,"[""inactive""]","[""invalid"", ""invalid""]",, diff --git a/test/system/admin_area/domains/csv_test.rb b/test/system/admin_area/domains/csv_test.rb index cae01b884..296117cf8 100644 --- a/test/system/admin_area/domains/csv_test.rb +++ b/test/system/admin_area/domains/csv_test.rb @@ -5,6 +5,11 @@ class AdminAreaCsvTest < ApplicationSystemTestCase def test_downloads_domain_list_as_csv travel_to Time.zone.parse('2010-07-05 10:30') + Domain.all.each do |domain| + domain.created_at = Time.zone.now + domain.save(:validate => false) + end + visit admin_domains_url click_link('CSV') From f44bdd1930888fbd924696187e41281f71ce7125 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Mon, 14 Mar 2022 09:22:03 +0200 Subject: [PATCH 036/172] Fix admin contacts CSV output --- app/models/contact.rb | 16 ++++++++++++++++ app/services/csv_generator.rb | 2 +- test/fixtures/files/contacts.csv | 10 ++++++++++ test/system/admin_area/contacts/csv_test.rb | 19 +++++++++++++++++++ test/system/admin_area/domains/csv_test.rb | 4 ++-- 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/files/contacts.csv create mode 100644 test/system/admin_area/contacts/csv_test.rb diff --git a/app/models/contact.rb b/app/models/contact.rb index f15637f6f..367777efb 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -576,4 +576,20 @@ class Contact < ApplicationRecord description end + + def as_csv_row + [ + name, + code, + ident_human_description, + email, + created_at.to_formatted_s(:db), + registrar, + phone, + ] + end + + def self.csv_header + ['Name', 'ID', 'Ident', 'E-mail', 'Created at', 'Registrar', 'Phone'].freeze + end end diff --git a/app/services/csv_generator.rb b/app/services/csv_generator.rb index c0d21ad62..122a04ff5 100644 --- a/app/services/csv_generator.rb +++ b/app/services/csv_generator.rb @@ -12,6 +12,6 @@ class CsvGenerator private def self.custom_csv(class_name) - [Version::DomainVersion, Version::ContactVersion, Domain].include?(class_name) + [Version::DomainVersion, Version::ContactVersion, Domain, Contact, Invoice].include?(class_name) end end diff --git a/test/fixtures/files/contacts.csv b/test/fixtures/files/contacts.csv new file mode 100644 index 000000000..73d9104af --- /dev/null +++ b/test/fixtures/files/contacts.csv @@ -0,0 +1,10 @@ +Name,ID,Ident,E-mail,Created at,Registrar,Phone +John,john-001,1234 [US priv],john@inbox.test,2010-07-05 07:30:00,Best Names,+555.555 +William,william-001,12345 [US priv],william@inbox.test,2010-07-05 07:30:00,Best Names,+555.555 +Jane,jane-001,123456 [US priv],jane@mail.test,2010-07-05 07:30:00,Best Names,+555.555 +Acme Ltd,acme-ltd-001,1234567 [US org],acme@outlook.test,2010-07-05 07:30:00,Best Names,+555.555 +Jack,jack-001,12345678 [US org],jack@inbox.test,2010-07-05 07:30:00,Good Names,+555.555 +William,william-002,12345 [US priv],william@inbox.test,2010-07-05 07:30:00,Good Names,+555.555 +Registrar Ltd,registrarltd-001,1234567890 [US org],registrar@inbox.test,2010-07-05 07:30:00,Good Names,+555.555 +any,invalid,[ ],invalid@invalid.test,2010-07-05 07:30:00,Best Names, +any,invalid_email,[ ],invalid@invalid.,2010-07-05 07:30:00,Best Names, diff --git a/test/system/admin_area/contacts/csv_test.rb b/test/system/admin_area/contacts/csv_test.rb new file mode 100644 index 000000000..552bcf437 --- /dev/null +++ b/test/system/admin_area/contacts/csv_test.rb @@ -0,0 +1,19 @@ +require 'application_system_test_case' + +class ContactsCsvTest < ApplicationSystemTestCase + setup { sign_in users(:admin) } + + def test_download_contacts_list_as_csv + travel_to Time.zone.parse('2010-07-05 10:30') + Contact.all.each do |contact| + contact.created_at = Time.zone.now + contact.save(:validate => false) + end + + visit admin_contacts_url + click_link('CSV') + + assert_equal "attachment; filename=\"contacts_#{Time.zone.now.to_formatted_s(:number)}.csv\"; filename*=UTF-8''contacts_#{Time.zone.now.to_formatted_s(:number)}.csv", response_headers['Content-Disposition'] + assert_equal file_fixture('contacts.csv').read, page.body + end +end diff --git a/test/system/admin_area/domains/csv_test.rb b/test/system/admin_area/domains/csv_test.rb index 296117cf8..568815dd7 100644 --- a/test/system/admin_area/domains/csv_test.rb +++ b/test/system/admin_area/domains/csv_test.rb @@ -1,9 +1,9 @@ require 'application_system_test_case' -class AdminAreaCsvTest < ApplicationSystemTestCase +class DomainsCsvTest < ApplicationSystemTestCase setup { sign_in users(:admin) } - def test_downloads_domain_list_as_csv + def test_download_domains_list_as_csv travel_to Time.zone.parse('2010-07-05 10:30') Domain.all.each do |domain| domain.created_at = Time.zone.now From 7d79e6528d3208e3dc8adb7b8f375ee75645393e Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Mon, 14 Mar 2022 12:09:13 +0200 Subject: [PATCH 037/172] Fix admin invoices CSV output --- app/models/invoice.rb | 27 +++++++++++++++++++++++++ app/services/csv_generator.rb | 2 +- test/fixtures/files/invoices.csv | 3 +++ test/system/admin_area/invoices_test.rb | 10 +++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/files/invoices.csv diff --git a/app/models/invoice.rb b/app/models/invoice.rb index df8b7aff8..d0a1950a5 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -117,6 +117,23 @@ class Invoice < ApplicationRecord e_invoice_sent_at.present? end + def as_csv_row + [ + number, + buyer, + cancelled? ? I18n.t(:cancelled) : due_date, + receipt_date_status, + issue_date, + total, + currency, + seller_name + ] + end + + def self.csv_header + ['Number', 'Buyer', 'Due Date', 'Receipt Date', 'Issue Date', 'Total', 'Currency', 'Seller Name'].freeze + end + def self.create_from_transaction!(transaction) registrar_user = Registrar.find_by(reference_no: transaction.parsed_ref_number) return unless registrar_user @@ -128,6 +145,16 @@ class Invoice < ApplicationRecord private + def receipt_date_status + if paid? + receipt_date + elsif cancelled? + I18n.t(:cancelled) + else + I18n.t(:unpaid) + end + end + def apply_default_buyer_vat_no self.buyer_vat_no = buyer.vat_no end diff --git a/app/services/csv_generator.rb b/app/services/csv_generator.rb index 122a04ff5..a2c1305a3 100644 --- a/app/services/csv_generator.rb +++ b/app/services/csv_generator.rb @@ -12,6 +12,6 @@ class CsvGenerator private def self.custom_csv(class_name) - [Version::DomainVersion, Version::ContactVersion, Domain, Contact, Invoice].include?(class_name) + [Version::DomainVersion, Version::ContactVersion, Domain, Contact, Invoice, Account].include?(class_name) end end diff --git a/test/fixtures/files/invoices.csv b/test/fixtures/files/invoices.csv new file mode 100644 index 000000000..641cfe036 --- /dev/null +++ b/test/fixtures/files/invoices.csv @@ -0,0 +1,3 @@ +Number,Buyer,Due Date,Receipt Date,Issue Date,Total,Currency,Seller Name +2,Best Names,2010-07-06,Unpaid,2010-07-05,16.5,EUR,Seller Ltd +1,Best Names,2010-07-06,2010-07-05,2010-07-05,16.5,EUR,Seller Ltd diff --git a/test/system/admin_area/invoices_test.rb b/test/system/admin_area/invoices_test.rb index 40a50e1c7..a8d0a8a75 100644 --- a/test/system/admin_area/invoices_test.rb +++ b/test/system/admin_area/invoices_test.rb @@ -40,4 +40,14 @@ class AdminAreaInvoicesTest < ApplicationSystemTestCase assert_current_path admin_invoice_path(@invoice) assert_text 'Invoice has been sent' end + + def test_download_invoices_list_as_csv + travel_to Time.zone.parse('2010-07-05 10:30') + + visit admin_invoices_url + click_link('CSV') + + assert_equal "attachment; filename=\"invoices_#{Time.zone.now.to_formatted_s(:number)}.csv\"; filename*=UTF-8''invoices_#{Time.zone.now.to_formatted_s(:number)}.csv", response_headers['Content-Disposition'] + assert_equal file_fixture('invoices.csv').read, page.body + end end From 1fac9d9618e3a250c544d2b2171d17ba6db33e9a Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Mon, 14 Mar 2022 12:12:22 +0200 Subject: [PATCH 038/172] Fix admin accounts CSV output --- app/models/account.rb | 8 ++++++++ test/fixtures/files/accounts.csv | 4 ++++ test/system/admin_area/accounts_test.rb | 12 ++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 test/fixtures/files/accounts.csv diff --git a/app/models/account.rb b/app/models/account.rb index fe0820888..73911817c 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -12,4 +12,12 @@ class Account < ApplicationRecord def activities account_activities end + + def as_csv_row + [id, balance, currency, registrar] + end + + def self.csv_header + ['Id', 'Balance', 'Currency', 'Registrar'].freeze + end end diff --git a/test/fixtures/files/accounts.csv b/test/fixtures/files/accounts.csv new file mode 100644 index 000000000..5bc44fc48 --- /dev/null +++ b/test/fixtures/files/accounts.csv @@ -0,0 +1,4 @@ +Id,Balance,Currency,Registrar +112846265,100.0,EUR,Best Names +298486374,100.0,EUR,Good Names +597560588,0.0,EUR,Not in use diff --git a/test/system/admin_area/accounts_test.rb b/test/system/admin_area/accounts_test.rb index f07ced9c3..393c3445a 100644 --- a/test/system/admin_area/accounts_test.rb +++ b/test/system/admin_area/accounts_test.rb @@ -29,4 +29,16 @@ class AdminAccountsSystemTest < ApplicationSystemTestCase assert_text 'Account has been successfully updated' assert_text '234' end + + def test_download_accounts_list_as_csv + travel_to Time.zone.parse('2010-07-05 10:30') + + get admin_accounts_path(format: :csv) + + assert_response :ok + assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type'] + assert_equal %(attachment; filename="accounts_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''accounts_#{Time.zone.now.to_formatted_s(:number)}.csv), + response.headers['Content-Disposition'] + assert_equal file_fixture('accounts.csv').read, response.body + end end From dd513b63138f24cad6e353ae8252ba1b2e644d70 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Mon, 14 Mar 2022 12:43:53 +0200 Subject: [PATCH 039/172] Remove `freeze` method call at `csv_header` --- app/models/account.rb | 2 +- app/models/contact.rb | 2 +- app/models/domain.rb | 2 +- app/models/invoice.rb | 2 +- app/models/version/contact_version.rb | 2 +- app/models/version/domain_version.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index 73911817c..334d292f2 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -18,6 +18,6 @@ class Account < ApplicationRecord end def self.csv_header - ['Id', 'Balance', 'Currency', 'Registrar'].freeze + ['Id', 'Balance', 'Currency', 'Registrar'] end end diff --git a/app/models/contact.rb b/app/models/contact.rb index 367777efb..f44b28f35 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -590,6 +590,6 @@ class Contact < ApplicationRecord end def self.csv_header - ['Name', 'ID', 'Ident', 'E-mail', 'Created at', 'Registrar', 'Phone'].freeze + ['Name', 'ID', 'Ident', 'E-mail', 'Created at', 'Registrar', 'Phone'] end end diff --git a/app/models/domain.rb b/app/models/domain.rb index 2f084ed4d..3728b0de1 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -779,7 +779,7 @@ class Domain < ApplicationRecord end def self.csv_header - ['Domain', 'Registrant', 'Valid to', 'Registrar', 'Created at', 'Statuses', 'Contacts code', 'Force delete date', 'Force delete data'].freeze + ['Domain', 'Registrant', 'Valid to', 'Registrar', 'Created at', 'Statuses', 'Contacts code', 'Force delete date', 'Force delete data'] end def self.pdf(html) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index d0a1950a5..80dbc6417 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -131,7 +131,7 @@ class Invoice < ApplicationRecord end def self.csv_header - ['Number', 'Buyer', 'Due Date', 'Receipt Date', 'Issue Date', 'Total', 'Currency', 'Seller Name'].freeze + ['Number', 'Buyer', 'Due Date', 'Receipt Date', 'Issue Date', 'Total', 'Currency', 'Seller Name'] end def self.create_from_transaction!(transaction) diff --git a/app/models/version/contact_version.rb b/app/models/version/contact_version.rb index 498e6d468..669c422fe 100644 --- a/app/models/version/contact_version.rb +++ b/app/models/version/contact_version.rb @@ -19,6 +19,6 @@ class Version::ContactVersion < PaperTrail::Version end def self.csv_header - ['Name', 'ID', 'Ident', 'Registrar', 'Action', 'Created at'].freeze + ['Name', 'ID', 'Ident', 'Registrar', 'Action', 'Created at'] end end diff --git a/app/models/version/domain_version.rb b/app/models/version/domain_version.rb index 52b10fc53..bef5208f3 100644 --- a/app/models/version/domain_version.rb +++ b/app/models/version/domain_version.rb @@ -57,6 +57,6 @@ class Version::DomainVersion < PaperTrail::Version end def self.csv_header - ['Name', 'Registrant', 'Registrar', 'Action', 'Created at'].freeze + ['Name', 'Registrant', 'Registrar', 'Action', 'Created at'] end end From fd41d773904afb346708f30dbbfac6a4de4d6a30 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Mon, 14 Mar 2022 14:46:31 +0200 Subject: [PATCH 040/172] Move contact ident description to helper method --- app/helpers/application_helper.rb | 8 ++++++++ app/views/admin/contact_versions/index.haml | 2 +- app/views/admin/contact_versions/show.haml | 2 +- app/views/admin/contacts/index.haml | 2 +- app/views/admin/contacts/partials/_general.haml | 2 +- app/views/registrar/contacts/index.html.erb | 2 +- app/views/registrar/contacts/list_pdf.html.erb | 2 +- app/views/registrar/contacts/partials/_general.haml | 2 +- 8 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6829040c2..122fc40d4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -9,6 +9,14 @@ module ApplicationHelper "background-image: url(#{image_path("#{unstable_env}.png")});" end + def ident_for(contact) + ident = contact.ident + description = "[#{contact.ident_country_code} #{contact.ident_type}]" + description.prepend("#{ident} ") if ident.present? + + description + end + def current_commit_link hash = `git rev-parse --short HEAD` current_repo = `git remote get-url origin`.gsub('com:', 'com/') diff --git a/app/views/admin/contact_versions/index.haml b/app/views/admin/contact_versions/index.haml index 97c267d30..8f973ee40 100644 --- a/app/views/admin/contact_versions/index.haml +++ b/app/views/admin/contact_versions/index.haml @@ -69,7 +69,7 @@ %tr %td= link_to(contact.name, admin_contact_version_path(version.id)) %td= contact.code - %td= contact.ident_human_description + %td= ident_for(contact) %td - if contact.registrar = link_to(contact.registrar, admin_registrar_path(contact.registrar)) diff --git a/app/views/admin/contact_versions/show.haml b/app/views/admin/contact_versions/show.haml index 57c8c3ccc..546ff4287 100644 --- a/app/views/admin/contact_versions/show.haml +++ b/app/views/admin/contact_versions/show.haml @@ -22,7 +22,7 @@ %dt= t(:ident) %dd{class: changing_css_class(@version,"ident_country_code", "ident_type", "ident")} - = contact.ident_human_description + = ident_for(contact) - if contact.email.present? %dt= t(:email) diff --git a/app/views/admin/contacts/index.haml b/app/views/admin/contacts/index.haml index b4198b8cc..0812913a1 100644 --- a/app/views/admin/contacts/index.haml +++ b/app/views/admin/contacts/index.haml @@ -100,7 +100,7 @@ %tr %td= link_to(contact, admin_contact_path(contact)) %td= contact.code - %td= contact.ident_human_description + %td= ident_for(contact) %td= contact.email %td= l(contact.created_at, format: :short) %td diff --git a/app/views/admin/contacts/partials/_general.haml b/app/views/admin/contacts/partials/_general.haml index 4b8d4ec32..2396861fb 100644 --- a/app/views/admin/contacts/partials/_general.haml +++ b/app/views/admin/contacts/partials/_general.haml @@ -14,7 +14,7 @@ %br %dt.left_25= t(:ident) - %dd.left_25= @contact.ident_human_description + %dd.left_25= ident_for(@contact) %dt.left_25= t(:email) %dd.left_25= @contact.email diff --git a/app/views/registrar/contacts/index.html.erb b/app/views/registrar/contacts/index.html.erb index 35683360e..4a7e8759a 100644 --- a/app/views/registrar/contacts/index.html.erb +++ b/app/views/registrar/contacts/index.html.erb @@ -44,7 +44,7 @@ <%= contact.code %> - <%= contact.ident_human_description %> + <%= ident_for(contact) %> <%= l(contact.created_at, format: :short) %> diff --git a/app/views/registrar/contacts/list_pdf.html.erb b/app/views/registrar/contacts/list_pdf.html.erb index 52e5956dd..b9bbb1c0e 100644 --- a/app/views/registrar/contacts/list_pdf.html.erb +++ b/app/views/registrar/contacts/list_pdf.html.erb @@ -20,7 +20,7 @@ <%= contact %> <%= contact.code %> - <%= contact.ident_human_description %> + <%= ident_for(contact) %> <%= l(contact.created_at, format: :short) %> <%= contact.registrar %> diff --git a/app/views/registrar/contacts/partials/_general.haml b/app/views/registrar/contacts/partials/_general.haml index 4e2a92621..5fc8ec027 100644 --- a/app/views/registrar/contacts/partials/_general.haml +++ b/app/views/registrar/contacts/partials/_general.haml @@ -14,7 +14,7 @@ %br %dt= t(:ident) - %dd= @contact.ident_human_description + %dd= ident_for(@contact) %dt= t(:email) %dd= @contact.email From c5855f006529456480bf1b27571d5543383b903c Mon Sep 17 00:00:00 2001 From: OlegPhenomenon <37714103+OlegPhenomenon@users.noreply.github.com> Date: Tue, 15 Mar 2022 15:47:07 +0200 Subject: [PATCH 041/172] Update .ruby-version --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 94ff29cc4..75a22a26a 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.1 +3.0.3 From 102fd559a0aa50e35a5914c113255b6b120981ac Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 18 Mar 2022 18:02:54 +0200 Subject: [PATCH 042/172] updated structure, resolve pending migration issue --- db/structure.sql | 160 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 144 insertions(+), 16 deletions(-) diff --git a/db/structure.sql b/db/structure.sql index 5b842d4a4..0c8420f43 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -51,6 +51,20 @@ CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA public; COMMENT ON EXTENSION hstore IS 'data type for storing sets of (key, value) pairs'; +-- +-- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public; + + +-- +-- Name: EXTENSION pg_stat_statements; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION pg_stat_statements IS 'track execution statistics of all SQL statements executed'; + + -- -- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: - -- @@ -202,6 +216,8 @@ CREATE FUNCTION public.generate_zonefile(i_origin character varying) RETURNS tex SET default_tablespace = ''; +SET default_with_oids = false; + -- -- Name: account_activities; Type: TABLE; Schema: public; Owner: - -- @@ -809,7 +825,9 @@ CREATE TABLE public.dnskeys ( creator_str character varying, updator_str character varying, legacy_domain_id integer, - updated_at timestamp without time zone + updated_at timestamp without time zone, + validation_datetime timestamp without time zone, + failed_validation_reason character varying ); @@ -936,6 +954,7 @@ CREATE TABLE public.domains ( pending_json jsonb, force_delete_date date, statuses character varying[], + status_notes public.hstore, statuses_before_force_delete character varying[] DEFAULT '{}'::character varying[], upid integer, up_date timestamp without time zone, @@ -943,8 +962,7 @@ CREATE TABLE public.domains ( locked_by_registrant_at timestamp without time zone, force_delete_start timestamp without time zone, force_delete_data public.hstore, - json_statuses_history jsonb, - status_notes public.hstore + json_statuses_history jsonb ); @@ -1177,6 +1195,7 @@ CREATE TABLE public.invoices ( buyer_vat_no character varying, issue_date date NOT NULL, e_invoice_sent_at timestamp without time zone, + payment_link character varying, CONSTRAINT invoices_due_date_is_not_before_issue_date CHECK ((due_date >= issue_date)) ); @@ -2263,6 +2282,74 @@ CREATE SEQUENCE public.payment_orders_id_seq ALTER SEQUENCE public.payment_orders_id_seq OWNED BY public.payment_orders.id; +-- +-- Name: pghero_query_stats; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.pghero_query_stats ( + id bigint NOT NULL, + database text, + "user" text, + query text, + query_hash bigint, + total_time double precision, + calls bigint, + captured_at timestamp without time zone +); + + +-- +-- Name: pghero_query_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.pghero_query_stats_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: pghero_query_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.pghero_query_stats_id_seq OWNED BY public.pghero_query_stats.id; + + +-- +-- Name: pghero_space_stats; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.pghero_space_stats ( + id bigint NOT NULL, + database text, + schema text, + relation text, + size bigint, + captured_at timestamp without time zone +); + + +-- +-- Name: pghero_space_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.pghero_space_stats_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: pghero_space_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.pghero_space_stats_id_seq OWNED BY public.pghero_space_stats.id; + + -- -- Name: prices; Type: TABLE; Schema: public; Owner: - -- @@ -2623,8 +2710,7 @@ CREATE TABLE public.validation_events ( validation_eventable_type character varying, validation_eventable_id bigint, created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL, - event_type public.validation_type + updated_at timestamp(6) without time zone NOT NULL ); @@ -3166,6 +3252,20 @@ ALTER TABLE ONLY public.notifications ALTER COLUMN id SET DEFAULT nextval('publi ALTER TABLE ONLY public.payment_orders ALTER COLUMN id SET DEFAULT nextval('public.payment_orders_id_seq'::regclass); +-- +-- Name: pghero_query_stats id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.pghero_query_stats ALTER COLUMN id SET DEFAULT nextval('public.pghero_query_stats_id_seq'::regclass); + + +-- +-- Name: pghero_space_stats id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.pghero_space_stats ALTER COLUMN id SET DEFAULT nextval('public.pghero_space_stats_id_seq'::regclass); + + -- -- Name: prices id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3689,6 +3789,22 @@ ALTER TABLE ONLY public.payment_orders ADD CONSTRAINT payment_orders_pkey PRIMARY KEY (id); +-- +-- Name: pghero_query_stats pghero_query_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.pghero_query_stats + ADD CONSTRAINT pghero_query_stats_pkey PRIMARY KEY (id); + + +-- +-- Name: pghero_space_stats pghero_space_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.pghero_space_stats + ADD CONSTRAINT pghero_space_stats_pkey PRIMARY KEY (id); + + -- -- Name: prices prices_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -4459,6 +4575,20 @@ CREATE INDEX index_notifications_on_registrar_id ON public.notifications USING b CREATE INDEX index_payment_orders_on_invoice_id ON public.payment_orders USING btree (invoice_id); +-- +-- Name: index_pghero_query_stats_on_database_and_captured_at; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_pghero_query_stats_on_database_and_captured_at ON public.pghero_query_stats USING btree (database, captured_at); + + +-- +-- Name: index_pghero_space_stats_on_database_and_captured_at; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_pghero_space_stats_on_database_and_captured_at ON public.pghero_space_stats USING btree (database, captured_at); + + -- -- Name: index_prices_on_zone_id; Type: INDEX; Schema: public; Owner: - -- @@ -4515,13 +4645,6 @@ CREATE INDEX index_users_on_registrar_id ON public.users USING btree (registrar_ CREATE INDEX index_validation_events_on_event_data ON public.validation_events USING gin (event_data); --- --- Name: index_validation_events_on_event_type; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_validation_events_on_event_type ON public.validation_events USING btree (event_type); - - -- -- Name: index_validation_events_on_validation_eventable; Type: INDEX; Schema: public; Owner: - -- @@ -5267,15 +5390,20 @@ INSERT INTO "schema_migrations" (version) VALUES ('20210708131814'), ('20210729131100'), ('20210729134625'), -('20210827185249'), -('20211029073644'), +('20211028122103'), +('20211028125245'), +('20211029082225'), ('20211124071418'), +('20211124084308'), ('20211125181033'), ('20211125184334'), ('20211126085139'), +('20211231113934'), ('20220106123143'), ('20220113201642'), -('20220113220809'); - +('20220113220809'), +('20220124105717'), +('20220216113112'), +('20220228093211'); From 6b028814c3362060496fcc262162233050aa8e38 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 14 Dec 2021 09:27:13 +0300 Subject: [PATCH 043/172] Add email checking for creating/updating domains --- .../registrar/domains_controller.rb | 21 ++++++++++++++----- config/locales/registrar/domains.en.yml | 2 ++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index e5ab59fa2..c1901ec12 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -91,11 +91,14 @@ class Registrar def create authorize! :create, Depp::Domain @domain_params = domain_params.to_h - @data = @domain.create(@domain_params) + if contacts_check = check_contacts + @data = @domain.create(@domain_params) + end - if response_ok? + if @data && response_ok? redirect_to info_registrar_domains_url(domain_name: @domain_params[:name]) else + flash[:alert] = t('.email_error_message') unless contacts_check render 'new' end end @@ -110,12 +113,15 @@ class Registrar def update authorize! :update, Depp::Domain @domain_params = params[:domain] - @data = @domain.update(@domain_params) - @dispute = Dispute.active.find_by(domain_name: @domain_params[:name]) + if contacts_check = check_contacts + @data = @domain.update(@domain_params) + @dispute = Dispute.active.find_by(domain_name: @domain_params[:name]) + end - if response_ok? + if @data && response_ok? redirect_to info_registrar_domains_url(domain_name: @domain_params[:name]) else + flash[:alert] = t('.email_error_message') unless contacts_check params[:domain_name] = @domain_params[:name] render 'new' end @@ -173,6 +179,11 @@ class Registrar private + def check_contacts + params_as_hash = @domain_params[:contacts_attributes].to_h + params_as_hash.all? { |_k, val| Contact.find_by(code: val[:code]).verify_email } + end + def init_domain @domain = Depp::Domain.new(current_user: depp_current_user) end diff --git a/config/locales/registrar/domains.en.yml b/config/locales/registrar/domains.en.yml index b8605bd42..be2574d92 100644 --- a/config/locales/registrar/domains.en.yml +++ b/config/locales/registrar/domains.en.yml @@ -1,6 +1,8 @@ en: registrar: domains: + email_error_message: 'Check contacts emails' + index: header: Domains new_btn: New domain From b8a59745deacd63d79f17d43250d713d11c47505 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 15 Dec 2021 10:39:34 +0300 Subject: [PATCH 044/172] Fix codeclimate errors --- app/controllers/registrar/domains_controller.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index c1901ec12..a2235d6c0 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -91,14 +91,12 @@ class Registrar def create authorize! :create, Depp::Domain @domain_params = domain_params.to_h - if contacts_check = check_contacts - @data = @domain.create(@domain_params) - end + @data = @domain.create(@domain_params) if emails_valid? if @data && response_ok? redirect_to info_registrar_domains_url(domain_name: @domain_params[:name]) else - flash[:alert] = t('.email_error_message') unless contacts_check + flash[:alert] = t('.email_error_message') unless @emails_check_result render 'new' end end @@ -113,7 +111,7 @@ class Registrar def update authorize! :update, Depp::Domain @domain_params = params[:domain] - if contacts_check = check_contacts + if emails_valid? @data = @domain.update(@domain_params) @dispute = Dispute.active.find_by(domain_name: @domain_params[:name]) end @@ -121,7 +119,7 @@ class Registrar if @data && response_ok? redirect_to info_registrar_domains_url(domain_name: @domain_params[:name]) else - flash[:alert] = t('.email_error_message') unless contacts_check + flash[:alert] = t('.email_error_message') unless @emails_check_result params[:domain_name] = @domain_params[:name] render 'new' end @@ -179,9 +177,9 @@ class Registrar private - def check_contacts + def emails_valid? params_as_hash = @domain_params[:contacts_attributes].to_h - params_as_hash.all? { |_k, val| Contact.find_by(code: val[:code]).verify_email } + @emails_check_result = params_as_hash.all? { |_k, val| Contact.find_by(code: val[:code]).verify_email } end def init_domain From 89bc8583baf2fff8ff41efdb4eafa672bb5a406f Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 15 Dec 2021 10:55:45 +0300 Subject: [PATCH 045/172] Disable cognitive copmlexity metric --- .../registrar/domains_controller.rb | 21 +++++++----- app/interactions/actions/domain_update.rb | 34 +++++++++++++++++++ 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index a2235d6c0..10f718849 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -88,10 +88,12 @@ class Registrar @domain_params[:period] = Depp::Domain.default_period end + # rubocop:disable Metrics/CognitiveComplexity def create authorize! :create, Depp::Domain @domain_params = domain_params.to_h - @data = @domain.create(@domain_params) if emails_valid? + # @data = @domain.create(@domain_params) if emails_valid? + @data = @domain.create(@domain_params) if @data && response_ok? redirect_to info_registrar_domains_url(domain_name: @domain_params[:name]) @@ -111,10 +113,10 @@ class Registrar def update authorize! :update, Depp::Domain @domain_params = params[:domain] - if emails_valid? - @data = @domain.update(@domain_params) - @dispute = Dispute.active.find_by(domain_name: @domain_params[:name]) - end + # if emails_valid? + @data = @domain.update(@domain_params) + @dispute = Dispute.active.find_by(domain_name: @domain_params[:name]) + # end if @data && response_ok? redirect_to info_registrar_domains_url(domain_name: @domain_params[:name]) @@ -124,6 +126,7 @@ class Registrar render 'new' end end + # rubocop:enable Metrics/CognitiveComplexity def delete authorize! :delete, Depp::Domain @@ -177,10 +180,10 @@ class Registrar private - def emails_valid? - params_as_hash = @domain_params[:contacts_attributes].to_h - @emails_check_result = params_as_hash.all? { |_k, val| Contact.find_by(code: val[:code]).verify_email } - end + # def emails_valid? + # params_as_hash = @domain_params[:contacts_attributes].to_h + # @emails_check_result = params_as_hash.all? { |_k, val| Contact.find_by(code: val[:code]).verify_email } + # end def init_domain @domain = Depp::Domain.new(current_user: depp_current_user) diff --git a/app/interactions/actions/domain_update.rb b/app/interactions/actions/domain_update.rb index 40b7876f6..69d7544ce 100644 --- a/app/interactions/actions/domain_update.rb +++ b/app/interactions/actions/domain_update.rb @@ -45,6 +45,13 @@ module Actions def assign_new_registrant domain.add_epp_error('2306', nil, nil, %i[registrant cannot_be_missing]) unless params[:registrant][:code] + contact_code = params[:registrant][:code] + contact = Contact.find_by_code(contact_code) + p ">>>>>>>>>" + p contact.email + p ">>>>>>>>>>>>" + validate_email(contact.email) + regt = Registrant.find_by(code: params[:registrant][:code]) unless regt domain.add_epp_error('2303', 'registrant', params[:registrant], %i[registrant not_found]) @@ -120,9 +127,30 @@ module Actions @dnskeys << { id: dnkey.id, _destroy: 1 } if dnkey end + def validate_email(email) + return if Rails.env.test? + + [:regex, :mx].each do |m| + result = Actions::SimpleMailValidator.run(email: email, level: m) + next if result + + domain.add_epp_error('2005', nil, "#{email} didn't pass validation", I18n.t(:parameter_value_syntax_error)) + @error = true + return + end + + true + end + def assign_admin_contact_changes props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'admin' }) + if props.present? + contact_code = props[0][:contact_code_cache] + contact = Contact.find_by_code(contact_code) + validate_email(contact.email) + end + if props.any? && domain.admin_change_prohibited? domain.add_epp_error('2304', 'admin', DomainStatus::SERVER_ADMIN_CHANGE_PROHIBITED, I18n.t(:object_status_prohibits_operation)) @@ -136,6 +164,12 @@ module Actions props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'tech' }, admin: false) + if props.present? + contact_code = props[0][:contact_code_cache] + contact = Contact.find_by_code(contact_code) + validate_email(contact.email) + end + if props.any? && domain.tech_change_prohibited? domain.add_epp_error('2304', 'tech', DomainStatus::SERVER_TECH_CHANGE_PROHIBITED, I18n.t(:object_status_prohibits_operation)) From c972308f030cee23a79d8f94e794cbbe78319619 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 18 Mar 2022 17:56:39 +0200 Subject: [PATCH 046/172] changed validation email principles --- app/controllers/registrar/domains_controller.rb | 8 -------- app/interactions/actions/domain_update.rb | 5 +---- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index 10f718849..3347f5d38 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -92,7 +92,6 @@ class Registrar def create authorize! :create, Depp::Domain @domain_params = domain_params.to_h - # @data = @domain.create(@domain_params) if emails_valid? @data = @domain.create(@domain_params) if @data && response_ok? @@ -113,10 +112,8 @@ class Registrar def update authorize! :update, Depp::Domain @domain_params = params[:domain] - # if emails_valid? @data = @domain.update(@domain_params) @dispute = Dispute.active.find_by(domain_name: @domain_params[:name]) - # end if @data && response_ok? redirect_to info_registrar_domains_url(domain_name: @domain_params[:name]) @@ -180,11 +177,6 @@ class Registrar private - # def emails_valid? - # params_as_hash = @domain_params[:contacts_attributes].to_h - # @emails_check_result = params_as_hash.all? { |_k, val| Contact.find_by(code: val[:code]).verify_email } - # end - def init_domain @domain = Depp::Domain.new(current_user: depp_current_user) end diff --git a/app/interactions/actions/domain_update.rb b/app/interactions/actions/domain_update.rb index 69d7544ce..bc43476e3 100644 --- a/app/interactions/actions/domain_update.rb +++ b/app/interactions/actions/domain_update.rb @@ -47,9 +47,6 @@ module Actions contact_code = params[:registrant][:code] contact = Contact.find_by_code(contact_code) - p ">>>>>>>>>" - p contact.email - p ">>>>>>>>>>>>" validate_email(contact.email) regt = Registrant.find_by(code: params[:registrant][:code]) @@ -128,7 +125,7 @@ module Actions end def validate_email(email) - return if Rails.env.test? + return true if Rails.env.test? [:regex, :mx].each do |m| result = Actions::SimpleMailValidator.run(email: email, level: m) From 3149dc06da6d07146c9731faa954e86d2734e505 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 18 Mar 2022 16:15:18 +0000 Subject: [PATCH 047/172] Update dependency ransack to ~> 2.6.0 --- Gemfile | 2 +- Gemfile.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 6fb2562b0..2e728f99f 100644 --- a/Gemfile +++ b/Gemfile @@ -19,7 +19,7 @@ gem 'figaro', '~> 1.2' gem 'paper_trail', '~> 12.1' gem 'pg', '1.3.3' # 1.8 is for Rails < 5.0 -gem 'ransack', '~> 2.5.0' +gem 'ransack', '~> 2.6.0' gem 'truemail', '~> 2.4' # validates email by regexp, mail server existence and address existence gem 'validates_email_format_of', '1.6.3' # validates email against RFC 2822 and RFC 3696 diff --git a/Gemfile.lock b/Gemfile.lock index ceb070f5a..eac8ce4f6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -258,7 +258,7 @@ GEM httpi (2.4.5) rack socksify - i18n (1.8.11) + i18n (1.10.0) concurrent-ruby (~> 1.0) i18n_data (0.13.0) isikukood (0.1.2) @@ -406,9 +406,9 @@ GEM rake (>= 0.13) thor (~> 1.0) rake (13.0.6) - ransack (2.5.0) - activerecord (>= 5.2.4) - activesupport (>= 5.2.4) + ransack (2.6.0) + activerecord (>= 6.0.4) + activesupport (>= 6.0.4) i18n rbtree3 (0.6.0) redis (4.6.0) @@ -524,7 +524,7 @@ GEM wkhtmltopdf-binary (0.12.5.4) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.5.2) + zeitwerk (2.5.4) PLATFORMS ruby @@ -582,7 +582,7 @@ DEPENDENCIES que que-web rails (~> 6.1.4) - ransack (~> 2.5.0) + ransack (~> 2.6.0) rest-client rexml sass-rails From 8babae9a0e94f5f0436415319dae5cd1d3ce096f Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 18 Mar 2022 19:36:36 +0000 Subject: [PATCH 048/172] Update dependency nokogiri to v1.13.2 [SECURITY] --- Gemfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index eac8ce4f6..10ae5358f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -303,7 +303,7 @@ GEM nokogiri (~> 1) rake mini_mime (1.1.1) - mini_portile2 (2.7.1) + mini_portile2 (2.8.0) minitest (5.15.0) monetize (1.9.4) money (~> 6.12) @@ -324,10 +324,10 @@ GEM newrelic_rpm (= 8.1.0) newrelic_rpm (8.1.0) nio4r (2.5.8) - nokogiri (1.13.0) - mini_portile2 (~> 2.7.0) + nokogiri (1.13.3) + mini_portile2 (~> 2.8.0) racc (~> 1.4) - nokogiri (1.13.0-x86_64-linux) + nokogiri (1.13.3-x86_64-linux) racc (~> 1.4) nori (2.6.0) omniauth (1.9.1) From 58db467229621ffa8eaed7f92b384a1b61c82ab7 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 21 Mar 2022 11:15:17 +0200 Subject: [PATCH 049/172] update validation of email when domain contacts are updated --- app/interactions/actions/domain_update.rb | 23 ++++++++++--------- .../repp/v1/domains/contacts_test.rb | 10 +++++++- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/interactions/actions/domain_update.rb b/app/interactions/actions/domain_update.rb index bc43476e3..c610e0117 100644 --- a/app/interactions/actions/domain_update.rb +++ b/app/interactions/actions/domain_update.rb @@ -46,7 +46,7 @@ module Actions domain.add_epp_error('2306', nil, nil, %i[registrant cannot_be_missing]) unless params[:registrant][:code] contact_code = params[:registrant][:code] - contact = Contact.find_by_code(contact_code) + contact = Contact.find_by(code: contact_code) validate_email(contact.email) regt = Registrant.find_by(code: params[:registrant][:code]) @@ -124,6 +124,15 @@ module Actions @dnskeys << { id: dnkey.id, _destroy: 1 } if dnkey end + def start_validate_email(props) + contact_code = props[0][:contact_code_cache] + contact = Contact.find_by(code: contact_code) + + return if contact.nil? + + validate_email(contact.email) + end + def validate_email(email) return true if Rails.env.test? @@ -142,11 +151,7 @@ module Actions def assign_admin_contact_changes props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'admin' }) - if props.present? - contact_code = props[0][:contact_code_cache] - contact = Contact.find_by_code(contact_code) - validate_email(contact.email) - end + start_validate_email(props) if props.present? if props.any? && domain.admin_change_prohibited? domain.add_epp_error('2304', 'admin', DomainStatus::SERVER_ADMIN_CHANGE_PROHIBITED, @@ -161,11 +166,7 @@ module Actions props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'tech' }, admin: false) - if props.present? - contact_code = props[0][:contact_code_cache] - contact = Contact.find_by_code(contact_code) - validate_email(contact.email) - end + start_validate_email(props) if props.present? if props.any? && domain.tech_change_prohibited? domain.add_epp_error('2304', 'tech', DomainStatus::SERVER_TECH_CHANGE_PROHIBITED, diff --git a/test/integration/repp/v1/domains/contacts_test.rb b/test/integration/repp/v1/domains/contacts_test.rb index b9b26a745..17f8f1f6b 100644 --- a/test/integration/repp/v1/domains/contacts_test.rb +++ b/test/integration/repp/v1/domains/contacts_test.rb @@ -52,6 +52,8 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest end def test_can_remove_admin_contacts + Spy.on_instance_method(Actions::DomainUpdate, :validate_email).and_return(true) + contact = contacts(:john) payload = { contacts: [ { code: contact.code, type: 'admin' } ] } post "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload @@ -68,6 +70,8 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest end def test_can_remove_tech_contacts + Spy.on_instance_method(Actions::DomainUpdate, :validate_email).and_return(true) + contact = contacts(:john) payload = { contacts: [ { code: contact.code, type: 'tech' } ] } post "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload @@ -77,6 +81,9 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest delete "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload json = JSON.parse(response.body, symbolize_names: true) + @domain.reload + contact.reload + assert_response :ok assert_equal 1000, json[:code] @@ -84,6 +91,8 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest end def test_can_not_remove_one_and_only_contact + Spy.on_instance_method(Actions::DomainUpdate, :validate_email).and_return(true) + contact = @domain.admin_contacts.last payload = { contacts: [ { code: contact.code, type: 'admin' } ] } @@ -96,5 +105,4 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest assert @domain.admin_contacts.any? end - end From 5c842a3100e941926318ea0693b032d672b3696d Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Mon, 21 Mar 2022 15:23:24 +0200 Subject: [PATCH 050/172] Add status notes data at the XML element --- app/views/epp/domains/info.xml.builder | 2 +- app/views/registrar/domains/partials/_statuses.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/epp/domains/info.xml.builder b/app/views/epp/domains/info.xml.builder index b154752e9..cc2190dc4 100644 --- a/app/views/epp/domains/info.xml.builder +++ b/app/views/epp/domains/info.xml.builder @@ -11,7 +11,7 @@ xml.epp_head do xml.tag!('domain:name', @domain.name) xml.tag!('domain:roid', @domain.roid) @domain.statuses.each do |s| - xml.tag!('domain:status', 's' => s) + xml.tag!('domain:status', @domain.status_notes[s], 's' => s) end xml.tag!('domain:registrant', @domain.registrant.code) diff --git a/app/views/registrar/domains/partials/_statuses.haml b/app/views/registrar/domains/partials/_statuses.haml index 57ecc4105..125309caf 100644 --- a/app/views/registrar/domains/partials/_statuses.haml +++ b/app/views/registrar/domains/partials/_statuses.haml @@ -6,7 +6,7 @@ %thead %tr %th{class: 'col-xs-6'}= t(:status) - %th{class: 'col-xs-6'}= t(:description) + %th{class: 'col-xs-6'}= t(:notes) %tbody - @data.css('status').each do |x| %tr From af82916d24e04a817aea096530b95f1ada2c22ca Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 22 Mar 2022 11:24:14 +0200 Subject: [PATCH 051/172] Improve select dropdown on new invoices --- app/controllers/admin/invoices_controller.rb | 4 ++-- app/views/admin/invoices/new.haml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/invoices_controller.rb b/app/controllers/admin/invoices_controller.rb index 68db492d8..223257605 100644 --- a/app/controllers/admin/invoices_controller.rb +++ b/app/controllers/admin/invoices_controller.rb @@ -7,8 +7,8 @@ module Admin end def create - r = Registrar.find_by(id: deposit_params[:registrar_id]) - @deposit = Deposit.new(deposit_params.merge(registrar: r)) + registrar = Registrar.find(deposit_params[:registrar_id]) + @deposit = Deposit.new(deposit_params.merge(registrar: registrar)) @invoice = @deposit.issue_prepayment_invoice if @invoice&.persisted? diff --git a/app/views/admin/invoices/new.haml b/app/views/admin/invoices/new.haml index 920b11903..b368cf479 100644 --- a/app/views/admin/invoices/new.haml +++ b/app/views/admin/invoices/new.haml @@ -12,7 +12,7 @@ .col-md-4.control-label = f.label :registrar_id, class: 'required' .col-md-8 - = f.select :registrar_id, Registrar.all.map { |r| [r.name, r.id] }, { include_blank: true }, class: 'form-control selectize', required: true + = select_tag '[deposit][registrar_id]', options_for_select(Registrar.all.map { |r| [r.name, r.id] }), { prompt: t(:choose), required: true, class: 'form-control js-combobox' } .form-group .col-md-4.control-label From d59b1e0fa7a67d52d2a1532dc220a6633dcd6853 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 22 Mar 2022 11:44:30 +0200 Subject: [PATCH 052/172] Fix params format --- app/views/admin/invoices/new.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/invoices/new.haml b/app/views/admin/invoices/new.haml index b368cf479..f688cfe04 100644 --- a/app/views/admin/invoices/new.haml +++ b/app/views/admin/invoices/new.haml @@ -12,7 +12,7 @@ .col-md-4.control-label = f.label :registrar_id, class: 'required' .col-md-8 - = select_tag '[deposit][registrar_id]', options_for_select(Registrar.all.map { |r| [r.name, r.id] }), { prompt: t(:choose), required: true, class: 'form-control js-combobox' } + = select_tag 'deposit[registrar_id]', options_for_select(Registrar.all.map { |r| [r.name, r.id] }), { prompt: t(:choose), required: true, class: 'form-control js-combobox' } .form-group .col-md-4.control-label From db012dd7da078851d301c1f77fb52e7d918f8460 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 11 Mar 2022 10:27:10 +0200 Subject: [PATCH 053/172] business registry contacts - endpoints for send status of contacts and receive confirmation --- .gitignore | 1 + .ruby-version | 2 +- .../api/v1/registrant/contacts_controller.rb | 11 ++ app/models/registrant_user.rb | 32 +++- config/routes.rb | 5 +- db/structure.sql | 160 ++++++++++++++++-- test/models/registrant_user_test.rb | 6 +- 7 files changed, 188 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 3f23f1277..1c4a85f46 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /config/application.yml /config/environments/development.rb /config/deploy.rb +/config/master.key /.idea # Do not commit one. Instead, download the latest from https://github.com/internetee/style-guide. diff --git a/.ruby-version b/.ruby-version index 94ff29cc4..75a22a26a 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.1 +3.0.3 diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index 30096ab8a..8e8b46631 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -34,6 +34,17 @@ module Api end end + def do_need_update_contact + result = current_registrant_user.do_need_update_contact? + render json: { update_contacts: result[:result], counter: result[:counter] } + end + + def update_company_contacts + companies = current_registrant_user.update_company_contacts + + render json: { message: 'get it', companies: companies } + end + def update logger.debug 'Received update request' logger.debug params diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index 5fe508125..b60a1b1a7 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -20,16 +20,34 @@ class RegistrantUser < User def companies(company_register = CompanyRegister::Client.new) return [] if ident.include?('-') - companies = company_register.representation_rights(citizen_personal_code: ident, - citizen_country_code: country.alpha3) - - companies = update_contacts_before_receive(companies) - companies + company_register.representation_rights(citizen_personal_code: ident, + citizen_country_code: country.alpha3) rescue CompanyRegister::NotAvailableError - return [] + [] end - def update_contacts_before_receive(companies) + def do_need_update_contact? + return { result: false, counter: 0 } if companies.blank? + + counter = 0 + companies.each do |company| + contacts = Contact.where(ident: company.registration_number, ident_country_code: 'EE') + + next if contacts.blank? + + contacts.each do |contact| + next if company.company_name == contact.name + + counter += 1 + end + end + + return { result: true, counter: counter } if counter.positive? + + { result: false, counter: 0 } + end + + def update_company_contacts return [] if companies.blank? companies.each do |company| diff --git a/config/routes.rb b/config/routes.rb index 66debd4b4..79807729a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -128,7 +128,10 @@ Rails.application.routes.draw do resources :domains, only: %i[index show], param: :uuid do resource :registry_lock, only: %i[create destroy] end - resources :contacts, only: %i[index show update], param: :uuid + resources :contacts, only: %i[index show update], param: :uuid do + get 'do_need_update_contact', to: 'contacts#do_need_update_contact', as: :do_need_update_contact + post 'update_company_contacts', to: 'contacts#update_company_contacts', as: :update_company_contacts + end resources :companies, only: %i[index] end diff --git a/db/structure.sql b/db/structure.sql index 5b842d4a4..0c8420f43 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -51,6 +51,20 @@ CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA public; COMMENT ON EXTENSION hstore IS 'data type for storing sets of (key, value) pairs'; +-- +-- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public; + + +-- +-- Name: EXTENSION pg_stat_statements; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION pg_stat_statements IS 'track execution statistics of all SQL statements executed'; + + -- -- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: - -- @@ -202,6 +216,8 @@ CREATE FUNCTION public.generate_zonefile(i_origin character varying) RETURNS tex SET default_tablespace = ''; +SET default_with_oids = false; + -- -- Name: account_activities; Type: TABLE; Schema: public; Owner: - -- @@ -809,7 +825,9 @@ CREATE TABLE public.dnskeys ( creator_str character varying, updator_str character varying, legacy_domain_id integer, - updated_at timestamp without time zone + updated_at timestamp without time zone, + validation_datetime timestamp without time zone, + failed_validation_reason character varying ); @@ -936,6 +954,7 @@ CREATE TABLE public.domains ( pending_json jsonb, force_delete_date date, statuses character varying[], + status_notes public.hstore, statuses_before_force_delete character varying[] DEFAULT '{}'::character varying[], upid integer, up_date timestamp without time zone, @@ -943,8 +962,7 @@ CREATE TABLE public.domains ( locked_by_registrant_at timestamp without time zone, force_delete_start timestamp without time zone, force_delete_data public.hstore, - json_statuses_history jsonb, - status_notes public.hstore + json_statuses_history jsonb ); @@ -1177,6 +1195,7 @@ CREATE TABLE public.invoices ( buyer_vat_no character varying, issue_date date NOT NULL, e_invoice_sent_at timestamp without time zone, + payment_link character varying, CONSTRAINT invoices_due_date_is_not_before_issue_date CHECK ((due_date >= issue_date)) ); @@ -2263,6 +2282,74 @@ CREATE SEQUENCE public.payment_orders_id_seq ALTER SEQUENCE public.payment_orders_id_seq OWNED BY public.payment_orders.id; +-- +-- Name: pghero_query_stats; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.pghero_query_stats ( + id bigint NOT NULL, + database text, + "user" text, + query text, + query_hash bigint, + total_time double precision, + calls bigint, + captured_at timestamp without time zone +); + + +-- +-- Name: pghero_query_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.pghero_query_stats_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: pghero_query_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.pghero_query_stats_id_seq OWNED BY public.pghero_query_stats.id; + + +-- +-- Name: pghero_space_stats; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.pghero_space_stats ( + id bigint NOT NULL, + database text, + schema text, + relation text, + size bigint, + captured_at timestamp without time zone +); + + +-- +-- Name: pghero_space_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.pghero_space_stats_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: pghero_space_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.pghero_space_stats_id_seq OWNED BY public.pghero_space_stats.id; + + -- -- Name: prices; Type: TABLE; Schema: public; Owner: - -- @@ -2623,8 +2710,7 @@ CREATE TABLE public.validation_events ( validation_eventable_type character varying, validation_eventable_id bigint, created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL, - event_type public.validation_type + updated_at timestamp(6) without time zone NOT NULL ); @@ -3166,6 +3252,20 @@ ALTER TABLE ONLY public.notifications ALTER COLUMN id SET DEFAULT nextval('publi ALTER TABLE ONLY public.payment_orders ALTER COLUMN id SET DEFAULT nextval('public.payment_orders_id_seq'::regclass); +-- +-- Name: pghero_query_stats id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.pghero_query_stats ALTER COLUMN id SET DEFAULT nextval('public.pghero_query_stats_id_seq'::regclass); + + +-- +-- Name: pghero_space_stats id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.pghero_space_stats ALTER COLUMN id SET DEFAULT nextval('public.pghero_space_stats_id_seq'::regclass); + + -- -- Name: prices id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3689,6 +3789,22 @@ ALTER TABLE ONLY public.payment_orders ADD CONSTRAINT payment_orders_pkey PRIMARY KEY (id); +-- +-- Name: pghero_query_stats pghero_query_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.pghero_query_stats + ADD CONSTRAINT pghero_query_stats_pkey PRIMARY KEY (id); + + +-- +-- Name: pghero_space_stats pghero_space_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.pghero_space_stats + ADD CONSTRAINT pghero_space_stats_pkey PRIMARY KEY (id); + + -- -- Name: prices prices_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -4459,6 +4575,20 @@ CREATE INDEX index_notifications_on_registrar_id ON public.notifications USING b CREATE INDEX index_payment_orders_on_invoice_id ON public.payment_orders USING btree (invoice_id); +-- +-- Name: index_pghero_query_stats_on_database_and_captured_at; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_pghero_query_stats_on_database_and_captured_at ON public.pghero_query_stats USING btree (database, captured_at); + + +-- +-- Name: index_pghero_space_stats_on_database_and_captured_at; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_pghero_space_stats_on_database_and_captured_at ON public.pghero_space_stats USING btree (database, captured_at); + + -- -- Name: index_prices_on_zone_id; Type: INDEX; Schema: public; Owner: - -- @@ -4515,13 +4645,6 @@ CREATE INDEX index_users_on_registrar_id ON public.users USING btree (registrar_ CREATE INDEX index_validation_events_on_event_data ON public.validation_events USING gin (event_data); --- --- Name: index_validation_events_on_event_type; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_validation_events_on_event_type ON public.validation_events USING btree (event_type); - - -- -- Name: index_validation_events_on_validation_eventable; Type: INDEX; Schema: public; Owner: - -- @@ -5267,15 +5390,20 @@ INSERT INTO "schema_migrations" (version) VALUES ('20210708131814'), ('20210729131100'), ('20210729134625'), -('20210827185249'), -('20211029073644'), +('20211028122103'), +('20211028125245'), +('20211029082225'), ('20211124071418'), +('20211124084308'), ('20211125181033'), ('20211125184334'), ('20211126085139'), +('20211231113934'), ('20220106123143'), ('20220113201642'), -('20220113220809'); - +('20220113220809'), +('20220124105717'), +('20220216113112'), +('20220228093211'); diff --git a/test/models/registrant_user_test.rb b/test/models/registrant_user_test.rb index 987e80c03..99618642a 100644 --- a/test/models/registrant_user_test.rb +++ b/test/models/registrant_user_test.rb @@ -41,10 +41,8 @@ class RegistrantUserTest < ActiveSupport::TestCase company = Company.new(org.ident, "ace") - company_register = Minitest::Mock.new - company_register.expect(:representation_rights, [company], [{ citizen_personal_code: '1234', - citizen_country_code: 'USA' }]) - @user.companies(company_register) + Spy.on(@user, :companies).and_return([company]) + @user.update_company_contacts org.reload assert_equal org.name, company.company_name From cee5f34bd8cd7ac46ec42ab690a7244c65afe579 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Wed, 23 Mar 2022 14:48:41 +0200 Subject: [PATCH 054/172] Remove legacy migration jobs --- ...igrate_before_force_delete_statuses_job.rb | 36 ------------------- .../migrate_statuses_to_domain_history_job.rb | 36 ------------------- lib/tasks/migrate_domain_statuses.rake | 10 ------ ...e_before_force_delete_statuses_job_test.rb | 27 -------------- ...ate_statuses_to_domain_history_job_test.rb | 22 ------------ 5 files changed, 131 deletions(-) delete mode 100644 app/jobs/migrate_before_force_delete_statuses_job.rb delete mode 100644 app/jobs/migrate_statuses_to_domain_history_job.rb delete mode 100644 lib/tasks/migrate_domain_statuses.rake delete mode 100644 test/jobs/migrate_before_force_delete_statuses_job_test.rb delete mode 100644 test/jobs/migrate_statuses_to_domain_history_job_test.rb diff --git a/app/jobs/migrate_before_force_delete_statuses_job.rb b/app/jobs/migrate_before_force_delete_statuses_job.rb deleted file mode 100644 index 7e6a1e1c0..000000000 --- a/app/jobs/migrate_before_force_delete_statuses_job.rb +++ /dev/null @@ -1,36 +0,0 @@ -class MigrateBeforeForceDeleteStatusesJob < ApplicationJob - def perform - logger.info 'Ran MigrateBeforeForceDeleteStatusesJob!' - - domains = Domain.where.not(statuses_before_force_delete: nil) - logger.info "Total domains are #{domains.count}" - - interate_domain_in_batches(domains) - end - - private - - def interate_domain_in_batches(domains) - count = 0 - - domains.find_in_batches do |domain_batches| - count += domain_batches.count - logger.info "Proccesing #{count} domains of #{domains.count}" - domain_batches.each do |domain| - migrate_data_to_statuses_history(domain) - end - end - end - - def migrate_data_to_statuses_history(domain) - domain.update(force_delete_domain_statuses_history: domain.statuses_before_force_delete) - rescue StandardError => e - logger.warn "#{domain.name} crashed!" - logger.warn e.to_s - raise e - end - - def logger - @logger ||= Logger.new(Rails.root.join('log/migrate_before_force_delete_statuses.log')) - end -end diff --git a/app/jobs/migrate_statuses_to_domain_history_job.rb b/app/jobs/migrate_statuses_to_domain_history_job.rb deleted file mode 100644 index f35c986b6..000000000 --- a/app/jobs/migrate_statuses_to_domain_history_job.rb +++ /dev/null @@ -1,36 +0,0 @@ -class MigrateStatusesToDomainHistoryJob < ApplicationJob - def perform - logger.info 'Ran MigrateStatusesToDomainHistoryJob!' - - domains = Domain.where(locked_by_registrant_at: nil) - logger.info "Total domains are #{domains.count}" - - interate_domain_in_batches(domains) - end - - private - - def interate_domain_in_batches(domains) - count = 0 - - domains.find_in_batches do |domain_batches| - count += domain_batches.count - logger.info "Proccesing #{count} domains of #{domains.count}" - domain_batches.each do |domain| - migrate_data_to_admin_store_field(domain) - end - end - end - - def migrate_data_to_admin_store_field(domain) - domain.update(admin_store_statuses_history: domain.statuses) - rescue StandardError => e - logger.warn "#{domain.name} crashed!" - logger.warn e.to_s - raise e - end - - def logger - @logger ||= Logger.new(Rails.root.join('log/migrate_statuses_to_domain_history.log')) - end -end diff --git a/lib/tasks/migrate_domain_statuses.rake b/lib/tasks/migrate_domain_statuses.rake deleted file mode 100644 index 8c68f9e70..000000000 --- a/lib/tasks/migrate_domain_statuses.rake +++ /dev/null @@ -1,10 +0,0 @@ -namespace :migrate_domain_statuses do - desc 'Starts collect invalid validation contacts' - task fd_domains: :environment do - MigrateBeforeForceDeleteStatusesJob.perform_later - end - - task admin_status_history: :environment do - MigrateStatusesToDomainHistoryJob.perform_later - end -end diff --git a/test/jobs/migrate_before_force_delete_statuses_job_test.rb b/test/jobs/migrate_before_force_delete_statuses_job_test.rb deleted file mode 100644 index 0288a686c..000000000 --- a/test/jobs/migrate_before_force_delete_statuses_job_test.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'test_helper' - -class MigrateBeforeForceDeleteStatusesJobTest < ActiveJob::TestCase - setup do - travel_to Time.zone.parse('2010-07-05') - @domain = domains(:shop) - end - - def test_migrate_data_before_force_delete - @domain.update(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) - @domain.reload - assert @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED - - @domain.schedule_force_delete(type: :soft) - @domain.reload - - assert @domain.force_delete_scheduled? - - perform_enqueued_jobs do - MigrateBeforeForceDeleteStatusesJob.perform_later - end - - @domain.reload - - assert @domain.force_delete_domain_statuses_history.include? DomainStatus::SERVER_UPDATE_PROHIBITED - end -end diff --git a/test/jobs/migrate_statuses_to_domain_history_job_test.rb b/test/jobs/migrate_statuses_to_domain_history_job_test.rb deleted file mode 100644 index dcacc327a..000000000 --- a/test/jobs/migrate_statuses_to_domain_history_job_test.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'test_helper' - -class MigrateBeforeForceDeleteStatusesJobTest < ActiveJob::TestCase - setup do - travel_to Time.zone.parse('2010-07-05') - @domain = domains(:shop) - end - - def test_migrate_statuses_to_domain_history_job - @domain.update(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) - @domain.reload - assert @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED - - perform_enqueued_jobs do - MigrateStatusesToDomainHistoryJob.perform_later - end - - @domain.reload - - assert @domain.admin_store_statuses_history.include? DomainStatus::SERVER_UPDATE_PROHIBITED - end -end From 85ac6c95f2a590369aee1cc142d7375a6d420213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Thu, 24 Mar 2022 16:27:16 +0200 Subject: [PATCH 055/172] Updated sidekiq gem version --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 2e728f99f..5aae015ba 100644 --- a/Gemfile +++ b/Gemfile @@ -70,7 +70,7 @@ gem 'jquery-ui-rails', '6.0.1' gem 'pdfkit' gem 'que' gem 'que-web' -gem 'sidekiq' +gem 'sidekiq', '>= 6.4.1' gem 'company_register', github: 'internetee/company_register', branch: 'master' diff --git a/Gemfile.lock b/Gemfile.lock index 10ae5358f..4c544c441 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -449,7 +449,7 @@ GEM selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) - sidekiq (6.4.0) + sidekiq (6.4.1) connection_pool (>= 2.2.2) rack (~> 2.0) redis (>= 4.2.0) @@ -588,7 +588,7 @@ DEPENDENCIES sass-rails select2-rails (= 4.0.13) selectize-rails (= 0.12.6) - sidekiq + sidekiq (>= 6.4.1) simplecov (= 0.17.1) simpleidn (= 0.2.1) spy @@ -601,4 +601,4 @@ DEPENDENCIES wkhtmltopdf-binary (~> 0.12.5.1) BUNDLED WITH - 2.2.31 + 2.3.9 From 71655c429230ee7623758065361485762ea91567 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 25 Mar 2022 11:56:12 +0200 Subject: [PATCH 056/172] refactored method which display count of contact --- app/models/registrant_user.rb | 11 ++-------- test/models/registrant_user_test.rb | 33 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index b60a1b1a7..80b8ecab9 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -31,15 +31,8 @@ class RegistrantUser < User counter = 0 companies.each do |company| - contacts = Contact.where(ident: company.registration_number, ident_country_code: 'EE') - - next if contacts.blank? - - contacts.each do |contact| - next if company.company_name == contact.name - - counter += 1 - end + counter += Contact.where(ident: company.registration_number, ident_country_code: 'EE')&. + reject { |contact| contact.name == company.company_name }.size end return { result: true, counter: counter } if counter.positive? diff --git a/test/models/registrant_user_test.rb b/test/models/registrant_user_test.rb index 99618642a..2b1d6a880 100644 --- a/test/models/registrant_user_test.rb +++ b/test/models/registrant_user_test.rb @@ -61,6 +61,39 @@ class RegistrantUserTest < ActiveSupport::TestCase company_register.verify end + def test_should_return_zero_count_of_companies + assert_equal 'US-1234', @user.registrant_ident + org = contacts(:acme_ltd) + org.ident_country_code = 'EE' + org.save(validate: false) + org.reload + + company_one = Company.new(org.ident, 'Acme Ltd') + + Spy.on(@user, :companies).and_return([company_one]) + response = @user.do_need_update_contact? + org.reload + + assert_equal response[:counter], 0 + end + + def test_should_return_count_of_contact_which_should_be_updated + assert_equal 'US-1234', @user.registrant_ident + org = contacts(:acme_ltd) + org.ident_country_code = 'EE' + org.save(validate: false) + org.reload + + company_one = Company.new(org.ident, 'ace') + company_two = Company.new(org.ident, 'acer') + + Spy.on(@user, :companies).and_return([company_one, company_two]) + response = @user.do_need_update_contact? + org.reload + + assert_equal response[:counter], 2 + end + def test_returns_contacts Contact.stub(:registrant_user_contacts, %w(john jane)) do assert_equal %w(john jane), @user.contacts From e2d59085c755c483d34a610fcbae64d62e1c2c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Fri, 25 Mar 2022 13:50:28 +0200 Subject: [PATCH 057/172] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0305aff95..57ff0b10e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +25.03.2022 +* Bulk change of business contacts' names requires now user confirmation (#2309)[https://github.com/internetee/registry/pull/2309] + 23.02.2022 * FD notes are updated when basis for FD changes [#2216](https://github.com/internetee/registry/issues/2216) * Admin: date filter end date in domain hostory is now inclusive [#2274](https://github.com/internetee/registry/issues/2274) From 48911b18b7c4beb5b0cac27400230beac16c74b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Fri, 25 Mar 2022 13:52:51 +0200 Subject: [PATCH 058/172] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57ff0b10e..a97c8f366 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ 25.03.2022 -* Bulk change of business contacts' names requires now user confirmation (#2309)[https://github.com/internetee/registry/pull/2309] +* Bulk change of business contacts' names requires now user confirmation [#2309](https://github.com/internetee/registry/pull/2309) 23.02.2022 * FD notes are updated when basis for FD changes [#2216](https://github.com/internetee/registry/issues/2216) From e4d56fe576622e1ab5d248ee91a79968b2422922 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 25 Mar 2022 13:03:54 +0000 Subject: [PATCH 059/172] Update dependency pg to v1.3.4 --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 2e728f99f..9b1981376 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,7 @@ gem 'figaro', '~> 1.2' # model related gem 'paper_trail', '~> 12.1' -gem 'pg', '1.3.3' +gem 'pg', '1.3.4' # 1.8 is for Rails < 5.0 gem 'ransack', '~> 2.6.0' gem 'truemail', '~> 2.4' # validates email by regexp, mail server existence and address existence diff --git a/Gemfile.lock b/Gemfile.lock index 10ae5358f..02034696a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -351,7 +351,7 @@ GEM activerecord (>= 5.2) request_store (~> 1.1) pdfkit (0.8.5) - pg (1.3.3) + pg (1.3.4) pg_query (2.1.2) google-protobuf (>= 3.17.1) pghero (2.8.1) @@ -574,7 +574,7 @@ DEPENDENCIES omniauth-tara! paper_trail (~> 12.1) pdfkit - pg (= 1.3.3) + pg (= 1.3.4) pg_query (>= 0.9.0) pghero pry (= 0.14.1) From 216048463d5f7e320a0334ba56cad0a1d9777315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Mon, 21 Mar 2022 09:10:34 +0200 Subject: [PATCH 060/172] Moved notifications about automatic contact name update to bulk change poll message --- app/models/ability.rb | 2 +- app/models/action.rb | 25 ++++- app/models/bulk_action.rb | 2 + app/models/epp/contact.rb | 2 +- app/models/notification.rb | 2 +- app/models/registrant_user.rb | 16 +-- app/models/registrar.rb | 11 ++- app/views/epp/contacts/check.xml.builder | 10 +- .../epp/contacts/partials/_check.xml.builder | 9 ++ app/views/epp/poll/_action.xml.builder | 5 +- app/views/epp/poll/poll_req.xml.builder | 19 +++- config/locales/notifications.en.yml | 1 + db/migrate/20220316140727_add_bulk_actions.rb | 5 + db/structure.sql | 7 +- test/fixtures/actions.yml | 22 ++++- .../epp/contact/check/base_test.rb | 6 +- test/integration/epp/poll_test.rb | 98 +++++++++---------- .../registrant_user_creation_test.rb | 55 ++++++++--- 18 files changed, 201 insertions(+), 96 deletions(-) create mode 100644 app/models/bulk_action.rb create mode 100644 app/views/epp/contacts/partials/_check.xml.builder create mode 100644 db/migrate/20220316140727_add_bulk_actions.rb diff --git a/app/models/ability.rb b/app/models/ability.rb index baa26e4cb..caca24524 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -12,7 +12,7 @@ class Ability @user.roles&.each { |role| send(role) } when 'ApiUser' @user.roles&.each { |role| send(role) } - when 'RegistrantUser' + when 'RegistrantUser' static_registrant end diff --git a/app/models/action.rb b/app/models/action.rb index ac5ee7f72..12435f3f0 100644 --- a/app/models/action.rb +++ b/app/models/action.rb @@ -2,18 +2,37 @@ class Action < ApplicationRecord has_paper_trail versions: { class_name: 'Version::ActionVersion' } belongs_to :user - belongs_to :contact + belongs_to :contact, optional: true + has_many :subactions, class_name: 'Action', foreign_key: 'bulk_action_id', dependent: :destroy + belongs_to :bulk_action, class_name: 'Action', optional: true validates :operation, inclusion: { in: proc { |action| action.class.valid_operations } } class << self def valid_operations - %w[update] + %w[update bulk_update] end end def notification_key - raise 'Action object is missing' unless contact + raise 'Action object is missing' unless bulk_action? || contact + "contact_#{operation}".to_sym end + + def bulk_action? + !!subactions.exists? + end + + def to_non_available_contact_codes + return [] unless bulk_action? + + subactions.map do |a| + { + code: a.contact&.code, + avail: 0, + reason: 'in use', + } + end + end end diff --git a/app/models/bulk_action.rb b/app/models/bulk_action.rb new file mode 100644 index 000000000..1a8cad771 --- /dev/null +++ b/app/models/bulk_action.rb @@ -0,0 +1,2 @@ +class BulkAction < Action +end \ No newline at end of file diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 614be201b..35691d789 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -47,7 +47,7 @@ class Epp::Contact < Contact codes = codes.map { |c| c.include?(':') ? c : "#{reg}:#{c}" } res = [] - codes.map { |c| c.include?(':') ? c : "#{reg}:#{c}" }.map { |c| c.strip.upcase }.each do |x| + codes.map { |c| c.strip.upcase }.each do |x| c = find_by_epp_code(x) res << (c ? { code: c.code, avail: 0, reason: 'in use' } : { code: x, avail: 1 }) end diff --git a/app/models/notification.rb b/app/models/notification.rb index 07e824367..c9af66c56 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -2,7 +2,7 @@ class Notification < ApplicationRecord include Versions # version/notification_version.rb belongs_to :registrar - belongs_to :action + belongs_to :action, optional: true scope :unread, -> { where(read: false) } diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index 80b8ecab9..a1f6993af 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -112,13 +112,17 @@ class RegistrantUser < User end def update_related_contacts - contacts = Contact.where(ident: ident, ident_country_code: country.alpha2) + grouped_contacts = Contact.where(ident: ident, ident_country_code: country.alpha2) .where('UPPER(name) != UPPER(?)', username) - - contacts.each do |contact| - contact.update(name: username) - action = actions.create!(contact: contact, operation: :update) - contact.registrar.notify(action) + .includes(:registrar).group_by { |c| c.registrar } + grouped_contacts.each do |registrar, contacts| + bulk_action, action = actions.create!(operation: :bulk_update) if contacts.size > 1 + contacts.each do |c| + if c.update(name: username) + action = actions.create!(contact: c, operation: :update, bulk_action_id: bulk_action&.id) + end + end + registrar.notify(bulk_action || action) end end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 8517bd6fe..d7ba62306 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -218,8 +218,15 @@ class Registrar < ApplicationRecord end def notify(action) - text = I18n.t("notifications.texts.#{action.notification_key}", contact: action.contact.code) - notifications.create!(text: text) + text = I18n.t("notifications.texts.#{action.notification_key}", contact: action.contact&.code, + count: action.subactions&.count) + if action.bulk_action? + notifications.create!(text: text, action_id: action.id, + attached_obj_type: 'BulkAction', + attached_obj_id: action.id) + else + notifications.create!(text: text) + end end def e_invoice_iban diff --git a/app/views/epp/contacts/check.xml.builder b/app/views/epp/contacts/check.xml.builder index 6b4ea4cc7..f3b1f555a 100644 --- a/app/views/epp/contacts/check.xml.builder +++ b/app/views/epp/contacts/check.xml.builder @@ -5,15 +5,7 @@ xml.epp_head do end xml.resData do - xml.tag!('contact:chkData', 'xmlns:contact' => - Xsd::Schema.filename(for_prefix: 'contact-ee', for_version: '1.1')) do - @results.each do |result| - xml.tag!('contact:cd') do - xml.tag! "contact:id", result[:code], avail: result[:avail] - xml.tag!('contact:reason', result[:reason]) unless result[:avail] == 1 - end - end - end + xml << render('epp/contacts/partials/check', builder: xml, results: @results) end render('epp/shared/trID', builder: xml) diff --git a/app/views/epp/contacts/partials/_check.xml.builder b/app/views/epp/contacts/partials/_check.xml.builder new file mode 100644 index 000000000..70bb1f4e3 --- /dev/null +++ b/app/views/epp/contacts/partials/_check.xml.builder @@ -0,0 +1,9 @@ +builder.tag!('contact:chkData', 'xmlns:contact' => + Xsd::Schema.filename(for_prefix: 'contact-ee', for_version: '1.1')) do + results.each do |result| + builder.tag!('contact:cd') do + builder.tag! 'contact:id', result[:code], avail: result[:avail] + # builder.tag!('contact:reason', result[:reason]) unless result[:avail] == 1 + end + end +end diff --git a/app/views/epp/poll/_action.xml.builder b/app/views/epp/poll/_action.xml.builder index dc0adb4e4..838ae9aaf 100644 --- a/app/views/epp/poll/_action.xml.builder +++ b/app/views/epp/poll/_action.xml.builder @@ -1,9 +1,12 @@ builder.extension do builder.tag!('changePoll:changeData', - 'xmlns:changePoll' => Xsd::Schema.filename(for_prefix: 'changePoll')) do + 'xmlns:changePoll' => Xsd::Schema.filename(for_prefix: 'changePoll', for_version: '1.0')) do builder.tag!('changePoll:operation', action.operation) builder.tag!('changePoll:date', action.created_at.utc.xmlschema) builder.tag!('changePoll:svTRID', action.id) builder.tag!('changePoll:who', action.user) + if action.bulk_action? + builder.tag!('changePoll:reason', 'Auto-update according to official data') + end end end diff --git a/app/views/epp/poll/poll_req.xml.builder b/app/views/epp/poll/poll_req.xml.builder index a1f12fd65..f6688fb48 100644 --- a/app/views/epp/poll/poll_req.xml.builder +++ b/app/views/epp/poll/poll_req.xml.builder @@ -9,13 +9,24 @@ xml.epp_head do xml.msg @notification.text end - if @notification.attached_obj_type == 'DomainTransfer' && @object - xml.resData do - xml << render('epp/domains/partials/transfer', builder: xml, dt: @object) + if @object + case @notification.attached_obj_type + when 'DomainTransfer' + xml.resData do + xml << render('epp/domains/partials/transfer', builder: xml, dt: @object) + end + when 'BulkAction' + xml.resData do + xml << render( + 'epp/contacts/partials/check', + builder: xml, + results: @object.to_non_available_contact_codes + ) + end end end - if @notification.action&.contact || @notification.registry_lock? + if @notification.action || @notification.registry_lock? if @notification.registry_lock? state = @notification.text.include?('unlocked') ? 'unlock' : 'lock' xml.extension do diff --git a/config/locales/notifications.en.yml b/config/locales/notifications.en.yml index b5c1dfd47..3bd65ea7e 100644 --- a/config/locales/notifications.en.yml +++ b/config/locales/notifications.en.yml @@ -6,6 +6,7 @@ en: It was associated with registrant %{old_registrant_code} and contacts %{old_contacts_codes}. contact_update: Contact %{contact} has been updated by registrant + contact_bulk_update: '%{count} contacts have been updated by registrant' csync: CSYNC DNSSEC %{action} for domain %{domain} registrar_locked: Domain %{domain_name} has been locked by registrant registrar_unlocked: Domain %{domain_name} has been unlocked by registrant diff --git a/db/migrate/20220316140727_add_bulk_actions.rb b/db/migrate/20220316140727_add_bulk_actions.rb new file mode 100644 index 000000000..1eae94220 --- /dev/null +++ b/db/migrate/20220316140727_add_bulk_actions.rb @@ -0,0 +1,5 @@ +class AddBulkActions < ActiveRecord::Migration[6.1] + def change + add_column :actions, :bulk_action_id, :integer, default: nil + end +end diff --git a/db/structure.sql b/db/structure.sql index 0c8420f43..f55203bb3 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -304,7 +304,8 @@ CREATE TABLE public.actions ( user_id integer, operation character varying NOT NULL, created_at timestamp without time zone, - contact_id integer + contact_id integer, + bulk_action_id integer ); @@ -5400,10 +5401,14 @@ INSERT INTO "schema_migrations" (version) VALUES ('20211126085139'), ('20211231113934'), ('20220106123143'), +<<<<<<< HEAD ('20220113201642'), ('20220113220809'), ('20220124105717'), ('20220216113112'), ('20220228093211'); +======= +('20220316140727'); +>>>>>>> f98598620 (Moved notifications about automatic contact name update to bulk change poll message) diff --git a/test/fixtures/actions.yml b/test/fixtures/actions.yml index 46736e0a1..b802679ba 100644 --- a/test/fixtures/actions.yml +++ b/test/fixtures/actions.yml @@ -2,4 +2,24 @@ contact_update: operation: update contact: john created_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %> - user: registrant \ No newline at end of file + user: registrant + +contacts_update_bulk_action: + operation: bulk_update + user: registrant + +contact_update_subaction_one: + operation: update + contact: william + created_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %> + user: registrant + bulk_action: contacts_update_bulk_action + +contact_update_subaction_two: + operation: update + contact: jane + created_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %> + user: registrant + bulk_action: contacts_update_bulk_action + + diff --git a/test/integration/epp/contact/check/base_test.rb b/test/integration/epp/contact/check/base_test.rb index f1b9f4d16..6ad027fc6 100644 --- a/test/integration/epp/contact/check/base_test.rb +++ b/test/integration/epp/contact/check/base_test.rb @@ -76,7 +76,7 @@ class EppContactCheckBaseTest < EppTestCase response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml assert_equal '0', response_xml.at_xpath('//contact:id', contact: xml_schema)['avail'] - assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text + # assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text end def test_multiple_contacts @@ -127,7 +127,7 @@ class EppContactCheckBaseTest < EppTestCase assert_correct_against_schema response_xml assert_epp_response :completed_successfully assert_equal "#{@contact.registrar.code}:JOHN-001".upcase, response_xml.at_xpath('//contact:id', contact: xml_schema).text - assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text + # assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text end def test_check_contact_without_prefix @@ -154,7 +154,7 @@ class EppContactCheckBaseTest < EppTestCase assert_correct_against_schema response_xml assert_epp_response :completed_successfully assert_equal "#{@contact.registrar.code}:JOHN-001".upcase, response_xml.at_xpath('//contact:id', contact: xml_schema).text - assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text + # assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text end private diff --git a/test/integration/epp/poll_test.rb b/test/integration/epp/poll_test.rb index 5cdb7e524..29c24af26 100644 --- a/test/integration/epp/poll_test.rb +++ b/test/integration/epp/poll_test.rb @@ -7,16 +7,8 @@ class EppPollTest < EppTestCase # Deliberately does not conform to RFC5730, which requires the first notification to be returned def test_return_latest_notification_when_queue_is_not_empty - request_xml = <<-XML - - - - - - - XML - post epp_poll_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + post epp_poll_path, params: { frame: request_req_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } xml_doc = Nokogiri::XML(response.body) assert_epp_response :completed_successfully_ack_to_dequeue @@ -30,17 +22,9 @@ class EppPollTest < EppTestCase version = Version::DomainVersion.last @notification.update(attached_obj_type: 'DomainVersion', attached_obj_id: version.id) - request_xml = <<-XML - - - - - - - XML assert_nothing_raised do - post epp_poll_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + post epp_poll_path, params: { frame: request_req_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end xml_doc = Nokogiri::XML(response.body) @@ -54,19 +38,11 @@ class EppPollTest < EppTestCase def test_return_action_data_when_present @notification.update!(action: actions(:contact_update)) - request_xml = <<-XML - - - - - - - XML - post epp_poll_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + post epp_poll_path, params: { frame: request_req_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } xml_doc = Nokogiri::XML(response.body) - namespace = Xsd::Schema.filename(for_prefix: 'changePoll') + namespace = Xsd::Schema.filename(for_prefix: 'changePoll', for_version: '1.0') assert_equal 'update', xml_doc.xpath('//changePoll:operation', 'changePoll' => namespace).text assert_equal Time.zone.parse('2010-07-05').utc.xmlschema, xml_doc.xpath('//changePoll:date', 'changePoll' => namespace).text @@ -76,19 +52,35 @@ class EppPollTest < EppTestCase 'changePoll' => namespace).text end + def test_return_notifcation_with_bulk_action_data + bulk_action = actions(:contacts_update_bulk_action) + @notification.update!(action: bulk_action, + attached_obj_id: bulk_action.id, + attached_obj_type: 'BulkAction') + + post epp_poll_path, params: { frame: request_req_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + xml_doc = Nokogiri::XML(response.body) + namespace = Xsd::Schema.filename(for_prefix: 'changePoll', for_version: '1.0') + + assert_equal 2, xml_doc.xpath('//contact:cd', contact: xml_schema).size + assert_epp_response :completed_successfully_ack_to_dequeue + assert_equal 'bulk_update', xml_doc.xpath('//changePoll:operation', + 'changePoll' => namespace).text + assert_equal @notification.action.id.to_s, xml_doc.xpath('//changePoll:svTRID', + 'changePoll' => namespace).text + assert_equal 'Registrant User', xml_doc.xpath('//changePoll:who', + 'changePoll' => namespace).text + assert_equal 'Auto-update according to official data', + xml_doc.xpath('//changePoll:reason', 'changePoll' => namespace).text + end + def test_no_notifications registrars(:bestnames).notifications.delete_all(:delete_all) - request_xml = <<-XML - - - - - - - XML - post epp_poll_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + post epp_poll_path, params: { frame: request_req_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } assert_epp_response :completed_successfully_no_messages end @@ -106,7 +98,7 @@ class EppPollTest < EppTestCase XML post epp_poll_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } notification.reload xml_doc = Nokogiri::XML(response.body) @@ -128,7 +120,7 @@ class EppPollTest < EppTestCase XML post epp_poll_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } notification.reload assert notification.unread? @@ -145,13 +137,22 @@ class EppPollTest < EppTestCase XML post epp_poll_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } assert_epp_response :object_does_not_exist end def test_anonymous_user_cannot_access - request_xml = <<-XML + post '/epp/command/poll', params: { frame: request_req_xml }, + headers: { 'HTTP_COOKIE' => 'session=non-existent' } + + assert_epp_response :authorization_error + end + + private + + def request_req_xml + <<-XML @@ -159,10 +160,9 @@ class EppPollTest < EppTestCase XML + end - post '/epp/command/poll', params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=non-existent' } - - assert_epp_response :authorization_error + def xml_schema + Xsd::Schema.filename(for_prefix: 'contact-ee', for_version: '1.1') end end diff --git a/test/models/registrant_user/registrant_user_creation_test.rb b/test/models/registrant_user/registrant_user_creation_test.rb index 9fff4ca02..f183c94dc 100644 --- a/test/models/registrant_user/registrant_user_creation_test.rb +++ b/test/models/registrant_user/registrant_user_creation_test.rb @@ -7,34 +7,40 @@ class RegistrantUserCreationTest < ActiveSupport::TestCase first_name: 'JOHN', last_name: 'SMITH' } - - RegistrantUser.find_or_create_by_api_data(user_data) + assert_difference 'RegistrantUser.count' do + RegistrantUser.find_or_create_by_api_data(user_data) + end user = User.find_by(registrant_ident: 'EE-37710100070') assert_equal('JOHN SMITH', user.username) end - def test_find_or_create_by_api_data_creates_a_user_with_original_name + def test_find_or_create_by_api_data_updates_a_user_with_existing_ident user_data = { - ident: '37710100070', + ident: '1234', + country_code: 'US', first_name: 'John', - last_name: 'Smith' + last_name: 'Smith', } + assert_no_difference 'RegistrantUser.count' do + RegistrantUser.find_or_create_by_api_data(user_data) + end - RegistrantUser.find_or_create_by_api_data(user_data) - - user = User.find_by(registrant_ident: 'EE-37710100070') + user = User.find_by(registrant_ident: 'US-1234') assert_equal('John Smith', user.username) end - def test_updates_related_contacts_name_if_differs_from_e_identity - contact = contacts(:john) - contact.update(ident: '39708290276', ident_country_code: 'EE') + def test_updates_related_contacts_name_if_different_from_e_identity + registrars = [registrars(:bestnames), registrars(:goodnames)] + contacts = [contacts(:john), contacts(:william), contacts(:identical_to_william)] + contacts.each do |c| + c.update(ident: '39708290276', ident_country_code: 'EE') + end user_data = { ident: '39708290276', first_name: 'John', - last_name: 'Doe' + last_name: 'Doe', } RegistrantUser.find_or_create_by_api_data(user_data) @@ -42,7 +48,28 @@ class RegistrantUserCreationTest < ActiveSupport::TestCase user = User.find_by(registrant_ident: 'EE-39708290276') assert_equal('John Doe', user.username) - contact.reload - assert_equal user.username, contact.name + contacts.each do |c| + c.reload + assert_equal user.username, c.name + assert user.actions.find_by(operation: :update, contact_id: c.id) + end + + bulk_action = BulkAction.find_by(user_id: user.id, operation: :bulk_update) + assert_equal 2, bulk_action.subactions.size + + registrars.each do |r| + notification = r.notifications.unread.order('created_at DESC').take + if r == registrars(:bestnames) + assert_equal '2 contacts have been updated by registrant', notification.text + assert_equal 'BulkAction', notification.attached_obj_type + assert_equal bulk_action.id, notification.attached_obj_id + assert_equal bulk_action.id, notification.action_id + else + assert_equal 'Contact william-002 has been updated by registrant', notification.text + refute notification.action_id + refute notification.attached_obj_id + refute notification.attached_obj_type + end + end end end From dadcc9580b2dfc021a663a838a86f66bf8e57851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Mon, 21 Mar 2022 09:49:29 +0200 Subject: [PATCH 061/172] Fixed structure.sql file --- db/structure.sql | 3 --- 1 file changed, 3 deletions(-) diff --git a/db/structure.sql b/db/structure.sql index f55203bb3..56d499289 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -5401,14 +5401,11 @@ INSERT INTO "schema_migrations" (version) VALUES ('20211126085139'), ('20211231113934'), ('20220106123143'), -<<<<<<< HEAD ('20220113201642'), ('20220113220809'), ('20220124105717'), ('20220216113112'), ('20220228093211'); -======= ('20220316140727'); ->>>>>>> f98598620 (Moved notifications about automatic contact name update to bulk change poll message) From f59c6ee5c3bff7cb15bf6f9149596fbf4668619d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Mon, 21 Mar 2022 10:03:21 +0200 Subject: [PATCH 062/172] Updated structure.sql --- .DS_Store | Bin 0 -> 8196 bytes app/.DS_Store | Bin 0 -> 6148 bytes app/controllers/.DS_Store | Bin 0 -> 6148 bytes app/controllers/repp/.DS_Store | Bin 0 -> 6148 bytes app/controllers/repp/v1/.DS_Store | Bin 0 -> 6148 bytes .../repp/v1/registrar/auth_controller.rb | 26 +++++++++++ .../repp/v1/registrar/summary_controller.rb | 44 ++++++++++++++++++ db/structure.sql | 7 +-- üpõ.preinstalled_gems | 25 ++++++++++ 9 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 .DS_Store create mode 100644 app/.DS_Store create mode 100644 app/controllers/.DS_Store create mode 100644 app/controllers/repp/.DS_Store create mode 100644 app/controllers/repp/v1/.DS_Store create mode 100644 app/controllers/repp/v1/registrar/auth_controller.rb create mode 100644 app/controllers/repp/v1/registrar/summary_controller.rb create mode 100644 üpõ.preinstalled_gems diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..05ef5629c7d8e1c4211d177d2a025725eb14b0e5 GIT binary patch literal 8196 zcmeHMTWl0n7(U-@ff+_%s09i#>DJ1O|sJ3~7%omqBfw_sDP zPZ~iJUo?uBH=;gxiK61G_r&->kSHJM#Q2{%vz0Djcrpa%B)#2NTsW`KVmlGHg(MRY>Y@Y6v$%v*RIw2@&s6n_A6|RV`7!d9xPeyjBh)xJ9+!>ognK0}@%tMdM?VQ;i6FoJ@gHu8Hp z*X?;urZhJ)du(fTP^)V5+`zD1D<3-8rbQpBMyIU}xjOhka_E5K%zMRfe1aEe`d*YVsT zl5p$kEXzFRvV+WKLyli;6HgV1_DoKMdcG8@GE-G&>AijZ1AF%kYFfd!IxWWt?4s3f z1eQOj&G9Mn%~{XgmA8r%ac|ah3L`FQ=4K5iTOea=qvLeh_Y3Q6-gBH?o^J=X=l1sn z){%hg_(D@ueFMIi58A@T`fOTXSXJ^pcILRVzsJh^L>1+g*$ZlJS$^x9+wM$tY~Im% zc8)f;Qms~%tyfPQ{O1Eo_SZ6D%7cRPK zv96a}msaU3WbDHQJ2DU#ZF!4EAy!xF z^@?W5-9CjZmRPMeDw?l!A0k8u*Jiav)=Z_xF*24TM6K#NS=*}g7DdEDSf$=2D}7mS zWQ2n8g)FVN%i72C0lx7z!w+`mESL7?q1|1p>-}85(KIcSB3M+tuu|WuZYX|{zOpn^Nfj?`&i`TNU1=gSmYte!>Y{Pc!zyPu^aS%grP(Tq!a1;;VVLXCIaSTu38Jxg#cpfM5Dqh3u zco*;CeSC{BcUyxj~a&`0V>o-o~ zPQbK;%!?5pf_zG8gdh)rP!3R0dTLD%Re^QnN)@Qh;MFRh<<_+~t2Np*suRI3T}JG5 zsu97is;{ZhBq~k8HZ<0#T7n8s34Pbr6N`vxy+c*C3MxUN+n^K6A|~BN%kYAduO8a} z3hYnV8TJMHhW$jq{tF4nSb!v!qMm@f0Vx7=J30u=yU>X)bYnjTVIV`$cHkn1!^mR{ z<9HAgc!+>~9FO5~JcXwT+|LrcPvS+qgqQIKPT_65gVQ0*KgH)bUk2N4Q(=p5%VAq~ zWK1=`{M-*ou&cI{_P|@Dio+h?*zE5hR3BPM6sozVTH*Pl} uXy`)2l!pM~C;wqc^CX#apHxIA1SJWz|NJ4~>i)it&;R)R5Ak`u4u1oy!Enp~ literal 0 HcmV?d00001 diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..830c593b89e71e935955619df619e42d09b641be GIT binary patch literal 6148 zcmeHK!AiqG5Z!I7O(;SR3VI88E!f&pC|*LXKVU=;Dm5`dgE3o@)Er77cl{xM#P4xt zccYZrgBOu96K3D+>`az@8+NjcF+Q3FUB)cNm;s7dGokrGa2$0-YTARyP`wziu_(`XsD?xQH& z+{=DKRYFb#8J z9n9z5VZYP1dxPGhZO@0tVE222#lkf94v$XGCr|NnB3>1z96moOI~pr^17pqdUfeW^ zMe+a3o3~UqwyfJpiBUqBItt*SeT5E&efudkssqiZW3|WdH f7EAFys1)$qXaG7IONHP8p&tQB12x3JpEB?XgX&K( literal 0 HcmV?d00001 diff --git a/app/controllers/.DS_Store b/app/controllers/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a3eee7bc42595345c5e13abf3402fcbff1011646 GIT binary patch literal 6148 zcmeHK%}T>S5Z-O0O({YS3VI88E!f&pC|*LWFJMFuDm5WNgE1SD)E-J9cYPsW#OHBl zcOw?-Rm9G~?l-@?*$=Wmj4|%c!aidbW6Xqx$Wd7%=w2IY=ww8WV+8Xe3lb54{ib7o z9q`)?ma~XuEc^QXL6*ct+3UUYM$_2ZZka8!W8QiXV(yiGIV)U0zeejqh$N_WKe&ve z`PAAy6=~_mX_U)?IE*0W<|SGFabZ#VZ2h)8JZo)echFEUuR;X`^p#5h7`Tt@%b<$es6(Eku~LYm TpkI~)(nUZLLLD*i3k-Y!)458c literal 0 HcmV?d00001 diff --git a/app/controllers/repp/.DS_Store b/app/controllers/repp/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fcb003e6543eeb63b4f0dc8a1b59afba2db039d3 GIT binary patch literal 6148 zcmeHKQA@)x5Kgw~GKSCx1$_(nI&gDiFnlR<{sAlcpfX!Jv{;+5cI(3!^j-guf5hM8 zU6O*+J&U+INWQz=UDABeT*4UR!+F?Y%wdcPXowt@4T8fPT@@RQ$Z?J!Rsrbm!8DGn z@2>-Xdxb4nC&<(3*Y8iWcKd@@s~j1Zza;9_u*rdJEqfMAcmqXmX5r0}SS62Om$79GAu&J<5Cg=()-zyB zgJ^C&6GQ+pKn#3m0M7>r4bin&7}Q4xba;J6e+>}@bbL!7N{g<=!XS7+xJd;xsoXv> zxJid`Y2#drg+Y_fxLz6Nu`8F47p_-_ajC-@cMVcc3=jkB3{;KjVEw;=7nkwfh?eu+B7xfTn9I17&J QbU?ZYXhNtX27ZBoPnbSPY5)KL literal 0 HcmV?d00001 diff --git a/app/controllers/repp/v1/.DS_Store b/app/controllers/repp/v1/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b22dad7630733675abfd34d2554a9b0a86ce7ed4 GIT binary patch literal 6148 zcmeHK%}T>S5T0$TO(;SS3VI88E!f&p5HF$D7cim+m735}gE3o@)E-J9cYPsW#OHBl zcO#Zo@FZeqVD_7xpDg=r*dG88z3H$8PzL}Dm9S)EvqmURx*{dxAr$HxDP)j<4@odv z$!5o2WPsMr#x)zk7()26e(5BLWPs7PU=oFC)@;6uQn|9VUA3xK&ARg*nhol^XEM(GFdikUARLY`<@P#^hjP}F(|DMwT2BWo+p-7sgZaF5 z(rGrFcDJ)=IP;TZv^(wYVqsf*hexLugU9G8mM@x5fxn)T9fJkDqOoRb&t4KoG9F{J zs4OZNnE_^i8Q2g8%=Ty1He|j$O=f@@_&Ec#KRBp_uEAWR+B&eI>m$W0gd}LwTY}Ir z=o-v5VgyC#Qbb)U%o9WCa`ZbU&o!89)a4-5$oL&IvM?_cp+-l)qtZdR8o6Z#n1N*m z%DP*p^Z)$&_y2Mc_m}}@;9oHyDt)it!zr1wb!BpN);g&7s3eq^Yy2!hLmkDKOGoiO bsuJ`&WFWc*bB*Xh;fsKxfg5JvR~h&K-S|z~ literal 0 HcmV?d00001 diff --git a/app/controllers/repp/v1/registrar/auth_controller.rb b/app/controllers/repp/v1/registrar/auth_controller.rb new file mode 100644 index 000000000..74737e5ca --- /dev/null +++ b/app/controllers/repp/v1/registrar/auth_controller.rb @@ -0,0 +1,26 @@ +module Repp + module V1 + module Registrar + class AuthController < BaseController + api :GET, 'repp/v1/registrar/auth' + desc 'check user auth info, track user last login datetime and return data' + + def index + registrar = current_user.registrar + + data = set_values_to_data(registrar: registrar) + + render_success(data: data) + end + + private + + def set_values_to_data(registrar:) + data = current_user.as_json(only: %i[id username roles]) + data[:registrar_name] = registrar.name + data + end + end + end + end +end \ No newline at end of file diff --git a/app/controllers/repp/v1/registrar/summary_controller.rb b/app/controllers/repp/v1/registrar/summary_controller.rb new file mode 100644 index 000000000..dfb54931c --- /dev/null +++ b/app/controllers/repp/v1/registrar/summary_controller.rb @@ -0,0 +1,44 @@ +module Repp + module V1 + module Registrar + class SummaryController < BaseController + api :GET, 'repp/v1/registrar/summary' + desc 'check user summary info and return data' + + def index + registrar = current_user.registrar + + data = evaluate_data(registrar: registrar) + + render_success(data: data) + end + + private + + def evaluate_data(registrar:) + data = current_user.as_json(only: %i[id username]) + data[:registrar_name] = registrar.name + data[:last_login_date] = last_login_date + data[:balance] = { amount: registrar.cash_account&.balance, + currency: registrar.cash_account&.currency } + data[:domains] = registrar.domains.count + data[:contacts] = registrar.contacts.count + data[:phone] = registrar.phone + data[:email] = registrar.email + data[:billing_email] = registrar.billing_email + data[:billing_address] = registrar.address + data + end + + def last_login_date + q = ApiLog::ReppLog.ransack({ request_path_eq: '/repp/v1/registrar/auth', + response_code_eq: '200', + api_user_name_cont: current_user.username, + request_method_eq: 'GET' }) + q.sorts = 'id desc' + q.result.offset(1).first&.created_at + end + end + end + end +end \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 56d499289..984a949df 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -827,8 +827,7 @@ CREATE TABLE public.dnskeys ( updator_str character varying, legacy_domain_id integer, updated_at timestamp without time zone, - validation_datetime timestamp without time zone, - failed_validation_reason character varying + validation_datetime timestamp without time zone ); @@ -1196,7 +1195,6 @@ CREATE TABLE public.invoices ( buyer_vat_no character varying, issue_date date NOT NULL, e_invoice_sent_at timestamp without time zone, - payment_link character varying, CONSTRAINT invoices_due_date_is_not_before_issue_date CHECK ((due_date >= issue_date)) ); @@ -5403,9 +5401,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220106123143'), ('20220113201642'), ('20220113220809'), -('20220124105717'), -('20220216113112'), -('20220228093211'); ('20220316140727'); diff --git a/üpõ.preinstalled_gems b/üpõ.preinstalled_gems new file mode 100644 index 000000000..0b8633422 --- /dev/null +++ b/üpõ.preinstalled_gems @@ -0,0 +1,25 @@ +FROM ghcr.io/internetee/registry:gems-latest +LABEL org.opencontainers.image.source=https://github.com/internetee/registry +ARG YARN_VER='1.22.10' +ARG RAILS_ENV +ARG SECRET_KEY_BASE + +ENV RAILS_ENV "$RAILS_ENV" +ENV SECRET_KEY_BASE "$SECRET_KEY_BASE" + +RUN npm install -g yarn@"$YARN_VER" + +RUN bash -c 'mkdir -pv -m776 {/opt/webapps/app/tmp/pids,/opt/ca,/opt/ca/newcerts}' +RUN echo -n 12 > /opt/ca/serial +RUN chmod 776 /opt/ca/serial +RUN echo '3A0e' > /opt/ca/crlnumber +RUN chmod 776 /opt/ca/crlnumber +RUN touch /opt/ca/index.txt +RUN chmod 776 /opt/ca/index.txt +WORKDIR /opt/webapps/app + +COPY . . + +RUN bundle exec rails assets:precompile + +EXPOSE 3000 From d50c3f0b453d6b288ff75eac36c1955ff402bc1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Mon, 21 Mar 2022 11:23:42 +0200 Subject: [PATCH 063/172] Fixed codeclimate issues and removed unnecessary files --- .DS_Store | Bin 8196 -> 0 bytes app/.DS_Store | Bin 6148 -> 0 bytes app/controllers/.DS_Store | Bin 6148 -> 0 bytes app/controllers/repp/.DS_Store | Bin 6148 -> 0 bytes app/controllers/repp/v1/.DS_Store | Bin 6148 -> 0 bytes .../repp/v1/registrar/auth_controller.rb | 26 ----------- .../repp/v1/registrar/summary_controller.rb | 44 ------------------ app/models/action.rb | 6 ++- app/models/bulk_action.rb | 3 +- app/models/registrant_user.rb | 9 ++-- app/views/epp/poll/_action.xml.builder | 4 +- üpõ.preinstalled_gems | 25 ---------- 12 files changed, 12 insertions(+), 105 deletions(-) delete mode 100644 .DS_Store delete mode 100644 app/.DS_Store delete mode 100644 app/controllers/.DS_Store delete mode 100644 app/controllers/repp/.DS_Store delete mode 100644 app/controllers/repp/v1/.DS_Store delete mode 100644 app/controllers/repp/v1/registrar/auth_controller.rb delete mode 100644 app/controllers/repp/v1/registrar/summary_controller.rb delete mode 100644 üpõ.preinstalled_gems diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 05ef5629c7d8e1c4211d177d2a025725eb14b0e5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHMTWl0n7(U-@ff+_%s09i#>DJ1O|sJ3~7%omqBfw_sDP zPZ~iJUo?uBH=;gxiK61G_r&->kSHJM#Q2{%vz0Djcrpa%B)#2NTsW`KVmlGHg(MRY>Y@Y6v$%v*RIw2@&s6n_A6|RV`7!d9xPeyjBh)xJ9+!>ognK0}@%tMdM?VQ;i6FoJ@gHu8Hp z*X?;urZhJ)du(fTP^)V5+`zD1D<3-8rbQpBMyIU}xjOhka_E5K%zMRfe1aEe`d*YVsT zl5p$kEXzFRvV+WKLyli;6HgV1_DoKMdcG8@GE-G&>AijZ1AF%kYFfd!IxWWt?4s3f z1eQOj&G9Mn%~{XgmA8r%ac|ah3L`FQ=4K5iTOea=qvLeh_Y3Q6-gBH?o^J=X=l1sn z){%hg_(D@ueFMIi58A@T`fOTXSXJ^pcILRVzsJh^L>1+g*$ZlJS$^x9+wM$tY~Im% zc8)f;Qms~%tyfPQ{O1Eo_SZ6D%7cRPK zv96a}msaU3WbDHQJ2DU#ZF!4EAy!xF z^@?W5-9CjZmRPMeDw?l!A0k8u*Jiav)=Z_xF*24TM6K#NS=*}g7DdEDSf$=2D}7mS zWQ2n8g)FVN%i72C0lx7z!w+`mESL7?q1|1p>-}85(KIcSB3M+tuu|WuZYX|{zOpn^Nfj?`&i`TNU1=gSmYte!>Y{Pc!zyPu^aS%grP(Tq!a1;;VVLXCIaSTu38Jxg#cpfM5Dqh3u zco*;CeSC{BcUyxj~a&`0V>o-o~ zPQbK;%!?5pf_zG8gdh)rP!3R0dTLD%Re^QnN)@Qh;MFRh<<_+~t2Np*suRI3T}JG5 zsu97is;{ZhBq~k8HZ<0#T7n8s34Pbr6N`vxy+c*C3MxUN+n^K6A|~BN%kYAduO8a} z3hYnV8TJMHhW$jq{tF4nSb!v!qMm@f0Vx7=J30u=yU>X)bYnjTVIV`$cHkn1!^mR{ z<9HAgc!+>~9FO5~JcXwT+|LrcPvS+qgqQIKPT_65gVQ0*KgH)bUk2N4Q(=p5%VAq~ zWK1=`{M-*ou&cI{_P|@Dio+h?*zE5hR3BPM6sozVTH*Pl} uXy`)2l!pM~C;wqc^CX#apHxIA1SJWz|NJ4~>i)it&;R)R5Ak`u4u1oy!Enp~ diff --git a/app/.DS_Store b/app/.DS_Store deleted file mode 100644 index 830c593b89e71e935955619df619e42d09b641be..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!AiqG5Z!I7O(;SR3VI88E!f&pC|*LXKVU=;Dm5`dgE3o@)Er77cl{xM#P4xt zccYZrgBOu96K3D+>`az@8+NjcF+Q3FUB)cNm;s7dGokrGa2$0-YTARyP`wziu_(`XsD?xQH& z+{=DKRYFb#8J z9n9z5VZYP1dxPGhZO@0tVE222#lkf94v$XGCr|NnB3>1z96moOI~pr^17pqdUfeW^ zMe+a3o3~UqwyfJpiBUqBItt*SeT5E&efudkssqiZW3|WdH f7EAFys1)$qXaG7IONHP8p&tQB12x3JpEB?XgX&K( diff --git a/app/controllers/.DS_Store b/app/controllers/.DS_Store deleted file mode 100644 index a3eee7bc42595345c5e13abf3402fcbff1011646..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5Z-O0O({YS3VI88E!f&pC|*LWFJMFuDm5WNgE1SD)E-J9cYPsW#OHBl zcOw?-Rm9G~?l-@?*$=Wmj4|%c!aidbW6Xqx$Wd7%=w2IY=ww8WV+8Xe3lb54{ib7o z9q`)?ma~XuEc^QXL6*ct+3UUYM$_2ZZka8!W8QiXV(yiGIV)U0zeejqh$N_WKe&ve z`PAAy6=~_mX_U)?IE*0W<|SGFabZ#VZ2h)8JZo)echFEUuR;X`^p#5h7`Tt@%b<$es6(Eku~LYm TpkI~)(nUZLLLD*i3k-Y!)458c diff --git a/app/controllers/repp/.DS_Store b/app/controllers/repp/.DS_Store deleted file mode 100644 index fcb003e6543eeb63b4f0dc8a1b59afba2db039d3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKQA@)x5Kgw~GKSCx1$_(nI&gDiFnlR<{sAlcpfX!Jv{;+5cI(3!^j-guf5hM8 zU6O*+J&U+INWQz=UDABeT*4UR!+F?Y%wdcPXowt@4T8fPT@@RQ$Z?J!Rsrbm!8DGn z@2>-Xdxb4nC&<(3*Y8iWcKd@@s~j1Zza;9_u*rdJEqfMAcmqXmX5r0}SS62Om$79GAu&J<5Cg=()-zyB zgJ^C&6GQ+pKn#3m0M7>r4bin&7}Q4xba;J6e+>}@bbL!7N{g<=!XS7+xJd;xsoXv> zxJid`Y2#drg+Y_fxLz6Nu`8F47p_-_ajC-@cMVcc3=jkB3{;KjVEw;=7nkwfh?eu+B7xfTn9I17&J QbU?ZYXhNtX27ZBoPnbSPY5)KL diff --git a/app/controllers/repp/v1/.DS_Store b/app/controllers/repp/v1/.DS_Store deleted file mode 100644 index b22dad7630733675abfd34d2554a9b0a86ce7ed4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5T0$TO(;SS3VI88E!f&p5HF$D7cim+m735}gE3o@)E-J9cYPsW#OHBl zcO#Zo@FZeqVD_7xpDg=r*dG88z3H$8PzL}Dm9S)EvqmURx*{dxAr$HxDP)j<4@odv z$!5o2WPsMr#x)zk7()26e(5BLWPs7PU=oFC)@;6uQn|9VUA3xK&ARg*nhol^XEM(GFdikUARLY`<@P#^hjP}F(|DMwT2BWo+p-7sgZaF5 z(rGrFcDJ)=IP;TZv^(wYVqsf*hexLugU9G8mM@x5fxn)T9fJkDqOoRb&t4KoG9F{J zs4OZNnE_^i8Q2g8%=Ty1He|j$O=f@@_&Ec#KRBp_uEAWR+B&eI>m$W0gd}LwTY}Ir z=o-v5VgyC#Qbb)U%o9WCa`ZbU&o!89)a4-5$oL&IvM?_cp+-l)qtZdR8o6Z#n1N*m z%DP*p^Z)$&_y2Mc_m}}@;9oHyDt)it!zr1wb!BpN);g&7s3eq^Yy2!hLmkDKOGoiO bsuJ`&WFWc*bB*Xh;fsKxfg5JvR~h&K-S|z~ diff --git a/app/controllers/repp/v1/registrar/auth_controller.rb b/app/controllers/repp/v1/registrar/auth_controller.rb deleted file mode 100644 index 74737e5ca..000000000 --- a/app/controllers/repp/v1/registrar/auth_controller.rb +++ /dev/null @@ -1,26 +0,0 @@ -module Repp - module V1 - module Registrar - class AuthController < BaseController - api :GET, 'repp/v1/registrar/auth' - desc 'check user auth info, track user last login datetime and return data' - - def index - registrar = current_user.registrar - - data = set_values_to_data(registrar: registrar) - - render_success(data: data) - end - - private - - def set_values_to_data(registrar:) - data = current_user.as_json(only: %i[id username roles]) - data[:registrar_name] = registrar.name - data - end - end - end - end -end \ No newline at end of file diff --git a/app/controllers/repp/v1/registrar/summary_controller.rb b/app/controllers/repp/v1/registrar/summary_controller.rb deleted file mode 100644 index dfb54931c..000000000 --- a/app/controllers/repp/v1/registrar/summary_controller.rb +++ /dev/null @@ -1,44 +0,0 @@ -module Repp - module V1 - module Registrar - class SummaryController < BaseController - api :GET, 'repp/v1/registrar/summary' - desc 'check user summary info and return data' - - def index - registrar = current_user.registrar - - data = evaluate_data(registrar: registrar) - - render_success(data: data) - end - - private - - def evaluate_data(registrar:) - data = current_user.as_json(only: %i[id username]) - data[:registrar_name] = registrar.name - data[:last_login_date] = last_login_date - data[:balance] = { amount: registrar.cash_account&.balance, - currency: registrar.cash_account&.currency } - data[:domains] = registrar.domains.count - data[:contacts] = registrar.contacts.count - data[:phone] = registrar.phone - data[:email] = registrar.email - data[:billing_email] = registrar.billing_email - data[:billing_address] = registrar.address - data - end - - def last_login_date - q = ApiLog::ReppLog.ransack({ request_path_eq: '/repp/v1/registrar/auth', - response_code_eq: '200', - api_user_name_cont: current_user.username, - request_method_eq: 'GET' }) - q.sorts = 'id desc' - q.result.offset(1).first&.created_at - end - end - end - end -end \ No newline at end of file diff --git a/app/models/action.rb b/app/models/action.rb index 12435f3f0..444e31bbf 100644 --- a/app/models/action.rb +++ b/app/models/action.rb @@ -3,7 +3,10 @@ class Action < ApplicationRecord belongs_to :user belongs_to :contact, optional: true - has_many :subactions, class_name: 'Action', foreign_key: 'bulk_action_id', dependent: :destroy + has_many :subactions, class_name: 'Action', + foreign_key: 'bulk_action_id', + inverse_of: :action, + dependent: :destroy belongs_to :bulk_action, class_name: 'Action', optional: true validates :operation, inclusion: { in: proc { |action| action.class.valid_operations } } @@ -36,3 +39,4 @@ class Action < ApplicationRecord end end end + diff --git a/app/models/bulk_action.rb b/app/models/bulk_action.rb index 1a8cad771..9c98ee2db 100644 --- a/app/models/bulk_action.rb +++ b/app/models/bulk_action.rb @@ -1,2 +1 @@ -class BulkAction < Action -end \ No newline at end of file +class BulkAction < Action; end diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index a1f6993af..a095b9b22 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -110,11 +110,12 @@ class RegistrantUser < User def last_name username.split.second end - + # rubocop:disable Metrics/MethodLength def update_related_contacts grouped_contacts = Contact.where(ident: ident, ident_country_code: country.alpha2) - .where('UPPER(name) != UPPER(?)', username) - .includes(:registrar).group_by { |c| c.registrar } + .where('UPPER(name) != UPPER(?)', username) + .includes(:registrar) + .group_by(&:registrar) grouped_contacts.each do |registrar, contacts| bulk_action, action = actions.create!(operation: :bulk_update) if contacts.size > 1 contacts.each do |c| @@ -125,7 +126,7 @@ class RegistrantUser < User registrar.notify(bulk_action || action) end end - + # rubocop:enable Metrics/MethodLength class << self def find_or_create_by_api_data(user_data = {}) return false unless user_data[:ident] diff --git a/app/views/epp/poll/_action.xml.builder b/app/views/epp/poll/_action.xml.builder index 838ae9aaf..37f2acccb 100644 --- a/app/views/epp/poll/_action.xml.builder +++ b/app/views/epp/poll/_action.xml.builder @@ -5,8 +5,6 @@ builder.extension do builder.tag!('changePoll:date', action.created_at.utc.xmlschema) builder.tag!('changePoll:svTRID', action.id) builder.tag!('changePoll:who', action.user) - if action.bulk_action? - builder.tag!('changePoll:reason', 'Auto-update according to official data') - end + builder.tag!('changePoll:reason', 'Auto-update according to official data') if action.bulk_action? end end diff --git a/üpõ.preinstalled_gems b/üpõ.preinstalled_gems deleted file mode 100644 index 0b8633422..000000000 --- a/üpõ.preinstalled_gems +++ /dev/null @@ -1,25 +0,0 @@ -FROM ghcr.io/internetee/registry:gems-latest -LABEL org.opencontainers.image.source=https://github.com/internetee/registry -ARG YARN_VER='1.22.10' -ARG RAILS_ENV -ARG SECRET_KEY_BASE - -ENV RAILS_ENV "$RAILS_ENV" -ENV SECRET_KEY_BASE "$SECRET_KEY_BASE" - -RUN npm install -g yarn@"$YARN_VER" - -RUN bash -c 'mkdir -pv -m776 {/opt/webapps/app/tmp/pids,/opt/ca,/opt/ca/newcerts}' -RUN echo -n 12 > /opt/ca/serial -RUN chmod 776 /opt/ca/serial -RUN echo '3A0e' > /opt/ca/crlnumber -RUN chmod 776 /opt/ca/crlnumber -RUN touch /opt/ca/index.txt -RUN chmod 776 /opt/ca/index.txt -WORKDIR /opt/webapps/app - -COPY . . - -RUN bundle exec rails assets:precompile - -EXPOSE 3000 From 392e2844636ef520261ce42b2e8790e952b2e4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Mon, 21 Mar 2022 11:50:00 +0200 Subject: [PATCH 064/172] Fixed inverse_of issues --- app/models/action.rb | 2 +- app/models/registrant_user.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/action.rb b/app/models/action.rb index 444e31bbf..231aec42a 100644 --- a/app/models/action.rb +++ b/app/models/action.rb @@ -5,7 +5,7 @@ class Action < ApplicationRecord belongs_to :contact, optional: true has_many :subactions, class_name: 'Action', foreign_key: 'bulk_action_id', - inverse_of: :action, + inverse_of: :bulk_action, dependent: :destroy belongs_to :bulk_action, class_name: 'Action', optional: true diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index a095b9b22..bbe4044b6 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -110,6 +110,7 @@ class RegistrantUser < User def last_name username.split.second end + # rubocop:disable Metrics/MethodLength def update_related_contacts grouped_contacts = Contact.where(ident: ident, ident_country_code: country.alpha2) @@ -126,7 +127,8 @@ class RegistrantUser < User registrar.notify(bulk_action || action) end end - # rubocop:enable Metrics/MethodLength + # rubocop:enable Metrics/MethodLength + class << self def find_or_create_by_api_data(user_data = {}) return false unless user_data[:ident] From 4afd32ebff0894f4c1026b6721b4ea1024f52eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Mon, 21 Mar 2022 11:58:46 +0200 Subject: [PATCH 065/172] Fixed codeclimate issue --- app/models/action.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/action.rb b/app/models/action.rb index 231aec42a..c87467949 100644 --- a/app/models/action.rb +++ b/app/models/action.rb @@ -39,4 +39,3 @@ class Action < ApplicationRecord end end end - From 5a0c812a15c7185dbf8db6c6e749f92848c8f02c Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 29 Mar 2022 10:11:22 +0300 Subject: [PATCH 066/172] Create partial search formatter service --- app/services/partial_search_formatter.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 app/services/partial_search_formatter.rb diff --git a/app/services/partial_search_formatter.rb b/app/services/partial_search_formatter.rb new file mode 100644 index 000000000..87ad602ed --- /dev/null +++ b/app/services/partial_search_formatter.rb @@ -0,0 +1,13 @@ +class PartialSearchFormatter + def self.format(search_params) + percentage = '%' + + search_params.each do |key, value| + next unless key.include?('matches') && value.present? + + value.prepend(percentage).concat(percentage) + end + + search_params + end +end From eb64b3aca4b31be44a99b56230b5fed2b15b4086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Tue, 29 Mar 2022 10:39:26 +0300 Subject: [PATCH 067/172] Modifications for updating business and private contacts --- .../api/v1/registrant/contacts_controller.rb | 10 +- app/models/action.rb | 2 +- app/models/contact.rb | 13 ++ app/models/registrant_user.rb | 82 +++++------- app/views/epp/poll/_action.xml.builder | 10 -- app/views/epp/poll/_extension.xml.builder | 18 +++ app/views/epp/poll/poll_req.xml.builder | 19 ++- config/routes.rb | 5 +- .../registrant_user_creation_test.rb | 43 ------- test/models/registrant_user_test.rb | 120 ++++++++++++------ 10 files changed, 159 insertions(+), 163 deletions(-) delete mode 100644 app/views/epp/poll/_action.xml.builder create mode 100644 app/views/epp/poll/_extension.xml.builder diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index 8e8b46631..b196c567a 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -34,15 +34,15 @@ module Api end end - def do_need_update_contact - result = current_registrant_user.do_need_update_contact? + def do_need_update_contacts + result = current_registrant_user.do_need_update_contacts? render json: { update_contacts: result[:result], counter: result[:counter] } end - def update_company_contacts - companies = current_registrant_user.update_company_contacts + def update_contacts + contacts = current_registrant_user.update_contacts - render json: { message: 'get it', companies: companies } + render json: { message: 'get it', contacts: contacts } end def update diff --git a/app/models/action.rb b/app/models/action.rb index c87467949..8a822f867 100644 --- a/app/models/action.rb +++ b/app/models/action.rb @@ -32,7 +32,7 @@ class Action < ApplicationRecord subactions.map do |a| { - code: a.contact&.code, + code: a.contact.code, avail: 0, reason: 'in use', } diff --git a/app/models/contact.rb b/app/models/contact.rb index 84d4ba962..8bb471e47 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -30,6 +30,19 @@ class Contact < ApplicationRecord .where('success = false and verified_at IS NOT NULL') } + scope :with_different_company_name, (lambda do |company| + where("ident = ? AND ident_country_code = 'EE' AND name != ?", + company.registration_number, + company.company_name) + end) + + scope :with_different_registrant_name, (lambda do |user| + where('ident = ? AND ident_country_code = ? AND UPPER(name) != UPPER(?)', + user.ident, + user.country.alpha2, + user.username) + end) + NAME_REGEXP = /([\u00A1-\u00B3\u00B5-\u00BF\u0021-\u0026\u0028-\u002C\u003A-\u0040]| [\u005B-\u005F\u007B-\u007E\u2040-\u206F\u20A0-\u20BF\u2100-\u218F])/x diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index bbe4044b6..96fef635e 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -26,13 +26,13 @@ class RegistrantUser < User [] end - def do_need_update_contact? - return { result: false, counter: 0 } if companies.blank? - + def do_need_update_contacts? counter = 0 + + counter += Contact.with_different_registrant_name(self).size + companies.each do |company| - counter += Contact.where(ident: company.registration_number, ident_country_code: 'EE')&. - reject { |contact| contact.name == company.company_name }.size + counter += Contact.with_different_company_name(company).size end return { result: true, counter: counter } if counter.positive? @@ -40,39 +40,35 @@ class RegistrantUser < User { result: false, counter: 0 } end - def update_company_contacts - return [] if companies.blank? - + def update_contacts + user = self + contacts = [] + contacts.concat Contact.with_different_registrant_name(user) + .each{ |c| c.write_attribute(:name, user.username) } companies.each do |company| - contacts = Contact.where(ident: company.registration_number, ident_country_code: 'EE') - - next if contacts.blank? - - contacts.each do |contact| - next if company.company_name == contact.name - - update_company_name(contact: contact, company: company) - end + contacts.concat Contact.with_different_company_name(company) + .each{ |c| c.write_attribute(:name, company.company_name) } end + + return [] if contacts.blank? - companies + grouped_contacts = contacts.group_by(&:registrar_id) + grouped_contacts.each do |registrar_id, contacts| + bulk_action, action = actions.create!(operation: :bulk_update) if contacts.size > 1 + contacts.each do |c| + if c.save(validate: false) + action = actions.create!(contact: c, operation: :update, bulk_action_id: bulk_action&.id) + end + end + notify_registrar_contacts_updated(action: bulk_action || action, + registrar_id: registrar_id) + end + contacts end - def update_company_name(contact:, company:) - old_contact_name = contact.name - contact.name = company.company_name - - contact.save(validate: false) - - notify_registrar_data_updated(company_name: company.company_name, - old_contact_name: old_contact_name, - contact: contact) - end - - def notify_registrar_data_updated(company_name:, old_contact_name:, contact:) - contact.registrar.notifications.create!( - text: "Contact update: #{contact.id} name updated from #{old_contact_name} to #{company_name} by the registry" - ) + def notify_registrar_contacts_updated(action:, registrar_id:) + registrar = Registrar.find(registrar_id) + registrar.notify(action) if registrar end def contacts(representable: true) @@ -111,24 +107,6 @@ class RegistrantUser < User username.split.second end - # rubocop:disable Metrics/MethodLength - def update_related_contacts - grouped_contacts = Contact.where(ident: ident, ident_country_code: country.alpha2) - .where('UPPER(name) != UPPER(?)', username) - .includes(:registrar) - .group_by(&:registrar) - grouped_contacts.each do |registrar, contacts| - bulk_action, action = actions.create!(operation: :bulk_update) if contacts.size > 1 - contacts.each do |c| - if c.update(name: username) - action = actions.create!(contact: c, operation: :update, bulk_action_id: bulk_action&.id) - end - end - registrar.notify(bulk_action || action) - end - end - # rubocop:enable Metrics/MethodLength - class << self def find_or_create_by_api_data(user_data = {}) return false unless user_data[:ident] @@ -165,8 +143,6 @@ class RegistrantUser < User user = find_or_create_by(registrant_ident: "#{user_data[:country_code]}-#{user_data[:ident]}") user.username = "#{user_data[:first_name]} #{user_data[:last_name]}" user.save - - user.update_related_contacts user end end diff --git a/app/views/epp/poll/_action.xml.builder b/app/views/epp/poll/_action.xml.builder deleted file mode 100644 index 37f2acccb..000000000 --- a/app/views/epp/poll/_action.xml.builder +++ /dev/null @@ -1,10 +0,0 @@ -builder.extension do - builder.tag!('changePoll:changeData', - 'xmlns:changePoll' => Xsd::Schema.filename(for_prefix: 'changePoll', for_version: '1.0')) do - builder.tag!('changePoll:operation', action.operation) - builder.tag!('changePoll:date', action.created_at.utc.xmlschema) - builder.tag!('changePoll:svTRID', action.id) - builder.tag!('changePoll:who', action.user) - builder.tag!('changePoll:reason', 'Auto-update according to official data') if action.bulk_action? - end -end diff --git a/app/views/epp/poll/_extension.xml.builder b/app/views/epp/poll/_extension.xml.builder new file mode 100644 index 000000000..a26e3db8b --- /dev/null +++ b/app/views/epp/poll/_extension.xml.builder @@ -0,0 +1,18 @@ +builder.extension do + builder.tag!('changePoll:changeData', + 'xmlns:changePoll' => Xsd::Schema.filename(for_prefix: 'changePoll', + for_version: '1.0')) do + case type + when 'action' + builder.tag!('changePoll:operation', obj.operation) + builder.tag!('changePoll:date', obj.created_at.utc.xmlschema) + builder.tag!('changePoll:svTRID', obj.id) + builder.tag!('changePoll:who', obj.user) + if obj.bulk_action? + builder.tag!('changePoll:reason', 'Auto-update according to official data') + end + when 'state' + builder.tag!('changePoll:operation', obj) + end + end +end \ No newline at end of file diff --git a/app/views/epp/poll/poll_req.xml.builder b/app/views/epp/poll/poll_req.xml.builder index f6688fb48..0a916e6ad 100644 --- a/app/views/epp/poll/poll_req.xml.builder +++ b/app/views/epp/poll/poll_req.xml.builder @@ -29,18 +29,15 @@ xml.epp_head do if @notification.action || @notification.registry_lock? if @notification.registry_lock? state = @notification.text.include?('unlocked') ? 'unlock' : 'lock' - xml.extension do - xml.tag!('changePoll:changeData', - 'xmlns:changePoll': Xsd::Schema.filename(for_prefix: 'changePoll')) do - xml.tag!('changePoll:operation', state) - end - end + render(partial: 'epp/poll/extension', + locals: { builder: xml, + obj: state, + type: 'state' }) else - render(partial: 'epp/poll/action', - locals: { - builder: xml, - action: @notification.action, - }) + render(partial: 'epp/poll/extension', + locals: { builder: xml, + obj: @notification.action, + type: 'action' }) end end diff --git a/config/routes.rb b/config/routes.rb index 79807729a..a2a4556f7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -129,8 +129,9 @@ Rails.application.routes.draw do resource :registry_lock, only: %i[create destroy] end resources :contacts, only: %i[index show update], param: :uuid do - get 'do_need_update_contact', to: 'contacts#do_need_update_contact', as: :do_need_update_contact - post 'update_company_contacts', to: 'contacts#update_company_contacts', as: :update_company_contacts + get 'do_need_update_contacts', to: 'contacts#do_need_update_contacts', + as: :do_need_update_contacts + post 'update_contacts', to: 'contacts#update_contacts', as: :update_contacts end resources :companies, only: %i[index] end diff --git a/test/models/registrant_user/registrant_user_creation_test.rb b/test/models/registrant_user/registrant_user_creation_test.rb index f183c94dc..a32191db8 100644 --- a/test/models/registrant_user/registrant_user_creation_test.rb +++ b/test/models/registrant_user/registrant_user_creation_test.rb @@ -29,47 +29,4 @@ class RegistrantUserCreationTest < ActiveSupport::TestCase user = User.find_by(registrant_ident: 'US-1234') assert_equal('John Smith', user.username) end - - def test_updates_related_contacts_name_if_different_from_e_identity - registrars = [registrars(:bestnames), registrars(:goodnames)] - contacts = [contacts(:john), contacts(:william), contacts(:identical_to_william)] - contacts.each do |c| - c.update(ident: '39708290276', ident_country_code: 'EE') - end - - user_data = { - ident: '39708290276', - first_name: 'John', - last_name: 'Doe', - } - - RegistrantUser.find_or_create_by_api_data(user_data) - - user = User.find_by(registrant_ident: 'EE-39708290276') - assert_equal('John Doe', user.username) - - contacts.each do |c| - c.reload - assert_equal user.username, c.name - assert user.actions.find_by(operation: :update, contact_id: c.id) - end - - bulk_action = BulkAction.find_by(user_id: user.id, operation: :bulk_update) - assert_equal 2, bulk_action.subactions.size - - registrars.each do |r| - notification = r.notifications.unread.order('created_at DESC').take - if r == registrars(:bestnames) - assert_equal '2 contacts have been updated by registrant', notification.text - assert_equal 'BulkAction', notification.attached_obj_type - assert_equal bulk_action.id, notification.attached_obj_id - assert_equal bulk_action.id, notification.action_id - else - assert_equal 'Contact william-002 has been updated by registrant', notification.text - refute notification.action_id - refute notification.attached_obj_id - refute notification.attached_obj_type - end - end - end end diff --git a/test/models/registrant_user_test.rb b/test/models/registrant_user_test.rb index 2b1d6a880..81e57fa72 100644 --- a/test/models/registrant_user_test.rb +++ b/test/models/registrant_user_test.rb @@ -32,30 +32,61 @@ class RegistrantUserTest < ActiveSupport::TestCase assert_equal Country.new('US'), user.country end - def test_should_update_org_contact_if_data_from_business_registry_dismatch + def test_should_update_contacts_if_names_dismatch assert_equal 'US-1234', @user.registrant_ident - org = contacts(:acme_ltd) - org.ident_country_code = 'EE' - org.save(validate: false) - org.reload + registrars = [registrars(:bestnames), registrars(:goodnames)] + contacts = [contacts(:john), contacts(:william), contacts(:identical_to_william), + contacts(:acme_ltd), contacts(:registrar_ltd)] + contacts.each do |c| + if c.ident_type == 'priv' + c.ident = @user.ident + else + c.ident_country_code = 'EE' + c.registrar = registrars(:bestnames) + end + c.save(validate: false) + end - company = Company.new(org.ident, "ace") + company_one = Company.new(contacts(:acme_ltd).ident, 'ace') + company_two = Company.new(contacts(:registrar_ltd).ident, 'acer') - Spy.on(@user, :companies).and_return([company]) - @user.update_company_contacts - org.reload + Spy.on(@user, :companies).and_return([company_one, company_two]) + @user.update_contacts - assert_equal org.name, company.company_name + contacts.each do |c| + c.reload + assert_equal @user.username, c.name if c.ident_type == 'priv' + assert @user.actions.find_by(operation: :update, contact_id: c.id) + end + + bulk_action = @user.actions.where(operation: :bulk_update).last + + assert_equal 4, bulk_action.subactions.size + + registrars.each do |r| + notification = r.notifications.unread.order('created_at DESC').take + if r == registrars(:bestnames) + assert_equal '4 contacts have been updated by registrant', notification.text + assert_equal 'BulkAction', notification.attached_obj_type + assert_equal bulk_action.id, notification.attached_obj_id + assert_equal bulk_action.id, notification.action_id + else + assert_equal 'Contact william-002 has been updated by registrant', notification.text + refute notification.action_id + refute notification.attached_obj_id + refute notification.attached_obj_type + end + end end def test_queries_company_register_for_associated_companies assert_equal 'US-1234', @user.registrant_ident - company = Company.new("acme", "ace") + company = Company.new('acme', 'ace') company_register = Minitest::Mock.new company_register.expect(:representation_rights, [company], [{ citizen_personal_code: '1234', - citizen_country_code: 'USA' }]) + citizen_country_code: 'USA' }]) assert_equal [company], @user.companies(company_register) company_register.verify @@ -63,58 +94,71 @@ class RegistrantUserTest < ActiveSupport::TestCase def test_should_return_zero_count_of_companies assert_equal 'US-1234', @user.registrant_ident - org = contacts(:acme_ltd) - org.ident_country_code = 'EE' - org.save(validate: false) - org.reload + contacts = [contacts(:john), contacts(:william), contacts(:identical_to_william), + contacts(:acme_ltd), contacts(:registrar_ltd)] - company_one = Company.new(org.ident, 'Acme Ltd') + contacts.each do |c| + if c.ident_type == 'priv' + c.ident = @user.ident + c.name = @user.username + else + c.ident_country_code = 'EE' + end + c.save(validate: false) + end - Spy.on(@user, :companies).and_return([company_one]) - response = @user.do_need_update_contact? - org.reload + company_one = Company.new(contacts(:acme_ltd).ident, 'Acme Ltd') + company_two = Company.new(contacts(:registrar_ltd).ident, 'Registrar Ltd') + + Spy.on(@user, :companies).and_return([company_one, company_two]) + response = @user.do_need_update_contacts? assert_equal response[:counter], 0 end - def test_should_return_count_of_contact_which_should_be_updated + def test_should_return_count_of_contacts_which_should_be_updated assert_equal 'US-1234', @user.registrant_ident - org = contacts(:acme_ltd) - org.ident_country_code = 'EE' - org.save(validate: false) - org.reload + contacts = [contacts(:john), contacts(:william), contacts(:identical_to_william), + contacts(:acme_ltd), contacts(:registrar_ltd)] + contacts.each do |c| + if c.ident_type == 'priv' + c.ident = @user.ident + else + c.ident_country_code = 'EE' + end + c.save(validate: false) + end - company_one = Company.new(org.ident, 'ace') - company_two = Company.new(org.ident, 'acer') + company_one = Company.new(contacts(:acme_ltd).ident, 'ace') + company_two = Company.new(contacts(:registrar_ltd).ident, 'acer') Spy.on(@user, :companies).and_return([company_one, company_two]) - response = @user.do_need_update_contact? - org.reload + response = @user.do_need_update_contacts? - assert_equal response[:counter], 2 + assert_equal response[:counter], 5 end def test_returns_contacts - Contact.stub(:registrant_user_contacts, %w(john jane)) do - assert_equal %w(john jane), @user.contacts + Contact.stub(:registrant_user_contacts, %w[john jane]) do + assert_equal %w[john jane], @user.contacts end end def test_returns_direct_contacts - Contact.stub(:registrant_user_direct_contacts, %w(john jane)) do - assert_equal %w(john jane), @user.direct_contacts + Contact.stub(:registrant_user_direct_contacts, %w[john jane]) do + assert_equal %w[john jane], @user.direct_contacts end end def test_returns_domains - Domain.stub(:registrant_user_domains, %w(shop airport)) do - assert_equal %w(shop airport), @user.domains + Domain.stub(:registrant_user_domains, %w[shop airport]) do + assert_equal %w[shop airport], @user.domains end end def test_returns_administered_domains - Domain.stub(:registrant_user_administered_domains, %w(shop airport)) do - assert_equal %w(shop airport), @user.administered_domains + Domain.stub(:registrant_user_administered_domains, %w[shop airport]) do + assert_equal %w[shop airport], @user.administered_domains end end end From b46f387fcff1766315a05091a44c6b69c162697f Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 29 Mar 2022 10:39:29 +0300 Subject: [PATCH 068/172] Add partial and wildcard search on `/admin/contacts` --- app/controllers/admin/contacts_controller.rb | 12 +++++------- app/views/admin/contacts/index.haml | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/contacts_controller.rb b/app/controllers/admin/contacts_controller.rb index 192b86242..955ab4df2 100644 --- a/app/controllers/admin/contacts_controller.rb +++ b/app/controllers/admin/contacts_controller.rb @@ -9,10 +9,8 @@ module Admin params[:q] ||= {} search_params = params[:q].deep_dup - if search_params[:domain_contacts_type_in].is_a?(Array) && - search_params[:domain_contacts_type_in].delete('registrant') - search_params[:registrant_domains_id_not_null] = 1 - end + search_params[:registrant_domains_id_not_null] = 1 if search_params[:domain_contacts_type_in].is_a?(Array) && + search_params[:domain_contacts_type_in].delete('registrant') contacts = Contact.includes(:registrar).joins(:registrar) .select('contacts.*, registrars.name as registrars_name') @@ -20,7 +18,7 @@ module Admin contacts = filter_by_flags(contacts) normalize_search_parameters do - @q = contacts.ransack(search_params) + @q = contacts.ransack(PartialSearchFormatter.format(search_params)) @contacts = @q.result.distinct.page(params[:page]) end @@ -33,6 +31,7 @@ module Admin if params[:only_no_country_code].eql?('1') contacts = contacts.where("ident_country_code is null or ident_country_code=''") end + contacts = contacts.email_verification_failed if params[:email_verification_failed].eql?('1') contacts end @@ -41,8 +40,7 @@ module Admin render json: Contact.search_by_query(params[:q]) end - def edit - end + def edit; end def update cp = ignore_empty_statuses diff --git a/app/views/admin/contacts/index.haml b/app/views/admin/contacts/index.haml index 0812913a1..8e7a2c244 100644 --- a/app/views/admin/contacts/index.haml +++ b/app/views/admin/contacts/index.haml @@ -11,11 +11,11 @@ .col-md-3 .form-group = f.label t(:id) - = f.search_field :code_matches, class: 'form-control', placeholder: t(:id) + = f.search_field :code_matches, value: params[:q][:code_matches], class: 'form-control', placeholder: t(:id) .col-md-3 .form-group = f.label t(:ident) - = f.search_field :ident_matches, class: 'form-control', placeholder: t(:ident) + = f.search_field :ident_matches, value: params[:q][:ident_matches], class: 'form-control', placeholder: t(:ident) .col-md-3 .form-group = label_tag t(:ident_type) @@ -24,7 +24,7 @@ .col-md-3 .form-group = f.label t(:email) - = f.search_field :email_matches, class: 'form-control', placeholder: t(:email) + = f.search_field :email_matches, value: params[:q][:email_matches], class: 'form-control', placeholder: t(:email) .col-md-3 .form-group = label_tag t(:country) From eaf89a02f72888ac48fd252746a4842f8e2f0db1 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 29 Mar 2022 11:08:13 +0300 Subject: [PATCH 069/172] Add missing partial and wildcard search on `/admin/domains` --- app/controllers/admin/domains_controller.rb | 14 +++----------- app/views/admin/domains/_search_form.html.erb | 6 +++--- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index 20f47da02..707b40654 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -17,18 +17,10 @@ module Admin end normalize_search_parameters do - @q = domains.ransack(params[:q]) + @q = domains.ransack(PartialSearchFormatter.format(params[:q])) @domains = @q.result.page(params[:page]) - (redirect_to [:admin, @domains.first] and return if @domains.count == 1 && params[:q][:name_matches].present?) - if @domains.count.zero? && params[:q][:name_matches] !~ /^%.+%$/ - # if we do not get any results, add wildcards to the name field and search again - n_cache = params[:q][:name_matches] - params[:q][:name_matches] = "%#{params[:q][:name_matches]}%" - @q = domains.ransack(params[:q]) - @domains = @q.result.page(params[:page]) - params[:q][:name_matches] = n_cache # we don't want to show wildcards in search form - end end + @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? render_by_format('admin/domains/index', 'domains') @@ -95,7 +87,7 @@ module Admin def build_associations @server_statuses = @domain.statuses.select { |x| DomainStatus::SERVER_STATUSES.include?(x) } @server_statuses = [nil] if @server_statuses.empty? - @other_statuses = @domain.statuses.select { |x| !DomainStatus::SERVER_STATUSES.include?(x) } + @other_statuses = @domain.statuses.reject { |x| DomainStatus::SERVER_STATUSES.include?(x) } end def ignore_empty_statuses diff --git a/app/views/admin/domains/_search_form.html.erb b/app/views/admin/domains/_search_form.html.erb index ecfdd1ced..a59abeec5 100644 --- a/app/views/admin/domains/_search_form.html.erb +++ b/app/views/admin/domains/_search_form.html.erb @@ -9,19 +9,19 @@
<%= f.label :registrant_ident, for: nil %> - <%= f.search_field :registrant_ident_eq, class: 'form-control', placeholder: t(:registrant_ident) %> + <%= f.search_field :registrant_ident_matches, value: params[:q][:registrant_ident_matches], class: 'form-control', placeholder: t(:registrant_ident) %>
<%= f.label :contact_ident, for: nil %> - <%= f.search_field :contacts_ident_eq, class: 'form-control', placeholder: t(:contact_ident) %> + <%= f.search_field :contacts_ident_matches, value: params[:q][:contacts_ident_matches], class: 'form-control', placeholder: t(:contact_ident) %>
<%= f.label :nameserver_hostname, for: nil %> - <%= f.search_field :nameservers_hostname_eq, class: 'form-control', placeholder: t(:nameserver_hostname) %> + <%= f.search_field :nameservers_hostname_matches, value: params[:q][:nameservers_hostname_matches], class: 'form-control', placeholder: t(:nameserver_hostname) %>
From b2bfc9412109ec733f6c9f18e99400e7518e6347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Tue, 29 Mar 2022 11:16:09 +0300 Subject: [PATCH 070/172] Refactoring due to codeclimate issues --- app/models/registrant_user.rb | 53 +++++++++++++---------- app/views/epp/poll/_extension.xml.builder | 9 ++-- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index 96fef635e..379fac25a 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -30,7 +30,7 @@ class RegistrantUser < User counter = 0 counter += Contact.with_different_registrant_name(self).size - + companies.each do |company| counter += Contact.with_different_company_name(company).size end @@ -43,32 +43,20 @@ class RegistrantUser < User def update_contacts user = self contacts = [] - contacts.concat Contact.with_different_registrant_name(user) - .each{ |c| c.write_attribute(:name, user.username) } + contacts.concat(Contact.with_different_registrant_name(user).each do |c| + c.write_attribute(:name, user.username) + end) companies.each do |company| - contacts.concat Contact.with_different_company_name(company) - .each{ |c| c.write_attribute(:name, company.company_name) } + contacts.concat(Contact.with_different_company_name(company).each do |c| + c.write_attribute(:name, company.company_name) + end) end - + return [] if contacts.blank? - grouped_contacts = contacts.group_by(&:registrar_id) - grouped_contacts.each do |registrar_id, contacts| - bulk_action, action = actions.create!(operation: :bulk_update) if contacts.size > 1 - contacts.each do |c| - if c.save(validate: false) - action = actions.create!(contact: c, operation: :update, bulk_action_id: bulk_action&.id) - end - end - notify_registrar_contacts_updated(action: bulk_action || action, - registrar_id: registrar_id) - end - contacts - end + group_and_bulk_update(contacts) - def notify_registrar_contacts_updated(action:, registrar_id:) - registrar = Registrar.find(registrar_id) - registrar.notify(action) if registrar + contacts end def contacts(representable: true) @@ -146,4 +134,25 @@ class RegistrantUser < User user end end + + private + + def group_and_bulk_update(contacts) + grouped_contacts = contacts.group_by(&:registrar_id) + grouped_contacts.each do |registrar_id, reg_contacts| + bulk_action, action = actions.create!(operation: :bulk_update) if reg_contacts.size > 1 + reg_contacts.each do |c| + if c.save(validate: false) + action = actions.create!(contact: c, operation: :update, bulk_action_id: bulk_action&.id) + end + end + notify_registrar_contacts_updated(action: bulk_action || action, + registrar_id: registrar_id) + end + end + + def notify_registrar_contacts_updated(action:, registrar_id:) + registrar = Registrar.find(registrar_id) + registrar&.notify(action) + end end diff --git a/app/views/epp/poll/_extension.xml.builder b/app/views/epp/poll/_extension.xml.builder index a26e3db8b..3682581c0 100644 --- a/app/views/epp/poll/_extension.xml.builder +++ b/app/views/epp/poll/_extension.xml.builder @@ -8,11 +8,12 @@ builder.extension do builder.tag!('changePoll:date', obj.created_at.utc.xmlschema) builder.tag!('changePoll:svTRID', obj.id) builder.tag!('changePoll:who', obj.user) - if obj.bulk_action? - builder.tag!('changePoll:reason', 'Auto-update according to official data') - end + builder.tag!( + 'changePoll:reason', + 'Auto-update according to official data' + ) if obj.bulk_action? when 'state' builder.tag!('changePoll:operation', obj) end end -end \ No newline at end of file +end From 4f96441f260279a82bbdff6df2f45b98aa4ef4f6 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 29 Mar 2022 11:18:46 +0300 Subject: [PATCH 071/172] Add missing partial and wildcard search on `/admin/blocked_domains` --- app/controllers/admin/blocked_domains_controller.rb | 11 +++-------- app/services/partial_search_formatter.rb | 5 +++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/blocked_domains_controller.rb b/app/controllers/admin/blocked_domains_controller.rb index 268eaca73..c039c5de1 100644 --- a/app/controllers/admin/blocked_domains_controller.rb +++ b/app/controllers/admin/blocked_domains_controller.rb @@ -5,7 +5,7 @@ module Admin def index params[:q] ||= {} domains = BlockedDomain.all.order(:name) - @q = domains.ransack(params[:q]) + @q = domains.ransack(PartialSearchFormatter.format(params[:q])) @domains = @q.result.page(params[:page]) @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? @@ -13,13 +13,10 @@ module Admin end def new - @domain = BlockedDomain.new - end def create - @domain = BlockedDomain.new(blocked_domain_params) if @domain.save @@ -29,18 +26,16 @@ module Admin flash.now[:alert] = I18n.t('failed_to_add_domain') render 'new' end - end def delete - if BlockedDomain.find(params[:id]).destroy flash[:notice] = I18n.t('domain_deleted') - redirect_to admin_blocked_domains_path else flash.now[:alert] = I18n.t('failed_to_delete_domain') - redirect_to admin_blocked_domains_path end + + redirect_to admin_blocked_domains_path end def blocked_domain_params diff --git a/app/services/partial_search_formatter.rb b/app/services/partial_search_formatter.rb index 87ad602ed..c65184d08 100644 --- a/app/services/partial_search_formatter.rb +++ b/app/services/partial_search_formatter.rb @@ -1,11 +1,12 @@ class PartialSearchFormatter - def self.format(search_params) + def self.format(params) percentage = '%' + search_params = params.deep_dup search_params.each do |key, value| next unless key.include?('matches') && value.present? - value.prepend(percentage).concat(percentage) + value << percentage end search_params From e5883443328065d2d78dd35534a0a475881ee47e Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 29 Mar 2022 11:24:03 +0300 Subject: [PATCH 072/172] Add missing partial and wildcard search on `/admin/reserved_domains` --- .../admin/reserved_domains_controller.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 35a81842d..1bfade83e 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -6,7 +6,7 @@ module Admin def index params[:q] ||= {} domains = ReservedDomain.all.order(:name) - @q = domains.ransack(params[:q]) + @q = domains.ransack(PartialSearchFormatter.format(params[:q])) @domains = @q.result.page(params[:page]) @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? @@ -17,11 +17,9 @@ module Admin @domain = ReservedDomain.new end - def edit - end + def edit; end def create - @domain = ReservedDomain.new(reserved_domain_params) if @domain.save @@ -31,30 +29,26 @@ module Admin flash.now[:alert] = I18n.t('failed_to_add_domain') render 'new' end - end def update - if @domain.update(reserved_domain_params) flash[:notice] = I18n.t('domain_updated') else flash.now[:alert] = I18n.t('failed_to_update_domain') end - render 'edit' + render 'edit' end def delete - if ReservedDomain.find(params[:id]).destroy flash[:notice] = I18n.t('domain_deleted') - redirect_to admin_reserved_domains_path else flash.now[:alert] = I18n.t('failed_to_delete_domain') - redirect_to admin_reserved_domains_path end + redirect_to admin_reserved_domains_path end private From 140e5dc22e050ec3b267e1e7b66618eb67491993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Tue, 29 Mar 2022 11:31:31 +0300 Subject: [PATCH 073/172] Fixed codeclimate issues --- app/models/registrant_user.rb | 8 ++++---- app/views/epp/poll/_extension.xml.builder | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index 379fac25a..073ab3214 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -40,6 +40,7 @@ class RegistrantUser < User { result: false, counter: 0 } end + # rubocop:disable Metrics/MethodLength def update_contacts user = self contacts = [] @@ -47,7 +48,7 @@ class RegistrantUser < User c.write_attribute(:name, user.username) end) companies.each do |company| - contacts.concat(Contact.with_different_company_name(company).each do |c| + contacts.concat(Contact.with_different_company_name(company).each do |c| c.write_attribute(:name, company.company_name) end) end @@ -55,9 +56,9 @@ class RegistrantUser < User return [] if contacts.blank? group_and_bulk_update(contacts) - contacts end + # rubocop:enable Metrics/MethodLength def contacts(representable: true) Contact.registrant_user_contacts(self, representable: representable) @@ -138,8 +139,7 @@ class RegistrantUser < User private def group_and_bulk_update(contacts) - grouped_contacts = contacts.group_by(&:registrar_id) - grouped_contacts.each do |registrar_id, reg_contacts| + contacts.group_by(&:registrar_id).each do |registrar_id, reg_contacts| bulk_action, action = actions.create!(operation: :bulk_update) if reg_contacts.size > 1 reg_contacts.each do |c| if c.save(validate: false) diff --git a/app/views/epp/poll/_extension.xml.builder b/app/views/epp/poll/_extension.xml.builder index 3682581c0..5a17995df 100644 --- a/app/views/epp/poll/_extension.xml.builder +++ b/app/views/epp/poll/_extension.xml.builder @@ -8,10 +8,12 @@ builder.extension do builder.tag!('changePoll:date', obj.created_at.utc.xmlschema) builder.tag!('changePoll:svTRID', obj.id) builder.tag!('changePoll:who', obj.user) - builder.tag!( - 'changePoll:reason', - 'Auto-update according to official data' - ) if obj.bulk_action? + if obj.bulk_action? + builder.tag!( + 'changePoll:reason', + 'Auto-update according to official data' + ) + end when 'state' builder.tag!('changePoll:operation', obj) end From 1106893a877dc130a72d18dc52c10e1669fc109a Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 29 Mar 2022 11:40:27 +0300 Subject: [PATCH 074/172] Add missing partial and wildcard search on `/admin/epp_logs` --- app/controllers/admin/epp_logs_controller.rb | 14 ++++++-------- app/views/admin/epp_logs/index.haml | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/epp_logs_controller.rb b/app/controllers/admin/epp_logs_controller.rb index 279ff1ab8..c67f0b562 100644 --- a/app/controllers/admin/epp_logs_controller.rb +++ b/app/controllers/admin/epp_logs_controller.rb @@ -5,7 +5,7 @@ module Admin # rubocop:disable Metrics/MethodLength def index - @q = ApiLog::EppLog.ransack(params[:q]) + @q = ApiLog::EppLog.ransack(PartialSearchFormatter.format(params[:q])) @q.sorts = 'id desc' if @q.sorts.empty? @epp_logs = @q.result @@ -30,15 +30,13 @@ module Admin def set_default_dates params[:q] ||= {} - if params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present? - default_date = params[:created_after] + return unless params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && + params[:created_after].present? - if !['today', 'tomorrow', 'yesterday'].include?(default_date) - default_date = 'today' - end + default_date = params[:created_after] + default_date = 'today' unless %w[today tomorrow yesterday].include?(default_date) - params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d") - end + params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d") end end end diff --git a/app/views/admin/epp_logs/index.haml b/app/views/admin/epp_logs/index.haml index e657bd7fe..01e63dfcb 100644 --- a/app/views/admin/epp_logs/index.haml +++ b/app/views/admin/epp_logs/index.haml @@ -22,12 +22,12 @@ .col-md-3 .form-group = f.label :api_user - = f.search_field :api_user_name_cont, class: 'form-control', placeholder: t(:api_user), autocomplete: 'off' + = f.search_field :api_user_name_matches, value: params[:q][:api_user_name_matches], class: 'form-control', placeholder: t(:api_user), autocomplete: 'off' .row .col-md-3 .form-group = f.label :registrar - = f.select :api_user_registrar_cont, Registrar.all.map { |x| [x, x.name] }, { include_blank: true }, class: 'form-control', placeholder: t(:choose) + = f.select :api_user_registrar_matches, Registrar.all.map { |x| [x, x.name] }, { include_blank: true }, class: 'form-control', placeholder: t(:choose) .col-md-3 .form-group = f.label t(:created_after) From 2cff7d93fd8e5d9a633a72dd47625243c447f0fe Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 29 Mar 2022 11:45:55 +0300 Subject: [PATCH 075/172] Add missing partial and wildcard search on `/admin/repp_logs` --- app/controllers/admin/repp_logs_controller.rb | 15 ++++++--------- app/views/admin/repp_logs/index.haml | 5 ++--- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/controllers/admin/repp_logs_controller.rb b/app/controllers/admin/repp_logs_controller.rb index 028dbffc8..9bc676ac1 100644 --- a/app/controllers/admin/repp_logs_controller.rb +++ b/app/controllers/admin/repp_logs_controller.rb @@ -5,7 +5,7 @@ module Admin # rubocop:disable Metrics/MethodLength def index - @q = ApiLog::ReppLog.ransack(params[:q]) + @q = ApiLog::ReppLog.ransack(PartialSearchFormatter.format(params[:q])) @q.sorts = 'id desc' if @q.sorts.empty? @repp_logs = @q.result @@ -32,16 +32,13 @@ module Admin def set_default_dates params[:q] ||= {} - if params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present? + return unless params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && + params[:created_after].present? - default_date = params[:created_after] + default_date = params[:created_after] + default_date = 'today' unless %w[today tomorrow yesterday].include?(default_date) - if !['today', 'tomorrow', 'yesterday'].include?(default_date) - default_date = 'today' - end - - params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d") - end + params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d") end end end diff --git a/app/views/admin/repp_logs/index.haml b/app/views/admin/repp_logs/index.haml index b2aadcae3..e90881645 100644 --- a/app/views/admin/repp_logs/index.haml +++ b/app/views/admin/repp_logs/index.haml @@ -20,13 +20,12 @@ .col-md-3 .form-group = f.label :api_user - = f.search_field :api_user_name_cont, class: 'form-control', placeholder: t(:api_user), autocomplete: 'off' + = f.search_field :api_user_name_matches, value: params[:q][:api_user_name_matches], class: 'form-control', placeholder: t(:api_user), autocomplete: 'off' .row .col-md-3 .form-group = f.label :registrar - = f.select :api_user_registrar_cont, Registrar.all.map { |x| [x, x.name] }, { include_blank: true }, class: 'form-control', placeholder: t(:choose) - -# = f.search_field :api_user_registrar_cont, class: 'form-control', placeholder: t(:registrar_name), autocomplete: 'off' + = f.select :api_user_registrar_matches, Registrar.all.map { |x| [x, x.name] }, { include_blank: true }, class: 'form-control', placeholder: t(:choose) .col-md-3 .form-group = f.label t(:created_after) From 7b47eab0d8f174be7e8ca1a56c0f4b1ef5fd0ed4 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 29 Mar 2022 13:31:31 +0300 Subject: [PATCH 076/172] Add missing partial and wildcard search on `/admin/contact_versions` --- .../admin/contact_versions_controller.rb | 30 +++++++------------ app/services/partial_search_formatter.rb | 3 +- app/views/admin/contact_versions/index.haml | 6 ++-- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/app/controllers/admin/contact_versions_controller.rb b/app/controllers/admin/contact_versions_controller.rb index 8ded131c0..c53a020ee 100644 --- a/app/controllers/admin/contact_versions_controller.rb +++ b/app/controllers/admin/contact_versions_controller.rb @@ -7,23 +7,9 @@ module Admin def index params[:q] ||= {} - search_params = params[:q].deep_dup.except(:created_at_gteq, :created_at_lteq) - - where_s = '1=1' - - search_params.each do |key, value| - next if value.empty? - - where_s += case key - when 'event' - " AND event = '#{value}'" - else - create_where_string(key, value) - end - end - - versions = Version::ContactVersion.includes(:item).where(where_s).order(created_at: :desc, id: :desc) - @q = versions.ransack(params[:q]) + search_params = PartialSearchFormatter.format(params[:q]) + versions = Version::ContactVersion.includes(:item).order(created_at: :desc, id: :desc) + @q = versions.ransack(polymorphic_association(search_params)) @versions = @q.result.page(params[:page]) @versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? @@ -53,8 +39,14 @@ module Admin render json: Version::ContactVersion.search_by_query(params[:q]) end - def create_where_string(key, value) - " AND object->>'#{key}' ~* '#{value}'" + private + + def polymorphic_association(search_params) + record_type = {} + fields = %w[name code ident] + fields.each { |field| record_type[:"item_of_Contact_type_#{field}_matches"] = search_params[:"#{field}_matches"] } + + record_type end end end diff --git a/app/services/partial_search_formatter.rb b/app/services/partial_search_formatter.rb index c65184d08..af0c7978d 100644 --- a/app/services/partial_search_formatter.rb +++ b/app/services/partial_search_formatter.rb @@ -1,12 +1,11 @@ class PartialSearchFormatter def self.format(params) - percentage = '%' search_params = params.deep_dup search_params.each do |key, value| next unless key.include?('matches') && value.present? - value << percentage + value << '%' end search_params diff --git a/app/views/admin/contact_versions/index.haml b/app/views/admin/contact_versions/index.haml index 4d7a9948d..581402197 100644 --- a/app/views/admin/contact_versions/index.haml +++ b/app/views/admin/contact_versions/index.haml @@ -7,15 +7,15 @@ .col-md-3 .form-group = f.label :name - = f.search_field :name, value: params[:q][:name], class: 'form-control', placeholder: t(:name) + = f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name) .col-md-3 .form-group = f.label :id - = f.search_field :code, value: params[:q][:code], class: 'form-control', placeholder: t(:id) + = f.search_field :code_matches, value: params[:q][:code_matches], class: 'form-control', placeholder: t(:id) .col-md-3 .form-group = f.label :ident - = f.search_field :ident, value: params[:q][:ident], class: 'form-control', placeholder: t(:ident) + = f.search_field :ident_matches, value: params[:q][:ident_matches], class: 'form-control', placeholder: t(:ident) .col-md-3 .form-group = label_tag :action From b2a1f49ba0f59ca838ffe2db1fcf6ce15b2f9120 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 29 Mar 2022 14:07:31 +0300 Subject: [PATCH 077/172] Codeclimate DRY --- app/controllers/admin/epp_logs_controller.rb | 11 ++++++++--- app/controllers/admin/repp_logs_controller.rb | 13 +++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/epp_logs_controller.rb b/app/controllers/admin/epp_logs_controller.rb index c67f0b562..021c90379 100644 --- a/app/controllers/admin/epp_logs_controller.rb +++ b/app/controllers/admin/epp_logs_controller.rb @@ -29,14 +29,19 @@ module Admin def set_default_dates params[:q] ||= {} - - return unless params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && - params[:created_after].present? + return unless default_dates? default_date = params[:created_after] default_date = 'today' unless %w[today tomorrow yesterday].include?(default_date) params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d") end + + private + + def default_dates? + params[:q] ||= {} + params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present? + end end end diff --git a/app/controllers/admin/repp_logs_controller.rb b/app/controllers/admin/repp_logs_controller.rb index 9bc676ac1..add77b1d2 100644 --- a/app/controllers/admin/repp_logs_controller.rb +++ b/app/controllers/admin/repp_logs_controller.rb @@ -1,7 +1,7 @@ module Admin class ReppLogsController < BaseController load_and_authorize_resource class: ApiLog::ReppLog - before_action :set_default_dates, only: [:index] + before_action :set_default_dates, only: [:index], if: -> { params[:q].to_i == current_user.id } # rubocop:disable Metrics/MethodLength def index @@ -31,14 +31,19 @@ module Admin def set_default_dates params[:q] ||= {} - - return unless params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && - params[:created_after].present? + return unless default_dates? default_date = params[:created_after] default_date = 'today' unless %w[today tomorrow yesterday].include?(default_date) params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d") end + + private + + def default_dates? + params[:q] ||= {} + params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present? + end end end From 6a8b50d72e2d093f25bbb1a909dafcf5ee8a3592 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 29 Mar 2022 15:09:46 +0300 Subject: [PATCH 078/172] Fix repp logs controller --- app/controllers/admin/repp_logs_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/repp_logs_controller.rb b/app/controllers/admin/repp_logs_controller.rb index add77b1d2..abb8415bc 100644 --- a/app/controllers/admin/repp_logs_controller.rb +++ b/app/controllers/admin/repp_logs_controller.rb @@ -1,7 +1,7 @@ module Admin class ReppLogsController < BaseController load_and_authorize_resource class: ApiLog::ReppLog - before_action :set_default_dates, only: [:index], if: -> { params[:q].to_i == current_user.id } + before_action :set_default_dates, only: [:index] # rubocop:disable Metrics/MethodLength def index From f93286c2e69a27630a96bce1906747441d7f67cd Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 29 Mar 2022 15:49:49 +0300 Subject: [PATCH 079/172] Fix github staging workflow --- .github/workflows/build_deploy_staging.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_deploy_staging.yml b/.github/workflows/build_deploy_staging.yml index e339353f2..b854ce820 100644 --- a/.github/workflows/build_deploy_staging.yml +++ b/.github/workflows/build_deploy_staging.yml @@ -67,7 +67,7 @@ jobs: - name: Set EPP port run: echo "EPP_PORT=${PR_REF:(-3)}" >> $GITHUB_ENV - + - name: Set config files for build env: ST_APP: ${{ secrets.ST_APPLICATION_YML}} @@ -101,7 +101,7 @@ jobs: sed -i -e 's/{certfile_path, "\/opt\/shared\/ca\/certs\/cert.pem"},/{certfile_path, "\/opt\/shared\/ca\/certs\/tls.crt"},/' sys.config sed -i -e 's/{keyfile_path, "\/opt\/shared\/ca\/certs\/key.pem"},/{keyfile_path, "\/opt\/shared\/ca\/certs\/tls.key"}]},/' sys.config sed -i -e 's/{crlfile_path, "\/opt\/shared\/ca\/certs\/key.pem"}]},//' sys.config - + - name: Build proxy image run: | cd epp_proxy @@ -143,7 +143,9 @@ jobs: chmod 0600 kubeconfig - name: Install Open VPN - run: sudo apt-get install openvpn + run: | + sudo apt-get update + sudo apt-get install openvpn - name: Deploy from remote server timeout-minutes: 5 From e5688e843d7c9884728bf5dc698d5499dae22950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 31 Mar 2022 16:21:43 +0300 Subject: [PATCH 080/172] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a97c8f366..ea1333016 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +31.03.2022 +* Sidekiq update to 6.4.1 [#2322](https://github.com/internetee/registry/pull/2322) + 25.03.2022 * Bulk change of business contacts' names requires now user confirmation [#2309](https://github.com/internetee/registry/pull/2309) From daafa756aa292dbdcf979f613ae3c0bd101dbc0d Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Thu, 31 Mar 2022 16:33:47 +0300 Subject: [PATCH 081/172] Refactor account activity csv generation --- app/models/account_activity.rb | 19 +++++++------------ app/services/csv_generator.rb | 8 +++----- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/app/models/account_activity.rb b/app/models/account_activity.rb index 05873a2a6..38fa70358 100644 --- a/app/models/account_activity.rb +++ b/app/models/account_activity.rb @@ -11,6 +11,7 @@ class AccountActivity < ApplicationRecord UPDATE_CREDIT = 'update_credit'.freeze after_create :update_balance + def update_balance account.balance += sum account.save @@ -19,23 +20,17 @@ class AccountActivity < ApplicationRecord save end + def as_csv_row + [account.registrar.try(:code), description, I18n.t(activity_type), I18n.l(created_at), sum] + end + class << self def types_for_select [CREATE, RENEW, ADD_CREDIT, UPDATE_CREDIT].map { |x| [I18n.t(x), x] } end - def to_csv - attributes = %w(description activity_type created_at sum) - - CSV.generate(headers: true) do |csv| - csv << %w(registrar description activity_type receipt_date sum) - - all.each do |x| - attrs = [x.account.registrar.try(:code)] - attrs += attributes.map { |attr| x.send(attr) } - csv << attrs - end - end + def csv_header + ['Registrar', 'Description', 'Activity Type', 'Receipt Date', 'Sum'] end end end diff --git a/app/services/csv_generator.rb b/app/services/csv_generator.rb index a2c1305a3..fd47fac45 100644 --- a/app/services/csv_generator.rb +++ b/app/services/csv_generator.rb @@ -1,7 +1,7 @@ class CsvGenerator def self.generate_csv(objects) class_name = objects.first.class - return objects.to_csv unless custom_csv(class_name) + return objects.to_csv unless custom_csv?(class_name) CSV.generate do |csv| csv << class_name.csv_header @@ -9,9 +9,7 @@ class CsvGenerator end end - private - - def self.custom_csv(class_name) - [Version::DomainVersion, Version::ContactVersion, Domain, Contact, Invoice, Account].include?(class_name) + def self.custom_csv?(class_name) + [Version::DomainVersion, Version::ContactVersion, Domain, Contact, Invoice, Account, AccountActivity].include?(class_name) end end From 3f1a84f67a1ca9afeb31ed73ea5814e8a2a9831f Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 1 Apr 2022 01:22:24 +0000 Subject: [PATCH 082/172] Update dependency pg to v1.3.5 --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 672291cf5..f172c869a 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,7 @@ gem 'figaro', '~> 1.2' # model related gem 'paper_trail', '~> 12.1' -gem 'pg', '1.3.4' +gem 'pg', '1.3.5' # 1.8 is for Rails < 5.0 gem 'ransack', '~> 2.6.0' gem 'truemail', '~> 2.4' # validates email by regexp, mail server existence and address existence diff --git a/Gemfile.lock b/Gemfile.lock index 618c4c161..73b1d3526 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -351,7 +351,7 @@ GEM activerecord (>= 5.2) request_store (~> 1.1) pdfkit (0.8.5) - pg (1.3.4) + pg (1.3.5) pg_query (2.1.2) google-protobuf (>= 3.17.1) pghero (2.8.1) @@ -574,7 +574,7 @@ DEPENDENCIES omniauth-tara! paper_trail (~> 12.1) pdfkit - pg (= 1.3.4) + pg (= 1.3.5) pg_query (>= 0.9.0) pghero pry (= 0.14.1) From e50501f13f0779253ea383d3d6702fd551a5a110 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Fri, 1 Apr 2022 10:59:04 +0300 Subject: [PATCH 083/172] Migrate `ToCsv` module to `CsvGenerator` service --- .../admin/account_activities_controller.rb | 2 +- .../account_activities_controller.rb | 2 +- .../registrar/contacts_controller.rb | 2 +- app/lib/to_csv.rb | 10 ----- app/models/account.rb | 1 - app/models/api_log/epp_log.rb | 4 +- app/models/api_log/repp_log.rb | 4 +- app/models/blocked_domain.rb | 1 - app/models/contact.rb | 9 ----- app/models/dispute.rb | 1 - app/models/domain.rb | 15 ------- app/models/invoice.rb | 1 - app/models/reserved_domain.rb | 1 - app/models/version/contact_version.rb | 1 - app/models/version/domain_version.rb | 1 - app/services/csv_generator.rb | 39 ++++++++++++++----- 16 files changed, 34 insertions(+), 60 deletions(-) delete mode 100644 app/lib/to_csv.rb diff --git a/app/controllers/admin/account_activities_controller.rb b/app/controllers/admin/account_activities_controller.rb index ebd44e28e..0d22a4298 100644 --- a/app/controllers/admin/account_activities_controller.rb +++ b/app/controllers/admin/account_activities_controller.rb @@ -35,7 +35,7 @@ module Admin respond_to do |format| format.html format.csv do - send_data @q.result.to_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" + send_data CsvGenerator.generate_csv(@q.result), filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" end end diff --git a/app/controllers/registrar/account_activities_controller.rb b/app/controllers/registrar/account_activities_controller.rb index 55e53f8fc..7b5281275 100644 --- a/app/controllers/registrar/account_activities_controller.rb +++ b/app/controllers/registrar/account_activities_controller.rb @@ -20,7 +20,7 @@ class Registrar respond_to do |format| format.html { @account_activities = @q.result.page(params[:page]) } format.csv do - send_data @q.result.to_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" + send_data CsvGenerator.generate_csv(@q.result), filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" end end diff --git a/app/controllers/registrar/contacts_controller.rb b/app/controllers/registrar/contacts_controller.rb index ec4ce5129..812e278e5 100644 --- a/app/controllers/registrar/contacts_controller.rb +++ b/app/controllers/registrar/contacts_controller.rb @@ -40,7 +40,7 @@ class Registrar @contacts = @contacts.per(contacts_per_page) if contacts_per_page.positive? end format.csv do - raw_csv = contacts.to_csv + raw_csv = CsvGenerator.generate_csv(contacts) send_data raw_csv, filename: 'contacts.csv', type: "#{Mime[:csv]}; charset=utf-8" end format.pdf do diff --git a/app/lib/to_csv.rb b/app/lib/to_csv.rb deleted file mode 100644 index 32c288978..000000000 --- a/app/lib/to_csv.rb +++ /dev/null @@ -1,10 +0,0 @@ -module ToCsv - def to_csv - CSV.generate do |csv| - csv << column_names - all.find_each do |item| - csv << item.attributes.values_at(*column_names) - end - end - end -end diff --git a/app/models/account.rb b/app/models/account.rb index 334d292f2..7639c61dd 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,5 +1,4 @@ class Account < ApplicationRecord - extend ToCsv include Versions belongs_to :registrar, required: true diff --git a/app/models/api_log/epp_log.rb b/app/models/api_log/epp_log.rb index feed1ecad..c89569be5 100644 --- a/app/models/api_log/epp_log.rb +++ b/app/models/api_log/epp_log.rb @@ -1,5 +1,3 @@ module ApiLog - class EppLog < Db - extend ToCsv - end + class EppLog < Db; end end diff --git a/app/models/api_log/repp_log.rb b/app/models/api_log/repp_log.rb index 62dcee238..540a9043a 100644 --- a/app/models/api_log/repp_log.rb +++ b/app/models/api_log/repp_log.rb @@ -1,5 +1,3 @@ module ApiLog - class ReppLog < Db - extend ToCsv - end + class ReppLog < Db; end end diff --git a/app/models/blocked_domain.rb b/app/models/blocked_domain.rb index fb50a8b52..f82faa771 100644 --- a/app/models/blocked_domain.rb +++ b/app/models/blocked_domain.rb @@ -1,6 +1,5 @@ class BlockedDomain < ApplicationRecord include Versions - extend ToCsv before_save :generate_data after_destroy :remove_data diff --git a/app/models/contact.rb b/app/models/contact.rb index f44b28f35..dab2dd6d9 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -188,15 +188,6 @@ class Contact < ApplicationRecord ] end - def to_csv - CSV.generate do |csv| - csv << column_names - all.each do |contact| - csv << contact.attributes.values_at(*column_names) - end - end - end - def pdf(html) kit = PDFKit.new(html) kit.to_pdf diff --git a/app/models/dispute.rb b/app/models/dispute.rb index cbf93566a..f5a948355 100644 --- a/app/models/dispute.rb +++ b/app/models/dispute.rb @@ -1,5 +1,4 @@ class Dispute < ApplicationRecord - extend ToCsv include WhoisStatusPopulate validates :domain_name, :password, :starts_at, :expires_at, presence: true before_validation :fill_empty_passwords, :set_expiry_date diff --git a/app/models/domain.rb b/app/models/domain.rb index 3728b0de1..53e2ddf9b 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -289,21 +289,6 @@ class Domain < ApplicationRecord ) end - def to_csv - CSV.generate do |csv| - headers = column_names.dup - swap_elements(headers, [[0, 1], [1, 5]]) - headers[0] = 'Domain' - headers[1] = headers[1].humanize - csv << headers - all.find_each do |item| - row = item.attributes.values_at(*column_names) - swap_elements(row, [[0, 1], [1, 5]]) - csv << row - end - end - end - private def registrant_user_domains_by_registrant(registrant_user) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 80dbc6417..c31ae15c4 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -3,7 +3,6 @@ class Invoice < ApplicationRecord include Invoice::Cancellable include Invoice::Payable include Invoice::BookKeeping - extend ToCsv belongs_to :buyer, class_name: 'Registrar' has_one :account_activity diff --git a/app/models/reserved_domain.rb b/app/models/reserved_domain.rb index 5d585e5d9..10d5edd11 100644 --- a/app/models/reserved_domain.rb +++ b/app/models/reserved_domain.rb @@ -1,5 +1,4 @@ class ReservedDomain < ApplicationRecord - extend ToCsv include Versions # version/reserved_domain_version.rb include WhoisStatusPopulate before_save :fill_empty_passwords diff --git a/app/models/version/contact_version.rb b/app/models/version/contact_version.rb index 669c422fe..d3ff1130c 100644 --- a/app/models/version/contact_version.rb +++ b/app/models/version/contact_version.rb @@ -1,5 +1,4 @@ class Version::ContactVersion < PaperTrail::Version - extend ToCsv include VersionSession self.table_name = :log_contacts diff --git a/app/models/version/domain_version.rb b/app/models/version/domain_version.rb index bef5208f3..e84fc9da2 100644 --- a/app/models/version/domain_version.rb +++ b/app/models/version/domain_version.rb @@ -1,5 +1,4 @@ class Version::DomainVersion < PaperTrail::Version - extend ToCsv include VersionSession self.table_name = :log_domains diff --git a/app/services/csv_generator.rb b/app/services/csv_generator.rb index fd47fac45..16901dcff 100644 --- a/app/services/csv_generator.rb +++ b/app/services/csv_generator.rb @@ -1,15 +1,34 @@ class CsvGenerator - def self.generate_csv(objects) - class_name = objects.first.class - return objects.to_csv unless custom_csv?(class_name) + class << self + def generate_csv(objects) + @class_name = objects.first.class + return default_generation(objects) unless custom_csv? - CSV.generate do |csv| - csv << class_name.csv_header - objects.each { |object| csv << object.as_csv_row } + CSV.generate do |csv| + csv << @class_name.csv_header + objects.each { |object| csv << object.as_csv_row } + end + end + + private + + def default_generation(objects) + CSV.generate do |csv| + csv << @class_name.column_names + objects.each { |object| csv << object.attributes.values_at(*@class_name.column_names) } + end + end + + def custom_csv? + [ + Version::DomainVersion, + Version::ContactVersion, + Domain, + Contact, + Invoice, + Account, + AccountActivity + ].include?(@class_name) end end - - def self.custom_csv?(class_name) - [Version::DomainVersion, Version::ContactVersion, Domain, Contact, Invoice, Account, AccountActivity].include?(class_name) - end end From aef30eeb4d76612c41be627c2fc0a6da8e65f40e Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Fri, 1 Apr 2022 11:50:35 +0300 Subject: [PATCH 084/172] Improve default csv generation --- .../admin/account_activities_controller.rb | 3 ++- .../account_activities_controller.rb | 3 ++- app/models/domain.rb | 7 ++++-- app/models/invoice.rb | 2 +- app/services/csv_generator.rb | 23 ++++++++----------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/controllers/admin/account_activities_controller.rb b/app/controllers/admin/account_activities_controller.rb index 0d22a4298..452acaee1 100644 --- a/app/controllers/admin/account_activities_controller.rb +++ b/app/controllers/admin/account_activities_controller.rb @@ -35,7 +35,8 @@ module Admin respond_to do |format| format.html format.csv do - send_data CsvGenerator.generate_csv(@q.result), filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" + raw_csv = CsvGenerator.generate_csv(@q.result) + send_data raw_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" end end diff --git a/app/controllers/registrar/account_activities_controller.rb b/app/controllers/registrar/account_activities_controller.rb index 7b5281275..0ad8c3d5a 100644 --- a/app/controllers/registrar/account_activities_controller.rb +++ b/app/controllers/registrar/account_activities_controller.rb @@ -20,7 +20,8 @@ class Registrar respond_to do |format| format.html { @account_activities = @q.result.page(params[:page]) } format.csv do - send_data CsvGenerator.generate_csv(@q.result), filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" + raw_csv = CsvGenerator.generate_csv(@q.result) + send_data raw_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" end end diff --git a/app/models/domain.rb b/app/models/domain.rb index 53e2ddf9b..2c6069cd1 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -748,7 +748,7 @@ class Domain < ApplicationRecord statuses, contacts.pluck(:code), force_delete_date, - force_delete_data + force_delete_data, ] end @@ -764,7 +764,10 @@ class Domain < ApplicationRecord end def self.csv_header - ['Domain', 'Registrant', 'Valid to', 'Registrar', 'Created at', 'Statuses', 'Contacts code', 'Force delete date', 'Force delete data'] + [ + 'Domain', 'Registrant', 'Valid to', 'Registrar', 'Created at', + 'Statuses', 'Contacts code', 'Force delete date', 'Force delete data', + ] end def self.pdf(html) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index c31ae15c4..6ba3a158d 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -125,7 +125,7 @@ class Invoice < ApplicationRecord issue_date, total, currency, - seller_name + seller_name, ] end diff --git a/app/services/csv_generator.rb b/app/services/csv_generator.rb index 16901dcff..d92beeddc 100644 --- a/app/services/csv_generator.rb +++ b/app/services/csv_generator.rb @@ -1,11 +1,11 @@ class CsvGenerator class << self def generate_csv(objects) - @class_name = objects.first.class - return default_generation(objects) unless custom_csv? + class_name = objects.first.class + return default_generation(objects) unless custom_csv?(class_name) CSV.generate do |csv| - csv << @class_name.csv_header + csv << class_name.csv_header objects.each { |object| csv << object.as_csv_row } end end @@ -14,21 +14,16 @@ class CsvGenerator def default_generation(objects) CSV.generate do |csv| - csv << @class_name.column_names - objects.each { |object| csv << object.attributes.values_at(*@class_name.column_names) } + csv << objects.column_names + objects.all.find_each { |object| csv << object.attributes.values_at(*objects.column_names) } end end - def custom_csv? + def custom_csv?(class_name) [ - Version::DomainVersion, - Version::ContactVersion, - Domain, - Contact, - Invoice, - Account, - AccountActivity - ].include?(@class_name) + Version::DomainVersion, Version::ContactVersion, Domain, + Contact, Invoice, Account, AccountActivity + ].include?(class_name) end end end From b6a5bc73cad4ea291c2d64a1ad27fa2d9f8052fc Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Fri, 1 Apr 2022 13:20:13 +0300 Subject: [PATCH 085/172] Code climate refactor --- app/models/domain.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 2c6069cd1..7afd8046e 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -766,7 +766,7 @@ class Domain < ApplicationRecord def self.csv_header [ 'Domain', 'Registrant', 'Valid to', 'Registrar', 'Created at', - 'Statuses', 'Contacts code', 'Force delete date', 'Force delete data', + 'Statuses', 'Contacts code', 'Force delete date', 'Force delete data' ] end From a55797eef6102ea102217fdc0012ab43129e313d Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 1 Apr 2022 04:31:33 +0000 Subject: [PATCH 086/172] Update dependency puma to v5.6.4 [SECURITY] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 73b1d3526..a99b31189 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -360,7 +360,7 @@ GEM coderay (~> 1.1) method_source (~> 1.0) public_suffix (4.0.6) - puma (5.6.2) + puma (5.6.4) nio4r (~> 2.0) que (0.14.3) que-web (0.7.2) From 20c5b4946c8d81910be95116c11b8060dd2b4869 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 1 Apr 2022 17:14:50 +0000 Subject: [PATCH 087/172] Update actions/checkout action to v3 --- .github/workflows/build_baseimage_with_gems.yml | 2 +- .github/workflows/ruby.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_baseimage_with_gems.yml b/.github/workflows/build_baseimage_with_gems.yml index 3487e838c..e6f72594a 100644 --- a/.github/workflows/build_baseimage_with_gems.yml +++ b/.github/workflows/build_baseimage_with_gems.yml @@ -17,7 +17,7 @@ jobs: steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Login to container registry env: diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index dd71c4bee..8a168aec7 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -22,7 +22,7 @@ jobs: continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} From 8397950329dc09b9d96c42bf547e244351c1659e Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 4 Apr 2022 11:39:51 +0000 Subject: [PATCH 088/172] Update actions/download-artifact action to v3 --- .github/workflows/ruby.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 8a168aec7..f275d8a96 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -104,7 +104,7 @@ jobs: - name: Give test coverage reporter executable permissions run: chmod +x cc-test-reporter - - uses: actions/download-artifact@v2.1.0 + - uses: actions/download-artifact@v3.0.0 with: name: coverage-${{ matrix.ruby }} path: coverage From a54a822d912922b4a03e545921650e070aa59021 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 4 Apr 2022 11:39:54 +0000 Subject: [PATCH 089/172] Update actions/upload-artifact action to v3 --- .github/workflows/ruby.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 8a168aec7..d872eed93 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -79,7 +79,7 @@ jobs: - name: Save coverage run: ./cc-test-reporter format-coverage --output coverage/codeclimate.${{ matrix.ruby }}.json - - uses: actions/upload-artifact@v2.3.1 + - uses: actions/upload-artifact@v3.0.0 with: name: coverage-${{ matrix.ruby }} path: coverage/codeclimate.${{ matrix.ruby }}.json From 076cc269893ca338cf011894c473c6cb614cd920 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 4 Apr 2022 11:53:26 +0000 Subject: [PATCH 090/172] Update actions/upload-artifact action to v3 --- .github/workflows/ruby.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index f275d8a96..d50636e26 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -79,7 +79,7 @@ jobs: - name: Save coverage run: ./cc-test-reporter format-coverage --output coverage/codeclimate.${{ matrix.ruby }}.json - - uses: actions/upload-artifact@v2.3.1 + - uses: actions/upload-artifact@v3.0.0 with: name: coverage-${{ matrix.ruby }} path: coverage/codeclimate.${{ matrix.ruby }}.json From 9c848bb4dc4c427a538b00e1b431df35c7ba375a Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 4 Apr 2022 12:17:32 +0000 Subject: [PATCH 091/172] Update dependency data_migrate to v8 --- Gemfile | 2 +- Gemfile.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index f172c869a..c907eb267 100644 --- a/Gemfile +++ b/Gemfile @@ -40,7 +40,7 @@ gem 'select2-rails', '4.0.13' # for autocomplete gem 'selectize-rails', '0.12.6' # include selectize.js for select # registry specfic -gem 'data_migrate', '~> 7.0' +gem 'data_migrate', '~> 8.0' gem 'dnsruby', '~> 1.61' gem 'isikukood' # for EE-id validation gem 'money-rails' diff --git a/Gemfile.lock b/Gemfile.lock index a99b31189..f7e9afa7e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -193,7 +193,7 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.1.9) + concurrent-ruby (1.1.10) connection_pool (2.2.5) countries (4.0.1) i18n_data (~> 0.13.0) @@ -205,7 +205,7 @@ GEM daemons-rails (1.2.1) daemons multi_json (~> 1.0) - data_migrate (7.0.2) + data_migrate (8.0.0) activerecord (>= 5.0) railties (>= 5.0) database_cleaner (2.0.1) @@ -289,7 +289,7 @@ GEM kaminari-core (1.2.1) libxml-ruby (3.2.1) logger (1.4.3) - loofah (2.12.0) + loofah (2.16.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -480,7 +480,7 @@ GEM attr_required (>= 0.0.5) httpclient (>= 2.4) temple (0.8.2) - thor (1.1.0) + thor (1.2.1) tilt (2.0.10) truemail (2.4.9) simpleidn (~> 0.2.1) @@ -544,7 +544,7 @@ DEPENDENCIES company_register! countries daemons-rails (= 1.2.1) - data_migrate (~> 7.0) + data_migrate (~> 8.0) database_cleaner devise (~> 4.8) digidoc_client! From c240aef717b1c406f3678b6a1e1a84ba573432a8 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 5 Apr 2022 12:06:53 +0300 Subject: [PATCH 092/172] Improve csv tests --- test/fixtures/files/contacts.csv | 8 -------- test/fixtures/files/domains.csv | 5 ----- test/system/admin_area/contacts/csv_test.rb | 13 ++++++++----- test/system/admin_area/domains/csv_test.rb | 12 +++++++----- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/test/fixtures/files/contacts.csv b/test/fixtures/files/contacts.csv index 73d9104af..9d8ca5357 100644 --- a/test/fixtures/files/contacts.csv +++ b/test/fixtures/files/contacts.csv @@ -1,10 +1,2 @@ Name,ID,Ident,E-mail,Created at,Registrar,Phone -John,john-001,1234 [US priv],john@inbox.test,2010-07-05 07:30:00,Best Names,+555.555 -William,william-001,12345 [US priv],william@inbox.test,2010-07-05 07:30:00,Best Names,+555.555 -Jane,jane-001,123456 [US priv],jane@mail.test,2010-07-05 07:30:00,Best Names,+555.555 Acme Ltd,acme-ltd-001,1234567 [US org],acme@outlook.test,2010-07-05 07:30:00,Best Names,+555.555 -Jack,jack-001,12345678 [US org],jack@inbox.test,2010-07-05 07:30:00,Good Names,+555.555 -William,william-002,12345 [US priv],william@inbox.test,2010-07-05 07:30:00,Good Names,+555.555 -Registrar Ltd,registrarltd-001,1234567890 [US org],registrar@inbox.test,2010-07-05 07:30:00,Good Names,+555.555 -any,invalid,[ ],invalid@invalid.test,2010-07-05 07:30:00,Best Names, -any,invalid_email,[ ],invalid@invalid.,2010-07-05 07:30:00,Best Names, diff --git a/test/fixtures/files/domains.csv b/test/fixtures/files/domains.csv index 69e9df8a8..b8261ebc2 100644 --- a/test/fixtures/files/domains.csv +++ b/test/fixtures/files/domains.csv @@ -1,7 +1,2 @@ Domain,Registrant,Valid to,Registrar,Created at,Statuses,Contacts code,Force delete date,Force delete data -shop.test,John,2010-07-04 21:00:00,Best Names,2010-07-05 07:30:00,"[""ok""]","[""william-001"", ""jane-001"", ""acme-ltd-001""]",2010-07-08, -airport.test,John,2010-07-05 00:00:00,Best Names,2010-07-05 07:30:00,"[""ok""]","[""john-001"", ""william-001"", ""william-001""]",, -library.test,Acme Ltd,2010-07-05 00:00:00,Best Names,2010-07-05 07:30:00,"[""inactive""]","[""john-001"", ""acme-ltd-001""]",, metro.test,Jack,2010-07-05 00:00:00,Good Names,2010-07-05 07:30:00,[],"[""jack-001"", ""jack-001""]",, -hospital.test,John,2010-07-05 00:00:00,Good Names,2010-07-05 07:30:00,"[""inactive""]","[""john-001"", ""john-001""]",, -invalid.test,any,2010-07-04 21:00:00,Best Names,2010-07-05 07:30:00,"[""inactive""]","[""invalid"", ""invalid""]",, diff --git a/test/system/admin_area/contacts/csv_test.rb b/test/system/admin_area/contacts/csv_test.rb index 552bcf437..de5bd440e 100644 --- a/test/system/admin_area/contacts/csv_test.rb +++ b/test/system/admin_area/contacts/csv_test.rb @@ -1,14 +1,17 @@ require 'application_system_test_case' class ContactsCsvTest < ApplicationSystemTestCase - setup { sign_in users(:admin) } + setup do + sign_in users(:admin) + Domain.destroy_all + Contact.all.each { |contact| contact.destroy unless contact.name == 'Acme Ltd' } + end def test_download_contacts_list_as_csv travel_to Time.zone.parse('2010-07-05 10:30') - Contact.all.each do |contact| - contact.created_at = Time.zone.now - contact.save(:validate => false) - end + contact = Contact.first + contact.created_at = Time.zone.now + contact.save(validate: false) visit admin_contacts_url click_link('CSV') diff --git a/test/system/admin_area/domains/csv_test.rb b/test/system/admin_area/domains/csv_test.rb index 568815dd7..691a8dc50 100644 --- a/test/system/admin_area/domains/csv_test.rb +++ b/test/system/admin_area/domains/csv_test.rb @@ -1,14 +1,16 @@ require 'application_system_test_case' class DomainsCsvTest < ApplicationSystemTestCase - setup { sign_in users(:admin) } + setup do + sign_in users(:admin) + Domain.all.each { |domain| domain.destroy unless domain.name == 'metro.test' } + end def test_download_domains_list_as_csv travel_to Time.zone.parse('2010-07-05 10:30') - Domain.all.each do |domain| - domain.created_at = Time.zone.now - domain.save(:validate => false) - end + domain = Domain.first + domain.created_at = Time.zone.now + domain.save(validate: false) visit admin_domains_url click_link('CSV') From fd6e625d251399e7cec891f033c4d07d1a7bffce Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 5 Apr 2022 14:18:04 +0300 Subject: [PATCH 093/172] Merge branch 'master' into 499-admin-wildcard-search --- .../workflows/build_baseimage_with_gems.yml | 2 +- .github/workflows/ruby.yml | 6 +-- .gitignore | 1 + CHANGELOG.md | 6 +++ Gemfile | 6 +-- Gemfile.lock | 22 ++++----- .../admin/account_activities_controller.rb | 3 +- app/controllers/admin/base_controller.rb | 2 +- .../admin/contact_versions_controller.rb | 13 ++++- .../admin/domain_versions_controller.rb | 7 +-- .../api/v1/registrant/contacts_controller.rb | 11 +++++ .../account_activities_controller.rb | 3 +- .../registrar/contacts_controller.rb | 2 +- app/helpers/application_helper.rb | 24 ++-------- app/helpers/object_versions_helper.rb | 19 -------- app/lib/to_csv.rb | 10 ---- app/models/account.rb | 9 +++- app/models/account_activity.rb | 19 +++----- app/models/api_log/epp_log.rb | 4 +- app/models/api_log/repp_log.rb | 4 +- app/models/blocked_domain.rb | 1 - app/models/contact.rb | 32 +++++++++---- app/models/dispute.rb | 1 - app/models/domain.rb | 47 +++++++++++++------ app/models/invoice.rb | 28 ++++++++++- app/models/registrant_user.rb | 25 +++++++--- app/models/reserved_domain.rb | 1 - app/models/version/contact_version.rb | 18 ++++++- app/models/version/domain_version.rb | 17 ++++++- app/services/csv_generator.rb | 29 ++++++++++++ app/services/object_versions_parser.rb | 28 +++++++++++ app/views/admin/contact_versions/index.haml | 4 +- app/views/admin/contact_versions/show.haml | 5 +- app/views/admin/domain_versions/archive.haml | 4 +- app/views/admin/domain_versions/show.haml | 4 +- config/routes.rb | 5 +- test/fixtures/files/accounts.csv | 4 ++ test/fixtures/files/contact_versions.csv | 3 ++ test/fixtures/files/contacts.csv | 2 + test/fixtures/files/domain_versions.csv | 3 ++ test/fixtures/files/domains.csv | 2 + test/fixtures/files/invoices.csv | 3 ++ test/models/registrant_user_test.rb | 39 +++++++++++++-- test/system/admin_area/accounts_test.rb | 12 +++++ .../admin_area/contact_versions_test.rb | 3 +- test/system/admin_area/contacts/csv_test.rb | 22 +++++++++ .../system/admin_area/domain_versions_test.rb | 2 +- test/system/admin_area/domains/csv_test.rb | 15 +++--- test/system/admin_area/invoices_test.rb | 10 ++++ 49 files changed, 382 insertions(+), 160 deletions(-) delete mode 100644 app/helpers/object_versions_helper.rb delete mode 100644 app/lib/to_csv.rb create mode 100644 app/services/csv_generator.rb create mode 100644 app/services/object_versions_parser.rb create mode 100644 test/fixtures/files/accounts.csv create mode 100644 test/fixtures/files/contact_versions.csv create mode 100644 test/fixtures/files/contacts.csv create mode 100644 test/fixtures/files/domain_versions.csv create mode 100644 test/fixtures/files/domains.csv create mode 100644 test/fixtures/files/invoices.csv create mode 100644 test/system/admin_area/contacts/csv_test.rb diff --git a/.github/workflows/build_baseimage_with_gems.yml b/.github/workflows/build_baseimage_with_gems.yml index 3487e838c..e6f72594a 100644 --- a/.github/workflows/build_baseimage_with_gems.yml +++ b/.github/workflows/build_baseimage_with_gems.yml @@ -17,7 +17,7 @@ jobs: steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Login to container registry env: diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index dd71c4bee..d50636e26 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -22,7 +22,7 @@ jobs: continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} @@ -79,7 +79,7 @@ jobs: - name: Save coverage run: ./cc-test-reporter format-coverage --output coverage/codeclimate.${{ matrix.ruby }}.json - - uses: actions/upload-artifact@v2.3.1 + - uses: actions/upload-artifact@v3.0.0 with: name: coverage-${{ matrix.ruby }} path: coverage/codeclimate.${{ matrix.ruby }}.json @@ -104,7 +104,7 @@ jobs: - name: Give test coverage reporter executable permissions run: chmod +x cc-test-reporter - - uses: actions/download-artifact@v2.1.0 + - uses: actions/download-artifact@v3.0.0 with: name: coverage-${{ matrix.ruby }} path: coverage diff --git a/.gitignore b/.gitignore index 3f23f1277..1c4a85f46 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /config/application.yml /config/environments/development.rb /config/deploy.rb +/config/master.key /.idea # Do not commit one. Instead, download the latest from https://github.com/internetee/style-guide. diff --git a/CHANGELOG.md b/CHANGELOG.md index 0305aff95..ea1333016 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +31.03.2022 +* Sidekiq update to 6.4.1 [#2322](https://github.com/internetee/registry/pull/2322) + +25.03.2022 +* Bulk change of business contacts' names requires now user confirmation [#2309](https://github.com/internetee/registry/pull/2309) + 23.02.2022 * FD notes are updated when basis for FD changes [#2216](https://github.com/internetee/registry/issues/2216) * Admin: date filter end date in domain hostory is now inclusive [#2274](https://github.com/internetee/registry/issues/2274) diff --git a/Gemfile b/Gemfile index 2e728f99f..c907eb267 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,7 @@ gem 'figaro', '~> 1.2' # model related gem 'paper_trail', '~> 12.1' -gem 'pg', '1.3.3' +gem 'pg', '1.3.5' # 1.8 is for Rails < 5.0 gem 'ransack', '~> 2.6.0' gem 'truemail', '~> 2.4' # validates email by regexp, mail server existence and address existence @@ -40,7 +40,7 @@ gem 'select2-rails', '4.0.13' # for autocomplete gem 'selectize-rails', '0.12.6' # include selectize.js for select # registry specfic -gem 'data_migrate', '~> 7.0' +gem 'data_migrate', '~> 8.0' gem 'dnsruby', '~> 1.61' gem 'isikukood' # for EE-id validation gem 'money-rails' @@ -70,7 +70,7 @@ gem 'jquery-ui-rails', '6.0.1' gem 'pdfkit' gem 'que' gem 'que-web' -gem 'sidekiq' +gem 'sidekiq', '>= 6.4.1' gem 'company_register', github: 'internetee/company_register', branch: 'master' diff --git a/Gemfile.lock b/Gemfile.lock index 10ae5358f..f7e9afa7e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -193,7 +193,7 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.1.9) + concurrent-ruby (1.1.10) connection_pool (2.2.5) countries (4.0.1) i18n_data (~> 0.13.0) @@ -205,7 +205,7 @@ GEM daemons-rails (1.2.1) daemons multi_json (~> 1.0) - data_migrate (7.0.2) + data_migrate (8.0.0) activerecord (>= 5.0) railties (>= 5.0) database_cleaner (2.0.1) @@ -289,7 +289,7 @@ GEM kaminari-core (1.2.1) libxml-ruby (3.2.1) logger (1.4.3) - loofah (2.12.0) + loofah (2.16.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -351,7 +351,7 @@ GEM activerecord (>= 5.2) request_store (~> 1.1) pdfkit (0.8.5) - pg (1.3.3) + pg (1.3.5) pg_query (2.1.2) google-protobuf (>= 3.17.1) pghero (2.8.1) @@ -360,7 +360,7 @@ GEM coderay (~> 1.1) method_source (~> 1.0) public_suffix (4.0.6) - puma (5.6.2) + puma (5.6.4) nio4r (~> 2.0) que (0.14.3) que-web (0.7.2) @@ -449,7 +449,7 @@ GEM selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) - sidekiq (6.4.0) + sidekiq (6.4.1) connection_pool (>= 2.2.2) rack (~> 2.0) redis (>= 4.2.0) @@ -480,7 +480,7 @@ GEM attr_required (>= 0.0.5) httpclient (>= 2.4) temple (0.8.2) - thor (1.1.0) + thor (1.2.1) tilt (2.0.10) truemail (2.4.9) simpleidn (~> 0.2.1) @@ -544,7 +544,7 @@ DEPENDENCIES company_register! countries daemons-rails (= 1.2.1) - data_migrate (~> 7.0) + data_migrate (~> 8.0) database_cleaner devise (~> 4.8) digidoc_client! @@ -574,7 +574,7 @@ DEPENDENCIES omniauth-tara! paper_trail (~> 12.1) pdfkit - pg (= 1.3.3) + pg (= 1.3.5) pg_query (>= 0.9.0) pghero pry (= 0.14.1) @@ -588,7 +588,7 @@ DEPENDENCIES sass-rails select2-rails (= 4.0.13) selectize-rails (= 0.12.6) - sidekiq + sidekiq (>= 6.4.1) simplecov (= 0.17.1) simpleidn (= 0.2.1) spy @@ -601,4 +601,4 @@ DEPENDENCIES wkhtmltopdf-binary (~> 0.12.5.1) BUNDLED WITH - 2.2.31 + 2.3.9 diff --git a/app/controllers/admin/account_activities_controller.rb b/app/controllers/admin/account_activities_controller.rb index ebd44e28e..452acaee1 100644 --- a/app/controllers/admin/account_activities_controller.rb +++ b/app/controllers/admin/account_activities_controller.rb @@ -35,7 +35,8 @@ module Admin respond_to do |format| format.html format.csv do - send_data @q.result.to_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" + raw_csv = CsvGenerator.generate_csv(@q.result) + send_data raw_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" end end diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index 016c0a750..56806ba3e 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -26,7 +26,7 @@ module Admin respond_to do |format| format.html { render page } format.csv do - raw_csv = @q.result.to_csv + raw_csv = CsvGenerator.generate_csv(@q.result) send_data raw_csv, filename: "#{filename}_#{Time.zone.now.to_formatted_s(:number)}.csv", type: "#{Mime[:csv]}; charset=utf-8" diff --git a/app/controllers/admin/contact_versions_controller.rb b/app/controllers/admin/contact_versions_controller.rb index c53a020ee..43d43d5e8 100644 --- a/app/controllers/admin/contact_versions_controller.rb +++ b/app/controllers/admin/contact_versions_controller.rb @@ -1,13 +1,13 @@ module Admin class ContactVersionsController < BaseController - include ObjectVersionsHelper + include ApplicationHelper load_and_authorize_resource class: Version::ContactVersion def index params[:q] ||= {} - search_params = PartialSearchFormatter.format(params[:q]) + search_params = PartialSearchFormatter.format(fix_date_params) versions = Version::ContactVersion.includes(:item).order(created_at: :desc, id: :desc) @q = versions.ransack(polymorphic_association(search_params)) @@ -48,5 +48,14 @@ module Admin record_type end + + def fix_date_params + params_copy = params[:q].deep_dup + if params_copy['created_at_lteq'].present? + params_copy['created_at_lteq'] = Date.parse(params_copy['created_at_lteq']) + 1.day + end + + params_copy + end end end diff --git a/app/controllers/admin/domain_versions_controller.rb b/app/controllers/admin/domain_versions_controller.rb index c6bba6d51..c82347ff9 100644 --- a/app/controllers/admin/domain_versions_controller.rb +++ b/app/controllers/admin/domain_versions_controller.rb @@ -1,7 +1,5 @@ module Admin class DomainVersionsController < BaseController - include ObjectVersionsHelper - load_and_authorize_resource class: Version::DomainVersion def index @@ -82,9 +80,8 @@ module Admin def fix_date_params params_copy = params[:q].deep_dup - if params_copy['created_at_lteq'].present? - params_copy['created_at_lteq'] = Date.parse(params_copy['created_at_lteq']) + 1.day - end + created_at = params_copy['created_at_lteq'] + params_copy['created_at_lteq'] = Date.parse(created_at) + 1.day if created_at.present? params_copy end diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index 30096ab8a..8e8b46631 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -34,6 +34,17 @@ module Api end end + def do_need_update_contact + result = current_registrant_user.do_need_update_contact? + render json: { update_contacts: result[:result], counter: result[:counter] } + end + + def update_company_contacts + companies = current_registrant_user.update_company_contacts + + render json: { message: 'get it', companies: companies } + end + def update logger.debug 'Received update request' logger.debug params diff --git a/app/controllers/registrar/account_activities_controller.rb b/app/controllers/registrar/account_activities_controller.rb index 55e53f8fc..0ad8c3d5a 100644 --- a/app/controllers/registrar/account_activities_controller.rb +++ b/app/controllers/registrar/account_activities_controller.rb @@ -20,7 +20,8 @@ class Registrar respond_to do |format| format.html { @account_activities = @q.result.page(params[:page]) } format.csv do - send_data @q.result.to_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" + raw_csv = CsvGenerator.generate_csv(@q.result) + send_data raw_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" end end diff --git a/app/controllers/registrar/contacts_controller.rb b/app/controllers/registrar/contacts_controller.rb index ec4ce5129..812e278e5 100644 --- a/app/controllers/registrar/contacts_controller.rb +++ b/app/controllers/registrar/contacts_controller.rb @@ -40,7 +40,7 @@ class Registrar @contacts = @contacts.per(contacts_per_page) if contacts_per_page.positive? end format.csv do - raw_csv = contacts.to_csv + raw_csv = CsvGenerator.generate_csv(contacts) send_data raw_csv, filename: 'contacts.csv', type: "#{Mime[:csv]}; charset=utf-8" end format.pdf do diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3de98b88c..122fc40d4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -10,27 +10,11 @@ module ApplicationHelper end def ident_for(contact) - if contact.is_a? Hash - ident_country_code = contact[:ident_country_code] - ident_type = contact[:ident_type] - ident = contact[:ident] - else - ident_country_code = contact.ident_country_code - ident_type = contact.ident_type - ident = contact.ident - end + ident = contact.ident + description = "[#{contact.ident_country_code} #{contact.ident_type}]" + description.prepend("#{ident} ") if ident.present? - case ident_type - when 'birthday' - "#{ident} [#{ident_country_code} #{ident_type}]" - else - if ident.present? - "#{ident} [#{ident_country_code} #{ident_type}]" - else - "[#{ident_country_code} #{ident_type}]" - end - - end + description end def current_commit_link diff --git a/app/helpers/object_versions_helper.rb b/app/helpers/object_versions_helper.rb deleted file mode 100644 index dae357cf6..000000000 --- a/app/helpers/object_versions_helper.rb +++ /dev/null @@ -1,19 +0,0 @@ -module ObjectVersionsHelper - def attach_existing_fields(version, new_object) - version.object_changes.to_h.each do |key, value| - method_name = "#{key}=".to_sym - new_object.public_send(method_name, event_value(version, value)) if new_object.respond_to?(method_name) - end - end - - def only_present_fields(version, model) - field_names = model.column_names - version.object.to_h.select { |key, _value| field_names.include?(key) } - end - - private - - def event_value(version, val) - version.event == 'destroy' ? val.first : val.last - end -end diff --git a/app/lib/to_csv.rb b/app/lib/to_csv.rb deleted file mode 100644 index 32c288978..000000000 --- a/app/lib/to_csv.rb +++ /dev/null @@ -1,10 +0,0 @@ -module ToCsv - def to_csv - CSV.generate do |csv| - csv << column_names - all.find_each do |item| - csv << item.attributes.values_at(*column_names) - end - end - end -end diff --git a/app/models/account.rb b/app/models/account.rb index fe0820888..7639c61dd 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,5 +1,4 @@ class Account < ApplicationRecord - extend ToCsv include Versions belongs_to :registrar, required: true @@ -12,4 +11,12 @@ class Account < ApplicationRecord def activities account_activities end + + def as_csv_row + [id, balance, currency, registrar] + end + + def self.csv_header + ['Id', 'Balance', 'Currency', 'Registrar'] + end end diff --git a/app/models/account_activity.rb b/app/models/account_activity.rb index 05873a2a6..38fa70358 100644 --- a/app/models/account_activity.rb +++ b/app/models/account_activity.rb @@ -11,6 +11,7 @@ class AccountActivity < ApplicationRecord UPDATE_CREDIT = 'update_credit'.freeze after_create :update_balance + def update_balance account.balance += sum account.save @@ -19,23 +20,17 @@ class AccountActivity < ApplicationRecord save end + def as_csv_row + [account.registrar.try(:code), description, I18n.t(activity_type), I18n.l(created_at), sum] + end + class << self def types_for_select [CREATE, RENEW, ADD_CREDIT, UPDATE_CREDIT].map { |x| [I18n.t(x), x] } end - def to_csv - attributes = %w(description activity_type created_at sum) - - CSV.generate(headers: true) do |csv| - csv << %w(registrar description activity_type receipt_date sum) - - all.each do |x| - attrs = [x.account.registrar.try(:code)] - attrs += attributes.map { |attr| x.send(attr) } - csv << attrs - end - end + def csv_header + ['Registrar', 'Description', 'Activity Type', 'Receipt Date', 'Sum'] end end end diff --git a/app/models/api_log/epp_log.rb b/app/models/api_log/epp_log.rb index feed1ecad..c89569be5 100644 --- a/app/models/api_log/epp_log.rb +++ b/app/models/api_log/epp_log.rb @@ -1,5 +1,3 @@ module ApiLog - class EppLog < Db - extend ToCsv - end + class EppLog < Db; end end diff --git a/app/models/api_log/repp_log.rb b/app/models/api_log/repp_log.rb index 62dcee238..540a9043a 100644 --- a/app/models/api_log/repp_log.rb +++ b/app/models/api_log/repp_log.rb @@ -1,5 +1,3 @@ module ApiLog - class ReppLog < Db - extend ToCsv - end + class ReppLog < Db; end end diff --git a/app/models/blocked_domain.rb b/app/models/blocked_domain.rb index fb50a8b52..f82faa771 100644 --- a/app/models/blocked_domain.rb +++ b/app/models/blocked_domain.rb @@ -1,6 +1,5 @@ class BlockedDomain < ApplicationRecord include Versions - extend ToCsv before_save :generate_data after_destroy :remove_data diff --git a/app/models/contact.rb b/app/models/contact.rb index 84d4ba962..dab2dd6d9 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -188,15 +188,6 @@ class Contact < ApplicationRecord ] end - def to_csv - CSV.generate do |csv| - csv << column_names - all.each do |contact| - csv << contact.attributes.values_at(*column_names) - end - end - end - def pdf(html) kit = PDFKit.new(html) kit.to_pdf @@ -569,4 +560,27 @@ class Contact < ApplicationRecord def deletable? !linked? end + + def ident_human_description + description = "[#{ident_country_code} #{ident_type}]" + description.prepend("#{ident} ") if ident.present? + + description + end + + def as_csv_row + [ + name, + code, + ident_human_description, + email, + created_at.to_formatted_s(:db), + registrar, + phone, + ] + end + + def self.csv_header + ['Name', 'ID', 'Ident', 'E-mail', 'Created at', 'Registrar', 'Phone'] + end end diff --git a/app/models/dispute.rb b/app/models/dispute.rb index cbf93566a..f5a948355 100644 --- a/app/models/dispute.rb +++ b/app/models/dispute.rb @@ -1,5 +1,4 @@ class Dispute < ApplicationRecord - extend ToCsv include WhoisStatusPopulate validates :domain_name, :password, :starts_at, :expires_at, presence: true before_validation :fill_empty_passwords, :set_expiry_date diff --git a/app/models/domain.rb b/app/models/domain.rb index 873216cf1..7afd8046e 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -289,21 +289,6 @@ class Domain < ApplicationRecord ) end - def to_csv - CSV.generate do |csv| - headers = column_names.dup - swap_elements(headers, [[0, 1], [1, 5]]) - headers[0] = 'Domain' - headers[1] = headers[1].humanize - csv << headers - all.find_each do |item| - row = item.attributes.values_at(*column_names) - swap_elements(row, [[0, 1], [1, 5]]) - csv << row - end - end - end - private def registrant_user_domains_by_registrant(registrant_user) @@ -753,6 +738,38 @@ class Domain < ApplicationRecord contacts.select(&:email_verification_failed?)&.map(&:email)&.uniq end + def as_csv_row + [ + name, + registrant_name, + valid_to.to_formatted_s(:db), + registrar, + created_at.to_formatted_s(:db), + statuses, + contacts.pluck(:code), + force_delete_date, + force_delete_data, + ] + end + + def registrant_name + return registrant.name if registrant + + ver = Version::ContactVersion.where(item_id: registrant_id).last + contact = Contact.all_versions_for([registrant_id], created_at).first + + contact = ObjectVersionsParser.new(ver).parse if contact.nil? && ver + + contact.try(:name) || 'Deleted' + end + + def self.csv_header + [ + 'Domain', 'Registrant', 'Valid to', 'Registrar', 'Created at', + 'Statuses', 'Contacts code', 'Force delete date', 'Force delete data' + ] + end + def self.pdf(html) kit = PDFKit.new(html) kit.to_pdf diff --git a/app/models/invoice.rb b/app/models/invoice.rb index df8b7aff8..6ba3a158d 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -3,7 +3,6 @@ class Invoice < ApplicationRecord include Invoice::Cancellable include Invoice::Payable include Invoice::BookKeeping - extend ToCsv belongs_to :buyer, class_name: 'Registrar' has_one :account_activity @@ -117,6 +116,23 @@ class Invoice < ApplicationRecord e_invoice_sent_at.present? end + def as_csv_row + [ + number, + buyer, + cancelled? ? I18n.t(:cancelled) : due_date, + receipt_date_status, + issue_date, + total, + currency, + seller_name, + ] + end + + def self.csv_header + ['Number', 'Buyer', 'Due Date', 'Receipt Date', 'Issue Date', 'Total', 'Currency', 'Seller Name'] + end + def self.create_from_transaction!(transaction) registrar_user = Registrar.find_by(reference_no: transaction.parsed_ref_number) return unless registrar_user @@ -128,6 +144,16 @@ class Invoice < ApplicationRecord private + def receipt_date_status + if paid? + receipt_date + elsif cancelled? + I18n.t(:cancelled) + else + I18n.t(:unpaid) + end + end + def apply_default_buyer_vat_no self.buyer_vat_no = buyer.vat_no end diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index 5fe508125..80b8ecab9 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -20,16 +20,27 @@ class RegistrantUser < User def companies(company_register = CompanyRegister::Client.new) return [] if ident.include?('-') - companies = company_register.representation_rights(citizen_personal_code: ident, - citizen_country_code: country.alpha3) - - companies = update_contacts_before_receive(companies) - companies + company_register.representation_rights(citizen_personal_code: ident, + citizen_country_code: country.alpha3) rescue CompanyRegister::NotAvailableError - return [] + [] end - def update_contacts_before_receive(companies) + def do_need_update_contact? + return { result: false, counter: 0 } if companies.blank? + + counter = 0 + companies.each do |company| + counter += Contact.where(ident: company.registration_number, ident_country_code: 'EE')&. + reject { |contact| contact.name == company.company_name }.size + end + + return { result: true, counter: counter } if counter.positive? + + { result: false, counter: 0 } + end + + def update_company_contacts return [] if companies.blank? companies.each do |company| diff --git a/app/models/reserved_domain.rb b/app/models/reserved_domain.rb index 5d585e5d9..10d5edd11 100644 --- a/app/models/reserved_domain.rb +++ b/app/models/reserved_domain.rb @@ -1,5 +1,4 @@ class ReservedDomain < ApplicationRecord - extend ToCsv include Versions # version/reserved_domain_version.rb include WhoisStatusPopulate before_save :fill_empty_passwords diff --git a/app/models/version/contact_version.rb b/app/models/version/contact_version.rb index 95bd4b677..d3ff1130c 100644 --- a/app/models/version/contact_version.rb +++ b/app/models/version/contact_version.rb @@ -1,7 +1,23 @@ class Version::ContactVersion < PaperTrail::Version - extend ToCsv include VersionSession self.table_name = :log_contacts self.sequence_name = :log_contacts_id_seq + + def as_csv_row + contact = ObjectVersionsParser.new(self).parse + + [ + contact.name, + contact.code, + contact.ident_human_description, + contact.registrar, + event, + created_at.to_formatted_s(:db) + ] + end + + def self.csv_header + ['Name', 'ID', 'Ident', 'Registrar', 'Action', 'Created at'] + end end diff --git a/app/models/version/domain_version.rb b/app/models/version/domain_version.rb index 2c6848d4b..e84fc9da2 100644 --- a/app/models/version/domain_version.rb +++ b/app/models/version/domain_version.rb @@ -1,5 +1,4 @@ class Version::DomainVersion < PaperTrail::Version - extend ToCsv include VersionSession self.table_name = :log_domains @@ -7,6 +6,18 @@ class Version::DomainVersion < PaperTrail::Version scope :deleted, -> { where(event: 'destroy') } + def as_csv_row + domain = ObjectVersionsParser.new(self).parse + + [ + domain.name, + domain.registrant_name, + domain.registrar, + event, + created_at.to_formatted_s(:db) + ] + end + def self.was_contact_linked?(contact_id) sql = <<-SQL SELECT @@ -43,4 +54,8 @@ class Version::DomainVersion < PaperTrail::Version count_by_sql(sql).nonzero? end + + def self.csv_header + ['Name', 'Registrant', 'Registrar', 'Action', 'Created at'] + end end diff --git a/app/services/csv_generator.rb b/app/services/csv_generator.rb new file mode 100644 index 000000000..d92beeddc --- /dev/null +++ b/app/services/csv_generator.rb @@ -0,0 +1,29 @@ +class CsvGenerator + class << self + def generate_csv(objects) + class_name = objects.first.class + return default_generation(objects) unless custom_csv?(class_name) + + CSV.generate do |csv| + csv << class_name.csv_header + objects.each { |object| csv << object.as_csv_row } + end + end + + private + + def default_generation(objects) + CSV.generate do |csv| + csv << objects.column_names + objects.all.find_each { |object| csv << object.attributes.values_at(*objects.column_names) } + end + end + + def custom_csv?(class_name) + [ + Version::DomainVersion, Version::ContactVersion, Domain, + Contact, Invoice, Account, AccountActivity + ].include?(class_name) + end + end +end diff --git a/app/services/object_versions_parser.rb b/app/services/object_versions_parser.rb new file mode 100644 index 000000000..5871a6bd6 --- /dev/null +++ b/app/services/object_versions_parser.rb @@ -0,0 +1,28 @@ +class ObjectVersionsParser + def initialize(version) + @version = version + end + + def parse + model = @version.item_type.constantize + attributes = only_present_fields(model) + history_object = model.new(attributes) + attach_existing_fields(history_object) unless @version.event == 'destroy' + + history_object + end + + private + + def attach_existing_fields(history_object) + @version.object_changes.to_h.each do |key, value| + method_name = "#{key}=".to_sym + history_object.public_send(method_name, value.last) if history_object.respond_to?(method_name) + end + end + + def only_present_fields(model) + field_names = model.column_names + @version.object.to_h.select { |key, _value| field_names.include?(key) } + end +end diff --git a/app/views/admin/contact_versions/index.haml b/app/views/admin/contact_versions/index.haml index 581402197..e181673f2 100644 --- a/app/views/admin/contact_versions/index.haml +++ b/app/views/admin/contact_versions/index.haml @@ -64,9 +64,7 @@ %tbody - @versions.each do |version| - if version - - attributes = only_present_fields(version, Contact) - - contact = Contact.new(attributes) - - attach_existing_fields(version, contact) + - contact = ObjectVersionsParser.new(version).parse %tr %td= link_to(contact.name, admin_contact_version_path(version.id)) diff --git a/app/views/admin/contact_versions/show.haml b/app/views/admin/contact_versions/show.haml index 901f5ee1a..546ff4287 100644 --- a/app/views/admin/contact_versions/show.haml +++ b/app/views/admin/contact_versions/show.haml @@ -1,6 +1,5 @@ -- attributes = only_present_fields(@version, Contact) -- contact = Contact.new(attributes) -- attach_existing_fields(@version, contact) +- contact = ObjectVersionsParser.new(@version).parse + = render 'shared/title', name: contact.name .row diff --git a/app/views/admin/domain_versions/archive.haml b/app/views/admin/domain_versions/archive.haml index ec2034ed1..85105b9f0 100644 --- a/app/views/admin/domain_versions/archive.haml +++ b/app/views/admin/domain_versions/archive.haml @@ -62,9 +62,7 @@ %tbody - @versions.each do |version| - if version - - attributes = only_present_fields(version, Domain) - - domain = Domain.new(attributes) - - attach_existing_fields(version, domain) unless version.event == 'destroy' + - domain = ObjectVersionsParser.new(version).parse %tr %td= link_to(domain.name, admin_domain_version_path(version.id)) diff --git a/app/views/admin/domain_versions/show.haml b/app/views/admin/domain_versions/show.haml index 11f70599f..ab49dffee 100644 --- a/app/views/admin/domain_versions/show.haml +++ b/app/views/admin/domain_versions/show.haml @@ -1,6 +1,4 @@ -- present_fields = only_present_fields(@version, Domain) -- domain = Domain.new(present_fields) -- attach_existing_fields(@version, domain) unless @version.event == 'destroy' +- domain = ObjectVersionsParser.new(@version).parse - if @version - children = HashWithIndifferentAccess.new(@version.children) diff --git a/config/routes.rb b/config/routes.rb index 66debd4b4..79807729a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -128,7 +128,10 @@ Rails.application.routes.draw do resources :domains, only: %i[index show], param: :uuid do resource :registry_lock, only: %i[create destroy] end - resources :contacts, only: %i[index show update], param: :uuid + resources :contacts, only: %i[index show update], param: :uuid do + get 'do_need_update_contact', to: 'contacts#do_need_update_contact', as: :do_need_update_contact + post 'update_company_contacts', to: 'contacts#update_company_contacts', as: :update_company_contacts + end resources :companies, only: %i[index] end diff --git a/test/fixtures/files/accounts.csv b/test/fixtures/files/accounts.csv new file mode 100644 index 000000000..5bc44fc48 --- /dev/null +++ b/test/fixtures/files/accounts.csv @@ -0,0 +1,4 @@ +Id,Balance,Currency,Registrar +112846265,100.0,EUR,Best Names +298486374,100.0,EUR,Good Names +597560588,0.0,EUR,Not in use diff --git a/test/fixtures/files/contact_versions.csv b/test/fixtures/files/contact_versions.csv new file mode 100644 index 000000000..c794026c2 --- /dev/null +++ b/test/fixtures/files/contact_versions.csv @@ -0,0 +1,3 @@ +Name,ID,Ident,Registrar,Action,Created at +,test_code,[ ],Best Names,update,2018-04-23 15:50:48 +,,[ ],,update,2010-07-04 21:00:00 diff --git a/test/fixtures/files/contacts.csv b/test/fixtures/files/contacts.csv new file mode 100644 index 000000000..9d8ca5357 --- /dev/null +++ b/test/fixtures/files/contacts.csv @@ -0,0 +1,2 @@ +Name,ID,Ident,E-mail,Created at,Registrar,Phone +Acme Ltd,acme-ltd-001,1234567 [US org],acme@outlook.test,2010-07-05 07:30:00,Best Names,+555.555 diff --git a/test/fixtures/files/domain_versions.csv b/test/fixtures/files/domain_versions.csv new file mode 100644 index 000000000..8fa7fa9fe --- /dev/null +++ b/test/fixtures/files/domain_versions.csv @@ -0,0 +1,3 @@ +Name,Registrant,Registrar,Action,Created at +,test_code,Best Names,update,2018-04-23 15:50:48 +,John,,update,2010-07-04 21:00:00 diff --git a/test/fixtures/files/domains.csv b/test/fixtures/files/domains.csv new file mode 100644 index 000000000..b8261ebc2 --- /dev/null +++ b/test/fixtures/files/domains.csv @@ -0,0 +1,2 @@ +Domain,Registrant,Valid to,Registrar,Created at,Statuses,Contacts code,Force delete date,Force delete data +metro.test,Jack,2010-07-05 00:00:00,Good Names,2010-07-05 07:30:00,[],"[""jack-001"", ""jack-001""]",, diff --git a/test/fixtures/files/invoices.csv b/test/fixtures/files/invoices.csv new file mode 100644 index 000000000..641cfe036 --- /dev/null +++ b/test/fixtures/files/invoices.csv @@ -0,0 +1,3 @@ +Number,Buyer,Due Date,Receipt Date,Issue Date,Total,Currency,Seller Name +2,Best Names,2010-07-06,Unpaid,2010-07-05,16.5,EUR,Seller Ltd +1,Best Names,2010-07-06,2010-07-05,2010-07-05,16.5,EUR,Seller Ltd diff --git a/test/models/registrant_user_test.rb b/test/models/registrant_user_test.rb index 987e80c03..2b1d6a880 100644 --- a/test/models/registrant_user_test.rb +++ b/test/models/registrant_user_test.rb @@ -41,10 +41,8 @@ class RegistrantUserTest < ActiveSupport::TestCase company = Company.new(org.ident, "ace") - company_register = Minitest::Mock.new - company_register.expect(:representation_rights, [company], [{ citizen_personal_code: '1234', - citizen_country_code: 'USA' }]) - @user.companies(company_register) + Spy.on(@user, :companies).and_return([company]) + @user.update_company_contacts org.reload assert_equal org.name, company.company_name @@ -63,6 +61,39 @@ class RegistrantUserTest < ActiveSupport::TestCase company_register.verify end + def test_should_return_zero_count_of_companies + assert_equal 'US-1234', @user.registrant_ident + org = contacts(:acme_ltd) + org.ident_country_code = 'EE' + org.save(validate: false) + org.reload + + company_one = Company.new(org.ident, 'Acme Ltd') + + Spy.on(@user, :companies).and_return([company_one]) + response = @user.do_need_update_contact? + org.reload + + assert_equal response[:counter], 0 + end + + def test_should_return_count_of_contact_which_should_be_updated + assert_equal 'US-1234', @user.registrant_ident + org = contacts(:acme_ltd) + org.ident_country_code = 'EE' + org.save(validate: false) + org.reload + + company_one = Company.new(org.ident, 'ace') + company_two = Company.new(org.ident, 'acer') + + Spy.on(@user, :companies).and_return([company_one, company_two]) + response = @user.do_need_update_contact? + org.reload + + assert_equal response[:counter], 2 + end + def test_returns_contacts Contact.stub(:registrant_user_contacts, %w(john jane)) do assert_equal %w(john jane), @user.contacts diff --git a/test/system/admin_area/accounts_test.rb b/test/system/admin_area/accounts_test.rb index f07ced9c3..393c3445a 100644 --- a/test/system/admin_area/accounts_test.rb +++ b/test/system/admin_area/accounts_test.rb @@ -29,4 +29,16 @@ class AdminAccountsSystemTest < ApplicationSystemTestCase assert_text 'Account has been successfully updated' assert_text '234' end + + def test_download_accounts_list_as_csv + travel_to Time.zone.parse('2010-07-05 10:30') + + get admin_accounts_path(format: :csv) + + assert_response :ok + assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type'] + assert_equal %(attachment; filename="accounts_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''accounts_#{Time.zone.now.to_formatted_s(:number)}.csv), + response.headers['Content-Disposition'] + assert_equal file_fixture('accounts.csv').read, response.body + end end diff --git a/test/system/admin_area/contact_versions_test.rb b/test/system/admin_area/contact_versions_test.rb index f040646bb..e199f5768 100644 --- a/test/system/admin_area/contact_versions_test.rb +++ b/test/system/admin_area/contact_versions_test.rb @@ -62,11 +62,10 @@ class ContactVersionsTest < ApplicationSystemTestCase travel_to now get admin_contact_versions_path(format: :csv) - assert_response :ok assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type'] assert_equal %(attachment; filename="contact_history_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''contact_history_#{Time.zone.now.to_formatted_s(:number)}.csv), response.headers['Content-Disposition'] - assert_not_empty response.body + assert_equal file_fixture('contact_versions.csv').read, response.body end end diff --git a/test/system/admin_area/contacts/csv_test.rb b/test/system/admin_area/contacts/csv_test.rb new file mode 100644 index 000000000..de5bd440e --- /dev/null +++ b/test/system/admin_area/contacts/csv_test.rb @@ -0,0 +1,22 @@ +require 'application_system_test_case' + +class ContactsCsvTest < ApplicationSystemTestCase + setup do + sign_in users(:admin) + Domain.destroy_all + Contact.all.each { |contact| contact.destroy unless contact.name == 'Acme Ltd' } + end + + def test_download_contacts_list_as_csv + travel_to Time.zone.parse('2010-07-05 10:30') + contact = Contact.first + contact.created_at = Time.zone.now + contact.save(validate: false) + + visit admin_contacts_url + click_link('CSV') + + assert_equal "attachment; filename=\"contacts_#{Time.zone.now.to_formatted_s(:number)}.csv\"; filename*=UTF-8''contacts_#{Time.zone.now.to_formatted_s(:number)}.csv", response_headers['Content-Disposition'] + assert_equal file_fixture('contacts.csv').read, page.body + end +end diff --git a/test/system/admin_area/domain_versions_test.rb b/test/system/admin_area/domain_versions_test.rb index a8aeb0cd4..75b66b1bb 100644 --- a/test/system/admin_area/domain_versions_test.rb +++ b/test/system/admin_area/domain_versions_test.rb @@ -98,7 +98,7 @@ class DomainVersionsTest < ApplicationSystemTestCase assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type'] assert_equal %(attachment; filename="domain_history_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''domain_history_#{Time.zone.now.to_formatted_s(:number)}.csv), response.headers['Content-Disposition'] - assert_not_empty response.body + assert_equal file_fixture('domain_versions.csv').read, response.body end def test_search_event_param diff --git a/test/system/admin_area/domains/csv_test.rb b/test/system/admin_area/domains/csv_test.rb index c84e2cf0e..691a8dc50 100644 --- a/test/system/admin_area/domains/csv_test.rb +++ b/test/system/admin_area/domains/csv_test.rb @@ -1,18 +1,21 @@ require 'application_system_test_case' -class AdminAreaCsvTest < ApplicationSystemTestCase +class DomainsCsvTest < ApplicationSystemTestCase setup do sign_in users(:admin) + Domain.all.each { |domain| domain.destroy unless domain.name == 'metro.test' } end - def test_downloads_domain_list_as_csv - search_params = {"valid_to_lteq"=>nil} - expected_csv = Domain.includes(:registrar, :registrant).search(search_params).result.to_csv - + def test_download_domains_list_as_csv travel_to Time.zone.parse('2010-07-05 10:30') + domain = Domain.first + domain.created_at = Time.zone.now + domain.save(validate: false) + visit admin_domains_url click_link('CSV') + assert_equal "attachment; filename=\"domains_#{Time.zone.now.to_formatted_s(:number)}.csv\"; filename*=UTF-8''domains_#{Time.zone.now.to_formatted_s(:number)}.csv", response_headers['Content-Disposition'] - assert_equal expected_csv, page.body + assert_equal file_fixture('domains.csv').read, page.body end end diff --git a/test/system/admin_area/invoices_test.rb b/test/system/admin_area/invoices_test.rb index 40a50e1c7..a8d0a8a75 100644 --- a/test/system/admin_area/invoices_test.rb +++ b/test/system/admin_area/invoices_test.rb @@ -40,4 +40,14 @@ class AdminAreaInvoicesTest < ApplicationSystemTestCase assert_current_path admin_invoice_path(@invoice) assert_text 'Invoice has been sent' end + + def test_download_invoices_list_as_csv + travel_to Time.zone.parse('2010-07-05 10:30') + + visit admin_invoices_url + click_link('CSV') + + assert_equal "attachment; filename=\"invoices_#{Time.zone.now.to_formatted_s(:number)}.csv\"; filename*=UTF-8''invoices_#{Time.zone.now.to_formatted_s(:number)}.csv", response_headers['Content-Disposition'] + assert_equal file_fixture('invoices.csv').read, page.body + end end From ac5fbff0e0a903889e11e33eb4c9ca18ef1a5ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 5 Apr 2022 14:18:49 +0300 Subject: [PATCH 094/172] Update CHANGELOG.md --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea1333016..3ec3740ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +05.04.2022 +* CSV download fix for admin history view [#2275](https://github.com/internetee/registry/issues/2275) +* CSV output fix for diman, contact, invoices and account views in admin [2303](https://github.com/internetee/registry/issues/2303) +* Refactored CSV generation in admin [#2321](https://github.com/internetee/registry/issues/2321) + +04.04.2022 +* Upload-artifact update to 3.0.0 [#2301](https://github.com/internetee/registry/pull/2301) +* data_migrate update to 8.0 [#2302](https://github.com/internetee/registry/pull/2302) + +01.04.2022 +* Pg update to 1.3.5 [#2328](https://github.com/internetee/registry/pull/2328) +* Puma update to 5.6.4 [#2327](https://github.com/internetee/registry/pull/2327) + 31.03.2022 * Sidekiq update to 6.4.1 [#2322](https://github.com/internetee/registry/pull/2322) From 21cc868247f638e7c02ea26aa8694ce3c1a5dba2 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 5 Apr 2022 14:22:15 +0300 Subject: [PATCH 095/172] Fix duplicate --- app/controllers/admin/contact_versions_controller.rb | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/controllers/admin/contact_versions_controller.rb b/app/controllers/admin/contact_versions_controller.rb index 387016e61..43d43d5e8 100644 --- a/app/controllers/admin/contact_versions_controller.rb +++ b/app/controllers/admin/contact_versions_controller.rb @@ -57,16 +57,5 @@ module Admin params_copy end - - private - - def fix_date_params - params_copy = params[:q].deep_dup - if params_copy['created_at_lteq'].present? - params_copy['created_at_lteq'] = Date.parse(params_copy['created_at_lteq']) + 1.day - end - - params_copy - end end end From d395d79d9871f1b422c3993441152d145b51e3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 5 Apr 2022 15:03:49 +0300 Subject: [PATCH 096/172] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ec3740ed..111479f00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ 05.04.2022 +* Wildcard search improvements in admin [#499](https://github.com/internetee/registry/issues/499) * CSV download fix for admin history view [#2275](https://github.com/internetee/registry/issues/2275) * CSV output fix for diman, contact, invoices and account views in admin [2303](https://github.com/internetee/registry/issues/2303) * Refactored CSV generation in admin [#2321](https://github.com/internetee/registry/issues/2321) From 512b19f2580c43347512ec9ab096a8cadbbc8142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 5 Apr 2022 15:16:35 +0300 Subject: [PATCH 097/172] Update CHANGELOG.md --- CHANGELOG.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 111479f00..16492c180 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ 05.04.2022 -* Wildcard search improvements in admin [#499](https://github.com/internetee/registry/issues/499) -* CSV download fix for admin history view [#2275](https://github.com/internetee/registry/issues/2275) -* CSV output fix for diman, contact, invoices and account views in admin [2303](https://github.com/internetee/registry/issues/2303) -* Refactored CSV generation in admin [#2321](https://github.com/internetee/registry/issues/2321) +* Admin: Wildcard search improvements [#499](https://github.com/internetee/registry/issues/499) +* Admin: CSV download fix for history view [#2275](https://github.com/internetee/registry/issues/2275) +* Admin: CSV output fix for diman, contact, invoices and account views [2303](https://github.com/internetee/registry/issues/2303) +* Admin: registrar dropdown is searchable in invoice creation view [#2313](https://github.com/internetee/registry/issues/2313) +* Admin: Refactored CSV generation [#2321](https://github.com/internetee/registry/issues/2321) 04.04.2022 * Upload-artifact update to 3.0.0 [#2301](https://github.com/internetee/registry/pull/2301) From 6be05c8a5763cb4359da4726560fd88b50699a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 5 Apr 2022 15:21:02 +0300 Subject: [PATCH 098/172] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16492c180..1e407a567 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Admin: CSV output fix for diman, contact, invoices and account views [2303](https://github.com/internetee/registry/issues/2303) * Admin: registrar dropdown is searchable in invoice creation view [#2313](https://github.com/internetee/registry/issues/2313) * Admin: Refactored CSV generation [#2321](https://github.com/internetee/registry/issues/2321) +* Removed legacy migration jobs [#2090](https://github.com/internetee/registry/issues/2090) 04.04.2022 * Upload-artifact update to 3.0.0 [#2301](https://github.com/internetee/registry/pull/2301) From 2dcdf0248810070b6e4832762f466490bee442fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 5 Apr 2022 15:56:00 +0300 Subject: [PATCH 099/172] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e407a567..a7475423f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ 05.04.2022 +* Status notes are now added to status elements of epp xml [#2211](https://github.com/internetee/registry/issues/2211) * Admin: Wildcard search improvements [#499](https://github.com/internetee/registry/issues/499) * Admin: CSV download fix for history view [#2275](https://github.com/internetee/registry/issues/2275) * Admin: CSV output fix for diman, contact, invoices and account views [2303](https://github.com/internetee/registry/issues/2303) From 031a825b3be82f113c5f6b8ac58d4015ca2eb955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 5 Apr 2022 18:58:22 +0300 Subject: [PATCH 100/172] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7475423f..ec57fcc40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ 05.04.2022 +* Automatic contact name update poll messages are now grouped together into one change poll message [#2307](https://github.com/internetee/registry/issues/2307) * Status notes are now added to status elements of epp xml [#2211](https://github.com/internetee/registry/issues/2211) * Admin: Wildcard search improvements [#499](https://github.com/internetee/registry/issues/499) * Admin: CSV download fix for history view [#2275](https://github.com/internetee/registry/issues/2275) From 9ba7af504ac4eb0c25a0cd9768335956a2aa2a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Wed, 6 Apr 2022 13:57:24 +0300 Subject: [PATCH 101/172] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec57fcc40..c5bf7fedd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +06.04.2022 +* Contact email validation on domain update [#2213](https://github.com/internetee/registry/issues/2213) + 05.04.2022 * Automatic contact name update poll messages are now grouped together into one change poll message [#2307](https://github.com/internetee/registry/issues/2307) * Status notes are now added to status elements of epp xml [#2211](https://github.com/internetee/registry/issues/2211) From 8be020582eaee5f05e99955ba9ef364dc47c16f9 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 12 Apr 2022 13:19:32 +0300 Subject: [PATCH 102/172] Add status notes to repp domain serializer --- lib/serializers/repp/domain.rb | 2 +- test/lib/serializers/repp/domain_test.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/lib/serializers/repp/domain_test.rb diff --git a/lib/serializers/repp/domain.rb b/lib/serializers/repp/domain.rb index 60863373c..6547f21b8 100644 --- a/lib/serializers/repp/domain.rb +++ b/lib/serializers/repp/domain.rb @@ -15,7 +15,7 @@ module Serializers updated_at: obj.updated_at, expire_time: obj.expire_time, outzone_at: obj.outzone_at, delete_date: obj.delete_date, force_delete_date: obj.force_delete_date, contacts: contacts, nameservers: nameservers, dnssec_keys: dnssec_keys, - statuses: obj.statuses, registrar: registrar + statuses: obj.status_notes, registrar: registrar } json[:transfer_code] = obj.auth_info if @sponsored json diff --git a/test/lib/serializers/repp/domain_test.rb b/test/lib/serializers/repp/domain_test.rb new file mode 100644 index 000000000..365930278 --- /dev/null +++ b/test/lib/serializers/repp/domain_test.rb @@ -0,0 +1,17 @@ +require 'test_helper' +require 'serializers/repp/domain' + +class SerializersReppDomainTest < ActiveSupport::TestCase + def setup + @domain = domains(:airport) + end + + def test_returns_status_notes + status_notes = { 'serverForceDelete' => '`@internet2.ee' } + @domain.update!(statuses: %w[serverForceDelete], status_notes: status_notes) + @serializer = Serializers::Repp::Domain.new(@domain) + @json = @serializer.to_json + + assert_equal(status_notes, @json[:statuses]) + end +end From e320a7ced1abcb8b4249e3e1e459ff13e65aaa8a Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 11 Apr 2022 15:18:11 +0300 Subject: [PATCH 103/172] fix poll message spam after validation email --- .../domains/force_delete/notify_registrar.rb | 26 ++++++++++++------- .../domains/force_delete_email/base.rb | 17 +++++++----- test/models/domain/force_delete_test.rb | 2 +- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/app/interactions/domains/force_delete/notify_registrar.rb b/app/interactions/domains/force_delete/notify_registrar.rb index e4aa48976..25d59bf29 100644 --- a/app/interactions/domains/force_delete/notify_registrar.rb +++ b/app/interactions/domains/force_delete/notify_registrar.rb @@ -6,18 +6,26 @@ module Domains end def notify_without_email - domain.registrar.notifications.create!(text: I18n.t('force_delete_set_on_domain', - domain_name: domain.name, - outzone_date: domain.outzone_date, - purge_date: domain.purge_date)) + template = I18n.t('force_delete_set_on_domain', + domain_name: domain.name, + outzone_date: domain.outzone_date, + purge_date: domain.purge_date) + + return if domain.registrar.notifications.last.text.include? template + + domain.registrar.notifications.create!(text: template) end def notify_with_email - domain.registrar.notifications.create!(text: I18n.t('force_delete_auto_email', - domain_name: domain.name, - outzone_date: domain.outzone_date, - purge_date: domain.purge_date, - email: email)) + template = I18n.t('force_delete_auto_email', + domain_name: domain.name, + outzone_date: domain.outzone_date, + purge_date: domain.purge_date, + email: email) + + return if domain.registrar.notifications.last.text.include? template + + domain.registrar.notifications.create!(text: template) end end end diff --git a/app/interactions/domains/force_delete_email/base.rb b/app/interactions/domains/force_delete_email/base.rb index 04e7dde5d..d75749b50 100644 --- a/app/interactions/domains/force_delete_email/base.rb +++ b/app/interactions/domains/force_delete_email/base.rb @@ -31,18 +31,21 @@ module Domains def before_execute_force_delete(domain) if domain.force_delete_scheduled? && !domain.status_notes[DomainStatus::FORCE_DELETE].nil? added_additional_email_into_notes(domain) - notify_registrar(domain) else process_force_delete(domain) end end def notify_registrar(domain) - domain.registrar.notifications.create!(text: I18n.t('force_delete_auto_email', - domain_name: domain.name, - outzone_date: domain.outzone_date, - purge_date: domain.purge_date, - email: domain.status_notes[DomainStatus::FORCE_DELETE])) + template = I18n.t('force_delete_auto_email', + domain_name: domain.name, + outzone_date: domain.outzone_date, + purge_date: domain.purge_date, + email: domain.status_notes[DomainStatus::FORCE_DELETE]) + + return if domain.registrar.notifications.last.text.include? template + + domain.registrar.notifications.create!(text: template) end def process_force_delete(domain) @@ -56,6 +59,8 @@ module Domains def added_additional_email_into_notes(domain) return if domain.status_notes[DomainStatus::FORCE_DELETE].include? email + # notify_registrar(domain) + domain.status_notes[DomainStatus::FORCE_DELETE].concat(" #{email}") domain.save(validate: false) end diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 974c445e6..b80313ca5 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -437,7 +437,7 @@ class ForceDeleteTest < ActionMailer::TestCase assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_emails notification = domain.registrar.notifications.last - assert notification.text.include? asserted_text + assert_not notification.text.include? asserted_text end def test_remove_invalid_email_from_domain_status_notes From 47a93b200afad8535730cf8a1a5a01646c8ba817 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 12 Apr 2022 12:16:30 +0000 Subject: [PATCH 104/172] Update dependency nokogiri to v1.13.4 [SECURITY] --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f7e9afa7e..033c9a88b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -324,10 +324,10 @@ GEM newrelic_rpm (= 8.1.0) newrelic_rpm (8.1.0) nio4r (2.5.8) - nokogiri (1.13.3) + nokogiri (1.13.4) mini_portile2 (~> 2.8.0) racc (~> 1.4) - nokogiri (1.13.3-x86_64-linux) + nokogiri (1.13.4-x86_64-linux) racc (~> 1.4) nori (2.6.0) omniauth (1.9.1) From f8612d687f9264c3765939c638936ba562dd3365 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Wed, 13 Apr 2022 11:51:08 +0300 Subject: [PATCH 105/172] Remove email verification legacy code --- app/controllers/admin/contacts_controller.rb | 1 - app/models/concerns/domain/force_delete.rb | 10 +- app/models/concerns/email_verifable.rb | 4 - app/models/contact.rb | 5 - app/models/domain.rb | 4 - app/presenters/domain_presenter.rb | 4 - app/views/admin/contacts/index.haml | 4 - .../forced/invalid_email.html.erb | 47 --- .../forced/invalid_email.text.erb | 47 --- ...3315_remove_email_address_verifications.rb | 5 + ...4536_remove_email_addresses_validations.rb | 5 + ...48_remove_email_addresses_verifications.rb | 5 + db/structure.sql | 353 +----------------- .../epp/domain/update/base_test.rb | 46 --- test/mailers/domain_expire_mailer_test.rb | 29 -- test/models/bounced_mail_address_test.rb | 3 +- test/models/domain/force_delete_test.rb | 2 - 17 files changed, 36 insertions(+), 538 deletions(-) delete mode 100644 app/views/mailers/domain_delete_mailer/forced/invalid_email.html.erb delete mode 100644 app/views/mailers/domain_delete_mailer/forced/invalid_email.text.erb create mode 100644 db/migrate/20220413073315_remove_email_address_verifications.rb create mode 100644 db/migrate/20220413084536_remove_email_addresses_validations.rb create mode 100644 db/migrate/20220413084748_remove_email_addresses_verifications.rb diff --git a/app/controllers/admin/contacts_controller.rb b/app/controllers/admin/contacts_controller.rb index 955ab4df2..73ead7b25 100644 --- a/app/controllers/admin/contacts_controller.rb +++ b/app/controllers/admin/contacts_controller.rb @@ -32,7 +32,6 @@ module Admin contacts = contacts.where("ident_country_code is null or ident_country_code=''") end - contacts = contacts.email_verification_failed if params[:email_verification_failed].eql?('1') contacts end diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index 3fa3bf627..cbdd04ca7 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -32,15 +32,9 @@ module Domain::ForceDelete def notification_template(explicit: nil) reason = explicit&.downcase - return reason if %w[invalid_email invalid_phone].include?(reason) + return reason if %w[invalid_phone].include?(reason) - if contact_emails_verification_failed.present? - 'invalid_email' - elsif registrant.org? - 'legal_person' - else - 'private_person' - end + registrant.org? ? 'legal_person' : 'private_person' end def force_delete_scheduled? diff --git a/app/models/concerns/email_verifable.rb b/app/models/concerns/email_verifable.rb index 4f9b4ffeb..77d457e9e 100644 --- a/app/models/concerns/email_verifable.rb +++ b/app/models/concerns/email_verifable.rb @@ -5,10 +5,6 @@ module EmailVerifable scope :recently_not_validated, -> { where.not(id: ValidationEvent.validated_ids_by(name)) } end - def email_verification_failed? - need_to_start_force_delete? - end - def validate_email_data(level:, count:) validation_events.order(created_at: :desc).limit(count).all? do |event| event.check_level == level.to_s && event.failed? diff --git a/app/models/contact.rb b/app/models/contact.rb index 676b0da87..e912bda31 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -25,11 +25,6 @@ class Contact < ApplicationRecord alias_attribute :kind, :ident_type alias_attribute :copy_from_id, :original_id # Old attribute name; for PaperTrail - scope :email_verification_failed, lambda { - joins('LEFT JOIN email_address_verifications emv ON contacts.email = emv.email') - .where('success = false and verified_at IS NOT NULL') - } - scope :with_different_company_name, (lambda do |company| where("ident = ? AND ident_country_code = 'EE' AND name != ?", company.registration_number, diff --git a/app/models/domain.rb b/app/models/domain.rb index 7afd8046e..4d7a4e706 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -734,10 +734,6 @@ class Domain < ApplicationRecord DNS::DomainName.new(name) end - def contact_emails_verification_failed - contacts.select(&:email_verification_failed?)&.map(&:email)&.uniq - end - def as_csv_row [ name, diff --git a/app/presenters/domain_presenter.rb b/app/presenters/domain_presenter.rb index 812881742..f19bbb62f 100644 --- a/app/presenters/domain_presenter.rb +++ b/app/presenters/domain_presenter.rb @@ -52,10 +52,6 @@ class DomainPresenter end end - def contact_emails_verification_failed - domain.contact_emails_verification_failed.join(', ') - end - def remove_registry_lock_btn return unless domain.locked_by_registrant? diff --git a/app/views/admin/contacts/index.haml b/app/views/admin/contacts/index.haml index 8e7a2c244..b5bfa89f1 100644 --- a/app/views/admin/contacts/index.haml +++ b/app/views/admin/contacts/index.haml @@ -63,10 +63,6 @@ .form-group = label_tag :only_no_country_code, "Ident CC missing" = check_box_tag :only_no_country_code, '1',params[:only_no_country_code].eql?('1'), style: 'width:auto;height:auto;float:right' - .col-md-3 - .form-group - = label_tag :email_verification_failed, "Email verification failed" - = check_box_tag :email_verification_failed, '1',params[:email_verification_failed].eql?('1'), style: 'width:auto;height:auto;float:right' .row .col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px'} diff --git a/app/views/mailers/domain_delete_mailer/forced/invalid_email.html.erb b/app/views/mailers/domain_delete_mailer/forced/invalid_email.html.erb deleted file mode 100644 index 817538afd..000000000 --- a/app/views/mailers/domain_delete_mailer/forced/invalid_email.html.erb +++ /dev/null @@ -1,47 +0,0 @@ -

Lugupeetud domeeni <%= @domain.name %> registreerija/halduskontakt

- -

Eesti Interneti Sihtasutusele (EIS) on saanud teatavaks, et domeeni <%= @domain.name %> kontaktandmed on puudulikud - eposti aadress <%= @domain.contact_emails_verification_failed %>.

- -

Et see olukord on vastuolus .ee domeenireeglitega algatas EIS <%= @delete_period_length %> päeva pikkuse kustutusmenetluse. Menetluse käigus on domeen <%= @expire_warning_period %> esimest päeva internetis kättesaadav.

- -

Andmete parandamiseks pöörduge palun oma registripidaja <%= @registrar.name %> poole või isiklike ja oma ettevõtte andmete puhul registreerija portaali.

- -

Kui kontaktandmed ei ole <%= @delete_period_length %> päeva jooksul parandatud, läheb domeen <%= @domain.name %> <%= @domain.force_delete_date %> domeenioksjonile .ee oksjonikeskkonda. Juhul kui domeenile <%= @domain.name %> ei tehta oksjonil 24h möödudes pakkumist, domeen vabaneb ja on registreerimiseks vabalt kättesaadav kõigile huvilistele. Muude võimalike oksjoni tulemuste kohta loe siit.

- -

Lisaküsimuste korral võtke palun ühendust oma registripidajaga:

-<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %> - -<%= render 'mailers/shared/signatures/signature.et.html' %> - -
- -

Dear registrant/administrative contact of .ee domain,

- -

Estonian Internet Foundation has learned that contact data of the domain <%= @domain.name %> s invalid - email(s) <%= @domain.contact_emails_verification_failed %>.

- -

Since this is a violation of Estonian domain regulations, <%= @delete_period_length %>-day deletion process has started for the <%= @domain.name %> domain. For the first <%= @expire_warning_period %> days the domain will remain available on the Internet during the deletion process.

- -

Please, contact your registrar <%= @registrar.name %> with updated contact data, or in case of your personal or business data use .ee portal for registrants

- -

If the data is not fixed within <%= @delete_period_length %> days, the domain <%= @domain.name %> will go to domain auction on <%= @domain.force_delete_date %> in the .ee auction environment. If no offer is made for the domain <%= @domain.name %> at auction within 24 hours, the domain will be released and made freely available for registration to anyone interested on a first-come, first-served basis. Read more about other potential auction results here.

- -

Should you have additional questions, please contact your registrar:

-<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %> - -<%= render 'mailers/shared/signatures/signature.en.html' %> -
- -

Уважаемый регистрант/административный контакт домена .ee

- -

Целевому учреждению Eesti Internet (EIS) стало известно, что контактные данные домена <%= @registrant.reg_no %> неверны - электронная почта <%= @domain.contact_emails_verification_failed %>.

- -

Так как это является нарушением Правил домена .ee, <%= @delete_period_length %>-дневный процесс удаления начат для доменного имени <%= @domain.name %>. В течение первых <%= @expire_warning_period %> дней домен будет доступен в интернете.

- -

Для уточнения контактных данных, пожалуйста, свяжитесь с регистратором <%= @registrar.name %>, либо воспользуйтесь порталом для регистрантов

- -

Если контактные данные не будут исправлены в течение <%= @delete_period_length %> дней, домен <%= @domain.name %> отправится <%= @domain.force_delete_date %> на доменный аукцион в аукционной среде.ee. Если в течение 24 часов в отношении домена <%= @domain.name %> е поступит предложений, домен освободится и станет доступным для всех желающих по принципу «кто раньше». О других возможных результатах аукциона читайте здесь.

- -

В случае возникновения дополнительных вопросов свяжитесь, пожалуйста, со своим регистратором: -<%= render 'mailers/shared/registrar/registrar.ru.html', registrar: @registrar %>

- -<%= render 'mailers/shared/signatures/signature.ru.html' %> diff --git a/app/views/mailers/domain_delete_mailer/forced/invalid_email.text.erb b/app/views/mailers/domain_delete_mailer/forced/invalid_email.text.erb deleted file mode 100644 index 8d2fc58ce..000000000 --- a/app/views/mailers/domain_delete_mailer/forced/invalid_email.text.erb +++ /dev/null @@ -1,47 +0,0 @@ -

Lugupeetud domeeni <%= @domain.name %> registreerija/halduskontakt

- -

Eesti Interneti Sihtasutusele (EIS) on saanud teatavaks, et domeeni <%= @domain.name %> kontaktandmed on puudulikud - eposti aadress <%= @domain.contact_emails_verification_failed %>

- -

Et see olukord on vastuolus .ee domeenireeglitega algatas EIS <%= @delete_period_length %> päeva pikkuse kustutusmenetluse. Menetluse käigus on domeen <%= @expire_warning_period %> esimest päeva internetis kättesaadav.

- -

Andmete parandamiseks pöörduge palun oma registripidaja <%= @registrar.name %> poole või isiklike ja oma ettevõtte andmete puhul registreerija portaali.

- -

Kui kontaktandmed ei ole <%= @delete_period_length %> päeva jooksul parandatud, läheb domeen <%= @domain.name %> <%= @domain.force_delete_date %> domeenioksjonile .ee oksjonikeskkonda. Juhul kui domeenile <%= @domain.name %> ei tehta oksjonil 24h möödudes pakkumist, domeen vabaneb ja on registreerimiseks vabalt kättesaadav kõigile huvilistele. Muude võimalike oksjoni tulemuste kohta loe siit.

- -

Lisaküsimuste korral võtke palun ühendust oma registripidajaga:

-<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %> - -<%= render 'mailers/shared/signatures/signature.et.html' %> - -
- -

Dear registrant/administrative contact of .ee domain,

- -

Estonian Internet Foundation has learned that contact data of the domain <%= @domain.name %> s invalid - email(s) <%= @domain.contact_emails_verification_failed %>.

- -

Since this is a violation of Estonian domain regulations, <%= @delete_period_length %>-day deletion process has started for the <%= @domain.name %> domain. For the first <%= @expire_warning_period %> days the domain will remain available on the Internet during the deletion process.

- -

Please, contact your registrar <%= @registrar.name %> with updated contact data, or in case of your personal or business data use .ee portal for registrants

- -

If the data is not fixed within <%= @delete_period_length %> days, the domain <%= @domain.name %> will go to domain auction on <%= @domain.force_delete_date %> in the .ee auction environment. If no offer is made for the domain <%= @domain.name %> at auction within 24 hours, the domain will be released and made freely available for registration to anyone interested on a first-come, first-served basis. Read more about other potential auction results here.

- -

Should you have additional questions, please contact your registrar:

-<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %> - -<%= render 'mailers/shared/signatures/signature.en.html' %> -
- -

Уважаемый регистрант/административный контакт домена .ee

- -

Целевому учреждению Eesti Internet (EIS) стало известно, что контактные данные домена <%= @registrant.reg_no %> неверны - электронная почта <%= @domain.contact_emails_verification_failed %>.

- -

Так как это является нарушением Правил домена .ee, <%= @delete_period_length %>-дневный процесс удаления начат для доменного имени <%= @domain.name %>. В течение первых <%= @expire_warning_period %> дней домен будет доступен в интернете.

- -

Для уточнения контактных данных, пожалуйста, свяжитесь с регистратором <%= @registrar.name %>, либо воспользуйтесь порталом для регистрантов

- -

Если контактные данные не будут исправлены в течение <%= @delete_period_length %> дней, домен <%= @domain.name %> отправится <%= @domain.force_delete_date %> на доменный аукцион в аукционной среде.ee. Если в течение 24 часов в отношении домена <%= @domain.name %> е поступит предложений, домен освободится и станет доступным для всех желающих по принципу «кто раньше». О других возможных результатах аукциона читайте здесь.

- -

В случае возникновения дополнительных вопросов свяжитесь, пожалуйста, со своим регистратором: - <%= render 'mailers/shared/registrar/registrar.ru.html', registrar: @registrar %>

- -<%= render 'mailers/shared/signatures/signature.ru.html' %> diff --git a/db/migrate/20220413073315_remove_email_address_verifications.rb b/db/migrate/20220413073315_remove_email_address_verifications.rb new file mode 100644 index 000000000..db1f4230c --- /dev/null +++ b/db/migrate/20220413073315_remove_email_address_verifications.rb @@ -0,0 +1,5 @@ +class RemoveEmailAddressVerifications < ActiveRecord::Migration[6.1] + def change + # drop_table :email_address_verifications + end +end diff --git a/db/migrate/20220413084536_remove_email_addresses_validations.rb b/db/migrate/20220413084536_remove_email_addresses_validations.rb new file mode 100644 index 000000000..0084dc08e --- /dev/null +++ b/db/migrate/20220413084536_remove_email_addresses_validations.rb @@ -0,0 +1,5 @@ +class RemoveEmailAddressesValidations < ActiveRecord::Migration[6.1] + def change + # drop_table :email_addresses_validations + end +end diff --git a/db/migrate/20220413084748_remove_email_addresses_verifications.rb b/db/migrate/20220413084748_remove_email_addresses_verifications.rb new file mode 100644 index 000000000..124086d86 --- /dev/null +++ b/db/migrate/20220413084748_remove_email_addresses_verifications.rb @@ -0,0 +1,5 @@ +class RemoveEmailAddressesVerifications < ActiveRecord::Migration[6.1] + def change + # drop_table :email_addresses_verifications + end +end diff --git a/db/structure.sql b/db/structure.sql index 984a949df..2c4723dce 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -51,20 +51,6 @@ CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA public; COMMENT ON EXTENSION hstore IS 'data type for storing sets of (key, value) pairs'; --- --- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public; - - --- --- Name: EXTENSION pg_stat_statements; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON EXTENSION pg_stat_statements IS 'track execution statistics of all SQL statements executed'; - - -- -- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: - -- @@ -954,7 +940,6 @@ CREATE TABLE public.domains ( pending_json jsonb, force_delete_date date, statuses character varying[], - status_notes public.hstore, statuses_before_force_delete character varying[] DEFAULT '{}'::character varying[], upid integer, up_date timestamp without time zone, @@ -962,7 +947,8 @@ CREATE TABLE public.domains ( locked_by_registrant_at timestamp without time zone, force_delete_start timestamp without time zone, force_delete_data public.hstore, - json_statuses_history jsonb + json_statuses_history jsonb, + status_notes public.hstore ); @@ -985,98 +971,6 @@ CREATE SEQUENCE public.domains_id_seq ALTER SEQUENCE public.domains_id_seq OWNED BY public.domains.id; --- --- Name: email_address_verifications; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.email_address_verifications ( - id bigint NOT NULL, - email public.citext NOT NULL, - verified_at timestamp without time zone, - success boolean DEFAULT false NOT NULL, - domain public.citext NOT NULL -); - - --- --- Name: email_address_verifications_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.email_address_verifications_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: email_address_verifications_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.email_address_verifications_id_seq OWNED BY public.email_address_verifications.id; - - --- --- Name: email_addresses_validations; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.email_addresses_validations ( - id bigint NOT NULL, - email character varying NOT NULL, - validated_at timestamp without time zone -); - - --- --- Name: email_addresses_validations_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.email_addresses_validations_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: email_addresses_validations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.email_addresses_validations_id_seq OWNED BY public.email_addresses_validations.id; - - --- --- Name: email_addresses_verifications; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.email_addresses_verifications ( - id bigint NOT NULL, - email character varying NOT NULL, - validated_at timestamp without time zone -); - - --- --- Name: email_addresses_verifications_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.email_addresses_verifications_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: email_addresses_verifications_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.email_addresses_verifications_id_seq OWNED BY public.email_addresses_verifications.id; - - -- -- Name: epp_sessions; Type: TABLE; Schema: public; Owner: - -- @@ -2281,74 +2175,6 @@ CREATE SEQUENCE public.payment_orders_id_seq ALTER SEQUENCE public.payment_orders_id_seq OWNED BY public.payment_orders.id; --- --- Name: pghero_query_stats; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.pghero_query_stats ( - id bigint NOT NULL, - database text, - "user" text, - query text, - query_hash bigint, - total_time double precision, - calls bigint, - captured_at timestamp without time zone -); - - --- --- Name: pghero_query_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.pghero_query_stats_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: pghero_query_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.pghero_query_stats_id_seq OWNED BY public.pghero_query_stats.id; - - --- --- Name: pghero_space_stats; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.pghero_space_stats ( - id bigint NOT NULL, - database text, - schema text, - relation text, - size bigint, - captured_at timestamp without time zone -); - - --- --- Name: pghero_space_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.pghero_space_stats_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: pghero_space_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.pghero_space_stats_id_seq OWNED BY public.pghero_space_stats.id; - - -- -- Name: prices; Type: TABLE; Schema: public; Owner: - -- @@ -2387,48 +2213,6 @@ CREATE SEQUENCE public.prices_id_seq ALTER SEQUENCE public.prices_id_seq OWNED BY public.prices.id; --- --- Name: que_jobs; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.que_jobs ( - priority smallint DEFAULT 100 NOT NULL, - run_at timestamp with time zone DEFAULT now() NOT NULL, - job_id bigint NOT NULL, - job_class text NOT NULL, - args json DEFAULT '[]'::json NOT NULL, - error_count integer DEFAULT 0 NOT NULL, - last_error text, - queue text DEFAULT ''::text NOT NULL -); - - --- --- Name: TABLE que_jobs; Type: COMMENT; Schema: public; Owner: - --- - -COMMENT ON TABLE public.que_jobs IS '3'; - - --- --- Name: que_jobs_job_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.que_jobs_job_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: que_jobs_job_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.que_jobs_job_id_seq OWNED BY public.que_jobs.job_id; - - -- -- Name: registrant_verifications; Type: TABLE; Schema: public; Owner: - -- @@ -2709,7 +2493,8 @@ CREATE TABLE public.validation_events ( validation_eventable_type character varying, validation_eventable_id bigint, created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL + updated_at timestamp(6) without time zone NOT NULL, + event_type public.validation_type ); @@ -3013,27 +2798,6 @@ ALTER TABLE ONLY public.domain_transfers ALTER COLUMN id SET DEFAULT nextval('pu ALTER TABLE ONLY public.domains ALTER COLUMN id SET DEFAULT nextval('public.domains_id_seq'::regclass); --- --- Name: email_address_verifications id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.email_address_verifications ALTER COLUMN id SET DEFAULT nextval('public.email_address_verifications_id_seq'::regclass); - - --- --- Name: email_addresses_validations id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.email_addresses_validations ALTER COLUMN id SET DEFAULT nextval('public.email_addresses_validations_id_seq'::regclass); - - --- --- Name: email_addresses_verifications id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.email_addresses_verifications ALTER COLUMN id SET DEFAULT nextval('public.email_addresses_verifications_id_seq'::regclass); - - -- -- Name: epp_sessions id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3251,20 +3015,6 @@ ALTER TABLE ONLY public.notifications ALTER COLUMN id SET DEFAULT nextval('publi ALTER TABLE ONLY public.payment_orders ALTER COLUMN id SET DEFAULT nextval('public.payment_orders_id_seq'::regclass); --- --- Name: pghero_query_stats id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pghero_query_stats ALTER COLUMN id SET DEFAULT nextval('public.pghero_query_stats_id_seq'::regclass); - - --- --- Name: pghero_space_stats id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pghero_space_stats ALTER COLUMN id SET DEFAULT nextval('public.pghero_space_stats_id_seq'::regclass); - - -- -- Name: prices id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3272,13 +3022,6 @@ ALTER TABLE ONLY public.pghero_space_stats ALTER COLUMN id SET DEFAULT nextval(' ALTER TABLE ONLY public.prices ALTER COLUMN id SET DEFAULT nextval('public.prices_id_seq'::regclass); --- --- Name: que_jobs job_id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.que_jobs ALTER COLUMN job_id SET DEFAULT nextval('public.que_jobs_job_id_seq'::regclass); - - -- -- Name: registrant_verifications id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3516,30 +3259,6 @@ ALTER TABLE ONLY public.domains ADD CONSTRAINT domains_pkey PRIMARY KEY (id); --- --- Name: email_address_verifications email_address_verifications_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.email_address_verifications - ADD CONSTRAINT email_address_verifications_pkey PRIMARY KEY (id); - - --- --- Name: email_addresses_validations email_addresses_validations_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.email_addresses_validations - ADD CONSTRAINT email_addresses_validations_pkey PRIMARY KEY (id); - - --- --- Name: email_addresses_verifications email_addresses_verifications_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.email_addresses_verifications - ADD CONSTRAINT email_addresses_verifications_pkey PRIMARY KEY (id); - - -- -- Name: epp_sessions epp_sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -3788,22 +3507,6 @@ ALTER TABLE ONLY public.payment_orders ADD CONSTRAINT payment_orders_pkey PRIMARY KEY (id); --- --- Name: pghero_query_stats pghero_query_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pghero_query_stats - ADD CONSTRAINT pghero_query_stats_pkey PRIMARY KEY (id); - - --- --- Name: pghero_space_stats pghero_space_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pghero_space_stats - ADD CONSTRAINT pghero_space_stats_pkey PRIMARY KEY (id); - - -- -- Name: prices prices_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -3812,14 +3515,6 @@ ALTER TABLE ONLY public.prices ADD CONSTRAINT prices_pkey PRIMARY KEY (id); --- --- Name: que_jobs que_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.que_jobs - ADD CONSTRAINT que_jobs_pkey PRIMARY KEY (queue, priority, run_at, job_id); - - -- -- Name: registrant_verifications registrant_verifications_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -4231,13 +3926,6 @@ CREATE INDEX index_domains_on_registrar_id ON public.domains USING btree (regist CREATE INDEX index_domains_on_statuses ON public.domains USING gin (statuses); --- --- Name: index_email_address_verifications_on_domain; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_email_address_verifications_on_domain ON public.email_address_verifications USING btree (domain); - - -- -- Name: index_epp_sessions_on_updated_at; Type: INDEX; Schema: public; Owner: - -- @@ -4574,20 +4262,6 @@ CREATE INDEX index_notifications_on_registrar_id ON public.notifications USING b CREATE INDEX index_payment_orders_on_invoice_id ON public.payment_orders USING btree (invoice_id); --- --- Name: index_pghero_query_stats_on_database_and_captured_at; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_pghero_query_stats_on_database_and_captured_at ON public.pghero_query_stats USING btree (database, captured_at); - - --- --- Name: index_pghero_space_stats_on_database_and_captured_at; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_pghero_space_stats_on_database_and_captured_at ON public.pghero_space_stats USING btree (database, captured_at); - - -- -- Name: index_prices_on_zone_id; Type: INDEX; Schema: public; Owner: - -- @@ -4644,6 +4318,13 @@ CREATE INDEX index_users_on_registrar_id ON public.users USING btree (registrar_ CREATE INDEX index_validation_events_on_event_data ON public.validation_events USING gin (event_data); +-- +-- Name: index_validation_events_on_event_type; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_validation_events_on_event_type ON public.validation_events USING btree (event_type); + + -- -- Name: index_validation_events_on_validation_eventable; Type: INDEX; Schema: public; Owner: - -- @@ -5389,11 +5070,9 @@ INSERT INTO "schema_migrations" (version) VALUES ('20210708131814'), ('20210729131100'), ('20210729134625'), -('20211028122103'), -('20211028125245'), -('20211029082225'), +('20210827185249'), +('20211029073644'), ('20211124071418'), -('20211124084308'), ('20211125181033'), ('20211125184334'), ('20211126085139'), @@ -5401,6 +5080,10 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220106123143'), ('20220113201642'), ('20220113220809'), -('20220316140727'); +('20220316140727'), +('20220406085500'), +('20220413073315'), +('20220413084536'), +('20220413084748'); diff --git a/test/integration/epp/domain/update/base_test.rb b/test/integration/epp/domain/update/base_test.rb index d021b496d..10c92ebc5 100644 --- a/test/integration/epp/domain/update/base_test.rb +++ b/test/integration/epp/domain/update/base_test.rb @@ -717,52 +717,6 @@ class EppDomainUpdateBaseTest < EppTestCase assert_no_emails end - # COMMENT OU REASON: FOR EXPIRED DOMAIN SHOULD NOT SET FD - # def test_makes_update_if_was_forcedelete - # contact = @domain.contacts.first - # contact.update_attribute(:email, '`@outlook.test') - # contact.verify_email - # assert contact.email_verification_failed? - # @domain.reload - # - # assert @domain.force_delete_scheduled? - # - # @domain.update_attribute(:statuses_before_force_delete, nil) - # - # Setting.request_confirmation_on_registrant_change_enabled = true - # new_registrant = contacts(:william).becomes(Registrant) - # assert_not_equal new_registrant, @domain.registrant - # - # request_xml = <<-XML - # - # - # - # - # - # #{@domain.name} - # - # #{new_registrant.code} - # - # - # - # - # - # #{'test' * 2000} - # - # - # - # - # XML - # - # post epp_update_path, params: { frame: request_xml }, - # headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } - # @domain.reload - # - # response_xml = Nokogiri::XML(response.body) - # assert_correct_against_schema response_xml - # assert_epp_response :completed_successfully - # end - def test_clears_force_delete_when_registrar_changed Setting.request_confirmation_on_registrant_change_enabled = true new_registrant = contacts(:william).becomes(Registrant) diff --git a/test/mailers/domain_expire_mailer_test.rb b/test/mailers/domain_expire_mailer_test.rb index ff2d93c79..92d900b42 100644 --- a/test/mailers/domain_expire_mailer_test.rb +++ b/test/mailers/domain_expire_mailer_test.rb @@ -28,33 +28,4 @@ class DomainExpireMailerTest < ActionMailer::TestCase assert_equal I18n.t("domain_expire_mailer.expired_soft.subject", domain_name: domain.name), email.subject end - - # COMMENT OU REASON: FOR EXPIRED DOMAIN SHOULD NOT SET FD - # def test_delivers_domain_expiration_soft_email_if_auto_fd - # domain = domains(:shop) - # email_address = domain.registrar.email - # assert_not domain.force_delete_scheduled? - # travel_to Time.zone.parse('2010-07-05') - # email = '`@internet.ee' - # - # Truemail.configure.default_validation_type = :regex - # - # contact = domain.admin_contacts.first - # contact.update_attribute(:email, email) - # contact.verify_email - # - # assert contact.email_verification_failed? - # - # domain.reload - # - # assert_no domain.force_delete_scheduled? - # - # email = DomainExpireMailer.expired_soft(domain: domain, - # registrar: domain.registrar, - # email: email_address).deliver_now - # - # assert_emails 1 - # assert_equal I18n.t("domain_expire_mailer.expired_soft.subject", domain_name: domain.name), - # email.subject - # end end diff --git a/test/models/bounced_mail_address_test.rb b/test/models/bounced_mail_address_test.rb index 2f266f8bd..b4f2166a0 100644 --- a/test/models/bounced_mail_address_test.rb +++ b/test/models/bounced_mail_address_test.rb @@ -137,9 +137,8 @@ class BouncedMailAddressTest < ActiveSupport::TestCase bounced_mail = BouncedMailAddress.last registrant = domains(:shop).registrant registrant.verify_email(check_level: 'smtp') - + assert_equal registrant.email, bounced_mail.email - assert registrant.email_verification_failed? end def sns_bounce_payload diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 974c445e6..775308f70 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -398,8 +398,6 @@ class ForceDeleteTest < ActionMailer::TestCase contact.verify_email end - assert contact.email_verification_failed? - @domain.reload assert @domain.force_delete_scheduled? From d0d40cc792bcaa7dfa6a4786d1538808bbfb1eee Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Wed, 13 Apr 2022 13:45:58 +0300 Subject: [PATCH 106/172] Fix tests --- app/models/concerns/domain/force_delete.rb | 2 +- test/models/domain/force_delete_test.rb | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index cbdd04ca7..7dd309c41 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -32,7 +32,7 @@ module Domain::ForceDelete def notification_template(explicit: nil) reason = explicit&.downcase - return reason if %w[invalid_phone].include?(reason) + return reason if %w[invalid_email invalid_phone].include?(reason) registrant.org? ? 'legal_person' : 'private_person' end diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 775308f70..1d9cc401e 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -356,7 +356,6 @@ class ForceDeleteTest < ActionMailer::TestCase @domain.reload assert @domain.force_delete_scheduled? - assert_equal 'invalid_email', @domain.template_name assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date notification = @domain.registrar.notifications.last @@ -375,7 +374,6 @@ class ForceDeleteTest < ActionMailer::TestCase @domain.reload assert @domain.force_delete_scheduled? - assert_equal 'invalid_email', @domain.template_name assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date notification = @domain.registrar.notifications.last @@ -401,7 +399,6 @@ class ForceDeleteTest < ActionMailer::TestCase @domain.reload assert @domain.force_delete_scheduled? - assert_equal 'invalid_email', @domain.template_name assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date assert_equal @domain.status_notes[DomainStatus::FORCE_DELETE], email @@ -487,7 +484,6 @@ class ForceDeleteTest < ActionMailer::TestCase @domain.reload assert @domain.force_delete_scheduled? - assert_equal 'invalid_email', @domain.template_name assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_one @@ -506,7 +502,6 @@ class ForceDeleteTest < ActionMailer::TestCase @domain.reload assert @domain.force_delete_scheduled? - assert_equal 'invalid_email', @domain.template_name assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date notification = @domain.registrar.notifications.last From 41a3c661aa4962c43a9757546c4f152990262605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Wed, 13 Apr 2022 15:59:01 +0300 Subject: [PATCH 107/172] Deleted disclosable concern from contact --- app/models/concerns/contact/disclosable.rb | 22 ------------ app/models/contact.rb | 1 - test/models/contact/disclosable_test.rb | 39 ---------------------- 3 files changed, 62 deletions(-) delete mode 100644 app/models/concerns/contact/disclosable.rb delete mode 100644 test/models/contact/disclosable_test.rb diff --git a/app/models/concerns/contact/disclosable.rb b/app/models/concerns/contact/disclosable.rb deleted file mode 100644 index a61b240b1..000000000 --- a/app/models/concerns/contact/disclosable.rb +++ /dev/null @@ -1,22 +0,0 @@ -module Contact::Disclosable - extend ActiveSupport::Concern - - class_methods do - attr_accessor :disclosable_attributes - end - - included do - self.disclosable_attributes = %w[name email] - validate :validate_disclosed_attributes - end - - private - - def validate_disclosed_attributes - return if disclosed_attributes.empty? - - has_undisclosable_attributes = (disclosed_attributes - self.class.disclosable_attributes) - .any? - errors.add(:disclosed_attributes, :invalid) if has_undisclosable_attributes - end -end diff --git a/app/models/contact.rb b/app/models/contact.rb index 676b0da87..fc8f9a10e 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -7,7 +7,6 @@ class Contact < ApplicationRecord include UserEvents include Contact::Transferable include Contact::Identical - include Contact::Disclosable include Contact::Archivable include EmailVerifable diff --git a/test/models/contact/disclosable_test.rb b/test/models/contact/disclosable_test.rb deleted file mode 100644 index 02adfbb08..000000000 --- a/test/models/contact/disclosable_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'test_helper' - -class ContactDisclosableTest < ActiveSupport::TestCase - setup do - @contact = contacts(:john) - @original_disclosable_attributes = Contact.disclosable_attributes - end - - teardown do - Contact.disclosable_attributes = @original_disclosable_attributes - end - - def test_no_disclosed_attributes_by_default - assert_empty Contact.new.disclosed_attributes - end - - def test_disclosable_attributes - assert_equal %w[name email], Contact.disclosable_attributes - end - - def test_valid_without_disclosed_attributes - @contact.disclosed_attributes = [] - assert @contact.valid? - end - - def test_invalid_when_attribute_is_not_disclosable - Contact.disclosable_attributes = %w[some disclosable] - @contact.disclosed_attributes = %w[some undisclosable] - - assert @contact.invalid? - assert_includes @contact.errors[:disclosed_attributes], 'contain unsupported attribute(s)' - end - - def test_valid_when_attribute_is_disclosable - Contact.disclosable_attributes = %w[some disclosable] - @contact.disclosed_attributes = %w[disclosable] - assert @contact.valid? - end -end From ecb23b41190a5df1d3c255e972c780c085eb07b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Thu, 14 Apr 2022 14:07:37 +0300 Subject: [PATCH 108/172] Fixed message format for epp 2005 error --- app/interactions/actions/contact_create.rb | 4 +++- app/interactions/actions/contact_update.rb | 6 ++++-- app/interactions/actions/domain_update.rb | 6 ++++-- config/locales/en.yml | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index 84ed10caf..f0d11896b 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -24,7 +24,9 @@ module Actions next if result - contact.add_epp_error('2005', nil, "email didn't pass validation", I18n.t(:parameter_value_syntax_error)) + err_text = "email '#{contact.email}' didn't pass validation" + contact.add_epp_error('2005', nil, nil, + "#{I18n.t(:parameter_value_syntax_error)} #{err_text}") @error = true return end diff --git a/app/interactions/actions/contact_update.rb b/app/interactions/actions/contact_update.rb index 685f1474c..abf55e96a 100644 --- a/app/interactions/actions/contact_update.rb +++ b/app/interactions/actions/contact_update.rb @@ -23,11 +23,13 @@ module Actions def maybe_change_email return if Rails.env.test? - [:regex, :mx].each do |m| + %i[regex mx].each do |m| result = Actions::SimpleMailValidator.run(email: @new_attributes[:email], level: m) next if result - contact.add_epp_error('2005', nil, "email didn't pass validation", I18n.t(:parameter_value_syntax_error)) + err_text = "email '#{new_attributes[:email]}' didn't pass validation" + contact.add_epp_error('2005', nil, nil, + "#{I18n.t(:parameter_value_syntax_error)} #{err_text}") @error = true return end diff --git a/app/interactions/actions/domain_update.rb b/app/interactions/actions/domain_update.rb index c610e0117..7d556b2e8 100644 --- a/app/interactions/actions/domain_update.rb +++ b/app/interactions/actions/domain_update.rb @@ -136,11 +136,13 @@ module Actions def validate_email(email) return true if Rails.env.test? - [:regex, :mx].each do |m| + %i[regex mx].each do |m| result = Actions::SimpleMailValidator.run(email: email, level: m) next if result - domain.add_epp_error('2005', nil, "#{email} didn't pass validation", I18n.t(:parameter_value_syntax_error)) + err_text = "email #{email} didn't pass validation" + domain.add_epp_error('2005', nil, nil, + "#{I18n.t(:parameter_value_syntax_error)} #{err_text}") @error = true return end diff --git a/config/locales/en.yml b/config/locales/en.yml index 2f7e8a0aa..28d2d0281 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -371,7 +371,7 @@ en: sim_error: 'SIM application error' internal_error: 'Internal error' client_side_status_editing_error: 'Parameter value policy error. Client-side object status management not supported' - parameter_value_syntax_error: 'Parameter value syntax error: ' + parameter_value_syntax_error: 'Parameter value syntax error:' # DEPP activemodel: From bcd1b3f745c68800d5abd729299a93d3a6a6db4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Thu, 14 Apr 2022 14:28:26 +0300 Subject: [PATCH 109/172] Fixed codeclimate errors --- app/interactions/actions/contact_create.rb | 6 ++---- app/interactions/actions/contact_update.rb | 3 +-- app/interactions/actions/domain_update.rb | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index f0d11896b..f3e6560b8 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -19,14 +19,12 @@ module Actions def maybe_change_email return if Rails.env.test? - [:regex, :mx].each do |m| + %i[regex mx].each do |m| result = Actions::SimpleMailValidator.run(email: contact.email, level: m) - next if result err_text = "email '#{contact.email}' didn't pass validation" - contact.add_epp_error('2005', nil, nil, - "#{I18n.t(:parameter_value_syntax_error)} #{err_text}") + contact.add_epp_error('2005', nil, nil, "#{I18n.t(:parameter_value_syntax_error)} #{err_text}") @error = true return end diff --git a/app/interactions/actions/contact_update.rb b/app/interactions/actions/contact_update.rb index abf55e96a..3442a5643 100644 --- a/app/interactions/actions/contact_update.rb +++ b/app/interactions/actions/contact_update.rb @@ -28,8 +28,7 @@ module Actions next if result err_text = "email '#{new_attributes[:email]}' didn't pass validation" - contact.add_epp_error('2005', nil, nil, - "#{I18n.t(:parameter_value_syntax_error)} #{err_text}") + contact.add_epp_error('2005', nil, nil, "#{I18n.t(:parameter_value_syntax_error)} #{err_text}") @error = true return end diff --git a/app/interactions/actions/domain_update.rb b/app/interactions/actions/domain_update.rb index 7d556b2e8..3c408e11f 100644 --- a/app/interactions/actions/domain_update.rb +++ b/app/interactions/actions/domain_update.rb @@ -141,8 +141,7 @@ module Actions next if result err_text = "email #{email} didn't pass validation" - domain.add_epp_error('2005', nil, nil, - "#{I18n.t(:parameter_value_syntax_error)} #{err_text}") + domain.add_epp_error('2005', nil, nil, "#{I18n.t(:parameter_value_syntax_error)} #{err_text}") @error = true return end From 71b4e69741926ee263b9e5d4a48cae58ba461888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 14 Apr 2022 16:27:27 +0300 Subject: [PATCH 110/172] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5bf7fedd..49de50c50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +14.04.2022 +* Removed legacy email verification code [#2349](https://github.com/internetee/registry/issues/2349) + 06.04.2022 * Contact email validation on domain update [#2213](https://github.com/internetee/registry/issues/2213) From fd9b71d7d456a38fd57e1baf44526274e0772b91 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Thu, 14 Apr 2022 14:14:26 +0000 Subject: [PATCH 111/172] Update dependency ruby to v3.1.2 --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 75a22a26a..ef538c281 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.3 +3.1.2 From 2d2584d605881da068563aa6cc7c3dc9c1df9293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Mon, 18 Apr 2022 10:33:12 +0300 Subject: [PATCH 112/172] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49de50c50..4862a4934 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +18.04.2022 +* Fixed poll issue with email validations [#2343](https://github.com/internetee/registry/issues/2343) + 14.04.2022 * Removed legacy email verification code [#2349](https://github.com/internetee/registry/issues/2349) From 8b256b0b74cd3902fedc717ce6945ad903e05685 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Mon, 18 Apr 2022 13:30:05 +0300 Subject: [PATCH 113/172] Remove registrant portal legacy code --- .../stylesheets/registrant-manifest.sass | 11 --- .../registrant/registrant-bootstrap.sass | 19 ---- .../stylesheets/registrant/registrant.sass | 44 ---------- app/helpers/registrant/application_helper.rb | 6 -- .../layouts/registrant/application.html.erb | 86 ------------------- .../application_helper_test.rb | 14 --- 6 files changed, 180 deletions(-) delete mode 100644 app/assets/stylesheets/registrant-manifest.sass delete mode 100644 app/assets/stylesheets/registrant/registrant-bootstrap.sass delete mode 100644 app/assets/stylesheets/registrant/registrant.sass delete mode 100644 app/helpers/registrant/application_helper.rb delete mode 100644 app/views/layouts/registrant/application.html.erb delete mode 100644 test/integration/registrant_area/application_helper_test.rb diff --git a/app/assets/stylesheets/registrant-manifest.sass b/app/assets/stylesheets/registrant-manifest.sass deleted file mode 100644 index 6d0a281fe..000000000 --- a/app/assets/stylesheets/registrant-manifest.sass +++ /dev/null @@ -1,11 +0,0 @@ -//= require 'registrant/registrant-bootstrap' -//= require 'jquery-ui/datepicker' -//= require 'select2' -//= require 'select2-bootstrap' -@import shared/fonts -@import shared/general -@import forms -@import typeaheadjs -@import selectize -@import selectize.bootstrap3 -@import registrant/registrant diff --git a/app/assets/stylesheets/registrant/registrant-bootstrap.sass b/app/assets/stylesheets/registrant/registrant-bootstrap.sass deleted file mode 100644 index 08f6eb984..000000000 --- a/app/assets/stylesheets/registrant/registrant-bootstrap.sass +++ /dev/null @@ -1,19 +0,0 @@ -$brand-primary: #7EA82F -$navbar-default-bg: #7EA82F -$navbar-default-brand-color: #fff -$navbar-default-link-color: #fff -$border-radius-base: 2px -$body-bg: #F8F8F8 -$container-large-desktop: 1040px -$font-family-sans-serif: 'EtelkaLightProRegular', Arial, Helvetica, sans-serif -$font-family-serif: 'EtelkaLightProBold', Georgia, "Times New Roman", Times, serif -$font-size-h1: 26px -$navbar-default-link-active-color: #333 - -@import 'bootstrap-sprockets' -@import 'bootstrap' -@import 'shared/general-bootstrap' - -// Support rails error element -.field_with_errors - @extend .has-error diff --git a/app/assets/stylesheets/registrant/registrant.sass b/app/assets/stylesheets/registrant/registrant.sass deleted file mode 100644 index ebe9f4974..000000000 --- a/app/assets/stylesheets/registrant/registrant.sass +++ /dev/null @@ -1,44 +0,0 @@ -html - position: relative - min-height: 100% - overflow-y: scroll - -body - padding-bottom: 130px - -body > .container - height: 100% - background: #fff - padding: 60px 30px 30px 30px - -h1, h2, h3, h4 - margin-bottom: 0px !important - -// Commented out, default 20px is needed on forms -// hr - // margin-top: 10px !important - // margin-bottom: 10px !important - -.navbar li - font-weight: bold - -.footer - position: absolute - bottom: 0 - width: 100% - height: 130px - background: image_url('bg.jpg') - color: white !important - background-size: 100% - -.confirmation - padding: 40px 0 20px 0 - .column-keys - text-align: right - width: 49% - float: left - .column-values - float: right - font-weight: bold - text-align: left - width: 49% diff --git a/app/helpers/registrant/application_helper.rb b/app/helpers/registrant/application_helper.rb deleted file mode 100644 index 6451f91a2..000000000 --- a/app/helpers/registrant/application_helper.rb +++ /dev/null @@ -1,6 +0,0 @@ -module Registrant::ApplicationHelper - def env_style - return '' if unstable_env.nil? - "background-image: url(#{image_path("registrar/bg-#{unstable_env}.png")});" - end -end diff --git a/app/views/layouts/registrant/application.html.erb b/app/views/layouts/registrant/application.html.erb deleted file mode 100644 index c5290b70f..000000000 --- a/app/views/layouts/registrant/application.html.erb +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - <% if content_for? :head_title %> - <%= yield :head_title %> - <% else %> - - <%= t(:registrant_head_title) %> - - <% end %> - <%= csrf_meta_tags %> - <%= stylesheet_link_tag 'registrant-manifest', media: 'all' %> - <%= favicon_link_tag 'favicon.ico' %> - - - - -
- <%= render 'flash_messages' %> - <%= yield %> -
-
-
-
-
- <%= image_tag 'eis-logo-et.png' %> -
-
- Version - <%= current_commit_link %> -
-
-
-
- <%= javascript_include_tag 'registrant-manifest', async: true %> - - diff --git a/test/integration/registrant_area/application_helper_test.rb b/test/integration/registrant_area/application_helper_test.rb deleted file mode 100644 index d915baf61..000000000 --- a/test/integration/registrant_area/application_helper_test.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'test_helper' - -class ApplicationHelperTest < ActionView::TestCase - def test_env_style_when_pic_present - assert_dom_equal %{}, - %{} - end - - def test_env_style_return_nil - env_style = '' - assert_dom_equal %{}, - %{} - end -end From 60165cc23a31e1f081b92e38033783931dd2aab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Mon, 18 Apr 2022 16:36:24 +0300 Subject: [PATCH 114/172] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4862a4934..1ac8e3de0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ 18.04.2022 * Fixed poll issue with email validations [#2343](https://github.com/internetee/registry/issues/2343) +* Removed registrant portal code from registry project [#2350](https://github.com/internetee/registry/issues/2350) 14.04.2022 * Removed legacy email verification code [#2349](https://github.com/internetee/registry/issues/2349) From 83308334639fdca8a8953285315fe47e6d207aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Mon, 18 Apr 2022 16:40:37 +0300 Subject: [PATCH 115/172] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ac8e3de0..8a649b776 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ 18.04.2022 +* Fixed error 2005 epp syntax issue [#2338](https://github.com/internetee/registry/issues/2338) * Fixed poll issue with email validations [#2343](https://github.com/internetee/registry/issues/2343) * Removed registrant portal code from registry project [#2350](https://github.com/internetee/registry/issues/2350) From e00329d9a105a7ee358c4ddd69928c9148a7ea20 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 19 Apr 2022 13:56:08 +0300 Subject: [PATCH 116/172] Change ruby version --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index ef538c281..75a22a26a 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.2 +3.0.3 From dffb7163bbd548ab9394e9773b6f60fa6bdd4d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 19 Apr 2022 15:07:29 +0300 Subject: [PATCH 117/172] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a649b776..04e92dd82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +19.04.2022 +* Rolled back ruby version to 3.0.3 [#2358](https://github.com/internetee/registry/pull/2358) + 18.04.2022 * Fixed error 2005 epp syntax issue [#2338](https://github.com/internetee/registry/issues/2338) * Fixed poll issue with email validations [#2343](https://github.com/internetee/registry/issues/2343) From 2a6bf9da193cb608d515ff75ca0fe57adf8a5c6a Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Wed, 20 Apr 2022 10:53:56 +0300 Subject: [PATCH 118/172] Remove registrant legacy controller --- app/controllers/registrant_controller.rb | 37 ------------------------ 1 file changed, 37 deletions(-) delete mode 100644 app/controllers/registrant_controller.rb diff --git a/app/controllers/registrant_controller.rb b/app/controllers/registrant_controller.rb deleted file mode 100644 index 1e97281e7..000000000 --- a/app/controllers/registrant_controller.rb +++ /dev/null @@ -1,37 +0,0 @@ -class RegistrantController < ApplicationController - before_action :authenticate_registrant_user! - before_action :set_paper_trail_whodunnit - layout 'registrant/application' - - include Registrant::ApplicationHelper - - helper_method :head_title_sufix - - def head_title_sufix - t(:registrant_head_title_sufix) - end - - private - - def current_ability - @current_ability ||= Ability.new(current_registrant_user, request.remote_ip) - end - - def user_for_paper_trail - current_registrant_user.present? ? current_registrant_user.id_role_username : 'anonymous' - end - - def current_user_contacts - current_registrant_user.contacts - rescue CompanyRegister::NotAvailableError - flash.now[:notice] = t('registrant.company_register_unavailable') - current_registrant_user.direct_contacts - end - - def current_user_domains - current_registrant_user.domains - rescue CompanyRegister::NotAvailableError - flash.now[:notice] = t('registrant.company_register_unavailable') - current_registrant_user.direct_domains - end -end From efdffd1cce2f2da78aa646a28539ae22eacc8b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Wed, 20 Apr 2022 11:29:41 +0300 Subject: [PATCH 119/172] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04e92dd82..115b7df0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +20.04.2022 +* Legacy code fix [#2360](https://github.com/internetee/registry/pull/2360) + 19.04.2022 * Rolled back ruby version to 3.0.3 [#2358](https://github.com/internetee/registry/pull/2358) From 669ba89d478cbdc3b42dbbc7b3e5cafb80e9c285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Wed, 20 Apr 2022 16:03:35 +0300 Subject: [PATCH 120/172] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 115b7df0a..28a1f9b6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ 20.04.2022 +* Contacts with disclosed attributes can now be updated [#2340](https://github.com/internetee/registry/issues/2340) * Legacy code fix [#2360](https://github.com/internetee/registry/pull/2360) 19.04.2022 From 2d3b3c0ba1331158484c01fa2a4d7c8045573fea Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Wed, 20 Apr 2022 17:00:20 +0300 Subject: [PATCH 121/172] Change renovate config to delay ruby version updates --- renovate.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/renovate.json b/renovate.json index a1a4fde6b..8666ee423 100644 --- a/renovate.json +++ b/renovate.json @@ -9,17 +9,20 @@ "automergeType": "pr" }, { - "depTypeList": ["ruby", "bundler", "Gemfile", "Gemfile.lock"], + "matchDepTypes": ["ruby", "bundler", "Gemfile", "Gemfile.lock"], "addLabels": ["bundler"] }, { - "depTypeList": [".ruby-version"], + "matchDepTypes": [".ruby-version"], "addLabels": ["ruby-version"] } ], "docker": { "enabled": false }, + "ruby": { + "stabilityDays": 30 + }, "ignorePaths": [ "Dockerfile", "Dockerfile.*", ".github/workflows/build_deploy_staging.yml", ".github/workflows/remove_st_after_pr.yml" From f8d73cc76bf39b687ec116524261f76634fbe882 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Thu, 21 Apr 2022 10:25:39 +0300 Subject: [PATCH 122/172] Increase delay for 2 months --- renovate.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/renovate.json b/renovate.json index 8666ee423..11d9ae957 100644 --- a/renovate.json +++ b/renovate.json @@ -21,7 +21,7 @@ "enabled": false }, "ruby": { - "stabilityDays": 30 + "stabilityDays": 60 }, "ignorePaths": [ "Dockerfile", "Dockerfile.*", ".github/workflows/build_deploy_staging.yml", From 219b48d9e3e9350ef6ce07270dd3ffe2c8549e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 21 Apr 2022 15:39:21 +0300 Subject: [PATCH 123/172] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28a1f9b6d..2e964c1f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +21.04.2022 +* Delay renovate Ruby version updates for 60 days [#2361](https://github.com/internetee/registry/issues/2361) + 20.04.2022 * Contacts with disclosed attributes can now be updated [#2340](https://github.com/internetee/registry/issues/2340) * Legacy code fix [#2360](https://github.com/internetee/registry/pull/2360) From d7df76329513c9add3bd9e50807b7e1f69db78d3 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 25 Apr 2022 14:23:27 +0300 Subject: [PATCH 124/172] refactoring-job-validation-email --- app/interactions/actions/email_check.rb | 9 +++-- app/jobs/verify_emails_job.rb | 29 ++++++++++++++-- lib/tasks/verify_email.rake | 44 +++++++++++++------------ 3 files changed, 56 insertions(+), 26 deletions(-) diff --git a/app/interactions/actions/email_check.rb b/app/interactions/actions/email_check.rb index 4b026ec2e..cf0ceaa55 100644 --- a/app/interactions/actions/email_check.rb +++ b/app/interactions/actions/email_check.rb @@ -50,6 +50,8 @@ module Actions end def save_result(result) + contacts = Contact.where(email: email) + if !result.success && @check_level == "mx" result_validation = Actions::AAndAaaaEmailValidation.call(email: @email, value: 'A') output_a_and_aaaa_validation_results(email: @email, @@ -62,9 +64,10 @@ module Actions type: 'AAAA') result_validation.present? ? result.success = true : result.success = false - validation_eventable.validation_events.create(validation_event_attrs(result)) - else - validation_eventable.validation_events.create(validation_event_attrs(result)) + end + + contacts.each do |contact| + contact.validation_events.create(validation_event_attrs(result)) end rescue ActiveRecord::RecordNotSaved logger.info "Cannot save validation result for #{log_object_id}" diff --git a/app/jobs/verify_emails_job.rb b/app/jobs/verify_emails_job.rb index 4b9b98fb7..6c75aa22c 100644 --- a/app/jobs/verify_emails_job.rb +++ b/app/jobs/verify_emails_job.rb @@ -1,8 +1,13 @@ class VerifyEmailsJob < ApplicationJob discard_on StandardError - def perform(contact:, check_level: 'mx') - contact_not_found(contact.id) unless contact + def perform(email:, check_level: 'mx') + # contact_not_found(contact.id) unless contact + + contact = Contact.find_by_email(email) + + return unless filter_check_level(contact) + validate_check_level(check_level) action = Actions::EmailCheck.new(email: contact.email, validation_eventable: contact, @@ -32,4 +37,24 @@ class VerifyEmailsJob < ApplicationJob def valid_check_levels ValidationEvent::VALID_CHECK_LEVELS end + + def get_validation_results(contact) + ValidationEvent.where(created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day) + end + + def filter_check_level(contact) + return true unless contact.validation_events.exists? + + data = contact.validation_events.order(created_at: :asc).last + + return true if data.successful? && data.created_at < (Time.zone.now - ValidationEvent::VALIDATION_PERIOD) + + if data.failed? + return false if data.event_data['check_level'] == 'regex' + + return true + end + + false + end end diff --git a/lib/tasks/verify_email.rake b/lib/tasks/verify_email.rake index c22587ab1..d20ac76a1 100644 --- a/lib/tasks/verify_email.rake +++ b/lib/tasks/verify_email.rake @@ -19,17 +19,28 @@ namespace :verify_email do banner: banner, hash: opts_hash) - batch_contacts = prepare_contacts(options) - logger.info 'No contacts to check email selected' and next if batch_contacts.blank? + # batch_contacts = prepare_contacts(options) + # logger.info 'No contacts to check email selected' and next if batch_contacts.blank? - batch_contacts.find_in_batches(batch_size: 10_000) do |contacts| - contacts.each do |contact| + # batch_contacts.find_in_batches(batch_size: 10_000) do |contacts| + # contacts.each do |contact| + # VerifyEmailsJob.set(wait_until: spam_protect_timeout(options)).perform_later( + # contact: contact, + # check_level: check_level(options) + # ) if filter_check_level(contact) + # end + # end + + email_contacts = prepare_contacts(options) + email_contacts.each do |email| VerifyEmailsJob.set(wait_until: spam_protect_timeout(options)).perform_later( - contact: contact, + # contact: contact, + email: email, check_level: check_level(options) - ) if filter_check_level(contact) - end + ) + # if filter_check_level(contact) end + end end @@ -51,13 +62,16 @@ end def prepare_contacts(options) if options[:domain_name].present? - contacts_by_domain(options[:domain_name]) + Rails.logger.info 'NEED TO TODO' + # contacts_by_domain(options[:domain_name]) else time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD validation_events_ids = ValidationEvent.where('created_at > ?', time).distinct.pluck(:validation_eventable_id) contacts_ids = Contact.where.not(id: validation_events_ids).pluck(:id) - Contact.where(id: contacts_ids + failed_contacts) + Contact.where(id: contacts_ids + failed_contacts).group_by(&:email).keys + + # Contact.all.group_by(&:email).keys end end @@ -71,10 +85,6 @@ def filter_check_level(contact) if data.failed? return false if data.event_data['check_level'] == 'regex' - # return false if data.event_data['check_level'] == 'smtp' - # - # return false if check_mx_contact_validation(contact) - return true end @@ -92,14 +102,6 @@ def failed_contacts failed_contacts.uniq end -# def check_mx_contact_validation(contact) -# data = contact.validation_events.mx.order(created_at: :asc).last(ValidationEvent::MX_CHECK) -# -# return false if data.size < ValidationEvent::MX_CHECK -# -# data.all? { |d| d.failed? } -# end - def contacts_by_domain(domain_name) domain = ::Domain.find_by(name: domain_name) return unless domain From 43bd6f2907736d2384c2f393952012fefc3be466 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 25 Apr 2022 14:37:46 +0300 Subject: [PATCH 125/172] added validation for single domain contacts --- app/interactions/actions/email_check.rb | 6 ++- app/jobs/verify_emails_job.rb | 4 +- lib/tasks/verify_email.rake | 55 +++++-------------------- 3 files changed, 17 insertions(+), 48 deletions(-) diff --git a/app/interactions/actions/email_check.rb b/app/interactions/actions/email_check.rb index cf0ceaa55..27d2315a6 100644 --- a/app/interactions/actions/email_check.rb +++ b/app/interactions/actions/email_check.rb @@ -66,8 +66,10 @@ module Actions result_validation.present? ? result.success = true : result.success = false end - contacts.each do |contact| - contact.validation_events.create(validation_event_attrs(result)) + contacts.find_in_batches(batch_size: 500) do |contact_batches| + contact_batches.each do |contact| + contact.validation_events.create(validation_event_attrs(result)) + end end rescue ActiveRecord::RecordNotSaved logger.info "Cannot save validation result for #{log_object_id}" diff --git a/app/jobs/verify_emails_job.rb b/app/jobs/verify_emails_job.rb index 6c75aa22c..de343f32b 100644 --- a/app/jobs/verify_emails_job.rb +++ b/app/jobs/verify_emails_job.rb @@ -2,9 +2,9 @@ class VerifyEmailsJob < ApplicationJob discard_on StandardError def perform(email:, check_level: 'mx') - # contact_not_found(contact.id) unless contact + contact = Contact.find_by(email: email) - contact = Contact.find_by_email(email) + return Rails.logger.info "No found #{email} contact" if contact.nil? return unless filter_check_level(contact) diff --git a/lib/tasks/verify_email.rake b/lib/tasks/verify_email.rake index d20ac76a1..9b35d5beb 100644 --- a/lib/tasks/verify_email.rake +++ b/lib/tasks/verify_email.rake @@ -18,29 +18,13 @@ namespace :verify_email do options = RakeOptionParserBoilerplate.process_args(options: options, banner: banner, hash: opts_hash) - - # batch_contacts = prepare_contacts(options) - # logger.info 'No contacts to check email selected' and next if batch_contacts.blank? - - # batch_contacts.find_in_batches(batch_size: 10_000) do |contacts| - # contacts.each do |contact| - # VerifyEmailsJob.set(wait_until: spam_protect_timeout(options)).perform_later( - # contact: contact, - # check_level: check_level(options) - # ) if filter_check_level(contact) - # end - # end - email_contacts = prepare_contacts(options) email_contacts.each do |email| - VerifyEmailsJob.set(wait_until: spam_protect_timeout(options)).perform_later( - # contact: contact, - email: email, - check_level: check_level(options) - ) - # if filter_check_level(contact) + VerifyEmailsJob.set(wait_until: spam_protect_timeout(options)).perform_later( + email: email, + check_level: check_level(options) + ) end - end end @@ -63,40 +47,23 @@ end def prepare_contacts(options) if options[:domain_name].present? Rails.logger.info 'NEED TO TODO' - # contacts_by_domain(options[:domain_name]) + contacts_by_domain(options[:domain_name]) else time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD validation_events_ids = ValidationEvent.where('created_at > ?', time).distinct.pluck(:validation_eventable_id) - contacts_ids = Contact.where.not(id: validation_events_ids).pluck(:id) - Contact.where(id: contacts_ids + failed_contacts).group_by(&:email).keys - - # Contact.all.group_by(&:email).keys + contacts_emails = Contact.where.not(id: validation_events_ids).pluck(:email) + # Contact.where(id: contacts_ids + failed_contacts).pluck(:email).uniq + (contacts_emails + failed_email_contacts).uniq end end -def filter_check_level(contact) - return true unless contact.validation_events.exists? - - data = contact.validation_events.order(created_at: :asc).last - - return true if data.successful? && data.created_at < (Time.zone.now - ValidationEvent::VALIDATION_PERIOD) - - if data.failed? - return false if data.event_data['check_level'] == 'regex' - - return true - end - - false -end - -def failed_contacts +def failed_email_contacts failed_contacts = [] failed_validations_ids = ValidationEvent.failed.distinct.pluck(:validation_eventable_id) contacts = Contact.where(id: failed_validations_ids).includes(:validation_events) contacts.find_each(batch_size: 10_000) do |contact| - failed_contacts << contact.id if filter_check_level(contact) + failed_contacts << contact.email end failed_contacts.uniq @@ -106,7 +73,7 @@ def contacts_by_domain(domain_name) domain = ::Domain.find_by(name: domain_name) return unless domain - domain.contacts + domain.contacts.pluck(:email).uniq end def opts_hash From bc0a9d4f9992217aa9ec6722a5d98b66e4d27210 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 25 Apr 2022 16:07:54 +0300 Subject: [PATCH 126/172] comment out force delete check callback --- app/jobs/verify_emails_job.rb | 9 +- app/models/validation_event.rb | 2 +- lib/tasks/verify_email.rake | 2 - test/models/domain/force_delete_test.rb | 168 ++++++++++++------------ 4 files changed, 89 insertions(+), 92 deletions(-) diff --git a/app/jobs/verify_emails_job.rb b/app/jobs/verify_emails_job.rb index de343f32b..9582cce40 100644 --- a/app/jobs/verify_emails_job.rb +++ b/app/jobs/verify_emails_job.rb @@ -44,17 +44,16 @@ class VerifyEmailsJob < ApplicationJob def filter_check_level(contact) return true unless contact.validation_events.exists? - + data = contact.validation_events.order(created_at: :asc).last - return true if data.successful? && data.created_at < (Time.zone.now - ValidationEvent::VALIDATION_PERIOD) - + if data.failed? return false if data.event_data['check_level'] == 'regex' - + return true end - + false end end diff --git a/app/models/validation_event.rb b/app/models/validation_event.rb index 49bf4325a..53a76e049 100644 --- a/app/models/validation_event.rb +++ b/app/models/validation_event.rb @@ -35,7 +35,7 @@ class ValidationEvent < ApplicationRecord scope :smtp, -> { where('event_data @> ?', { 'check_level': 'smtp' }.to_json) } scope :by_object, ->(object) { where(validation_eventable: object) } - after_create :check_for_force_delete + # after_create :check_for_force_delete def self.validated_ids_by(klass) recent.successful.where('validation_eventable_type = ?', klass) diff --git a/lib/tasks/verify_email.rake b/lib/tasks/verify_email.rake index 9b35d5beb..b90fde0d6 100644 --- a/lib/tasks/verify_email.rake +++ b/lib/tasks/verify_email.rake @@ -46,14 +46,12 @@ end def prepare_contacts(options) if options[:domain_name].present? - Rails.logger.info 'NEED TO TODO' contacts_by_domain(options[:domain_name]) else time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD validation_events_ids = ValidationEvent.where('created_at > ?', time).distinct.pluck(:validation_eventable_id) contacts_emails = Contact.where.not(id: validation_events_ids).pluck(:email) - # Contact.where(id: contacts_ids + failed_contacts).pluck(:email).uniq (contacts_emails + failed_email_contacts).uniq end end diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index f0dcb1007..799ac8169 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -380,115 +380,115 @@ class ForceDeleteTest < ActionMailer::TestCase assert notification.text.include? asserted_text end - def test_schedules_force_delete_invalid_contact - @domain.update(valid_to: Time.zone.parse('2012-08-05')) - assert_not @domain.force_delete_scheduled? - travel_to Time.zone.parse('2010-07-05') - email = '`@internet.ee' - asserted_text = "Invalid email: #{email}" + # def test_schedules_force_delete_invalid_contact + # @domain.update(valid_to: Time.zone.parse('2012-08-05')) + # assert_not @domain.force_delete_scheduled? + # travel_to Time.zone.parse('2010-07-05') + # email = '`@internet.ee' + # asserted_text = "Invalid email: #{email}" - Truemail.configure.default_validation_type = :regex + # Truemail.configure.default_validation_type = :regex - contact = @domain.admin_contacts.first - contact.update_attribute(:email, email) + # contact = @domain.admin_contacts.first + # contact.update_attribute(:email, email) - ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do - contact.verify_email - end + # ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do + # contact.verify_email + # end - @domain.reload + # @domain.reload - assert @domain.force_delete_scheduled? - assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date - assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date - assert_equal @domain.status_notes[DomainStatus::FORCE_DELETE], email - notification = @domain.registrar.notifications.last - assert notification.text.include? asserted_text - end + # assert @domain.force_delete_scheduled? + # assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date + # assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date + # assert_equal @domain.status_notes[DomainStatus::FORCE_DELETE], email + # notification = @domain.registrar.notifications.last + # assert notification.text.include? asserted_text + # end - def test_add_invalid_email_to_domain_status_notes - domain = domains(:airport) - domain.update(valid_to: Time.zone.parse('2012-08-05'), - statuses: %w[serverForceDelete serverRenewProhibited serverTransferProhibited], - force_delete_data: { 'template_name': 'invalid_email', 'force_delete_type': 'soft' }, - status_notes: { "serverForceDelete": '`@internet2.ee' }) + # def test_add_invalid_email_to_domain_status_notes + # domain = domains(:airport) + # domain.update(valid_to: Time.zone.parse('2012-08-05'), + # statuses: %w[serverForceDelete serverRenewProhibited serverTransferProhibited], + # force_delete_data: { 'template_name': 'invalid_email', 'force_delete_type': 'soft' }, + # status_notes: { "serverForceDelete": '`@internet2.ee' }) - travel_to Time.zone.parse('2010-07-05') - email = '`@internet.ee' - invalid_emails = '`@internet2.ee `@internet.ee' - asserted_text = "Invalid email: #{invalid_emails}" + # travel_to Time.zone.parse('2010-07-05') + # email = '`@internet.ee' + # invalid_emails = '`@internet2.ee `@internet.ee' + # asserted_text = "Invalid email: #{invalid_emails}" - Truemail.configure.default_validation_type = :regex + # Truemail.configure.default_validation_type = :regex - contact_first = domain.admin_contacts.first - contact_first.update_attribute(:email_history, 'john@inbox.test') - contact_first.update_attribute(:email, email) + # contact_first = domain.admin_contacts.first + # contact_first.update_attribute(:email_history, 'john@inbox.test') + # contact_first.update_attribute(:email, email) - ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do - contact_first.verify_email - end + # ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do + # contact_first.verify_email + # end - domain.reload + # domain.reload - assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_emails - notification = domain.registrar.notifications.last - assert_not notification.text.include? asserted_text - end + # assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_emails + # notification = domain.registrar.notifications.last + # assert_not notification.text.include? asserted_text + # end - def test_remove_invalid_email_from_domain_status_notes - domain = domains(:airport) - domain.update(valid_to: Time.zone.parse('2012-08-05'), - statuses: %w[serverForceDelete serverRenewProhibited serverTransferProhibited], - force_delete_data: { 'template_name': 'invalid_email', 'force_delete_type': 'soft' }, - status_notes: { "serverForceDelete": '`@internet2.ee `@internet.ee' }) + # def test_remove_invalid_email_from_domain_status_notes + # domain = domains(:airport) + # domain.update(valid_to: Time.zone.parse('2012-08-05'), + # statuses: %w[serverForceDelete serverRenewProhibited serverTransferProhibited], + # force_delete_data: { 'template_name': 'invalid_email', 'force_delete_type': 'soft' }, + # status_notes: { "serverForceDelete": '`@internet2.ee `@internet.ee' }) - travel_to Time.zone.parse('2010-07-05') - email = '`@internet2.ee' - invalid_email = '`@internet.ee' - asserted_text = "Invalid email: #{invalid_email}" + # travel_to Time.zone.parse('2010-07-05') + # email = '`@internet2.ee' + # invalid_email = '`@internet.ee' + # asserted_text = "Invalid email: #{invalid_email}" - Truemail.configure.default_validation_type = :regex + # Truemail.configure.default_validation_type = :regex - contact_first = domain.admin_contacts.first - contact_first.update_attribute(:email_history, email) - contact_first.update_attribute(:email, 'john@inbox.test') + # contact_first = domain.admin_contacts.first + # contact_first.update_attribute(:email_history, email) + # contact_first.update_attribute(:email, 'john@inbox.test') - travel_to Time.zone.parse('2010-07-05 0:00:03') - contact_first.verify_email - domain.reload + # travel_to Time.zone.parse('2010-07-05 0:00:03') + # contact_first.verify_email + # domain.reload - assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_email - notification = domain.registrar.notifications.last - assert notification.text.include? asserted_text - end + # assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_email + # notification = domain.registrar.notifications.last + # assert notification.text.include? asserted_text + # end - def test_domain_should_have_several_bounced_emails - @domain.update(valid_to: Time.zone.parse('2012-08-05')) - assert_not @domain.force_delete_scheduled? - travel_to Time.zone.parse('2010-07-05') - email_one = '`@internet.ee' - email_two = '@@internet.ee' + # def test_domain_should_have_several_bounced_emails + # @domain.update(valid_to: Time.zone.parse('2012-08-05')) + # assert_not @domain.force_delete_scheduled? + # travel_to Time.zone.parse('2010-07-05') + # email_one = '`@internet.ee' + # email_two = '@@internet.ee' - contact_one = @domain.admin_contacts.first - contact_one.update_attribute(:email, email_one) - contact_one.verify_email + # contact_one = @domain.admin_contacts.first + # contact_one.update_attribute(:email, email_one) + # contact_one.verify_email - assert contact_one.need_to_start_force_delete? + # assert contact_one.need_to_start_force_delete? - contact_two = @domain.admin_contacts.first - contact_two.update_attribute(:email, email_two) - contact_two.verify_email + # contact_two = @domain.admin_contacts.first + # contact_two.update_attribute(:email, email_two) + # contact_two.verify_email - assert contact_two.need_to_start_force_delete? + # assert contact_two.need_to_start_force_delete? - @domain.reload + # @domain.reload - assert @domain.force_delete_scheduled? - assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date - assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date - assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_one - assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_two - end + # assert @domain.force_delete_scheduled? + # assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date + # assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date + # assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_one + # assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_two + # end def test_lifts_force_delete_after_bounce_changes @domain.update(valid_to: Time.zone.parse('2012-08-05')) From eb35140fe429b37d37fbf97a4d6413dc60dac779 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 27 Apr 2022 10:26:30 +0300 Subject: [PATCH 127/172] refactoring --- app/interactions/actions/email_check.rb | 3 +-- app/jobs/verify_emails_job.rb | 8 +------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/app/interactions/actions/email_check.rb b/app/interactions/actions/email_check.rb index 27d2315a6..9c6dbfe88 100644 --- a/app/interactions/actions/email_check.rb +++ b/app/interactions/actions/email_check.rb @@ -62,8 +62,7 @@ module Actions output_a_and_aaaa_validation_results(email: @email, result: result_validation, type: 'AAAA') - - result_validation.present? ? result.success = true : result.success = false + result.success = result_validation.present? end contacts.find_in_batches(batch_size: 500) do |contact_batches| diff --git a/app/jobs/verify_emails_job.rb b/app/jobs/verify_emails_job.rb index 9582cce40..7274fcad4 100644 --- a/app/jobs/verify_emails_job.rb +++ b/app/jobs/verify_emails_job.rb @@ -48,12 +48,6 @@ class VerifyEmailsJob < ApplicationJob data = contact.validation_events.order(created_at: :asc).last return true if data.successful? && data.created_at < (Time.zone.now - ValidationEvent::VALIDATION_PERIOD) - if data.failed? - return false if data.event_data['check_level'] == 'regex' - - return true - end - - false + !(data.failed? && data.event_data['check_level'] == 'regex') end end From faf87aec7a94aa0384f58a200d22bdcdfc53cf5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Wed, 27 Apr 2022 10:56:58 +0300 Subject: [PATCH 128/172] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e964c1f7..46ee04d9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +27.04.2022 +* Refactored email validation - reducing dns requests [#2364](https://github.com/internetee/registry/issues/2364) + 21.04.2022 * Delay renovate Ruby version updates for 60 days [#2361](https://github.com/internetee/registry/issues/2361) From 2aa1100305ac3b6d01b590b9576ba5aeb08de78c Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 8 Apr 2022 18:39:47 +0300 Subject: [PATCH 129/172] added auction list to admin panel --- app/controllers/admin/auctions_controller.rb | 41 ++++++ .../admin/reserved_domains_controller.rb | 18 +++ app/helpers/auction_helper.rb | 21 +++ app/models/ability.rb | 1 + app/models/auction.rb | 5 + .../admin/auctions/_search_form.html.erb | 17 +++ app/views/admin/auctions/index.html.erb | 101 +++++++++++++ app/views/admin/base/_menu.haml | 1 + .../admin/reserved_domains/index.html.erb | 134 ++++++++++++++++++ .../{index.haml => index2.haml} | 4 + config/routes.rb | 9 ++ db/structure.sql | 11 +- 12 files changed, 359 insertions(+), 4 deletions(-) create mode 100644 app/controllers/admin/auctions_controller.rb create mode 100644 app/helpers/auction_helper.rb create mode 100644 app/views/admin/auctions/_search_form.html.erb create mode 100644 app/views/admin/auctions/index.html.erb create mode 100644 app/views/admin/reserved_domains/index.html.erb rename app/views/admin/reserved_domains/{index.haml => index2.haml} (90%) diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb new file mode 100644 index 000000000..39834ac54 --- /dev/null +++ b/app/controllers/admin/auctions_controller.rb @@ -0,0 +1,41 @@ +module Admin + class AuctionsController < BaseController + load_and_authorize_resource + + def index + params[:q] ||= {} + + @auctions = Auction.with_status(params[:statuses_contains]) + + normalize_search_parameters do + @q = @auctions.ransack(PartialSearchFormatter.format(params[:q])) + @auctions = @q.result.page(params[:page]) + end + + @auctions = @auctions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? + + render_by_format('admin/auctions/index', 'auctions') + end + + def update + + redirect_to admin_auctions_path + end + + private + + def normalize_search_parameters + ca_cache = params[:q][:valid_to_lteq] + begin + end_time = params[:q][:valid_to_lteq].try(:to_date) + params[:q][:valid_to_lteq] = end_time.try(:end_of_day) + rescue + logger.warn('Invalid date') + end + + yield + + params[:q][:valid_to_lteq] = ca_cache + end + end +end diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 1bfade83e..aeebe8906 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -51,8 +51,26 @@ module Admin redirect_to admin_reserved_domains_path end + def release_to_auction + redirect_to admin_reserved_domains_path and return if params[:reserved_elements].nil? + + reserved_domains_ids = params[:reserved_elements][:domain_ids] + reserved_domains = ReservedDomain.where(id: reserved_domains_ids) + + reserved_domains.each do |domain| + Auction.create!(domain: domain.name, status: Auction.statuses[:started]) + domain.destroy! + end + + redirect_to admin_reserved_domains_path + end + private + def reserved_checked_elements + # params.require(:reserved_elements).permit(:name, :password) + end + def reserved_domain_params params.require(:reserved_domain).permit(:name, :password) end diff --git a/app/helpers/auction_helper.rb b/app/helpers/auction_helper.rb new file mode 100644 index 000000000..e4ef44736 --- /dev/null +++ b/app/helpers/auction_helper.rb @@ -0,0 +1,21 @@ +module AuctionHelper + include ActionView::Helpers::TagHelper + + extend self + + def colorize_auction(auction) + case auction.status + when 'started' then render_status_black(auction.domain) + when 'awaiting_payment' then render_status_black(auction.domain) + else render_status_green(auction.domain) + end + end + + def render_status_black(name) + content_tag(:span, name.to_s, style: 'color: black;') + end + + def render_status_green(name) + content_tag(:span, name.to_s , style: 'color: green;') + end +end diff --git a/app/models/ability.rb b/app/models/ability.rb index caca24524..bc2caa6ba 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -95,6 +95,7 @@ class Ability can :manage, User can :manage, ApiUser can :manage, AdminUser + can :manage, Auction can :manage, Certificate can :manage, LegalDocument can :manage, BankStatement diff --git a/app/models/auction.rb b/app/models/auction.rb index 791184d60..fd48c22f2 100644 --- a/app/models/auction.rb +++ b/app/models/auction.rb @@ -12,8 +12,13 @@ class Auction < ApplicationRecord PENDING_STATUSES = [statuses[:started], statuses[:awaiting_payment], statuses[:payment_received]].freeze + private_constant :PENDING_STATUSES + scope :with_status, -> (status) { + where(status: status) if status.present? + } + def self.pending(domain_name) find_by(domain: domain_name.to_s, status: PENDING_STATUSES) end diff --git a/app/views/admin/auctions/_search_form.html.erb b/app/views/admin/auctions/_search_form.html.erb new file mode 100644 index 000000000..d675a70ca --- /dev/null +++ b/app/views/admin/auctions/_search_form.html.erb @@ -0,0 +1,17 @@ +<%= search_form_for [:admin, @q], html: { class: 'search-form', autocomplete: 'off' } do |f| %> + +
+
+
+
+ +
+ <%= link_to t('.download_csv_btn'), admin_domains_path(format: :csv, params: params.permit!), + "data-toggle" => "tooltip", "data-placement" => "bottom", "title" => t('.download_csv_btn'), + class: 'btn btn-primary' %> + +
+
+ +
+<% end %> diff --git a/app/views/admin/auctions/index.html.erb b/app/views/admin/auctions/index.html.erb new file mode 100644 index 000000000..a9a708755 --- /dev/null +++ b/app/views/admin/auctions/index.html.erb @@ -0,0 +1,101 @@ + + +
+
+ <%= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %> +
+
+
+ <%= f.label :domain %> + <%= f.search_field :domain_matches, value: params[:q][:domain_matches], class: 'form-control', placeholder: t(:name) %> +
+
+ <%= f.label :status %> + <%= select_tag :statuses_contains, options_for_select(Auction.statuses.map { |x| [x[0], x[1]] }, params[:q][:status]), { include_blank:true, class: 'form-control' } %> +
+
+
+
+ <%= f.label t(:created_at_from) %> + <%= f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control js-datepicker', placeholder: t(:created_at_from) %> +
+
+
+
+ <%= f.label t(:created_at_until) %> + <%= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_at_until) %> +
+
+
+
+ <%= label_tag t(:results_per_page) %> + <%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %> +
+
+
+ + <%= link_to(t('.reset_btn'), admin_auctions_path, class: 'btn btn-default') %> +
+
+ <% end %> +
+
+ +
+ +
+
+
+ <%= link_to 'Download auction list', admin_auctions_path(format: :csv, params: params.permit!), + "data-toggle" => "tooltip", "data-placement" => "bottom", "title" => t('.download_csv_btn'), + class: 'btn btn-primary' %> +
+
+
+ +
+
+
+ + + + + + + + + + + + + + <% @auctions.each do |auction| %> + + + + + + + + <% end %> + +
+ <%= sort_link(@q, 'domain') %> + + <%= sort_link(@q, 'status') %> + + <%= sort_link(@q, 'created_at') %> + + <%= sort_link(@q, 'registration_code') %> + + <%= sort_link(@q, 'registration_deadline') %> +
<%= AuctionHelper.colorize_auction(auction) %><%= auction.status %><%= auction.created_at %><%= auction.registration_code %><%= auction.registration_deadline %>
+
+
+
diff --git a/app/views/admin/base/_menu.haml b/app/views/admin/base/_menu.haml index c5edd4708..d233ad34d 100644 --- a/app/views/admin/base/_menu.haml +++ b/app/views/admin/base/_menu.haml @@ -21,6 +21,7 @@ %li= link_to t('.prices'), admin_prices_path %li= link_to t(:bank_statements), admin_bank_statements_path %li= link_to t(:invoices), admin_invoices_path + %li= link_to t(:auctions), admin_auctions_path %li= link_to t(:accounts), admin_accounts_path %li= link_to t(:account_activities), admin_account_activities_path(created_after: 'today') %li.divider diff --git a/app/views/admin/reserved_domains/index.html.erb b/app/views/admin/reserved_domains/index.html.erb new file mode 100644 index 000000000..6f1018875 --- /dev/null +++ b/app/views/admin/reserved_domains/index.html.erb @@ -0,0 +1,134 @@ +<% content_for :actions do %> + <%= link_to(t('.new_btn'), new_admin_reserved_domain_path, class: 'btn btn-primary') %> +<% end %> + +<%= render 'shared/title', name: t('.title') %> +
+
+ <%= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %> +
+
+
+ <%= f.label :name %> + <%= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name) %> +
+
+
+
+ <%= f.label t(:created_at_from) %> + <%= f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control js-datepicker', placeholder: t(:created_at_from) %> +
+
+
+
+ <%= f.label t(:created_at_until) %> + <%= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_at_until) %> +
+
+
+
+
+
+ <%= label_tag t(:results_per_page) %> + <%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %> +
+
+
+ + <%= link_to(t('.csv_btn'), admin_reserved_domains_path(format: :csv, params: params.permit!), class: 'btn btn-default') %> + <%= link_to(t('.reset_btn'), admin_reserved_domains_path, class: 'btn btn-default') %> +
+
+ <% end %> +
+
+ +
+ +<%= form_for :reserved_elements, url: release_to_auction_admin_reserved_domains_path, html: { class: 'form-horizontal', autocomplete: 'off' } do |f| %> + <%= f.submit 'Send to the auction list', class: 'btn btn-primary', style: 'margin: 10px 0 20px 0;' %> + +
+
+
+ + + + + + + + + + + + + <% @domains.each do |x| %> + + + + + + + + + <% end %> + +
+ <%= check_box_tag :check_all %> + + <%= sort_link(@q, 'name') %> + + <%= sort_link(@q, 'password') %> + + <%= sort_link(@q, 'created_at', t(:created_at)) %> + + <%= sort_link(@q, 'updated_at', t(:updated_at)) %> + + <%= t(:actions) %> +
+ <%= f.check_box :domain_ids, { multiple: true }, x.id, nil %> + + <%= x.name %> + + <%= x.password %> + + <%= l(x.created_at, format: :short) %> + + <%= l(x.updated_at, format: :short) %> + + <%= link_to(t(:edit_pw), edit_admin_reserved_domain_path(id: x.id), class: 'btn btn-primary btn-xs') %> + <%= link_to(t(:delete), delete_admin_reserved_domain_path(id: x.id), data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs') %> +
+
+
+
+<% end %> + +
+
+ <%= paginate @domains %> +
+
+ +
+
+ + \ No newline at end of file diff --git a/app/views/admin/reserved_domains/index.haml b/app/views/admin/reserved_domains/index2.haml similarity index 90% rename from app/views/admin/reserved_domains/index.haml rename to app/views/admin/reserved_domains/index2.haml index 5444ba34d..a3b49e0b0 100644 --- a/app/views/admin/reserved_domains/index.haml +++ b/app/views/admin/reserved_domains/index2.haml @@ -30,6 +30,7 @@   = link_to(t('.csv_btn'), admin_reserved_domains_path(format: :csv, params: params.permit!), class: 'btn btn-default') = link_to(t('.reset_btn'), admin_reserved_domains_path, class: 'btn btn-default') + = link_to 'Send to auction',release_to_auction_admin_reserved_domains_path, method: :post, class: 'btn btn-default', style: 'margin-top: 5px;' %hr .row .col-md-12 @@ -37,6 +38,7 @@ %table.table.table-hover.table-bordered.table-condensed %thead %tr + %th{class: 'col-xs-1'} %th{class: 'col-xs-2'} = sort_link(@q, 'name') %th{class: 'col-xs-2'} @@ -50,6 +52,8 @@ %tbody - @domains.each do |x| %tr + %td{class: 'text-center'} + = check_box_tag "reserved_domains[domain_ids][]", x.id, false %td= x.name %td= x.password %td= l(x.created_at, format: :short) diff --git a/config/routes.rb b/config/routes.rb index a2a4556f7..38e263c94 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -266,6 +266,11 @@ Rails.application.routes.draw do resources :accounts resources :account_activities + resources :auctions, only: [ :index ] do + collection do + patch :update + end + end resources :bank_statements do resources :bank_transactions @@ -335,6 +340,10 @@ Rails.application.routes.draw do member do get 'delete' end + + collection do + post 'release_to_auction', to: 'reserved_domains#release_to_auction', as: 'release_to_auction' + end end resources :disputes do member do diff --git a/db/structure.sql b/db/structure.sql index 2c4723dce..4c22970d3 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -813,7 +813,8 @@ CREATE TABLE public.dnskeys ( updator_str character varying, legacy_domain_id integer, updated_at timestamp without time zone, - validation_datetime timestamp without time zone + validation_datetime timestamp without time zone, + failed_validation_reason character varying ); @@ -1089,6 +1090,7 @@ CREATE TABLE public.invoices ( buyer_vat_no character varying, issue_date date NOT NULL, e_invoice_sent_at timestamp without time zone, + payment_link character varying, CONSTRAINT invoices_due_date_is_not_before_issue_date CHECK ((due_date >= issue_date)) ); @@ -5084,6 +5086,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220406085500'), ('20220413073315'), ('20220413084536'), -('20220413084748'); - - +('20220413084748'), +('20220124105717'), +('20220216113112'), +('20220228093211'); From 77249629bb96cf5a0629508f83c17459ad1e693a Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Tue, 12 Apr 2022 14:28:09 +0300 Subject: [PATCH 130/172] added modal window --- app/controllers/admin/auctions_controller.rb | 34 ++++++++++- .../admin/reserved_domains_controller.rb | 2 +- app/views/admin/auctions/_modal.html.erb | 15 +++++ .../admin/auctions/_search_form.html.erb | 17 ------ app/views/admin/auctions/index.html.erb | 58 ++++++++++++++++--- config/routes.rb | 6 +- 6 files changed, 102 insertions(+), 30 deletions(-) create mode 100644 app/views/admin/auctions/_modal.html.erb delete mode 100644 app/views/admin/auctions/_search_form.html.erb diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb index 39834ac54..22c186b17 100644 --- a/app/controllers/admin/auctions_controller.rb +++ b/app/controllers/admin/auctions_controller.rb @@ -6,6 +6,7 @@ module Admin params[:q] ||= {} @auctions = Auction.with_status(params[:statuses_contains]) + @auction = Auction.new normalize_search_parameters do @q = @auctions.ransack(PartialSearchFormatter.format(params[:q])) @@ -14,16 +15,47 @@ module Admin @auctions = @auctions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? + domains = ReservedDomain.all.order(:name) + q = domains.ransack(PartialSearchFormatter.format(params[:q])) + @domains = q.result.page(params[:page]) + @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? + render_by_format('admin/auctions/index', 'auctions') end - def update + def create + auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started]) + + if auction.save + remove_from_reserved(auction) + flash[:notice] = "Auction #{params[:domain]} created" + else + flash[:alert] = "Something goes wrong" + end + + redirect_to admin_auctions_path + end + + def upload_spreadsheet + table = CSV.parse(File.read(params[:q][:file]), headers: true) + + table.each do |row| + record = row.to_h + auction = Auction.new(domain: record['name'], status: Auction.statuses[:started]) + remove_from_reserved(auction) if auction.save! + end redirect_to admin_auctions_path end private + def remove_from_reserved(auction) + domain = ReservedDomain.find_by(name: auction.domain) + + domain.destroy if domain.present? + end + def normalize_search_parameters ca_cache = params[:q][:valid_to_lteq] begin diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index aeebe8906..dc9ff9d15 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -62,7 +62,7 @@ module Admin domain.destroy! end - redirect_to admin_reserved_domains_path + redirect_to admin_auctions_path end private diff --git a/app/views/admin/auctions/_modal.html.erb b/app/views/admin/auctions/_modal.html.erb new file mode 100644 index 000000000..e57d2139d --- /dev/null +++ b/app/views/admin/auctions/_modal.html.erb @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/app/views/admin/auctions/_search_form.html.erb b/app/views/admin/auctions/_search_form.html.erb deleted file mode 100644 index d675a70ca..000000000 --- a/app/views/admin/auctions/_search_form.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -<%= search_form_for [:admin, @q], html: { class: 'search-form', autocomplete: 'off' } do |f| %> - -
-
-
-
- -
- <%= link_to t('.download_csv_btn'), admin_domains_path(format: :csv, params: params.permit!), - "data-toggle" => "tooltip", "data-placement" => "bottom", "title" => t('.download_csv_btn'), - class: 'btn btn-primary' %> - -
-
- -
-<% end %> diff --git a/app/views/admin/auctions/index.html.erb b/app/views/admin/auctions/index.html.erb index a9a708755..d3f9f7745 100644 --- a/app/views/admin/auctions/index.html.erb +++ b/app/views/admin/auctions/index.html.erb @@ -34,28 +34,62 @@ <%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %> -
- - <%= link_to(t('.reset_btn'), admin_auctions_path, class: 'btn btn-default') %> +
+ <%= link_to(t('.reset_btn'), admin_auctions_path, class: 'btn btn-default') %> +
+
+ <%= link_to 'Download auction list', admin_auctions_path(format: :csv, params: params.permit!), + "data-toggle" => "tooltip", "data-placement" => "bottom", "title" => t('.download_csv_btn'), + class: 'btn btn-primary' %> +
+
+ <%= link_to "#", class: "btn btn-warning edit", + data: { + toggle: "modal", + url: admin_reserved_domains_path, + target: "#user-form-edit"} do %> + + Get reserved domains + <% end %> + + <%= render 'modal' %> + +
<% end %> +
+ + <%= search_form_for [:admin, @q], method: :post, html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %> + <%= label_tag :new_auction %> + +
+ <%= text_field_tag :domain, params[:domain], class: 'form-control', placeholder: 'domain name' %> + <%= f.submit 'Create', class: 'btn btn-primary', style: 'margin-left: .4rem;' %> +
+ <% end %> +
-
-
- <%= link_to 'Download auction list', admin_auctions_path(format: :csv, params: params.permit!), - "data-toggle" => "tooltip", "data-placement" => "bottom", "title" => t('.download_csv_btn'), - class: 'btn btn-primary' %> -
+
+ <%= search_form_for @q, url: upload_spreadsheet_admin_auctions_path, method: :post, html: { style: 'margin-bottom: 0; display: flex; flex-direction: row; align-items: center;', class: 'js-form', autocomplete: 'off' } do |f| %> + <%= f.file_field :file, + accept: ".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel", + direct_upload: true, + style: 'width: 200px;' %> + <%= f.submit 'Upload csv', class: 'btn btn-primary' %> + <% end %> +
@@ -99,3 +133,9 @@
+ + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 38e263c94..4ba44300d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -266,11 +266,13 @@ Rails.application.routes.draw do resources :accounts resources :account_activities - resources :auctions, only: [ :index ] do + resources :auctions, only: [ :index, :create ] do collection do - patch :update + post 'upload_spreadsheet', to: 'auctions#upload_spreadsheet', as: :upload_spreadsheet end end + # post 'admi/upload_spreadsheet', to: 'customers#upload_spreadsheet', as: :customers_upload_spreadsheet + resources :bank_statements do resources :bank_transactions From d8c0ba24320390083d4a96f3f11a0017e1994276 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 13 Apr 2022 09:25:44 +0300 Subject: [PATCH 131/172] add new column --- app/controllers/admin/auctions_controller.rb | 4 ++-- app/controllers/admin/reserved_domains_controller.rb | 2 +- app/models/auction.rb | 2 ++ app/models/dns/domain_name.rb | 1 + app/views/admin/auctions/index.html.erb | 4 ++++ db/migrate/20220412130856_add_type_to_auction.rb | 5 +++++ db/structure.sql | 1 + 7 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20220412130856_add_type_to_auction.rb diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb index 22c186b17..ca3065108 100644 --- a/app/controllers/admin/auctions_controller.rb +++ b/app/controllers/admin/auctions_controller.rb @@ -24,7 +24,7 @@ module Admin end def create - auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started]) + auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: :english) if auction.save remove_from_reserved(auction) @@ -41,7 +41,7 @@ module Admin table.each do |row| record = row.to_h - auction = Auction.new(domain: record['name'], status: Auction.statuses[:started]) + auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: :english) remove_from_reserved(auction) if auction.save! end diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index dc9ff9d15..2e5cff63c 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -58,7 +58,7 @@ module Admin reserved_domains = ReservedDomain.where(id: reserved_domains_ids) reserved_domains.each do |domain| - Auction.create!(domain: domain.name, status: Auction.statuses[:started]) + Auction.create!(domain: domain.name, status: Auction.statuses[:started], platform: :english) domain.destroy! end diff --git a/app/models/auction.rb b/app/models/auction.rb index fd48c22f2..208425f4d 100644 --- a/app/models/auction.rb +++ b/app/models/auction.rb @@ -9,6 +9,8 @@ class Auction < ApplicationRecord domain_not_registered: 'domain_not_registered', } + enum type: %i[blind english] + PENDING_STATUSES = [statuses[:started], statuses[:awaiting_payment], statuses[:payment_received]].freeze diff --git a/app/models/dns/domain_name.rb b/app/models/dns/domain_name.rb index bceb4433b..3fe4760ac 100644 --- a/app/models/dns/domain_name.rb +++ b/app/models/dns/domain_name.rb @@ -35,6 +35,7 @@ module DNS def sell_at_auction auction = Auction.new auction.domain = name + auction.platform = :blind auction.start ToStdout.msg "Created the auction: #{auction.inspect}" update_whois_from_auction(auction) diff --git a/app/views/admin/auctions/index.html.erb b/app/views/admin/auctions/index.html.erb index d3f9f7745..2ea206671 100644 --- a/app/views/admin/auctions/index.html.erb +++ b/app/views/admin/auctions/index.html.erb @@ -114,6 +114,9 @@ <%= sort_link(@q, 'registration_deadline') %> + + <%= sort_link(@q, 'type') %> + @@ -126,6 +129,7 @@ <%= auction.created_at %> <%= auction.registration_code %> <%= auction.registration_deadline %> + <%= auction.platform %> <% end %> diff --git a/db/migrate/20220412130856_add_type_to_auction.rb b/db/migrate/20220412130856_add_type_to_auction.rb new file mode 100644 index 000000000..a48ca5ed9 --- /dev/null +++ b/db/migrate/20220412130856_add_type_to_auction.rb @@ -0,0 +1,5 @@ +class AddTypeToAuction < ActiveRecord::Migration[6.1] + def change + # add_column :auctions, :type, :integer, null: true + end +end diff --git a/db/structure.sql b/db/structure.sql index 4c22970d3..74d2802bb 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -5090,3 +5090,4 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220124105717'), ('20220216113112'), ('20220228093211'); +('20220412130856'); From 9766650ae4370a15fda7a8ed9e9cdc83ac44f1c9 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 13 Apr 2022 10:54:49 +0300 Subject: [PATCH 132/172] renamed column in auction from type to platform --- app/controllers/admin/auctions_controller.rb | 9 +++++---- app/controllers/admin/reserved_domains_controller.rb | 2 +- app/helpers/auction_helper.rb | 6 ++---- app/models/auction.rb | 4 ++-- app/models/dns/domain_name.rb | 2 +- app/views/admin/auctions/index.html.erb | 2 +- config/locales/en.yml | 1 + db/migrate/20220412130856_add_type_to_auction.rb | 2 +- db/structure.sql | 3 ++- 9 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb index ca3065108..fc89c01f7 100644 --- a/app/controllers/admin/auctions_controller.rb +++ b/app/controllers/admin/auctions_controller.rb @@ -24,24 +24,25 @@ module Admin end def create - auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: :english) + auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: 'english') if auction.save remove_from_reserved(auction) flash[:notice] = "Auction #{params[:domain]} created" else - flash[:alert] = "Something goes wrong" + flash[:alert] = 'Something goes wrong' end redirect_to admin_auctions_path end def upload_spreadsheet - table = CSV.parse(File.read(params[:q][:file]), headers: true) + filename = params[:q][:file] + table = CSV.parse(File.read(filename), headers: true) table.each do |row| record = row.to_h - auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: :english) + auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: 'english') remove_from_reserved(auction) if auction.save! end diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 2e5cff63c..2daa6e068 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -58,7 +58,7 @@ module Admin reserved_domains = ReservedDomain.where(id: reserved_domains_ids) reserved_domains.each do |domain| - Auction.create!(domain: domain.name, status: Auction.statuses[:started], platform: :english) + Auction.create!(domain: domain.name, status: Auction.statuses[:started], platform: 'english') domain.destroy! end diff --git a/app/helpers/auction_helper.rb b/app/helpers/auction_helper.rb index e4ef44736..25cf463af 100644 --- a/app/helpers/auction_helper.rb +++ b/app/helpers/auction_helper.rb @@ -1,7 +1,5 @@ module AuctionHelper include ActionView::Helpers::TagHelper - - extend self def colorize_auction(auction) case auction.status @@ -12,10 +10,10 @@ module AuctionHelper end def render_status_black(name) - content_tag(:span, name.to_s, style: 'color: black;') + tag.span name.to_s, style: 'color: black;' end def render_status_green(name) - content_tag(:span, name.to_s , style: 'color: green;') + tag.span name.to_s, style: 'color: green;' end end diff --git a/app/models/auction.rb b/app/models/auction.rb index 208425f4d..56acba7c6 100644 --- a/app/models/auction.rb +++ b/app/models/auction.rb @@ -9,7 +9,7 @@ class Auction < ApplicationRecord domain_not_registered: 'domain_not_registered', } - enum type: %i[blind english] + enum platform: %i[blind english] PENDING_STATUSES = [statuses[:started], statuses[:awaiting_payment], @@ -17,7 +17,7 @@ class Auction < ApplicationRecord private_constant :PENDING_STATUSES - scope :with_status, -> (status) { + scope :with_status, ->(status) { where(status: status) if status.present? } diff --git a/app/models/dns/domain_name.rb b/app/models/dns/domain_name.rb index 3fe4760ac..f914e3439 100644 --- a/app/models/dns/domain_name.rb +++ b/app/models/dns/domain_name.rb @@ -35,7 +35,7 @@ module DNS def sell_at_auction auction = Auction.new auction.domain = name - auction.platform = :blind + auction.platform = 'blind' auction.start ToStdout.msg "Created the auction: #{auction.inspect}" update_whois_from_auction(auction) diff --git a/app/views/admin/auctions/index.html.erb b/app/views/admin/auctions/index.html.erb index 2ea206671..52472e7fa 100644 --- a/app/views/admin/auctions/index.html.erb +++ b/app/views/admin/auctions/index.html.erb @@ -124,7 +124,7 @@ <% @auctions.each do |auction| %> - <%= AuctionHelper.colorize_auction(auction) %> + <%= colorize_auction(auction) %> <%= auction.status %> <%= auction.created_at %> <%= auction.registration_code %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 28d2d0281..c36dcadeb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -189,6 +189,7 @@ en: log_out: 'Log out (%{user})' system: 'System' domains: 'Domains' + auctions: 'Auctions' registrars: 'Registrars' valid_to: 'Valid to' name: 'Name' diff --git a/db/migrate/20220412130856_add_type_to_auction.rb b/db/migrate/20220412130856_add_type_to_auction.rb index a48ca5ed9..14714e868 100644 --- a/db/migrate/20220412130856_add_type_to_auction.rb +++ b/db/migrate/20220412130856_add_type_to_auction.rb @@ -1,5 +1,5 @@ class AddTypeToAuction < ActiveRecord::Migration[6.1] def change - # add_column :auctions, :type, :integer, null: true + add_column :auctions, :platform, :integer, null: true end end diff --git a/db/structure.sql b/db/structure.sql index 74d2802bb..8512da48e 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -337,7 +337,8 @@ CREATE TABLE public.auctions ( uuid uuid DEFAULT public.gen_random_uuid() NOT NULL, created_at timestamp without time zone NOT NULL, registration_code character varying, - registration_deadline timestamp without time zone + registration_deadline timestamp without time zone, + platform integer ); From 3b9ff74bd24210798e94acb08d8434c7e72eff46 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 22 Apr 2022 14:04:29 +0300 Subject: [PATCH 133/172] fix issues --- app/controllers/admin/auctions_controller.rb | 35 +++++++++++++++---- .../admin/reserved_domains_controller.rb | 2 +- app/models/auction.rb | 10 +++++- app/models/dns/domain_name.rb | 2 +- app/views/admin/auctions/index.html.erb | 26 +++++++++++--- app/views/admin/base/_menu.haml | 2 +- config/routes.rb | 3 ++ 7 files changed, 66 insertions(+), 14 deletions(-) diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb index fc89c01f7..8e3e0ce3d 100644 --- a/app/controllers/admin/auctions_controller.rb +++ b/app/controllers/admin/auctions_controller.rb @@ -24,7 +24,7 @@ module Admin end def create - auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: 'english') + auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: 'manually') if auction.save remove_from_reserved(auction) @@ -40,17 +40,40 @@ module Admin filename = params[:q][:file] table = CSV.parse(File.read(filename), headers: true) - table.each do |row| - record = row.to_h - auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: 'english') - remove_from_reserved(auction) if auction.save! + if validate_table(table) + table.each do |row| + record = row.to_h + auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: 'manually') + remove_from_reserved(auction) if auction.save! + end + flash[:notice] = "Domains added" + redirect_to admin_auctions_path + else + flash[:alert] = "Invalid CSV format." + redirect_to admin_auctions_path end + end - redirect_to admin_auctions_path + def send_to_auction + auction = Auction.find(params[:id]) + + p ">>>>>.." + p auction + p ">>>>>>" end private + def validate_table(table) + first_row = table.headers + first_row[0] == 'id' && + first_row[1] == 'created_at' && + first_row[2] == 'updated_at' && + first_row[3] == 'creator_str' && + first_row[4] == 'updator_str' && + first_row[5] == 'name' + end + def remove_from_reserved(auction) domain = ReservedDomain.find_by(name: auction.domain) diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 2daa6e068..3812a2394 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -58,7 +58,7 @@ module Admin reserved_domains = ReservedDomain.where(id: reserved_domains_ids) reserved_domains.each do |domain| - Auction.create!(domain: domain.name, status: Auction.statuses[:started], platform: 'english') + Auction.create!(domain: domain.name, status: Auction.statuses[:started], platform: 'manually') domain.destroy! end diff --git a/app/models/auction.rb b/app/models/auction.rb index 56acba7c6..cb0e9916d 100644 --- a/app/models/auction.rb +++ b/app/models/auction.rb @@ -9,7 +9,7 @@ class Auction < ApplicationRecord domain_not_registered: 'domain_not_registered', } - enum platform: %i[blind english] + enum platform: %i[automatically manually] PENDING_STATUSES = [statuses[:started], statuses[:awaiting_payment], @@ -21,6 +21,14 @@ class Auction < ApplicationRecord where(status: status) if status.present? } + scope :with_start_created_at_date, -> (start_created_at) { + where("created_at >= ?", start_created_at) if start_created_at.present? + } + + scope :with_end_created_at_date, -> (end_created_at) { + where("created_at <= ?", end_created_at) if end_created_at.present? + } + def self.pending(domain_name) find_by(domain: domain_name.to_s, status: PENDING_STATUSES) end diff --git a/app/models/dns/domain_name.rb b/app/models/dns/domain_name.rb index f914e3439..5d89868ff 100644 --- a/app/models/dns/domain_name.rb +++ b/app/models/dns/domain_name.rb @@ -35,7 +35,7 @@ module DNS def sell_at_auction auction = Auction.new auction.domain = name - auction.platform = 'blind' + auction.platform = 'automatically' auction.start ToStdout.msg "Created the auction: #{auction.inspect}" update_whois_from_auction(auction) diff --git a/app/views/admin/auctions/index.html.erb b/app/views/admin/auctions/index.html.erb index 52472e7fa..bae4a2239 100644 --- a/app/views/admin/auctions/index.html.erb +++ b/app/views/admin/auctions/index.html.erb @@ -41,11 +41,11 @@  
- <%= link_to(t('.reset_btn'), admin_auctions_path, class: 'btn btn-default') %> + <%= link_to('Clear', admin_auctions_path, class: 'btn btn-default') %>
<%= link_to 'Download auction list', admin_auctions_path(format: :csv, params: params.permit!), - "data-toggle" => "tooltip", "data-placement" => "bottom", "title" => t('.download_csv_btn'), + "data-toggle" => "tooltip", "data-placement" => "bottom", "title" => 'Download CSV', class: 'btn btn-primary' %>
@@ -114,10 +114,12 @@ <%= sort_link(@q, 'registration_deadline') %> - + <%= sort_link(@q, 'type') %> - + + Action + @@ -130,6 +132,11 @@ <%= auction.registration_code %> <%= auction.registration_deadline %> <%= auction.platform %> + + <%= button_tag type: 'button', data: { confirm: "Are you sure?" }, class: 'btn btn-primary' do %> + <% link_to 'Send to auction', send_to_auction_admin_auction_path(auction), method: :post, style: "color: white;" %> + <% end %> + <% end %> @@ -138,6 +145,17 @@
+
+
+ <%= paginate @auctions %> +
+
+ +
+
+