Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Dockerfile.staging
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ RUN gem install bundler && \
# Copy application code
COPY . .

# Precompile assets in build stage (Node.js 14 is available here)
# Use dummy SECRET_KEY_BASE for asset precompilation only
ARG SECRET_KEY_BASE=dummy_key_for_assets_precompilation
ENV SECRET_KEY_BASE=${SECRET_KEY_BASE}
RUN RAILS_ENV=staging bundle exec rails assets:precompile && \
# Copy sample config for asset precompilation (real values come from env at runtime)
RUN cp config/application.yml.sample config/application.yml && \
cp config/database.yml.sample config/database.yml

# Precompile assets
RUN RAILS_ENV=staging SECRET_KEY_BASE=dummy_for_assets \
bundle exec rails assets:precompile && \
echo "Assets precompiled successfully for staging" && \
ls -la public/assets/ | head -20

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/repp/v1/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def details
api_users: serialized_users(current_user.api_users),
white_ips: serialized_ips(registrar.white_ips),
balance_auto_reload: type,
accept_pdf_invoices: registrar.accept_pdf_invoices,
min_deposit: Setting.minimum_deposit },
roles: ApiUser::ROLES,
interfaces: WhiteIp::INTERFACES }
Expand Down Expand Up @@ -117,7 +118,7 @@ def balance
private

def account_params
params.require(:account).permit(:billing_email, :iban, :new_user_id)
params.require(:account).permit(:billing_email, :iban, :new_user_id, :accept_pdf_invoices)
end

def index_params
Expand Down
26 changes: 24 additions & 2 deletions app/models/contact/company_register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def return_company_status
end

def return_company_data
return unless org?
return unless is_contact_estonian_org?

company_register.simple_data(registration_number: ident.to_s)
rescue CompanyRegister::NotAvailableError
Expand All @@ -25,7 +25,7 @@ def return_company_data
end

def return_company_details
return unless org?
return unless is_contact_estonian_org?

company_register.company_details(registration_number: ident.to_s)
rescue CompanyRegister::SOAPFaultError => e
Expand All @@ -35,6 +35,28 @@ def return_company_details
[]
end

def e_invoice_recipients
return unless is_contact_estonian_org?

company_register.e_invoice_recipients(registration_numbers: ident.to_s)
rescue CompanyRegister::SOAPFaultError => e
Rails.logger.error("SOAP Fault getting company details for #{ident}: #{e.message}")
raise e
rescue CompanyRegister::NotAvailableError
[]
end

def org_contact_accept_e_invoice?
return unless is_contact_estonian_org?

result = e_invoice_recipients.first
result.status == 'OK'
end

def is_contact_estonian_org?
org? && ident_country_code == 'EE'
end

def company_register
@company_register ||= CompanyRegister::Client.new
end
Expand Down
16 changes: 15 additions & 1 deletion app/models/registrar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def issue_prepayment_invoice(amount, description = nil, payable: true)
]
)

unless payable
unless payable && (accepts_e_invoices? && !accept_pdf_invoices?)
InvoiceMailer.invoice_email(invoice: invoice, recipient: billing_email, paid: !payable)
.deliver_later(wait: 1.minute)
end
Expand Down Expand Up @@ -307,6 +307,20 @@ def billing_email
self[:billing_email]
end

def accepts_e_invoices?
return false unless address_country_code == 'EE'

result = company_register.e_invoice_recipients(registration_numbers: reg_no).first
result.status == 'OK'
rescue CompanyRegister::NotAvailableError, CompanyRegister::SOAPFaultError => e
Rails.logger.error("Error checking e-invoice status for #{reg_no}: #{e.message}")
false
end

def company_register
@company_register ||= CompanyRegister::Client.new
end

private

def domain_not_updatable?(hostname:, domain:)
Expand Down
4 changes: 2 additions & 2 deletions config/application.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ release_domains_to_auction: 'true'
auction_api_allowed_ips: '' # 192.0.2.0, 192.0.2.1

action_mailer_default_protocol: # default: http
action_mailer_default_host:
action_mailer_default_host: 'registry.staging'
action_mailer_default_port: # default: no port (80)
action_mailer_default_from: # no-reply@example.com
action_mailer_default_from: 'no-reply@registry.staging'
action_mailer_force_delete_from: # `From` header for `DomainDeleteMailer#forced` email

lhv_p12_keystore:
Expand Down
9 changes: 7 additions & 2 deletions config/database.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ default: &default
#

staging:
<<: *default
database: registry_staging
primary:
<<: *default
database: registry_staging
primary_replica:
<<: *default
database: registry_staging
replica: true

demo:
<<: *default
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20251230104312_accept_pdf_invoices.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AcceptPdfInvoices < ActiveRecord::Migration[6.1]
def change
add_column :registrars, :accept_pdf_invoices, :boolean, default: true
end
end
23 changes: 16 additions & 7 deletions db/structure.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
\restrict manNM7YktJCYjflsdAWd12PkDkR5VB5nDAhRVyBVVHwcDScSXNtcviWOHPpPk1Q

-- Dumped from database version 13.4 (Debian 13.4-4.pgdg110+1)
-- Dumped by pg_dump version 13.22 (Debian 13.22-0+deb11u1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
Expand Down Expand Up @@ -2642,7 +2647,8 @@ CREATE TABLE public.registrars (
settings jsonb DEFAULT '{}'::jsonb NOT NULL,
legaldoc_optout boolean DEFAULT false NOT NULL,
legaldoc_optout_comment text,
email_history character varying
email_history character varying,
accept_pdf_invoices boolean DEFAULT true
);


Expand Down Expand Up @@ -5280,6 +5286,8 @@ ALTER TABLE ONLY public.users
-- PostgreSQL database dump complete
--

\unrestrict manNM7YktJCYjflsdAWd12PkDkR5VB5nDAhRVyBVVHwcDScSXNtcviWOHPpPk1Q

SET search_path TO "$user", public;

INSERT INTO "schema_migrations" (version) VALUES
Expand Down Expand Up @@ -5768,10 +5776,13 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230707084741'),
('20230710120154'),
('20230711083811'),
('20240722085530'),
('20240723110208'),
('20240816091049'),
('20240816092636'),
('20240924103554'),
('20241015071505'),
('20241022121525'),
('20241030095636'),
('20241104104620'),
('20241112093540'),
Expand All @@ -5780,13 +5791,11 @@ INSERT INTO "schema_migrations" (version) VALUES
('20241206085817'),
('20250204094550'),
('20250219102811'),
('20250313122119'),
('20250319104749'),
('20250310133151'),
('20250313122119'),
('20250314133357'),
('20240722085530'),
('20240723110208'),
('20241022121525'),
('20250627084536');
('20250627084536'),
('20250319104749'),
('20251230104312');


45 changes: 45 additions & 0 deletions lib/tasks/disclose_phone_numbers.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# rake disclose_phone_numbers:disclose

namespace :disclose_phone_numbers do
desc 'Disclose phone numbers'
task disclose: :environment do
reg_numbers = %w[
10597973
10890199
10096260
10784403
10641728
10762679
10557933
12659649
12176224
90010019
10960801
16406158
10510593
70000740
10838419
11099473
451394720
10647754
10176042
14127885
11163283
11685113
14281238
10098106
10577829
10234957
12345678
11072764
11100236
]

reg_numbers.each do |reg_no|
registrar = Registrar.find_by(reg_no: reg_no)
registrar.update!(accept_pdf_invoices: false)

Rails.logger.info("For registrar with name #{registrar.name} and reg no #{registrar.reg_no} set accept_pdf_invoices to false")
end
end
end
2 changes: 2 additions & 0 deletions test/models/contact/company_register_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
class CompanyRegisterTest < ActiveSupport::TestCase
def setup
@acme_ltd = contacts(:acme_ltd)
@acme_ltd.update!(ident_country_code: 'EE', ident_type: 'org', ident: '12345678')

@john = contacts(:john)
@company_register_stub = CompanyRegister::Client.new
end
Expand Down
55 changes: 55 additions & 0 deletions test/models/registrar/invoice_email_cancellation_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'test_helper'

class RegistrarInvoiceEmailCancellationTest < ActiveJob::TestCase
setup do
@registrar = registrars(:bestnames)
@registrar.update!(address_country_code: 'EE', reference_no: '1232', vat_rate: 24)
@invoice_params = 100

stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
to_return(status: 200, body: "{\"invoice_number\":\"123456\"}", headers: {})

stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})

stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
to_return(status: 200, body: "{\"invoice_number\":\"123456\"}, {\"date\":\"#{Time.zone.now}\"}", headers: {})

stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
end

def test_sends_email_when_registrar_does_not_accept_e_invoices_and_pdf_opt_in_is_true
# Name does not contain 'einvoice', so stub returns 'MR' (not OK)
@registrar.update!(name: 'simple-registrar', accept_pdf_invoices: true)

assert_enqueued_jobs 1, only: ActionMailer::MailDeliveryJob do
@registrar.issue_prepayment_invoice(@invoice_params)
end
end

def test_sends_email_when_registrar_does_not_accept_e_invoices_and_pdf_opt_in_is_false
# Name does not contain 'einvoice', so stub returns 'MR' (not OK)
@registrar.update!(name: 'simple-registrar', accept_pdf_invoices: false)

assert_enqueued_jobs 1, only: ActionMailer::MailDeliveryJob do
@registrar.issue_prepayment_invoice(@invoice_params)
end
end

def test_skips_email_when_registrar_accepts_e_invoices_and_pdf_opt_in_is_false
@registrar.update!(name: 'einvoice-registrar', accept_pdf_invoices: false)

assert_enqueued_jobs 0, only: ActionMailer::MailDeliveryJob do
@registrar.issue_prepayment_invoice(@invoice_params)
end
end

def test_sends_email_when_registrar_accepts_e_invoices_BUT_pdf_opt_in_is_true
@registrar.update!(name: 'einvoice-registrar', accept_pdf_invoices: true)

assert_enqueued_jobs 1, only: ActionMailer::MailDeliveryJob do
@registrar.issue_prepayment_invoice(@invoice_params)
end
end
end
9 changes: 9 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ def simple_data(registration_number:)
def company_details(registration_number:)
[]
end

def e_invoice_recipients(registration_numbers:)
if ::Registrar.exists?(reg_no: registration_numbers)
registrar = ::Registrar.find_by(reg_no: registration_numbers)
status = registrar.name.include?('einvoice') ? 'OK' : 'MR'
return [Struct.new(:status).new(status)]
end
[Struct.new(:status).new('OK')]
end
end

CompanyRegister::Client = CompanyRegisterClientStub
Expand Down