From c47b093a451adae768f1a905d99676104f8bf5d8 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 14 Jan 2022 00:39:31 +0300 Subject: [PATCH 01/16] 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 02/16] 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 03/16] 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 04/16] 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 05/16] 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 06/16] 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 07/16] 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 08/16] 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 09/16] 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 10/16] 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 11/16] 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 12/16] 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 13/16] 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 14/16] 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 15/16] 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 16/16] 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