From 294b60ebdc912bddb15dae85b5d8e5d7a92372cd Mon Sep 17 00:00:00 2001 From: dinsmol Date: Sat, 19 Feb 2022 22:43:05 +0300 Subject: [PATCH 001/241] Add removing old records for validation events --- app/interactions/actions/email_check.rb | 5 +++++ app/models/validation_event.rb | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/interactions/actions/email_check.rb b/app/interactions/actions/email_check.rb index 4b026ec2e..248952a47 100644 --- a/app/interactions/actions/email_check.rb +++ b/app/interactions/actions/email_check.rb @@ -12,12 +12,17 @@ module Actions result = check_email(email) save_result(result) filtering_old_failed_records(result) + remove_old_records! result.success ? log_success : log_failure(result) result.success end private + def remove_old_records! + validation_eventable.validation_events.old_records.destroy_all + end + def check_email(parsed_email) Truemail.validate(parsed_email, with: calculate_check_level).result end diff --git a/app/models/validation_event.rb b/app/models/validation_event.rb index 621fec030..1c0ec155d 100644 --- a/app/models/validation_event.rb +++ b/app/models/validation_event.rb @@ -6,7 +6,7 @@ # For email_validation event kind also check_level (regex/mx/smtp) is stored in the event_data class ValidationEvent < ApplicationRecord enum event_type: ValidationEvent::EventType::TYPES, _suffix: true - VALIDATION_PERIOD = 1.year.freeze + VALIDATION_PERIOD = 4.month.freeze VALID_CHECK_LEVELS = %w[regex mx smtp].freeze VALID_EVENTS_COUNT_THRESHOLD = 5 MX_CHECK = 3 @@ -27,7 +27,7 @@ class ValidationEvent < ApplicationRecord belongs_to :validation_eventable, polymorphic: true - scope :recent, -> { where('created_at < ?', Time.zone.now - VALIDATION_PERIOD) } + scope :old_records, -> { where('created_at < ?', Time.zone.now - VALIDATION_PERIOD) } scope :successful, -> { where(success: true) } scope :failed, -> { where(success: false) } scope :regex, -> { where('event_data @> ?', { 'check_level': 'regex' }.to_json) } @@ -38,7 +38,7 @@ class ValidationEvent < ApplicationRecord after_create :check_for_force_delete def self.validated_ids_by(klass) - recent.successful.where('validation_eventable_type = ?', klass) + old_records.successful.where('validation_eventable_type = ?', klass) .pluck(:validation_eventable_id) end From c13a3e39fd57825be14425a9c631a53e7bc576a4 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 22 Feb 2022 23:51:39 +0300 Subject: [PATCH 002/241] Add tests --- test/interactions/email_check_test.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/interactions/email_check_test.rb b/test/interactions/email_check_test.rb index 4e77a5bee..0aed12ea0 100644 --- a/test/interactions/email_check_test.rb +++ b/test/interactions/email_check_test.rb @@ -95,4 +95,27 @@ class EmailCheckTest < ActiveSupport::TestCase assert_equal @contact.validation_events.count, 1 assert @contact.validation_events.last.success end + + def test_should_remove_old_validation_records + trumail_results = OpenStruct.new(success: false, + email: @contact.email, + domain: "box.tests", + errors: {:mx=>"target host(s) not found"}, + ) + + Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results) + Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([true]) + + action = Actions::EmailCheck.new(email: @contact.email, + validation_eventable: @contact, + check_level: 'regex') + + + action.call + assert_equal @contact.validation_events.count, 1 + + travel_to(Time.zone.now + ::ValidationEvent::VALIDATION_PERIOD + 1.minute) + action.call + assert_equal @contact.validation_events.count, 1 + end end From ab3ababc1a139cc43c4cc6c684e91684efcee604 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 23 Feb 2022 00:17:18 +0300 Subject: [PATCH 003/241] Fix codeclimate errors --- app/models/validation_event.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/validation_event.rb b/app/models/validation_event.rb index 1c0ec155d..dd8edd057 100644 --- a/app/models/validation_event.rb +++ b/app/models/validation_event.rb @@ -6,7 +6,7 @@ # For email_validation event kind also check_level (regex/mx/smtp) is stored in the event_data class ValidationEvent < ApplicationRecord enum event_type: ValidationEvent::EventType::TYPES, _suffix: true - VALIDATION_PERIOD = 4.month.freeze + VALIDATION_PERIOD = 4.month VALID_CHECK_LEVELS = %w[regex mx smtp].freeze VALID_EVENTS_COUNT_THRESHOLD = 5 MX_CHECK = 3 @@ -38,8 +38,10 @@ class ValidationEvent < ApplicationRecord after_create :check_for_force_delete def self.validated_ids_by(klass) - old_records.successful.where('validation_eventable_type = ?', klass) - .pluck(:validation_eventable_id) + old_records + .successful + .where('validation_eventable_type = ?', klass) + .pluck(:validation_eventable_id) end def failed? From 3586eb999bdd4e23f1cfc9c25bc721db06868412 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 23 Feb 2022 09:41:03 +0300 Subject: [PATCH 004/241] Return constant for validation period --- app/models/validation_event.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/validation_event.rb b/app/models/validation_event.rb index dd8edd057..28fc2173b 100644 --- a/app/models/validation_event.rb +++ b/app/models/validation_event.rb @@ -6,7 +6,7 @@ # For email_validation event kind also check_level (regex/mx/smtp) is stored in the event_data class ValidationEvent < ApplicationRecord enum event_type: ValidationEvent::EventType::TYPES, _suffix: true - VALIDATION_PERIOD = 4.month + VALIDATION_PERIOD = 4.month.freeze VALID_CHECK_LEVELS = %w[regex mx smtp].freeze VALID_EVENTS_COUNT_THRESHOLD = 5 MX_CHECK = 3 From 2dc5685393623639a15af6ea520427a516978655 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 23 Feb 2022 09:48:51 +0300 Subject: [PATCH 005/241] Fix validation period --- app/models/validation_event.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/validation_event.rb b/app/models/validation_event.rb index 28fc2173b..69fd660e5 100644 --- a/app/models/validation_event.rb +++ b/app/models/validation_event.rb @@ -6,7 +6,7 @@ # For email_validation event kind also check_level (regex/mx/smtp) is stored in the event_data class ValidationEvent < ApplicationRecord enum event_type: ValidationEvent::EventType::TYPES, _suffix: true - VALIDATION_PERIOD = 4.month.freeze + VALIDATION_PERIOD = 1.year.freeze VALID_CHECK_LEVELS = %w[regex mx smtp].freeze VALID_EVENTS_COUNT_THRESHOLD = 5 MX_CHECK = 3 From 6b028814c3362060496fcc262162233050aa8e38 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 14 Dec 2021 09:27:13 +0300 Subject: [PATCH 006/241] 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 007/241] 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 008/241] 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 009/241] 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 58db467229621ffa8eaed7f92b384a1b61c82ab7 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 21 Mar 2022 11:15:17 +0200 Subject: [PATCH 010/241] 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 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 011/241] 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 012/241] 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 013/241] 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 014/241] 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 015/241] 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 016/241] 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 017/241] 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 018/241] 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 019/241] 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 020/241] 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 021/241] 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 022/241] 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 023/241] 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 024/241] 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 025/241] 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 026/241] 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 027/241] 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 028/241] 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 029/241] 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 030/241] 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 031/241] 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 032/241] 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 033/241] 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 034/241] 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 035/241] 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 036/241] 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 037/241] 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 038/241] 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 039/241] 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 040/241] 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 041/241] 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 042/241] 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 043/241] 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 %> +
+
+ +
+
+