From 71b5af5b70979f1a02d2928e1f0e2e460243023d Mon Sep 17 00:00:00 2001 From: Georg Kahest Date: Tue, 18 Aug 2020 05:16:26 +0300 Subject: [PATCH 01/61] run configured crlupdater --- app/models/certificate.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models/certificate.rb b/app/models/certificate.rb index d2428365a..2840c691e 100644 --- a/app/models/certificate.rb +++ b/app/models/certificate.rb @@ -134,11 +134,16 @@ class Certificate < ApplicationRecord class << self def update_crl - update_id_crl - update_registry_crl - reload_apache +# update_id_crl +# update_registry_crl +# reload_apache + run_crlupdater + end + def run_crlupdater + STDOUT << "#{Time.zone.now.utc} - Running crlupdater\n" unless Rails.env.test? + system "#{ENV['crl_update_path']}" + STDOUT << "#{Time.zone.now.utc} - Finished running crlupdater\n" unless Rails.env.test? end - def update_id_crl STDOUT << "#{Time.zone.now.utc} - Updating ID CRL\n" unless Rails.env.test? From 0e686c5af552f5dc91d61ac613fc88a8f9a0d989 Mon Sep 17 00:00:00 2001 From: Georg Kahest Date: Tue, 18 Aug 2020 08:42:16 +0300 Subject: [PATCH 02/61] split crl updating and application code --- app/models/certificate.rb | 71 +---------------------------------- config/application.yml.sample | 1 + 2 files changed, 3 insertions(+), 69 deletions(-) diff --git a/app/models/certificate.rb b/app/models/certificate.rb index 2840c691e..98ad7eea9 100644 --- a/app/models/certificate.rb +++ b/app/models/certificate.rb @@ -127,83 +127,16 @@ class Certificate < ApplicationRecord return false end - self.class.update_registry_crl - self.class.reload_apache + self.class.update_crl self end class << self def update_crl -# update_id_crl -# update_registry_crl -# reload_apache - run_crlupdater - end - def run_crlupdater STDOUT << "#{Time.zone.now.utc} - Running crlupdater\n" unless Rails.env.test? - system "#{ENV['crl_update_path']}" + system "#{ENV['crl_updater_path']}" STDOUT << "#{Time.zone.now.utc} - Finished running crlupdater\n" unless Rails.env.test? end - def update_id_crl - STDOUT << "#{Time.zone.now.utc} - Updating ID CRL\n" unless Rails.env.test? - - _out, _err, _st = Open3.capture3(" - mkdir -p #{ENV['crl_dir']}/crl-id-temp - cd #{ENV['crl_dir']}/crl-id-temp - - wget https://sk.ee/crls/esteid/esteid2007.crl - wget https://sk.ee/crls/juur/crl.crl - wget https://sk.ee/crls/eeccrca/eeccrca.crl - wget https://sk.ee/repository/crls/esteid2011.crl - - openssl crl -in esteid2007.crl -out esteid2007.crl -inform DER - openssl crl -in crl.crl -out crl.crl -inform DER - openssl crl -in eeccrca.crl -out eeccrca.crl -inform DER - openssl crl -in esteid2011.crl -out esteid2011.crl -inform DER - - ln -s crl.crl `openssl crl -hash -noout -in crl.crl`.r0 - ln -s esteid2007.crl `openssl crl -hash -noout -in esteid2007.crl`.r0 - ln -s eeccrca.crl `openssl crl -hash -noout -in eeccrca.crl`.r0 - ln -s esteid2011.crl `openssl crl -hash -noout -in esteid2011.crl`.r0 - - rm -rf #{ENV['crl_dir']}/*.crl #{ENV['crl_dir']}/*.r0 - - mv #{ENV['crl_dir']}/crl-id-temp/* #{ENV['crl_dir']} - - rm -rf #{ENV['crl_dir']}/crl-id-temp - ") - - STDOUT << "#{Time.zone.now.utc} - ID CRL updated\n" unless Rails.env.test? - end - - def update_registry_crl - STDOUT << "#{Time.zone.now.utc} - Updating registry CRL\n" unless Rails.env.test? - - _out, _err, _st = Open3.capture3(" - mkdir -p #{ENV['crl_dir']}/crl-temp - cd #{ENV['crl_dir']}/crl-temp - - openssl ca -config #{ENV['openssl_config_path']} -keyfile #{ENV['ca_key_path']} -cert \ - #{ENV['ca_cert_path']} -gencrl -out #{ENV['crl_dir']}/crl-temp/crl.pem -key \ - '#{ENV['ca_key_password']}' -batch - - ln -s crl.pem `openssl crl -hash -noout -in crl.pem`.r1 - - rm -rf #{ENV['crl_dir']}/*.pem #{ENV['crl_dir']}/*.r1 - - mv #{ENV['crl_dir']}/crl-temp/* #{ENV['crl_dir']} - - rm -rf #{ENV['crl_dir']}/crl-temp - ") - - STDOUT << "#{Time.zone.now.utc} - Registry CRL updated\n" unless Rails.env.test? - end - - def reload_apache - STDOUT << "#{Time.zone.now.utc} - Reloading apache\n" unless Rails.env.test? - _out, _err, _st = Open3.capture3("sudo /etc/init.d/apache2 reload") - STDOUT << "#{Time.zone.now.utc} - Apache reloaded\n" unless Rails.env.test? - end def parse_md_from_string(crt) return nil if crt.blank? diff --git a/config/application.yml.sample b/config/application.yml.sample index 2cd19b768..9bf0f769c 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -34,6 +34,7 @@ time_zone: 'Tallinn' # more zones by rake time:zones:all openssl_config_path: '/etc/ssl/openssl.cnf' crl_dir: '/home/registry/registry/shared/ca/crl' crl_path: '/home/registry/registry/shared/ca/crl/crl.pem' +crl_updater_path: '/home/registry/registry/shared/ca/crl/crlupdater.sh' ca_cert_path: '/home/registry/registry/shared/ca/certs/ca.crt.pem' ca_key_path: '/home/registry/registry/shared/ca/private/ca.key.pem' ca_key_password: 'your-root-key-password' From 630c8878d8a2fc9fecc78d55e1c2afa020fe2b20 Mon Sep 17 00:00:00 2001 From: Georg Kahest Date: Tue, 1 Sep 2020 13:46:12 +0300 Subject: [PATCH 03/61] force usage of bash command with args --- app/models/certificate.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/certificate.rb b/app/models/certificate.rb index 98ad7eea9..d372058ff 100644 --- a/app/models/certificate.rb +++ b/app/models/certificate.rb @@ -134,7 +134,7 @@ class Certificate < ApplicationRecord class << self def update_crl STDOUT << "#{Time.zone.now.utc} - Running crlupdater\n" unless Rails.env.test? - system "#{ENV['crl_updater_path']}" + system('/bin/bash', ENV['crl_updater_path'].to_s) STDOUT << "#{Time.zone.now.utc} - Finished running crlupdater\n" unless Rails.env.test? end From 452fa49a7153ded176b05bf29a1614a1da6b7d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 3 Sep 2020 13:16:16 +0300 Subject: [PATCH 04/61] Send each registrar's monthly summary to Directo separately --- app/jobs/directo_invoice_forward_job.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/jobs/directo_invoice_forward_job.rb b/app/jobs/directo_invoice_forward_job.rb index 6c3eb034c..d017e9df2 100644 --- a/app/jobs/directo_invoice_forward_job.rb +++ b/app/jobs/directo_invoice_forward_job.rb @@ -28,17 +28,18 @@ class DirectoInvoiceForwardJob < Que::Job def send_monthly_invoices Registrar.where.not(test_registrar: true).find_each do |registrar| + @client = DirectoApi::Client.new(api_url, sales_agent, payment_term) fetch_monthly_summary(registrar: registrar) + next unless @client.invoices.count.positive? + + sync_with_directo end - - return unless @client.invoices.count.positive? - - sync_with_directo end def fetch_monthly_summary(registrar:) return unless registrar.cash_account + Rails.logger.info "Fetching monthly summary for registrar #{registrar.name}" summary = registrar.monthly_summary(month: @month) @client.invoices.add_with_schema(invoice: summary, schema: 'summary') unless summary.nil? end From 732afd8cbfd3f4e1fe75671915e0989b11c71306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 3 Sep 2020 13:36:34 +0300 Subject: [PATCH 05/61] Reinit Directo client by function --- app/jobs/directo_invoice_forward_job.rb | 26 +++++++++++-------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/app/jobs/directo_invoice_forward_job.rb b/app/jobs/directo_invoice_forward_job.rb index d017e9df2..705dcf480 100644 --- a/app/jobs/directo_invoice_forward_job.rb +++ b/app/jobs/directo_invoice_forward_job.rb @@ -2,15 +2,16 @@ class DirectoInvoiceForwardJob < Que::Job def run(monthly: false, dry: false) @dry = dry (@month = Time.zone.now - 1.month) if monthly - api_url = ENV['directo_invoice_url'] - sales_agent = Setting.directo_sales_agent - payment_term = Setting.directo_receipt_payment_term - @prepayment_product_id = Setting.directo_receipt_product_name - @client = DirectoApi::Client.new(api_url, sales_agent, payment_term) + @client = new_directo_client monthly ? send_monthly_invoices : send_receipts end + def new_directo_client + DirectoApi::Client.new(ENV['directo_invoice_url'], Setting.directo_sales_agent, + Setting.directo_receipt_payment_term) + end + def send_receipts unsent_invoices = Invoice.where(in_directo: false).non_cancelled @@ -28,22 +29,17 @@ class DirectoInvoiceForwardJob < Que::Job def send_monthly_invoices Registrar.where.not(test_registrar: true).find_each do |registrar| - @client = DirectoApi::Client.new(api_url, sales_agent, payment_term) - fetch_monthly_summary(registrar: registrar) + next unless registrar.cash_account + + @client = new_directo_client + summary = registrar.monthly_summary(month: @month) + @client.invoices.add_with_schema(invoice: summary, schema: 'summary') unless summary.nil? next unless @client.invoices.count.positive? sync_with_directo end end - def fetch_monthly_summary(registrar:) - return unless registrar.cash_account - - Rails.logger.info "Fetching monthly summary for registrar #{registrar.name}" - summary = registrar.monthly_summary(month: @month) - @client.invoices.add_with_schema(invoice: summary, schema: 'summary') unless summary.nil? - end - def assign_monthly_numbers if directo_counter_exceedable?(@client.invoices.count) raise 'Directo Counter is going to be out of period!' From 53a45f60a4eb154a5769b847188751bc866a9294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 3 Sep 2020 14:00:26 +0300 Subject: [PATCH 06/61] Fix CC issues --- app/jobs/directo_invoice_forward_job.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/jobs/directo_invoice_forward_job.rb b/app/jobs/directo_invoice_forward_job.rb index 705dcf480..4b2c06e2c 100644 --- a/app/jobs/directo_invoice_forward_job.rb +++ b/app/jobs/directo_invoice_forward_job.rb @@ -32,14 +32,17 @@ class DirectoInvoiceForwardJob < Que::Job next unless registrar.cash_account @client = new_directo_client - summary = registrar.monthly_summary(month: @month) - @client.invoices.add_with_schema(invoice: summary, schema: 'summary') unless summary.nil? - next unless @client.invoices.count.positive? - - sync_with_directo + send_invoice_for_registrar(registrar) end end + def send_invoice_for_registrar(registrar) + summary = registrar.monthly_summary(month: @month) + @client.invoices.add_with_schema(invoice: summary, schema: 'summary') unless summary.nil? + + sync_with_directo if @client.invoices.count.positive? + end + def assign_monthly_numbers if directo_counter_exceedable?(@client.invoices.count) raise 'Directo Counter is going to be out of period!' From 773e39c88d525a05e3d88fcba3ff619aae1e647c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 3 Sep 2020 15:29:48 +0300 Subject: [PATCH 07/61] Target newer commit of Directo gem --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f7eb6cf2a..4144c9ed3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,7 +9,7 @@ GIT GIT remote: https://github.com/internetee/directo.git - revision: 8ff8a382d004ffb85722a6a7a68a020bd4d7159b + revision: e4ba54f601d1815fd8782a196788730d47861e86 branch: master specs: directo (1.0.1) @@ -165,7 +165,7 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.1.6) + concurrent-ruby (1.1.7) countries (3.0.1) i18n_data (~> 0.10.0) sixarm_ruby_unaccent (~> 1.1) @@ -241,7 +241,7 @@ GEM httpi (2.4.4) rack socksify - i18n (1.8.3) + i18n (1.8.5) concurrent-ruby (~> 1.0) i18n_data (0.10.0) isikukood (0.1.2) From 41fee1d098e146c1f282be066475ab8716a20cd9 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 17 Dec 2019 03:55:13 +0200 Subject: [PATCH 08/61] Remove redundant database column `domains.registered_at` Alias `Domain#registered_at` to `created_at` Closes #1442 --- app/models/domain.rb | 3 ++- app/models/epp/domain.rb | 2 -- db/migrate/20191217013225_remove_domains_registered_at.rb | 5 +++++ db/structure.sql | 2 +- test/fixtures/domains.yml | 1 - test/models/domain_test.rb | 6 ++++++ test/system/registrant_area/domains/details_test.rb | 4 ++-- 7 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20191217013225_remove_domains_registered_at.rb diff --git a/app/models/domain.rb b/app/models/domain.rb index b706744bd..e57117bc2 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -18,6 +18,7 @@ class Domain < ApplicationRecord alias_attribute :on_hold_time, :outzone_at alias_attribute :outzone_time, :outzone_at alias_attribute :auth_info, :transfer_code # Old attribute name; for PaperTrail + alias_attribute :registered_at, :created_at # TODO: whois requests ip whitelist for full info for own domains and partial info for other domains # TODO: most inputs should be trimmed before validatation, probably some global logic? @@ -627,7 +628,7 @@ class Domain < ApplicationRecord def as_json(_options) hash = super hash['auth_info'] = hash.delete('transfer_code') # API v1 requirement - hash['valid_from'] = hash['registered_at'] # API v1 requirement + hash['valid_from'] = hash['created_at'] # API v1 requirement hash.delete('statuses_before_force_delete') hash end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index a6fe58c71..7cfe3107a 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -41,7 +41,6 @@ class Epp::Domain < Domain domain = Epp::Domain.new domain.attributes = domain.attrs_from(frame, current_user) domain.attach_default_contacts - domain.registered_at = Time.zone.now period = domain.period.to_i plural_period_unit_name = (domain.period_unit == 'm' ? 'months' : 'years').to_sym @@ -150,7 +149,6 @@ class Epp::Domain < Domain at[:name] = frame.css('name').text if new_record? at[:registrar_id] = current_user.registrar.try(:id) - at[:registered_at] = Time.zone.now if new_record? period = frame.css('period').text at[:period] = (period.to_i == 0) ? 1 : period.to_i diff --git a/db/migrate/20191217013225_remove_domains_registered_at.rb b/db/migrate/20191217013225_remove_domains_registered_at.rb new file mode 100644 index 000000000..458c5ebda --- /dev/null +++ b/db/migrate/20191217013225_remove_domains_registered_at.rb @@ -0,0 +1,5 @@ +class RemoveDomainsRegisteredAt < ActiveRecord::Migration[5.0] + def change + remove_column :domains, :registered_at + end +end diff --git a/db/structure.sql b/db/structure.sql index 377259100..6224671ad 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -778,7 +778,6 @@ CREATE TABLE public.domains ( id integer NOT NULL, name character varying NOT NULL, registrar_id integer NOT NULL, - registered_at timestamp without time zone, valid_to timestamp without time zone NOT NULL, registrant_id integer NOT NULL, transfer_code character varying NOT NULL, @@ -4828,6 +4827,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20191203083643'), ('20191206183853'), ('20191212133136'), +('20191217013225'), ('20191219112434'), ('20191219124429'), ('20191227110904'), diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml index 87059e68a..c8ea1bfce 100644 --- a/test/fixtures/domains.yml +++ b/test/fixtures/domains.yml @@ -5,7 +5,6 @@ shop: registrar: bestnames registrant: john transfer_code: 65078d5 - registered_at: <%= Time.zone.parse('2010-07-04').to_s(:db) %> valid_to: <%= Time.zone.parse('2010-07-05').to_s(:db) %> outzone_at: <%= Time.zone.parse('2010-07-06').to_s(:db) %> delete_date: 2010-07-07 diff --git a/test/models/domain_test.rb b/test/models/domain_test.rb index ec6f60c52..b4a1d7b47 100644 --- a/test/models/domain_test.rb +++ b/test/models/domain_test.rb @@ -425,6 +425,12 @@ class DomainTest < ActiveSupport::TestCase assert_not(@domain.force_delete_scheduled?) end + def test_aliases_registered_at_to_created_at + created_at = Time.zone.parse('2010-07-05 10:00') + domain = Domain.new(created_at: created_at) + assert_equal created_at, domain.registered_at + end + private def valid_domain diff --git a/test/system/registrant_area/domains/details_test.rb b/test/system/registrant_area/domains/details_test.rb index 5b2e30ba3..2f61d46be 100644 --- a/test/system/registrant_area/domains/details_test.rb +++ b/test/system/registrant_area/domains/details_test.rb @@ -12,7 +12,7 @@ class RegistrantAreaDomainDetailsTest < ApplicationSystemTestCase visit registrant_domain_url(@domain) assert_text 'Name shop.test' - assert_text "Registered at #{l Time.zone.parse('2010-07-04')}" + assert_text "Registered at #{l @domain.registered_at}" assert_link 'Best Names', href: registrant_registrar_path(@domain.registrar) assert_text 'Transfer code' @@ -73,4 +73,4 @@ class RegistrantAreaDomainDetailsTest < ApplicationSystemTestCase assert_field nil, with: registrant_domain_update_confirm_url(@domain, token: 'a01') end -end \ No newline at end of file +end From bd6ebb9d06c2da936294fe37c644d7f576055102 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 17 Dec 2019 03:55:37 +0200 Subject: [PATCH 09/61] Use default translation --- app/views/admin/domains/partials/_general.html.erb | 2 +- app/views/registrant/domains/partials/_general.html.erb | 2 +- config/locales/en.yml | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/views/admin/domains/partials/_general.html.erb b/app/views/admin/domains/partials/_general.html.erb index 0151094b9..dd99d45b8 100644 --- a/app/views/admin/domains/partials/_general.html.erb +++ b/app/views/admin/domains/partials/_general.html.erb @@ -10,7 +10,7 @@
<%= t(:name) %>
<%= @domain.name %>
-
<%= t(:registered_at) %>
+
<%= Domain.human_attribute_name :registered_at %>
<%= l(@domain.registered_at) %>
<%= t(:registrar_name) %>
diff --git a/app/views/registrant/domains/partials/_general.html.erb b/app/views/registrant/domains/partials/_general.html.erb index d79980797..38995be01 100644 --- a/app/views/registrant/domains/partials/_general.html.erb +++ b/app/views/registrant/domains/partials/_general.html.erb @@ -10,7 +10,7 @@
<%= t(:name) %>
<%= @domain.name %>
-
<%= t(:registered_at) %>
+
<%= Domain.human_attribute_name :registered_at %>
<%= l(@domain.registered_at) %>
<%= Registrar.model_name.human %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 27299072e..0a45c83ba 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -195,7 +195,6 @@ en: registrar_name: 'Registrar' owner: 'Registrant' domain_details: 'Domain details' - registered_at: 'Registered at' password: 'Password' valid_from: 'Valid from' general: 'General' From b3d056b295204d01087c620e736b0755a4455465 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 17 Dec 2019 04:23:35 +0200 Subject: [PATCH 10/61] Do not #try It's safe to assume that `registered_at` is always present --- app/models/whois_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index 4994283c9..3563b9630 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -36,7 +36,7 @@ class WhoisRecord < ApplicationRecord h[:disclaimer] = disclaimer_text if disclaimer_text.present? h[:name] = domain.name h[:status] = domain.statuses.map { |x| status_map[x] || x } - h[:registered] = domain.registered_at.try(:to_s, :iso8601) + h[:registered] = domain.registered_at.iso8601 h[:changed] = domain.updated_at.try(:to_s, :iso8601) h[:expire] = domain.valid_to.to_date.to_s h[:outzone] = domain.outzone_at.try(:to_date).try(:to_s) From e428ab9b276763514d06def653776453b8a48dde Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Fri, 4 Sep 2020 14:00:01 +0500 Subject: [PATCH 11/61] Remove whitelist checking from poll ability --- app/models/ability.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 0e18f433a..dce8a515b 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -32,12 +32,14 @@ class Ability def epp # Registrar/api_user dynamic role if @user.registrar.api_ip_white?(@ip) - can :manage, :poll can :manage, Depp::Contact can :manage, :xml_console can :manage, Depp::Domain end + # Poll + can :manage, :poll + # REPP can(:manage, :repp) From 00eca4df5ee51c29b7b48e846ade6067e6846193 Mon Sep 17 00:00:00 2001 From: georg Date: Fri, 4 Sep 2020 13:16:18 +0300 Subject: [PATCH 12/61] Branch Condition --- app/models/certificate.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/certificate.rb b/app/models/certificate.rb index d372058ff..cbed05d6e 100644 --- a/app/models/certificate.rb +++ b/app/models/certificate.rb @@ -133,9 +133,11 @@ class Certificate < ApplicationRecord class << self def update_crl - STDOUT << "#{Time.zone.now.utc} - Running crlupdater\n" unless Rails.env.test? + start = "#{Time.zone.now.utc} - Running crlupdater\n" + stop = "#{Time.zone.now.utc} - Finished running crlupdater\n" + STDOUT << start unless Rails.env.test? system('/bin/bash', ENV['crl_updater_path'].to_s) - STDOUT << "#{Time.zone.now.utc} - Finished running crlupdater\n" unless Rails.env.test? + STDOUT << stop unless Rails.env.test? end def parse_md_from_string(crt) From 718249971f47fbb247f753e1a37b696d7aa78c06 Mon Sep 17 00:00:00 2001 From: georg Date: Fri, 4 Sep 2020 13:28:49 +0300 Subject: [PATCH 13/61] tostdout --- app/models/certificate.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/certificate.rb b/app/models/certificate.rb index cbed05d6e..b3f1ed070 100644 --- a/app/models/certificate.rb +++ b/app/models/certificate.rb @@ -132,12 +132,16 @@ class Certificate < ApplicationRecord end class << self + + def tostdout(message) + time = Time.zone.now.utc + STDOUT << "#{time} - #{message}\n" unless Rails.env.test? + end def update_crl - start = "#{Time.zone.now.utc} - Running crlupdater\n" - stop = "#{Time.zone.now.utc} - Finished running crlupdater\n" - STDOUT << start unless Rails.env.test? + + tostdout('Running crlupdater') system('/bin/bash', ENV['crl_updater_path'].to_s) - STDOUT << stop unless Rails.env.test? + tostdout('Finished running crlupdater') end def parse_md_from_string(crt) From 7d4fe1c64b14773a84dfc7fcad2e3ace22e0bb17 Mon Sep 17 00:00:00 2001 From: georg Date: Fri, 4 Sep 2020 13:30:57 +0300 Subject: [PATCH 14/61] whitespace --- app/models/certificate.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/certificate.rb b/app/models/certificate.rb index b3f1ed070..3bea9e9fc 100644 --- a/app/models/certificate.rb +++ b/app/models/certificate.rb @@ -132,13 +132,12 @@ class Certificate < ApplicationRecord end class << self - def tostdout(message) time = Time.zone.now.utc STDOUT << "#{time} - #{message}\n" unless Rails.env.test? end - def update_crl + def update_crl tostdout('Running crlupdater') system('/bin/bash', ENV['crl_updater_path'].to_s) tostdout('Finished running crlupdater') From dea76d09fbb1b133c8118686b2df78311a71dd29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Fri, 4 Sep 2020 13:36:45 +0300 Subject: [PATCH 15/61] Test that each registrar monthly summary is sent separately --- test/jobs/directo_invoice_forward_job_test.rb | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/jobs/directo_invoice_forward_job_test.rb b/test/jobs/directo_invoice_forward_job_test.rb index 32ae39e7a..dab25f3a2 100644 --- a/test/jobs/directo_invoice_forward_job_test.rb +++ b/test/jobs/directo_invoice_forward_job_test.rb @@ -151,4 +151,42 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase DirectoInvoiceForwardJob.run(monthly: true, dry: false) end end + + def test_sends_each_monthly_invoice_separately + activity = account_activities(:one) + price = billing_prices(:create_one_year) + price.update(duration: '3 years') + activity.update(activity_type: 'create', price: price) + + # Creating account activity for second action + another_activity = activity.dup + another_activity.account = accounts(:two) + + AccountActivity.skip_callback(:create, :after, :update_balance) + another_activity.created_at = Time.zone.parse('2010-07-05 10:00') + another_activity.save + AccountActivity.set_callback(:create, :after, :update_balance) + + response = <<-XML + + + + + XML + + first_registrar_stub = stub_request(:post, ENV['directo_invoice_url']).with do |request| + body = CGI.unescape(request.body) + (body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'bestnames') + end.to_return(status: 200, body: response) + + second_registrar_stub = stub_request(:post, ENV['directo_invoice_url']).with do |request| + body = CGI.unescape(request.body) + (body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'goodnames') + end.to_return(status: 200, body: response) + + DirectoInvoiceForwardJob.run(monthly: true, dry: false) + + assert_requested first_registrar_stub + assert_requested second_registrar_stub + end end From 4e79cc2eba4d237413d6c65f5f146e6ea1e1765e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Fri, 4 Sep 2020 13:52:36 +0300 Subject: [PATCH 16/61] Reset Webmock stub counter for directo requests --- test/jobs/directo_invoice_forward_job_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/jobs/directo_invoice_forward_job_test.rb b/test/jobs/directo_invoice_forward_job_test.rb index dab25f3a2..4e0edf7e5 100644 --- a/test/jobs/directo_invoice_forward_job_test.rb +++ b/test/jobs/directo_invoice_forward_job_test.rb @@ -153,6 +153,8 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase end def test_sends_each_monthly_invoice_separately + WebMock.reset! + activity = account_activities(:one) price = billing_prices(:create_one_year) price.update(duration: '3 years') From 9c79d1269d23c952e924092ba69c67e7d64380e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Fri, 4 Sep 2020 14:00:10 +0300 Subject: [PATCH 17/61] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74c177bf0..2cf9a89ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +04.09.2020 +* Removed reduntant domains.registered_at db column [#1445](https://github.com/internetee/registry/pull/1445) +* Fixed poll request ip whitelist issue [#1672](https://github.com/internetee/registry/pull/1672) + 03.09.2020 * Refactored session timeout management [#711](https://github.com/internetee/registry/issues/711) * Improved error handling for epp requests without proper session [#1276](https://github.com/internetee/registry/pull/1276) From 2fa5c425da823a42dc073e0fc1176d6e4fd98610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Fri, 4 Sep 2020 14:25:41 +0300 Subject: [PATCH 18/61] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cf9a89ce..62904b8a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ 04.09.2020 * Removed reduntant domains.registered_at db column [#1445](https://github.com/internetee/registry/pull/1445) +* Monthly invoices are sent one by one to elliminate reply delay from accounting system [#1671](https://github.com/internetee/registry/pull/1671) * Fixed poll request ip whitelist issue [#1672](https://github.com/internetee/registry/pull/1672) 03.09.2020 From 39a21cb79043dcaf00a6c868fd760e3cd7040c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Fri, 4 Sep 2020 14:33:34 +0300 Subject: [PATCH 19/61] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62904b8a2..325fb29db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ 04.09.2020 * Removed reduntant domains.registered_at db column [#1445](https://github.com/internetee/registry/pull/1445) +* Certificate revocation lists are now hanlded outside of the application code [#1662](https://github.com/internetee/registry/pull/1662) * Monthly invoices are sent one by one to elliminate reply delay from accounting system [#1671](https://github.com/internetee/registry/pull/1671) * Fixed poll request ip whitelist issue [#1672](https://github.com/internetee/registry/pull/1672) From aa2d9547a4e1cbb47e5ab3759abc975312cc8011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 7 Sep 2020 12:55:42 +0300 Subject: [PATCH 20/61] Remove bank statement import functionality --- .../admin/bank_statements_controller.rb | 25 +-------- app/models/bank_statement.rb | 53 ------------------- app/views/admin/bank_statements/import.haml | 20 ------- app/views/admin/bank_statements/index.haml | 1 - app/views/admin/bank_statements/show.haml | 4 -- config/locales/en.yml | 2 - config/routes.rb | 6 --- test/system/admin_area/bank_statement_test.rb | 16 ------ 8 files changed, 2 insertions(+), 125 deletions(-) delete mode 100644 app/views/admin/bank_statements/import.haml delete mode 100644 test/system/admin_area/bank_statement_test.rb diff --git a/app/controllers/admin/bank_statements_controller.rb b/app/controllers/admin/bank_statements_controller.rb index 1e3b31bf5..d507f359c 100644 --- a/app/controllers/admin/bank_statements_controller.rb +++ b/app/controllers/admin/bank_statements_controller.rb @@ -2,7 +2,7 @@ module Admin class BankStatementsController < BaseController load_and_authorize_resource - before_action :set_bank_statement, only: [:show, :download_import_file, :bind_invoices] + before_action :set_bank_statement, only: [:show, :bind_invoices] def index @q = BankStatement.search(params[:q]) @@ -43,22 +43,6 @@ module Admin end end - def import - @bank_statement = BankStatement.new - end - - def create_from_import - @bank_statement = BankStatement.new(bank_statement_params) - - if @bank_statement.import - flash[:notice] = I18n.t('record_created') - redirect_to [:admin, @bank_statement] - else - flash.now[:alert] = I18n.t('failed_to_create_record') - render 'new' - end - end - def bind_invoices @bank_statement.bind_invoices(manual: true) @@ -69,11 +53,6 @@ module Admin redirect_to [:admin, @bank_statement] end - def download_import_file - filename = @bank_statement.import_file_path.split('/').last - send_data File.open(@bank_statement.import_file_path, 'r').read, filename: filename - end - private def set_bank_statement @@ -81,7 +60,7 @@ module Admin end def bank_statement_params - params.require(:bank_statement).permit(:th6_file, :bank_code, :iban, bank_transactions_attributes: [ + params.require(:bank_statement).permit(:bank_code, :iban, bank_transactions_attributes: [ :description, :sum, :currency, :reference_no, :paid_at ]) end diff --git a/app/models/bank_statement.rb b/app/models/bank_statement.rb index c73e6bb44..763506989 100644 --- a/app/models/bank_statement.rb +++ b/app/models/bank_statement.rb @@ -4,65 +4,12 @@ class BankStatement < ApplicationRecord accepts_nested_attributes_for :bank_transactions - attr_accessor :th6_file - validates :bank_code, :iban, presence: true FULLY_BINDED = 'fully_binded' PARTIALLY_BINDED = 'partially_binded' NOT_BINDED = 'not_binded' - def import - import_th6_file && save - end - - def import_th6_file - return false unless th6_file - - th6_file.open.each_line do |row| - bt_params = parse_th6_row(row) - next unless bt_params - bank_transactions.build(bt_params) - end - - prepare_dir - self.import_file_path = "#{ENV['bank_statement_import_dir']}/#{Time.zone.now.to_formatted_s(:number)}.txt" - File.open(import_file_path, 'w') { |f| f.write(th6_file.open.read) } - end - - def prepare_dir - dirname = ENV['bank_statement_import_dir'] - FileUtils.mkdir_p(dirname) unless File.directory?(dirname) - end - - def parse_th6_row(row) - return parse_th6_header(row) if row[4, 3].strip == '000' - return if row[4, 3].strip == '999' # skip footer - return unless row[4, 1].strip == '1' # import only transactions - return unless row[266, 2].strip == 'C' # import only Credit transactions - - { - paid_at: DateTime.strptime(row[5, 8].strip, '%Y%m%d'), - bank_reference: row[5, 16].strip, - iban: row[25, 20].strip, - currency: row[45, 3].strip, - buyer_bank_code: row[48, 3].strip, - buyer_iban: row[51, 32].strip, - buyer_name: row[83, 35].strip, - document_no: row[118, 8].strip, - description: row[126, 140].strip, - sum: BigDecimal(row[268, 12].strip) / BigDecimal('100.0'), - reference_no: row[280, 35].strip - } - end - - def parse_th6_header(row) - self.bank_code = row[7, 3].strip - self.iban = row[10, 20].strip - self.queried_at = DateTime.strptime(row[30, 10].strip, '%y%m%d%H%M') - nil - end - # TODO: Cache this to database so it can be used for searching def status if bank_transactions.unbinded.count == bank_transactions.count diff --git a/app/views/admin/bank_statements/import.haml b/app/views/admin/bank_statements/import.haml deleted file mode 100644 index e432abdf1..000000000 --- a/app/views/admin/bank_statements/import.haml +++ /dev/null @@ -1,20 +0,0 @@ -- content_for :actions do - = link_to(t(:back_to_bank_statements), admin_bank_statements_path, class: 'btn btn-default') -= render 'shared/title', name: t(:import_th6_bank_statement) - -= form_for(@bank_statement, url: { action: :create_from_import }, multipart: true) do |f| - = render 'shared/full_errors', object: @bank_statement - - .row - .col-md-8 - .form-group - .col-md-4.control-label - = f.label :th6_file - .col-md-8 - = f.file_field :th6_file - .col-md-4 - %p= t(:bank_statement_desc).html_safe - %hr - .row - .col-md-8.text-right - = button_tag(t(:save), class: 'btn btn-primary') diff --git a/app/views/admin/bank_statements/index.haml b/app/views/admin/bank_statements/index.haml index 2c604c035..f04557b0b 100644 --- a/app/views/admin/bank_statements/index.haml +++ b/app/views/admin/bank_statements/index.haml @@ -1,6 +1,5 @@ - content_for :actions do = link_to(t(:add), new_admin_bank_statement_path, class: 'btn btn-primary') - = link_to(t('.import_btn'), import_admin_bank_statements_path, class: 'btn btn-primary') = render 'shared/title', name: t(:bank_statements) .row diff --git a/app/views/admin/bank_statements/show.haml b/app/views/admin/bank_statements/show.haml index 9797c59bf..ff139012b 100644 --- a/app/views/admin/bank_statements/show.haml +++ b/app/views/admin/bank_statements/show.haml @@ -30,10 +30,6 @@ %dt= t(:created_at) %dd= l(@bank_statement.created_at) - - if @bank_statement.import_file_path - %dt= t(:import_file) - %dd= link_to(t(:download), download_import_file_admin_bank_statement_path(@bank_statement)) - .row .col-sm-6 %h3.text-center-xs diff --git a/config/locales/en.yml b/config/locales/en.yml index 27299072e..c9faca1eb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -467,7 +467,6 @@ en: paid_at: 'Paid at' invoice: 'Invoice' bank_statements: 'Bank statements' - import_th6_bank_statement: 'Import TH6 bank statement' back_to_bank_statements: 'Back to bank statements' back_to_bank_statement: 'Back to bank statement' back_to_billing: 'Back to billing' @@ -584,7 +583,6 @@ en: valid: Valid object_is_not_eligible_for_renewal: 'Object is not eligible for renewal' object_is_not_holded: 'Object is not holded' - bank_statement_desc: 'Import file row will match only when matching following attributes:
ref number
payment amount
invoice number (the first numerical value in comment field)
.' create_bank_statement: 'Create bank statement' create_bank_transaction: 'Create bank transaction' create_new_invoice: 'Create new invoice' diff --git a/config/routes.rb b/config/routes.rb index 2f341866b..223cf3171 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -213,13 +213,7 @@ Rails.application.routes.draw do resources :bank_statements do resources :bank_transactions - collection do - get 'import' - post 'create_from_import' - end - post 'bind_invoices', on: :member - get 'download_import_file', on: :member end resources :bank_transactions do diff --git a/test/system/admin_area/bank_statement_test.rb b/test/system/admin_area/bank_statement_test.rb deleted file mode 100644 index 53cbcc177..000000000 --- a/test/system/admin_area/bank_statement_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'application_system_test_case' - -class AdminAreaBankStatementTest < ApplicationSystemTestCase - setup do - sign_in users(:admin) - travel_to Time.zone.parse('2010-07-05 00:30:00') - end - - def test_import_statement - assert_difference 'BankStatement.count', 1 do - visit import_admin_bank_statements_path - attach_file 'Th6 file', Rails.root.join('test', 'fixtures', 'files', 'bank_statement_test.txt').to_s - click_link_or_button 'Save' - end - end -end From b981c616715d6f4d248a36e038830fa8479823e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 7 Sep 2020 13:02:41 +0300 Subject: [PATCH 21/61] Fix CC issues --- app/controllers/admin/bank_statements_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/bank_statements_controller.rb b/app/controllers/admin/bank_statements_controller.rb index d507f359c..4295c155f 100644 --- a/app/controllers/admin/bank_statements_controller.rb +++ b/app/controllers/admin/bank_statements_controller.rb @@ -2,7 +2,7 @@ module Admin class BankStatementsController < BaseController load_and_authorize_resource - before_action :set_bank_statement, only: [:show, :bind_invoices] + before_action :set_bank_statement, only: %i[show bind_invoices] def index @q = BankStatement.search(params[:q]) From b5668ea49485066d2452d5021c2afb32da4f5278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 7 Sep 2020 13:11:40 +0300 Subject: [PATCH 22/61] Fix some CC issues --- app/models/bank_statement.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/bank_statement.rb b/app/models/bank_statement.rb index 763506989..d57f3e4d7 100644 --- a/app/models/bank_statement.rb +++ b/app/models/bank_statement.rb @@ -6,15 +6,15 @@ class BankStatement < ApplicationRecord validates :bank_code, :iban, presence: true - FULLY_BINDED = 'fully_binded' - PARTIALLY_BINDED = 'partially_binded' - NOT_BINDED = 'not_binded' + FULLY_BINDED = 'fully_binded'.freeze + PARTIALLY_BINDED = 'partially_binded'.freeze + NOT_BINDED = 'not_binded'.freeze # TODO: Cache this to database so it can be used for searching def status if bank_transactions.unbinded.count == bank_transactions.count NOT_BINDED - elsif bank_transactions.unbinded.count == 0 + elsif bank_transactions.unbinded.count.zero? FULLY_BINDED else PARTIALLY_BINDED From 2d1402f6bffa1548896a5b74a26fa4950bae7924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 7 Sep 2020 13:21:32 +0300 Subject: [PATCH 23/61] Increase test coverage for bank statements --- test/system/admin_area/bank_statement_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/system/admin_area/bank_statement_test.rb diff --git a/test/system/admin_area/bank_statement_test.rb b/test/system/admin_area/bank_statement_test.rb new file mode 100644 index 000000000..b4a482f3b --- /dev/null +++ b/test/system/admin_area/bank_statement_test.rb @@ -0,0 +1,15 @@ +require 'application_system_test_case' + +class AdminAreaBankStatementTest < ApplicationSystemTestCase + setup do + sign_in users(:admin) + travel_to Time.zone.parse('2010-07-05 00:30:00') + end + + def test_can_create_statement_manually + visit admin_bank_statements_path + click_link_or_button 'Add' + click_link_or_button 'Save' + assert_text 'Record created' + end +end From fbef572dfc646a0dcd6cdeb41c3c724e4e187848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 7 Sep 2020 15:10:13 +0300 Subject: [PATCH 24/61] Include tests for admin area statement autobinding --- test/system/admin_area/bank_statement_test.rb | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/test/system/admin_area/bank_statement_test.rb b/test/system/admin_area/bank_statement_test.rb index b4a482f3b..6de21b1c3 100644 --- a/test/system/admin_area/bank_statement_test.rb +++ b/test/system/admin_area/bank_statement_test.rb @@ -7,9 +7,47 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase end def test_can_create_statement_manually - visit admin_bank_statements_path + create_bank_statement + assert_text 'Record created' + end + + def test_can_add_transaction_to_statement_manually + create_bank_statement click_link_or_button 'Add' + assert_text 'Create bank transaction' + + fill_in 'Description', with: 'Invoice with id 123' + fill_in 'Reference number', with: '1232' + fill_in 'Sum', with: '500' + fill_in 'Paid at', with: Time.zone.today.to_s click_link_or_button 'Save' assert_text 'Record created' end + + def test_can_bind_statement_transactions + registrar = registrars(:bestnames) + registrar.issue_prepayment_invoice(amount: 500) + invoice = registrar.invoices.last + + create_bank_statement + click_link_or_button 'Add' + assert_text 'Create bank transaction' + + fill_in 'Description', with: "Invoice with id #{invoice.number}" + fill_in 'Reference number', with: invoice.reference_no + fill_in 'Sum', with: invoice.total + fill_in 'Paid at', with: Time.zone.today.to_s + click_link_or_button 'Save' + + click_link_or_button 'Back to bank statement' + click_link_or_button 'Bind invoices' + + assert_text 'Invoices were fully binded' + end + + def create_bank_statement + visit admin_bank_statements_path + click_link_or_button 'Add' + click_link_or_button 'Save' + end end From be960457e6ed11430c2342cb09f6fbff404a4d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 7 Sep 2020 16:58:27 +0300 Subject: [PATCH 25/61] Process payments: Create new invoice by transaction to allow direct top ups --- app/models/bank_transaction.rb | 14 ++++++++++---- app/models/invoice.rb | 9 +++++++++ app/models/registrar.rb | 4 ++-- lib/tasks/invoices/process_payments.rake | 2 ++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index f53a286ba..51895ae5e 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -31,12 +31,18 @@ class BankTransaction < ApplicationRecord @registrar ||= Invoice.find_by(reference_no: parsed_ref_number)&.buyer end + def autobindable? + return false if binded? + return false unless registrar + return false unless invoice + return false unless invoice.payable? + + true + end + # For successful binding, reference number, invoice id and sum must match with the invoice def autobind_invoice(manual: false) - return if binded? - return unless registrar - return unless invoice - return unless invoice.payable? + return unless autobindable? channel = if manual 'admin_payment' diff --git a/app/models/invoice.rb b/app/models/invoice.rb index a130a90ff..28fd60f00 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -112,6 +112,15 @@ class Invoice < ApplicationRecord e_invoice_sent_at.present? end + def self.create_from_transaction!(transaction) + registrar_user = Registrar.find_by(reference_no: transasction.parsed_ref_number) + return unless registrar_user + + registrar_user.issue_prepayment_invoice(amount: transaction.sum, + description: 'Direct top-up via bank transfer', + paid: true) + end + private def apply_default_buyer_vat_no diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 470d768b7..25380b4ef 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -54,7 +54,7 @@ class Registrar < ApplicationRecord end end - def issue_prepayment_invoice(amount, description = nil) + def issue_prepayment_invoice(amount, description = nil, paid: false) vat_rate = ::Invoice::VatRateCalculator.new(registrar: self).calculate invoice = invoices.create!( @@ -99,7 +99,7 @@ class Registrar < ApplicationRecord } ] ) - SendEInvoiceJob.enqueue(invoice.id) + SendEInvoiceJob.enqueue(invoice.id) unless paid invoice end diff --git a/lib/tasks/invoices/process_payments.rake b/lib/tasks/invoices/process_payments.rake index 340aba187..3e02a8838 100644 --- a/lib/tasks/invoices/process_payments.rake +++ b/lib/tasks/invoices/process_payments.rake @@ -36,6 +36,8 @@ namespace :invoices do reference_no: incoming_transaction.payment_reference_number, description: incoming_transaction.payment_description } transaction = bank_statement.bank_transactions.create!(transaction_attributes) + Invoice.create_from_transaction!(transaction) unless transaction.autobindable? + transaction.autobind_invoice end end From 5991ea6be7e13dbe2caadf72d4f837149e7d450c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 7 Sep 2020 17:06:36 +0300 Subject: [PATCH 26/61] Reduce complexity of autobindable?() conditional --- app/models/bank_transaction.rb | 17 +++++++---------- app/models/invoice.rb | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 51895ae5e..fa4d63bff 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -32,12 +32,9 @@ class BankTransaction < ApplicationRecord end def autobindable? - return false if binded? - return false unless registrar - return false unless invoice - return false unless invoice.payable? - - true + binded? && registrar.present && invoice.payable? ? true : false + rescue NoMethodError + false end # For successful binding, reference number, invoice id and sum must match with the invoice @@ -113,6 +110,10 @@ class BankTransaction < ApplicationRecord end end + def parsed_ref_number + reference_no || ref_number_from_description + end + private def reset_pending_registrar_balance_reload @@ -122,10 +123,6 @@ class BankTransaction < ApplicationRecord registrar.save! end - def parsed_ref_number - reference_no || ref_number_from_description - end - def ref_number_from_description /(\d{7})/.match(description)[0] end diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 28fd60f00..9e4f43dd8 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -113,7 +113,7 @@ class Invoice < ApplicationRecord end def self.create_from_transaction!(transaction) - registrar_user = Registrar.find_by(reference_no: transasction.parsed_ref_number) + registrar_user = Registrar.find_by(reference_no: transaction.parsed_ref_number) return unless registrar_user registrar_user.issue_prepayment_invoice(amount: transaction.sum, From c7d768fbed2ed01c54ecf59f2004835cbfb9b71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 8 Sep 2020 11:14:26 +0300 Subject: [PATCH 27/61] Fix autobindable? condition --- app/models/bank_transaction.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index fa4d63bff..0fe6b63af 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -32,7 +32,7 @@ class BankTransaction < ApplicationRecord end def autobindable? - binded? && registrar.present && invoice.payable? ? true : false + !binded? && registrar && invoice.payable? ? true : false rescue NoMethodError false end From 20e3b2c09fae8633252a64d21897c7d057daebe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 8 Sep 2020 11:19:33 +0300 Subject: [PATCH 28/61] Fix some CC issues --- app/models/bank_transaction.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 0fe6b63af..18e6e8c57 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -41,11 +41,7 @@ class BankTransaction < ApplicationRecord def autobind_invoice(manual: false) return unless autobindable? - channel = if manual - 'admin_payment' - else - 'system_payment' - end + channel = manual ? 'admin_payment' : 'system_payment' create_internal_payment_record(channel: channel, invoice: invoice, registrar: registrar) end From 14a319a4da9cc6acb9025c93b186886196633521 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Tue, 8 Sep 2020 13:34:16 +0500 Subject: [PATCH 29/61] Fix description ref number parsing --- app/models/bank_transaction.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index f53a286ba..69cf6fc2a 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -121,6 +121,7 @@ class BankTransaction < ApplicationRecord end def ref_number_from_description - /(\d{7})/.match(description)[0] + match_data = /(\d{7})/.match(description) + match_data[0] if match_data.present? end end From 8cc24b828f37ead38acd772f5dd756f79ee81945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 8 Sep 2020 11:53:37 +0300 Subject: [PATCH 30/61] Submit VAT-exclusive sum to prepayment invoice Prepayment invoices are subject to VAT, which is calculated from before-taxes sum --- app/models/invoice.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 9e4f43dd8..8122e46dd 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -116,7 +116,9 @@ class Invoice < ApplicationRecord registrar_user = Registrar.find_by(reference_no: transaction.parsed_ref_number) return unless registrar_user - registrar_user.issue_prepayment_invoice(amount: transaction.sum, + vat = VatRateCalculator.new(registrar: registrar_user).calculate + wo_vat = transaction.sum / (1 + (vat / 100)) + registrar_user.issue_prepayment_invoice(amount: wo_vat, description: 'Direct top-up via bank transfer', paid: true) end From 6b2aaf305f3225f47ed4e15004d6e97763de3ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 8 Sep 2020 13:08:19 +0300 Subject: [PATCH 31/61] Reference e_invoice development branch in Gemfile --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 12b826e3c..95abfc56a 100644 --- a/Gemfile +++ b/Gemfile @@ -64,7 +64,7 @@ gem 'jquery-ui-rails', '5.0.5' gem 'airbrake' gem 'company_register', github: 'internetee/company_register', branch: :master -gem 'e_invoice', github: 'internetee/e_invoice', branch: :master +gem 'e_invoice', github: 'internetee/e_invoice', branch: 'make-payable-configurable' gem 'lhv', github: 'internetee/lhv', branch: 'master' gem 'domain_name' gem 'haml', '~> 5.0' diff --git a/Gemfile.lock b/Gemfile.lock index 4144c9ed3..8a154953e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,8 +18,8 @@ GIT GIT remote: https://github.com/internetee/e_invoice.git - revision: b374ffd7be77b559b30c7a0210dc0df5ac3ed723 - branch: master + revision: 8a1aea2a1f0d46e1a8f3145b7b46a1810318d229 + branch: make-payable-configurable specs: e_invoice (0.1.0) builder (~> 3.2) From 17188ec6351637c2784b6baf07f9380907424eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 8 Sep 2020 13:09:12 +0300 Subject: [PATCH 32/61] Send unpayable e-invoice when invoice has already been paid via wire transfer --- app/jobs/send_e_invoice_job.rb | 10 +++++----- app/models/invoice.rb | 6 +++--- app/models/invoice/e_invoice_generator.rb | 7 +++++-- app/models/registrar.rb | 4 ++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/jobs/send_e_invoice_job.rb b/app/jobs/send_e_invoice_job.rb index e281db14d..91e068b9f 100644 --- a/app/jobs/send_e_invoice_job.rb +++ b/app/jobs/send_e_invoice_job.rb @@ -1,8 +1,8 @@ class SendEInvoiceJob < Que::Job - def run(invoice_id) - invoice = run_condition(Invoice.find_by(id: invoice_id)) + def run(invoice_id, payable: true) + invoice = run_condition(Invoice.find_by(id: invoice_id), payable: payable) - invoice.to_e_invoice.deliver + invoice.to_e_invoice(payable: payable).deliver ActiveRecord::Base.transaction do invoice.update(e_invoice_sent_at: Time.zone.now) log_success(invoice) @@ -15,9 +15,9 @@ class SendEInvoiceJob < Que::Job private - def run_condition(invoice) + def run_condition(invoice, payable: true) destroy unless invoice - destroy if invoice.do_not_send_e_invoice? + destroy if invoice.do_not_send_e_invoice? && payable invoice end diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 8122e46dd..87f27af36 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -99,8 +99,8 @@ class Invoice < ApplicationRecord generator.as_pdf end - def to_e_invoice - generator = Invoice::EInvoiceGenerator.new(self) + def to_e_invoice(payable: true) + generator = Invoice::EInvoiceGenerator.new(self, payable: payable) generator.generate end @@ -120,7 +120,7 @@ class Invoice < ApplicationRecord wo_vat = transaction.sum / (1 + (vat / 100)) registrar_user.issue_prepayment_invoice(amount: wo_vat, description: 'Direct top-up via bank transfer', - paid: true) + payable: false) end private diff --git a/app/models/invoice/e_invoice_generator.rb b/app/models/invoice/e_invoice_generator.rb index 9a2ab2e01..d2963b93e 100644 --- a/app/models/invoice/e_invoice_generator.rb +++ b/app/models/invoice/e_invoice_generator.rb @@ -1,9 +1,11 @@ class Invoice class EInvoiceGenerator attr_reader :invoice + attr_reader :payable - def initialize(invoice) + def initialize(invoice, payable) @invoice = invoice + @payable = payable end def generate @@ -70,9 +72,10 @@ class Invoice i.total = invoice.total i.currency = invoice.currency i.delivery_channel = %i[internet_bank portal] + i.payable = payable end EInvoice::EInvoice.new(date: Time.zone.today, invoice: e_invoice_invoice) end end -end \ No newline at end of file +end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 25380b4ef..86ff5ef4d 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -54,7 +54,7 @@ class Registrar < ApplicationRecord end end - def issue_prepayment_invoice(amount, description = nil, paid: false) + def issue_prepayment_invoice(amount, description = nil, payable: true) vat_rate = ::Invoice::VatRateCalculator.new(registrar: self).calculate invoice = invoices.create!( @@ -99,7 +99,7 @@ class Registrar < ApplicationRecord } ] ) - SendEInvoiceJob.enqueue(invoice.id) unless paid + SendEInvoiceJob.enqueue(invoice.id, payable: payable) invoice end From 1a56fcf179e499805b6ffba274d5a510bb420936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 8 Sep 2020 13:49:20 +0300 Subject: [PATCH 33/61] Test balance reloading after bank transfer without invoice --- test/tasks/invoices/process_payments_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/tasks/invoices/process_payments_test.rb b/test/tasks/invoices/process_payments_test.rb index bd447be29..38c2e8fdc 100644 --- a/test/tasks/invoices/process_payments_test.rb +++ b/test/tasks/invoices/process_payments_test.rb @@ -82,6 +82,18 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase assert payment_order.failed? end + def test_credits_registrar_account_without_invoice_beforehand + registrar = registrars(:bestnames) + + assert_changes -> { registrar.accounts.first.balance } do + run_task + end + + assert_changes -> { registrar.invoices.count } do + run_task + end + end + def test_output assert_output "Transactions processed: 1\n" do run_task From beb467484c0a1df4563349592501442750cac166 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Tue, 8 Sep 2020 16:20:55 +0500 Subject: [PATCH 34/61] Fix bank transaction tests, add test for non-valid refnumber in description --- test/models/bank_transaction_test.rb | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/test/models/bank_transaction_test.rb b/test/models/bank_transaction_test.rb index b8b0f65f7..944b47573 100644 --- a/test/models/bank_transaction_test.rb +++ b/test/models/bank_transaction_test.rb @@ -26,14 +26,12 @@ class BankTransactionTest < ActiveSupport::TestCase another_item.save another_invoice.reload - first_transaction = BankTransaction.new(description: 'invoice #2221', - sum: 10, + first_transaction = BankTransaction.new(sum: 10, description: 'Order nr 1 from registrar 1234567 second number 2345678') first_transaction.create_activity(another_invoice.buyer, another_invoice) - transaction = BankTransaction.new(description: 'invoice #2222', - sum: 10, + transaction = BankTransaction.new(sum: 10, description: 'Order nr 1 from registrar 1234567 second number 2345678') assert_difference 'AccountActivity.count' do @@ -54,8 +52,7 @@ class BankTransactionTest < ActiveSupport::TestCase another_invoice.reload another_invoice.update(reference_no: '1234567', number: '2221', cancelled_at: Time.zone.now) - transaction = BankTransaction.new(description: 'invoice #2222', - sum: 10, + transaction = BankTransaction.new(sum: 10, description: 'Order nr 1 from registrar 1234567 second number 2345678') assert_difference 'AccountActivity.count' do @@ -74,8 +71,7 @@ class BankTransactionTest < ActiveSupport::TestCase another_item.save another_invoice.reload - transaction = BankTransaction.new(description: 'invoice #2222', - sum: 10, + transaction = BankTransaction.new(sum: 10, description: 'Order nr 1 from registrar 1234567 second number 2345678') assert_difference 'AccountActivity.count' do @@ -90,8 +86,7 @@ class BankTransactionTest < ActiveSupport::TestCase def test_matches_against_invoice_nubmber_and_reference_number_in_description create_payable_invoice(number: '2222', total: 10, reference_no: '1234567') - transaction = BankTransaction.new(description: 'invoice #2222', - sum: 10, + transaction = BankTransaction.new(sum: 10, description: 'Order nr 1 from registrar 1234567 second number 2345678') assert_difference 'AccountActivity.count' do @@ -99,6 +94,18 @@ class BankTransactionTest < ActiveSupport::TestCase end end + def test_no_errors_if_no_valid_refnumber_in_description + create_payable_invoice(number: '2222', total: 10, reference_no: '1234567') + transaction = BankTransaction.new(sum: 10, + description: 'Order nr 1 from registrar 123456') + + assert_no_difference 'AccountActivity.count' do + assert_nothing_raised do + transaction.autobind_invoice + end + end + end + def test_resets_pending_registrar_balance_reload registrar = registrar_with_pending_balance_auto_reload create_payable_invoice(number: '2222', total: 10, reference_no: '1111') From 04377d8997ce9415721b5c441061ca7dd736001a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 8 Sep 2020 16:26:32 +0300 Subject: [PATCH 35/61] Remove 'import_file_path' from bank_statements model --- config/application.yml.sample | 1 - ...31554_remove_import_file_path_from_bank_statements.rb | 9 +++++++++ db/structure.sql | 6 ++++-- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20200908131554_remove_import_file_path_from_bank_statements.rb diff --git a/config/application.yml.sample b/config/application.yml.sample index d5753adb6..1b6c40951 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -27,7 +27,6 @@ smtp_authentication: 'plain' # 'plain', 'login', 'cram_md5' # app_name: '.EE Registry' zonefile_export_dir: 'export/zonefiles' -bank_statement_import_dir: 'import/bank_statements' legal_documents_dir: 'import/legal_documents' time_zone: 'Tallinn' # more zones by rake time:zones:all diff --git a/db/migrate/20200908131554_remove_import_file_path_from_bank_statements.rb b/db/migrate/20200908131554_remove_import_file_path_from_bank_statements.rb new file mode 100644 index 000000000..a80a1e5a5 --- /dev/null +++ b/db/migrate/20200908131554_remove_import_file_path_from_bank_statements.rb @@ -0,0 +1,9 @@ +class RemoveImportFilePathFromBankStatements < ActiveRecord::Migration[6.0] + def up + remove_column :bank_statements, :import_file_path + end + + def down + add_column :bank_statements, :import_file_path, :string + end +end diff --git a/db/structure.sql b/db/structure.sql index 6224671ad..1e32bf318 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -371,7 +371,6 @@ CREATE TABLE public.bank_statements ( id integer NOT NULL, bank_code character varying, iban character varying, - import_file_path character varying, queried_at timestamp without time zone, created_at timestamp without time zone, updated_at timestamp without time zone, @@ -4850,4 +4849,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200807110611'), ('20200811074839'), ('20200812090409'), -('20200812125810'); +('20200812125810'), +('20200908131554'); + + From 47be1283f9182606f3e295e5fa35d4f384ccf3df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 8 Sep 2020 16:56:49 +0300 Subject: [PATCH 36/61] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 325fb29db..4d6a0190c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +08.09.2020 +* Removed bank statement import option [#1674](https://github.com/internetee/registry/pull/1674) + 04.09.2020 * Removed reduntant domains.registered_at db column [#1445](https://github.com/internetee/registry/pull/1445) * Certificate revocation lists are now hanlded outside of the application code [#1662](https://github.com/internetee/registry/pull/1662) From a40888189774272d42289be57f74ee01fbd605dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 8 Sep 2020 17:17:39 +0300 Subject: [PATCH 37/61] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d6a0190c..5f2dc4016 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ 08.09.2020 * Removed bank statement import option [#1674](https://github.com/internetee/registry/pull/1674) +* Fixed error with reference nr not being found in the transaction [#1677](https://github.com/internetee/registry/issues/1677) 04.09.2020 * Removed reduntant domains.registered_at db column [#1445](https://github.com/internetee/registry/pull/1445) From 05ca909741c1a88d204ba97de173e92429adec27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Wed, 9 Sep 2020 12:14:01 +0300 Subject: [PATCH 38/61] Always generate reference_no of length 7 --- app/models/billing/reference_no/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/billing/reference_no/base.rb b/app/models/billing/reference_no/base.rb index dcc7718e7..8614f81f8 100644 --- a/app/models/billing/reference_no/base.rb +++ b/app/models/billing/reference_no/base.rb @@ -2,7 +2,7 @@ module Billing class ReferenceNo class Base def self.generate - new(SecureRandom.random_number(1..1_000_000)) + new((SecureRandom.random_number(9e5) + 1e5).to_i) end def initialize(base) From e61601fdd7dbddca1778845d25fd88c13ebe42ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Wed, 9 Sep 2020 12:25:29 +0300 Subject: [PATCH 39/61] BankTransaction: Find reference numbers with any length from description --- app/models/bank_transaction.rb | 5 +++-- app/models/billing/reference_no.rb | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 69cf6fc2a..76ed9ae27 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -121,7 +121,8 @@ class BankTransaction < ApplicationRecord end def ref_number_from_description - match_data = /(\d{7})/.match(description) - match_data[0] if match_data.present? + (Billing::ReferenceNo::MULTI_REGEXP.match(description) || []).captures.each do |match| + break match if match.length == 7 || Registrar.where(reference_no: match).present? + end end end diff --git a/app/models/billing/reference_no.rb b/app/models/billing/reference_no.rb index 23812214c..849c06b85 100644 --- a/app/models/billing/reference_no.rb +++ b/app/models/billing/reference_no.rb @@ -1,6 +1,7 @@ module Billing class ReferenceNo REGEXP = /\A\d{2,20}\z/ + MULTI_REGEXP = /(\d{2,20})/ def self.generate base = Base.generate From 15470b7ec40c1085fafe8ec3fd8c771865d389eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Wed, 9 Sep 2020 13:14:26 +0300 Subject: [PATCH 40/61] Fix CC issues --- app/models/bank_transaction.rb | 6 +----- app/models/billing/reference_no.rb | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 76ed9ae27..4b6b6eda0 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -38,11 +38,7 @@ class BankTransaction < ApplicationRecord return unless invoice return unless invoice.payable? - channel = if manual - 'admin_payment' - else - 'system_payment' - end + channel = manual ? 'admin_payment' : 'system_payment' create_internal_payment_record(channel: channel, invoice: invoice, registrar: registrar) end diff --git a/app/models/billing/reference_no.rb b/app/models/billing/reference_no.rb index 849c06b85..263100e79 100644 --- a/app/models/billing/reference_no.rb +++ b/app/models/billing/reference_no.rb @@ -1,7 +1,7 @@ module Billing class ReferenceNo - REGEXP = /\A\d{2,20}\z/ - MULTI_REGEXP = /(\d{2,20})/ + REGEXP = /\A\d{2,20}\z/.freeze + MULTI_REGEXP = /(\d{2,20})/.freeze def self.generate base = Base.generate From 166ff44491e7dd32c3e75699ae56bbfe1cf2c906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Wed, 9 Sep 2020 13:42:29 +0300 Subject: [PATCH 41/61] Validate given reference number --- app/models/bank_transaction.rb | 2 +- app/models/billing/reference_no.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 4b6b6eda0..0370ad666 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -118,7 +118,7 @@ class BankTransaction < ApplicationRecord def ref_number_from_description (Billing::ReferenceNo::MULTI_REGEXP.match(description) || []).captures.each do |match| - break match if match.length == 7 || Registrar.where(reference_no: match).present? + break match if match.length == 7 || Billing::ReferenceNo.valid?(match) end end end diff --git a/app/models/billing/reference_no.rb b/app/models/billing/reference_no.rb index 263100e79..d164f7565 100644 --- a/app/models/billing/reference_no.rb +++ b/app/models/billing/reference_no.rb @@ -7,5 +7,10 @@ module Billing base = Base.generate "#{base}#{base.check_digit}" end + + def self.valid?(ref) + base = Base.new(ref.to_s[0...-1]) + ref.to_s == "#{base}#{base.check_digit}" + end end end From 3decec8b02e479ba48f5a4f688aa7d0385586515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 8 Sep 2020 14:24:52 +0300 Subject: [PATCH 42/61] Test valid invoice sums when created by bank transaction --- app/models/invoice.rb | 8 ++++---- app/models/registrar.rb | 3 ++- test/models/invoice_test.rb | 12 ++++++++++++ test/tasks/invoices/process_payments_test.rb | 7 +++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 87f27af36..adaad87d6 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -117,10 +117,10 @@ class Invoice < ApplicationRecord return unless registrar_user vat = VatRateCalculator.new(registrar: registrar_user).calculate - wo_vat = transaction.sum / (1 + (vat / 100)) - registrar_user.issue_prepayment_invoice(amount: wo_vat, - description: 'Direct top-up via bank transfer', - payable: false) + wo_vat = (transaction.sum / (1 + (vat / 100))) + + registrar_user.issue_prepayment_invoice(wo_vat, 'Direct top-up via bank transfer', + payable: false, total: transaction.sum) end private diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 86ff5ef4d..42fbc2b78 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -54,7 +54,7 @@ class Registrar < ApplicationRecord end end - def issue_prepayment_invoice(amount, description = nil, payable: true) + def issue_prepayment_invoice(amount, description = nil, payable: true, total: nil) vat_rate = ::Invoice::VatRateCalculator.new(registrar: self).calculate invoice = invoices.create!( @@ -90,6 +90,7 @@ class Registrar < ApplicationRecord buyer_email: email, reference_no: reference_no, vat_rate: vat_rate, + total: total, items_attributes: [ { description: 'prepayment', diff --git a/test/models/invoice_test.rb b/test/models/invoice_test.rb index 9c1c45610..6ee2dc85c 100644 --- a/test/models/invoice_test.rb +++ b/test/models/invoice_test.rb @@ -109,4 +109,16 @@ class InvoiceTest < ActiveSupport::TestCase seller_zip: nil) assert_equal 'street, city, state', invoice.seller_address end + + def test_assumes_correct_sum_amount_when_created_by_transaction + registrar = registrars(:bestnames) + + bank_transaction = bank_transactions(:one).dup + bank_transaction.reference_no = registrar.reference_no + bank_transaction.sum = 5 + bank_transaction.save + + invoice = Invoice.create_from_transaction!(bank_transaction) + assert_equal 5, invoice.total + end end diff --git a/test/tasks/invoices/process_payments_test.rb b/test/tasks/invoices/process_payments_test.rb index 38c2e8fdc..eeaf411cc 100644 --- a/test/tasks/invoices/process_payments_test.rb +++ b/test/tasks/invoices/process_payments_test.rb @@ -94,6 +94,13 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase end end + def test_topup_creates_invoice_with_total_of_transactioned_amount + registrar = registrars(:bestnames) + run_task + + assert_equal 0.1, registrar.invoices.last.total + end + def test_output assert_output "Transactions processed: 1\n" do run_task From dd48bb61d910020fb292660c46875979c9d96121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 10 Sep 2020 10:44:18 +0300 Subject: [PATCH 43/61] Verify ref_number_from_description return correct match --- app/models/bank_transaction.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 0370ad666..a610b41f8 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -118,7 +118,11 @@ class BankTransaction < ApplicationRecord def ref_number_from_description (Billing::ReferenceNo::MULTI_REGEXP.match(description) || []).captures.each do |match| - break match if match.length == 7 || Billing::ReferenceNo.valid?(match) + break match if match.length == 7 || valid_ref_no?(match) end end + + def valid_ref_no?(match) + return true if Billing::ReferenceNo.valid?(match) && Registrar.find_by(reference_no: match).any? + end end From d62e55e6a179a98a269644fbdcc3ec79774fac15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 10 Sep 2020 12:00:13 +0300 Subject: [PATCH 44/61] Change Invoice::Item price scale to 3 places --- app/models/invoice.rb | 7 +++---- app/models/invoice_item.rb | 6 +++--- app/models/registrar.rb | 3 +-- ...ange_invoice_item_price_scale_to_three_places.rb | 5 +++++ db/structure.sql | 13 ++++++------- 5 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20200910085157_change_invoice_item_price_scale_to_three_places.rb diff --git a/app/models/invoice.rb b/app/models/invoice.rb index adaad87d6..2f4be2e60 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -82,7 +82,7 @@ class Invoice < ApplicationRecord end def vat_amount - subtotal * vat_rate / 100 + (subtotal * vat_rate / 100) end def total @@ -118,9 +118,8 @@ class Invoice < ApplicationRecord vat = VatRateCalculator.new(registrar: registrar_user).calculate wo_vat = (transaction.sum / (1 + (vat / 100))) - registrar_user.issue_prepayment_invoice(wo_vat, 'Direct top-up via bank transfer', - payable: false, total: transaction.sum) + payable: false) end private @@ -130,6 +129,6 @@ class Invoice < ApplicationRecord end def calculate_total - self.total = subtotal + vat_amount + self.total = (subtotal + vat_amount).round(3) end end diff --git a/app/models/invoice_item.rb b/app/models/invoice_item.rb index ec0c77767..61339f5cb 100644 --- a/app/models/invoice_item.rb +++ b/app/models/invoice_item.rb @@ -5,7 +5,7 @@ class InvoiceItem < ApplicationRecord delegate :vat_rate, to: :invoice def item_sum_without_vat - (price * quantity).round(2) + (price * quantity).round(3) end alias_method :subtotal, :item_sum_without_vat @@ -14,6 +14,6 @@ class InvoiceItem < ApplicationRecord end def total - subtotal + vat_amount + (subtotal + vat_amount) end -end \ No newline at end of file +end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 42fbc2b78..86ff5ef4d 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -54,7 +54,7 @@ class Registrar < ApplicationRecord end end - def issue_prepayment_invoice(amount, description = nil, payable: true, total: nil) + def issue_prepayment_invoice(amount, description = nil, payable: true) vat_rate = ::Invoice::VatRateCalculator.new(registrar: self).calculate invoice = invoices.create!( @@ -90,7 +90,6 @@ class Registrar < ApplicationRecord buyer_email: email, reference_no: reference_no, vat_rate: vat_rate, - total: total, items_attributes: [ { description: 'prepayment', diff --git a/db/migrate/20200910085157_change_invoice_item_price_scale_to_three_places.rb b/db/migrate/20200910085157_change_invoice_item_price_scale_to_three_places.rb new file mode 100644 index 000000000..f1f41343b --- /dev/null +++ b/db/migrate/20200910085157_change_invoice_item_price_scale_to_three_places.rb @@ -0,0 +1,5 @@ +class ChangeInvoiceItemPriceScaleToThreePlaces < ActiveRecord::Migration[6.0] + def change + change_column :invoice_items, :price, :decimal, precision: 10, scale: 3 + end +end diff --git a/db/structure.sql b/db/structure.sql index 6224671ad..c8b141745 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1,7 +1,3 @@ ---- ---- PostgreSQL database dump ---- - SET statement_timeout = 0; SET lock_timeout = 0; SET client_encoding = 'UTF8'; @@ -371,7 +367,6 @@ CREATE TABLE public.bank_statements ( id integer NOT NULL, bank_code character varying, iban character varying, - import_file_path character varying, queried_at timestamp without time zone, created_at timestamp without time zone, updated_at timestamp without time zone, @@ -963,7 +958,7 @@ CREATE TABLE public.invoice_items ( description character varying NOT NULL, unit character varying NOT NULL, quantity integer NOT NULL, - price numeric(10,2) NOT NULL, + price numeric(10,3) NOT NULL, created_at timestamp without time zone, updated_at timestamp without time zone, creator_str character varying, @@ -4850,4 +4845,8 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200807110611'), ('20200811074839'), ('20200812090409'), -('20200812125810'); +('20200812125810'), +('20200908131554'), +('20200910085157'); + + From b3fd31f679bdd9a84d31e9e642db0a0fe938e257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 10 Sep 2020 12:24:38 +0300 Subject: [PATCH 45/61] Send invoice to Registrar's billing email after topup --- app/models/invoice.rb | 7 +++---- app/models/registrar.rb | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 2f4be2e60..8e82bbea6 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -82,7 +82,7 @@ class Invoice < ApplicationRecord end def vat_amount - (subtotal * vat_rate / 100) + subtotal * vat_rate / 100 end def total @@ -117,9 +117,8 @@ class Invoice < ApplicationRecord return unless registrar_user vat = VatRateCalculator.new(registrar: registrar_user).calculate - wo_vat = (transaction.sum / (1 + (vat / 100))) - registrar_user.issue_prepayment_invoice(wo_vat, 'Direct top-up via bank transfer', - payable: false) + net = (transaction.sum / (1 + (vat / 100))) + registrar_user.issue_prepayment_invoice(net, 'Direct top-up via bank transfer', payable: false) end private diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 86ff5ef4d..4d3d9f926 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -101,6 +101,10 @@ class Registrar < ApplicationRecord ) SendEInvoiceJob.enqueue(invoice.id, payable: payable) + unless payable + InvoiceMailer.invoice_email(invoice: invoice, recipient: billing_email).deliver_now + end + invoice end From 58079c6955aaef35d21fc87a7be50c76db8df6a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 10 Sep 2020 13:00:05 +0300 Subject: [PATCH 46/61] Improve topup tests --- app/models/registrar.rb | 3 ++- test/models/invoice_test.rb | 33 ++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 4d3d9f926..e5020d83f 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -99,12 +99,13 @@ class Registrar < ApplicationRecord } ] ) - SendEInvoiceJob.enqueue(invoice.id, payable: payable) unless payable InvoiceMailer.invoice_email(invoice: invoice, recipient: billing_email).deliver_now end + SendEInvoiceJob.enqueue(invoice.id, payable: payable) + invoice end diff --git a/test/models/invoice_test.rb b/test/models/invoice_test.rb index 6ee2dc85c..300de3a58 100644 --- a/test/models/invoice_test.rb +++ b/test/models/invoice_test.rb @@ -1,6 +1,8 @@ require 'test_helper' class InvoiceTest < ActiveSupport::TestCase + include ActionMailer::TestHelper + setup do @invoice = invoices(:one) end @@ -110,15 +112,32 @@ class InvoiceTest < ActiveSupport::TestCase assert_equal 'street, city, state', invoice.seller_address end - def test_assumes_correct_sum_amount_when_created_by_transaction + def test_creates_invoice_with_bank_transaction_total registrar = registrars(:bestnames) + transaction = bank_transactions(:one).dup + transaction.reference_no = registrar.reference_no + transaction.sum = 250 - bank_transaction = bank_transactions(:one).dup - bank_transaction.reference_no = registrar.reference_no - bank_transaction.sum = 5 - bank_transaction.save + invoice = Invoice.create_from_transaction!(transaction) + assert_equal 250, invoice.total - invoice = Invoice.create_from_transaction!(bank_transaction) - assert_equal 5, invoice.total + transaction.sum = 146.88 + invoice = Invoice.create_from_transaction!(transaction) + assert_equal 146.88, invoice.total + + transaction.sum = 0.99 + invoice = Invoice.create_from_transaction!(transaction) + assert_equal 0.99, invoice.total + end + + def test_emails_invoice_after_creating_topup_invoice + registrar = registrars(:bestnames) + transaction = bank_transactions(:one).dup + transaction.reference_no = registrar.reference_no + transaction.sum = 250 + + Invoice.create_from_transaction!(transaction) + + assert_emails 1 end end From f143be47ff60e3efe29837788a223deef2fffb35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 10 Sep 2020 13:55:38 +0300 Subject: [PATCH 47/61] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f2dc4016..58302a0b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +10.09.2020 +* New registrar ref nr are now always created 7 digits long [#1679](https://github.com/internetee/registry/pull/1679) + 08.09.2020 * Removed bank statement import option [#1674](https://github.com/internetee/registry/pull/1674) * Fixed error with reference nr not being found in the transaction [#1677](https://github.com/internetee/registry/issues/1677) From 18aa7e3d63ba21892724eacee1ba6f16035c1db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 10 Sep 2020 14:14:42 +0300 Subject: [PATCH 48/61] Fix CC issues --- app/models/bank_transaction.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 5a70a4380..e5ae76505 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -42,8 +42,7 @@ class BankTransaction < ApplicationRecord return unless autobindable? channel = manual ? 'admin_payment' : 'system_payment' - create_internal_payment_record(channel: channel, invoice: invoice, - registrar: registrar) + create_internal_payment_record(channel: channel, invoice: invoice, registrar: registrar) end def create_internal_payment_record(channel: nil, invoice:, registrar:) @@ -92,12 +91,11 @@ class BankTransaction < ApplicationRecord end def create_activity(registrar, invoice) - activity = AccountActivity.new( - account: registrar.cash_account, bank_transaction: self, - invoice: invoice, sum: invoice.subtotal, - currency: currency, description: description, - activity_type: AccountActivity::ADD_CREDIT - ) + activity = AccountActivity.new(account: registrar.cash_account, bank_transaction: self, + invoice: invoice, sum: invoice.subtotal, + currency: currency, description: description, + activity_type: AccountActivity::ADD_CREDIT) + if activity.save reset_pending_registrar_balance_reload true From 8a5208057a271fe74212f10998f2424f007e5153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 10 Sep 2020 16:38:27 +0300 Subject: [PATCH 49/61] Fix parsing from ref number --- app/models/bank_transaction.rb | 7 +++---- test/models/invoice_test.rb | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index e5ae76505..24bf51e0c 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -118,12 +118,11 @@ class BankTransaction < ApplicationRecord end def ref_number_from_description - (Billing::ReferenceNo::MULTI_REGEXP.match(description) || []).captures.each do |match| - break match if match.length == 7 || valid_ref_no?(match) - end + matches = description.to_s.scan(Billing::ReferenceNo::MULTI_REGEXP).flatten + matches.detect { |m| break m if m.length == 7 || valid_ref_no?(m) } end def valid_ref_no?(match) - return true if Billing::ReferenceNo.valid?(match) && Registrar.find_by(reference_no: match).any? + return true if Billing::ReferenceNo.valid?(match) && Registrar.find_by(reference_no: match) end end diff --git a/test/models/invoice_test.rb b/test/models/invoice_test.rb index 300de3a58..150e8032c 100644 --- a/test/models/invoice_test.rb +++ b/test/models/invoice_test.rb @@ -136,8 +136,8 @@ class InvoiceTest < ActiveSupport::TestCase transaction.reference_no = registrar.reference_no transaction.sum = 250 - Invoice.create_from_transaction!(transaction) - - assert_emails 1 + assert_emails 1 do + Invoice.create_from_transaction!(transaction) + end end end From 90b5baa29dfc7efc287ce130818a4dd6f1735baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 10 Sep 2020 17:30:39 +0300 Subject: [PATCH 50/61] Test reference_no parsing from transaction description --- test/models/bank_transaction_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/models/bank_transaction_test.rb b/test/models/bank_transaction_test.rb index 944b47573..9a9b02a74 100644 --- a/test/models/bank_transaction_test.rb +++ b/test/models/bank_transaction_test.rb @@ -156,6 +156,24 @@ class BankTransactionTest < ActiveSupport::TestCase assert transaction.errors.full_messages.include?('Cannot bind cancelled invoice') end + def test_assumes_7_digit_number_is_reference_no_in_desc + statement = BankTransaction.new + statement.description = 'number 1234567 defo valid' + assert_equal '1234567', statement.parsed_ref_number + end + + def test_determines_correct_ref_no_from_description + statement = BankTransaction.new + ref_no = registrars(:bestnames).reference_no + statement.description = "invoice 123 125 55 4521 #{ref_no} 7541 defo valid" + assert_equal ref_no.to_s, statement.parsed_ref_number + end + + def test_parsed_ref_no_returns_nil_if_ref_not_found + statement = BankTransaction.new + statement.description = "all invalid 12 123 55 77777 --" + assert_nil statement.parsed_ref_number + end private def create_payable_invoice(attributes) From a2b26a0c820276b4e13b383004643b0ed25e6dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Fri, 11 Sep 2020 11:39:49 +0300 Subject: [PATCH 51/61] Reference master git branch of e_invoice gem --- Gemfile | 2 +- Gemfile.lock | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 95abfc56a..12b826e3c 100644 --- a/Gemfile +++ b/Gemfile @@ -64,7 +64,7 @@ gem 'jquery-ui-rails', '5.0.5' gem 'airbrake' gem 'company_register', github: 'internetee/company_register', branch: :master -gem 'e_invoice', github: 'internetee/e_invoice', branch: 'make-payable-configurable' +gem 'e_invoice', github: 'internetee/e_invoice', branch: :master gem 'lhv', github: 'internetee/lhv', branch: 'master' gem 'domain_name' gem 'haml', '~> 5.0' diff --git a/Gemfile.lock b/Gemfile.lock index 8a154953e..a49c9becb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,8 +18,8 @@ GIT GIT remote: https://github.com/internetee/e_invoice.git - revision: 8a1aea2a1f0d46e1a8f3145b7b46a1810318d229 - branch: make-payable-configurable + revision: 5f8d0029bf1affdbf2bd6e3d1ce87d34066add4d + branch: master specs: e_invoice (0.1.0) builder (~> 3.2) @@ -238,7 +238,7 @@ GEM http-cookie (1.0.3) domain_name (~> 0.5) httpclient (2.8.3) - httpi (2.4.4) + httpi (2.4.5) rack socksify i18n (1.8.5) @@ -467,7 +467,8 @@ GEM i18n warden (1.2.8) rack (>= 2.0.6) - wasabi (3.5.0) + wasabi (3.6.1) + addressable httpi (~> 2.0) nokogiri (>= 1.4.2) webdrivers (4.4.1) From 3a0112becab62fa8af88ddac78b3ae391bd50517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Fri, 11 Sep 2020 11:50:20 +0300 Subject: [PATCH 52/61] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58302a0b4..636053ea3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +11.09.2020 +* Registrars can now top up their credit accounts without generating invoice in advance [#1101](https://github.com/internetee/registry/issues/1101) + 10.09.2020 * New registrar ref nr are now always created 7 digits long [#1679](https://github.com/internetee/registry/pull/1679) From 2ef430a87716f57ffbbc23bda6d5bf0054af9c61 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Fri, 11 Sep 2020 15:53:46 +0500 Subject: [PATCH 53/61] Fix typo in setting key --- app/models/epp/domain.rb | 2 +- ...20200911104302_fix_typo_in_setting_name.rb | 11 ++++++++++ db/seeds.rb | 2 +- test/fixtures/setting_entries.yml | 4 ++-- .../epp/domain/update/base_test.rb | 22 +++++++++---------- 5 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 db/data/20200911104302_fix_typo_in_setting_name.rb diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 7cfe3107a..3ed26f0e1 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -500,7 +500,7 @@ class Epp::Domain < Domain frame.css('registrant').attr('verified').to_s.downcase != 'yes' if registrant_verification_needed && errors.empty? && verify && - Setting.request_confrimation_on_registrant_change_enabled && + Setting.request_confirmation_on_registrant_change_enabled && unverified_registrant_params registrant_verification_asked!(frame.to_s, current_user.id) unless disputed? end diff --git a/db/data/20200911104302_fix_typo_in_setting_name.rb b/db/data/20200911104302_fix_typo_in_setting_name.rb new file mode 100644 index 000000000..9dd2b3b2b --- /dev/null +++ b/db/data/20200911104302_fix_typo_in_setting_name.rb @@ -0,0 +1,11 @@ +class FixTypoInSettingName < ActiveRecord::Migration[6.0] + def up + setting = Setting.find_by(code: 'request_confrimation_on_registrant_change_enabled') + setting.update(code: 'request_confirmation_on_registrant_change_enabled') + end + + def down + setting = Setting.find_by(code: 'request_confirmation_on_registrant_change_enabled') + setting.update(code: 'request_confrimation_on_registrant_change_enabled') + end +end diff --git a/db/seeds.rb b/db/seeds.rb index c74136b9d..691c18b0f 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -26,7 +26,7 @@ ActiveRecord::Base.transaction do SettingEntry.create(code: 'client_side_status_editing_enabled', value: 'false', format: 'boolean', group: 'other') SettingEntry.create(code: 'api_ip_whitelist_enabled', value: 'false', format: 'boolean', group: 'other') SettingEntry.create(code: 'registrar_ip_whitelist_enabled', value: 'false', format: 'boolean', group: 'other') - SettingEntry.create(code: 'request_confrimation_on_registrant_change_enabled', value: 'true', format: 'boolean', group: 'other') + SettingEntry.create(code: 'request_confirmation_on_registrant_change_enabled', value: 'true', format: 'boolean', group: 'other') SettingEntry.create(code: 'request_confirmation_on_domain_deletion_enabled', value: 'true', format: 'boolean', group: 'other') SettingEntry.create(code: 'default_language', value: 'en', format: 'string', group: 'other') SettingEntry.create(code: 'invoice_number_min', value: '131050', format: 'integer', group: 'billing') diff --git a/test/fixtures/setting_entries.yml b/test/fixtures/setting_entries.yml index 067f77c12..78db36465 100644 --- a/test/fixtures/setting_entries.yml +++ b/test/fixtures/setting_entries.yml @@ -182,8 +182,8 @@ registrar_ip_whitelist_enabled: created_at: <%= Time.zone.parse('2010-07-05') %> updated_at: <%= Time.zone.parse('2010-07-05') %> -request_confrimation_on_registrant_change_enabled: - code: request_confrimation_on_registrant_change_enabled +request_confirmation_on_registrant_change_enabled: + code: request_confirmation_on_registrant_change_enabled value: 'true' group: other format: boolean diff --git a/test/integration/epp/domain/update/base_test.rb b/test/integration/epp/domain/update/base_test.rb index de1ba84d8..6ce455948 100644 --- a/test/integration/epp/domain/update/base_test.rb +++ b/test/integration/epp/domain/update/base_test.rb @@ -6,12 +6,12 @@ class EppDomainUpdateBaseTest < EppTestCase setup do @domain = domains(:shop) @original_registrant_change_verification = - Setting.request_confrimation_on_registrant_change_enabled + Setting.request_confirmation_on_registrant_change_enabled ActionMailer::Base.deliveries.clear end teardown do - Setting.request_confrimation_on_registrant_change_enabled = + Setting.request_confirmation_on_registrant_change_enabled = @original_registrant_change_verification end @@ -87,7 +87,7 @@ class EppDomainUpdateBaseTest < EppTestCase end def test_requires_verification_from_current_registrant_when_provided_registrant_is_a_new_one - Setting.request_confrimation_on_registrant_change_enabled = true + Setting.request_confirmation_on_registrant_change_enabled = true new_registrant = contacts(:william).becomes(Registrant) assert_not_equal new_registrant, @domain.registrant @@ -124,7 +124,7 @@ class EppDomainUpdateBaseTest < EppTestCase end def test_requires_verification_from_current_registrant_when_not_yet_verified_by_registrar - Setting.request_confrimation_on_registrant_change_enabled = true + Setting.request_confirmation_on_registrant_change_enabled = true new_registrant = contacts(:william) assert_not_equal new_registrant, @domain.registrant @@ -161,7 +161,7 @@ class EppDomainUpdateBaseTest < EppTestCase end def test_updates_registrant_when_legaldoc_is_not_mandatory - Setting.request_confrimation_on_registrant_change_enabled = true + Setting.request_confirmation_on_registrant_change_enabled = true new_registrant = contacts(:william) assert_not_equal new_registrant, @domain.registrant @@ -197,7 +197,7 @@ class EppDomainUpdateBaseTest < EppTestCase end def test_dows_not_update_registrant_when_legaldoc_is_mandatory - Setting.request_confrimation_on_registrant_change_enabled = true + Setting.request_confirmation_on_registrant_change_enabled = true old_value = Setting.legal_document_is_mandatory Setting.legal_document_is_mandatory = true new_registrant = contacts(:william) @@ -226,7 +226,7 @@ class EppDomainUpdateBaseTest < EppTestCase end def test_skips_verification_when_provided_registrant_is_the_same_as_current_one - Setting.request_confrimation_on_registrant_change_enabled = true + Setting.request_confirmation_on_registrant_change_enabled = true request_xml = <<-XML @@ -260,7 +260,7 @@ class EppDomainUpdateBaseTest < EppTestCase end def test_skips_verification_when_registrant_changed_with_dispute_password - Setting.request_confrimation_on_registrant_change_enabled = true + Setting.request_confirmation_on_registrant_change_enabled = true dispute = disputes(:expired) dispute.update!(starts_at: Time.zone.now, expires_at: Time.zone.now + 5.days, closed: nil) new_registrant = contacts(:william) @@ -303,7 +303,7 @@ class EppDomainUpdateBaseTest < EppTestCase end def test_skips_verification_when_disabled - Setting.request_confrimation_on_registrant_change_enabled = false + Setting.request_confirmation_on_registrant_change_enabled = false new_registrant = contacts(:william).becomes(Registrant) assert_not_equal new_registrant, @domain.registrant @@ -340,7 +340,7 @@ class EppDomainUpdateBaseTest < EppTestCase end def test_skips_verification_from_current_registrant_when_already_verified_by_registrar - Setting.request_confrimation_on_registrant_change_enabled = true + Setting.request_confirmation_on_registrant_change_enabled = true new_registrant = contacts(:william).becomes(Registrant) assert_not_equal new_registrant, @domain.registrant @@ -377,7 +377,7 @@ class EppDomainUpdateBaseTest < EppTestCase end def test_clears_force_delete_when_registrar_changed - Setting.request_confrimation_on_registrant_change_enabled = true + Setting.request_confirmation_on_registrant_change_enabled = true new_registrant = contacts(:william).becomes(Registrant) @domain.schedule_force_delete(type: :fast_track) assert_not_equal new_registrant, @domain.registrant From 66288fe16075707f18e8e7fd71aba473a23d362c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Fri, 11 Sep 2020 15:17:18 +0300 Subject: [PATCH 54/61] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 636053ea3..33dbdcefa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ 11.09.2020 * Registrars can now top up their credit accounts without generating invoice in advance [#1101](https://github.com/internetee/registry/issues/1101) +* Fixed typo in admin settings [#371](https://github.com/internetee/registry/issues/371) 10.09.2020 * New registrar ref nr are now always created 7 digits long [#1679](https://github.com/internetee/registry/pull/1679) From e03ae63acfb1c0e1de42ea980ece29206a2bbf99 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 16 Sep 2018 16:53:02 +0300 Subject: [PATCH 55/61] Remove PaperTrail columns from `prices` DB table PaperTrail's `Version` model itself has been removed in #475, so those columns are now useless --- ...20180916133911_remove_paper_trail_columns_from_prices.rb | 6 ++++++ db/structure.sql | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb diff --git a/db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb b/db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb new file mode 100644 index 000000000..a30aa939a --- /dev/null +++ b/db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb @@ -0,0 +1,6 @@ +class RemovePaperTrailColumnsFromPrices < ActiveRecord::Migration + def change + remove_column :prices, :creator_str + remove_column :prices, :updator_str + end +end diff --git a/db/structure.sql b/db/structure.sql index 912946c60..2567cbca9 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2092,8 +2092,6 @@ CREATE TABLE public.prices ( price_cents integer NOT NULL, valid_from timestamp without time zone, valid_to timestamp without time zone, - creator_str character varying, - updator_str character varying, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, duration interval, @@ -4854,3 +4852,5 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200910085157'); +INSERT INTO schema_migrations (version) VALUES ('20180916133911'); + From 86ea2319c80ef0aebf999db4dedb6449e6206213 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 10 Sep 2020 15:55:30 +0500 Subject: [PATCH 56/61] Add versions table/model for prices --- app/models/billing/price.rb | 1 + app/models/version/billing/price_version.rb | 7 ++ ..._remove_paper_trail_columns_from_prices.rb | 6 -- ...0200910102028_create_version_for_prices.rb | 26 +++++++ db/structure.sql | 68 ++++++++++++++++--- 5 files changed, 92 insertions(+), 16 deletions(-) create mode 100644 app/models/version/billing/price_version.rb delete mode 100644 db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb create mode 100644 db/migrate/20200910102028_create_version_for_prices.rb diff --git a/app/models/billing/price.rb b/app/models/billing/price.rb index 283a6e5bc..dac458b00 100644 --- a/app/models/billing/price.rb +++ b/app/models/billing/price.rb @@ -1,6 +1,7 @@ module Billing class Price < ApplicationRecord include Concerns::Billing::Price::Expirable + include Versions belongs_to :zone, class_name: 'DNS::Zone', required: true has_many :account_activities diff --git a/app/models/version/billing/price_version.rb b/app/models/version/billing/price_version.rb new file mode 100644 index 000000000..7502c18e2 --- /dev/null +++ b/app/models/version/billing/price_version.rb @@ -0,0 +1,7 @@ +module Billing + class PriceVersion < PaperTrail::Version + self.table_name = :log_prices + self.sequence_name = :log_prices_id_seq + end +end + diff --git a/db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb b/db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb deleted file mode 100644 index a30aa939a..000000000 --- a/db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb +++ /dev/null @@ -1,6 +0,0 @@ -class RemovePaperTrailColumnsFromPrices < ActiveRecord::Migration - def change - remove_column :prices, :creator_str - remove_column :prices, :updator_str - end -end diff --git a/db/migrate/20200910102028_create_version_for_prices.rb b/db/migrate/20200910102028_create_version_for_prices.rb new file mode 100644 index 000000000..85eea737f --- /dev/null +++ b/db/migrate/20200910102028_create_version_for_prices.rb @@ -0,0 +1,26 @@ +class CreateVersionForPrices < ActiveRecord::Migration[6.0] + def up + create_table :log_prices, force: :cascade do |t| + t.string :item_type, null: false + t.integer :item_id, null: false + t.string :event, null: false + t.string :whodunnit + t.json :object + t.json :object_changes + t.datetime :created_at + t.string :session + t.json :children + t.string :uuid + end + + add_index 'log_prices', ['item_type', 'item_id'], name: 'index_log_prices_on_item_type_and_item_id', using: :btree + add_index 'log_prices', ['whodunnit'], name: 'index_log_prices_on_whodunnit', using: :btree + end + + def down + remove_index :log_prices, name: 'index_log_prices_on_item_type_and_item_id' + remove_index :log_prices, name: 'index_log_prices_on_whodunnit' + + drop_table :log_prices + end +end diff --git a/db/structure.sql b/db/structure.sql index 2567cbca9..73d5f9436 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -371,6 +371,7 @@ CREATE TABLE public.bank_statements ( id integer NOT NULL, bank_code character varying, iban character varying, + import_file_path character varying, queried_at timestamp without time zone, created_at timestamp without time zone, updated_at timestamp without time zone, @@ -777,6 +778,7 @@ CREATE TABLE public.domains ( id integer NOT NULL, name character varying NOT NULL, registrar_id integer NOT NULL, + registered_at timestamp without time zone, valid_to timestamp without time zone NOT NULL, registrant_id integer NOT NULL, transfer_code character varying NOT NULL, @@ -1706,7 +1708,45 @@ ALTER SEQUENCE public.log_payment_orders_id_seq OWNED BY public.log_payment_orde -- --- Name: log_registrant_verifications; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- Name: log_prices; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.log_prices ( + id bigint NOT NULL, + item_type character varying NOT NULL, + item_id integer NOT NULL, + event character varying NOT NULL, + whodunnit character varying, + object json, + object_changes json, + created_at timestamp without time zone, + session character varying, + children json, + uuid character varying +); + + +-- +-- Name: log_prices_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.log_prices_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: log_prices_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.log_prices_id_seq OWNED BY public.log_prices.id; + + +-- +-- Name: log_registrant_verifications; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.log_registrant_verifications ( @@ -2084,7 +2124,7 @@ ALTER SEQUENCE public.payment_orders_id_seq OWNED BY public.payment_orders.id; -- --- Name: prices; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- Name: prices; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.prices ( @@ -2096,7 +2136,9 @@ CREATE TABLE public.prices ( updated_at timestamp without time zone NOT NULL, duration interval, operation_category character varying, - zone_id integer NOT NULL + zone_id integer NOT NULL, + updator_str character varying, + creator_str character varying ); @@ -3302,7 +3344,15 @@ ALTER TABLE ONLY public.log_payment_orders -- --- Name: log_registrant_verifications_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- Name: log_prices log_prices_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.log_prices + ADD CONSTRAINT log_prices_pkey PRIMARY KEY (id); + + +-- +-- Name: log_registrant_verifications log_registrant_verifications_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.log_registrant_verifications @@ -3310,7 +3360,7 @@ ALTER TABLE ONLY public.log_registrant_verifications -- --- Name: log_registrars_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- Name: log_registrars log_registrars_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.log_registrars @@ -4751,6 +4801,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20180825193437'), ('20180825232819'), ('20180826162821'), +('20180916133911'), ('20181001090536'), ('20181002090319'), ('20181017092829'), @@ -4824,7 +4875,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20191203083643'), ('20191206183853'), ('20191212133136'), -('20191217013225'), ('20191219112434'), ('20191219124429'), ('20191227110904'), @@ -4849,8 +4899,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200812090409'), ('20200812125810'), ('20200908131554'), -('20200910085157'); - - -INSERT INTO schema_migrations (version) VALUES ('20180916133911'); +('20200910085157'), +('20200910102028'); From 6d908f6969892b90cf08dd51b4ec200652156313 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 10 Sep 2020 16:21:42 +0500 Subject: [PATCH 57/61] Revert "Remove PaperTrail columns from `prices` DB table" This reverts commit 5aa949847ad391f72d6df5bf714573012a7d9cec. --- db/structure.sql | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/db/structure.sql b/db/structure.sql index 73d5f9436..15958ec0a 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -371,7 +371,6 @@ CREATE TABLE public.bank_statements ( id integer NOT NULL, bank_code character varying, iban character varying, - import_file_path character varying, queried_at timestamp without time zone, created_at timestamp without time zone, updated_at timestamp without time zone, @@ -778,7 +777,6 @@ CREATE TABLE public.domains ( id integer NOT NULL, name character varying NOT NULL, registrar_id integer NOT NULL, - registered_at timestamp without time zone, valid_to timestamp without time zone NOT NULL, registrant_id integer NOT NULL, transfer_code character varying NOT NULL, @@ -2124,7 +2122,7 @@ ALTER SEQUENCE public.payment_orders_id_seq OWNED BY public.payment_orders.id; -- --- Name: prices; Type: TABLE; Schema: public; Owner: - +-- Name: prices; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.prices ( @@ -2132,13 +2130,13 @@ CREATE TABLE public.prices ( price_cents integer NOT NULL, valid_from timestamp without time zone, valid_to timestamp without time zone, + updator_str character varying, + creator_str character varying, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, duration interval, operation_category character varying, - zone_id integer NOT NULL, - updator_str character varying, - creator_str character varying + zone_id integer NOT NULL ); @@ -2878,7 +2876,14 @@ ALTER TABLE ONLY public.log_payment_orders ALTER COLUMN id SET DEFAULT nextval(' -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: log_prices id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.log_prices ALTER COLUMN id SET DEFAULT nextval('public.log_prices_id_seq'::regclass); + + +-- +-- Name: log_registrant_verifications id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.log_registrant_verifications ALTER COLUMN id SET DEFAULT nextval('public.log_registrant_verifications_id_seq'::regclass); @@ -3360,7 +3365,7 @@ ALTER TABLE ONLY public.log_registrant_verifications -- --- Name: log_registrars log_registrars_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: log_registrars_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.log_registrars @@ -4801,7 +4806,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20180825193437'), ('20180825232819'), ('20180826162821'), -('20180916133911'), ('20181001090536'), ('20181002090319'), ('20181017092829'), @@ -4875,6 +4879,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20191203083643'), ('20191206183853'), ('20191212133136'), +('20191217013225'), ('20191219112434'), ('20191219124429'), ('20191227110904'), From ad73a3876b9332e98c354a5805f442a1a5417eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Mon, 14 Sep 2020 14:07:05 +0300 Subject: [PATCH 58/61] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33dbdcefa..c5b9e489b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +14.09.2020 +* Restored version logging for registry prices [#980](https://github.com/internetee/registry/pull/980) + 11.09.2020 * Registrars can now top up their credit accounts without generating invoice in advance [#1101](https://github.com/internetee/registry/issues/1101) * Fixed typo in admin settings [#371](https://github.com/internetee/registry/issues/371) From 764e35e198988a1ab7fcf46c9ca806fe1cd82eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 15 Sep 2020 12:43:40 +0300 Subject: [PATCH 59/61] Make payable argument required --- app/jobs/send_e_invoice_job.rb | 2 +- app/models/registrar.rb | 2 +- test/jobs/send_e_invoice_job_test.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/jobs/send_e_invoice_job.rb b/app/jobs/send_e_invoice_job.rb index 91e068b9f..e3880963e 100644 --- a/app/jobs/send_e_invoice_job.rb +++ b/app/jobs/send_e_invoice_job.rb @@ -1,5 +1,5 @@ class SendEInvoiceJob < Que::Job - def run(invoice_id, payable: true) + def run(invoice_id, payable = true) invoice = run_condition(Invoice.find_by(id: invoice_id), payable: payable) invoice.to_e_invoice(payable: payable).deliver diff --git a/app/models/registrar.rb b/app/models/registrar.rb index e5020d83f..e2ffcbfd4 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -104,7 +104,7 @@ class Registrar < ApplicationRecord InvoiceMailer.invoice_email(invoice: invoice, recipient: billing_email).deliver_now end - SendEInvoiceJob.enqueue(invoice.id, payable: payable) + SendEInvoiceJob.enqueue(invoice.id, payable) invoice end diff --git a/test/jobs/send_e_invoice_job_test.rb b/test/jobs/send_e_invoice_job_test.rb index 384479e92..86d761b42 100644 --- a/test/jobs/send_e_invoice_job_test.rb +++ b/test/jobs/send_e_invoice_job_test.rb @@ -13,7 +13,7 @@ class SendEInvoiceJobTest < ActiveSupport::TestCase EInvoice::Providers::TestProvider.deliveries.clear assert_nothing_raised do - SendEInvoiceJob.enqueue(@invoice.id) + SendEInvoiceJob.enqueue(@invoice.id, true) end @invoice.reload @@ -29,7 +29,7 @@ class SendEInvoiceJobTest < ActiveSupport::TestCase stub_request(:get, "https://testfinance.post.ee/finance/erp/erpServices.wsdl").to_timeout assert_raise HTTPClient::TimeoutError do - SendEInvoiceJob.enqueue(@invoice.id) + SendEInvoiceJob.enqueue(@invoice.id, true) end assert @invoicee_invoice_sent_at.blank? @@ -37,7 +37,7 @@ class SendEInvoiceJobTest < ActiveSupport::TestCase EInvoice::Providers::TestProvider.deliveries.clear assert_nothing_raised do - SendEInvoiceJob.enqueue(@invoice.id) + SendEInvoiceJob.enqueue(@invoice.id, true) end @invoice.reload From 88b1b30be7c75fa9cae4758763e5fd12dd12cb6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 15 Sep 2020 16:12:03 +0300 Subject: [PATCH 60/61] Fix EInvoiceGenerator initializer method --- app/models/invoice.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 8e82bbea6..fb625f7b9 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -100,7 +100,7 @@ class Invoice < ApplicationRecord end def to_e_invoice(payable: true) - generator = Invoice::EInvoiceGenerator.new(self, payable: payable) + generator = Invoice::EInvoiceGenerator.new(self, payable) generator.generate end From 09e952184c4ba9b97da5fd2b0a9fd3d84fc3be04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 15 Sep 2020 17:15:39 +0300 Subject: [PATCH 61/61] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5b9e489b..66ba13df5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +15.09.2020 +* Fixed e-invoice sending issue with QUE [#1683](https://github.com/internetee/registry/pull/1683) + 14.09.2020 * Restored version logging for registry prices [#980](https://github.com/internetee/registry/pull/980)