Skip to content

Commit

Permalink
Update company_register gem and fix logger dependency
Browse files Browse the repository at this point in the history
- Switch company_register gem to 'issues-with-upcoming-data' branch
- Add concurrent-ruby 1.3.4 to fix ThreadSafeLevel logger error
- Update various gem dependencies

Resolves logger initialization error related to ActiveSupport::Logger::ThreadSafeLevel
  • Loading branch information
OlegPhenomenon committed Jan 29, 2025
1 parent c81aed0 commit d3d91b5
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 12 deletions.
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ gem 'redis'
gem 'sidekiq', '~> 7.0'

gem 'company_register', github: 'internetee/company_register',
branch: '4-check-for-company-existence'
branch: 'issues-with-upcoming-data'
gem 'domain_name'
gem 'e_invoice', github: 'internetee/e_invoice', branch: :master
gem 'haml', '~> 6.0'
Expand Down Expand Up @@ -108,3 +108,6 @@ gem 'pg_query', '>= 0.9.0'
# token
gem 'jwt'
gem 'net-ftp'

# https://stackoverflow.com/questions/79360526/uninitialized-constant-activesupportloggerthreadsafelevellogger-nameerror
gem 'concurrent-ruby', '1.3.4'
31 changes: 20 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/internetee/company_register.git
revision: 6465d5c49478b9de5a5fa009cb6b8123b3956dd1
branch: 4-check-for-company-existence
revision: 1e91fec78212d7e549a1c2362c011761a447bbcd
branch: issues-with-upcoming-data
specs:
company_register (0.1.0)
activesupport
Expand Down Expand Up @@ -170,7 +170,7 @@ GEM
aws-eventstream (~> 1, >= 1.0.2)
base64 (0.2.0)
bcrypt (3.1.16)
bigdecimal (3.1.8)
bigdecimal (3.1.9)
bindata (2.5.0)
bootsnap (1.17.1)
msgpack (~> 1.2)
Expand Down Expand Up @@ -270,7 +270,7 @@ GEM
mutex_m
nkf
rack (>= 2.0, < 4)
i18n (1.14.6)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
i18n_data (0.13.0)
isikukood (0.1.2)
Expand All @@ -282,7 +282,7 @@ GEM
thor (>= 0.14, < 2.0)
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
json (2.5.1)
json (2.9.1)
json-jwt (1.16.6)
activesupport (>= 4.2)
aes_key_wrap
Expand All @@ -304,12 +304,15 @@ GEM
kaminari-core (= 1.2.1)
kaminari-core (1.2.1)
libxml-ruby (3.2.1)
logger (1.4.3)
logger (1.6.5)
loofah (2.24.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.7.1)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
marcel (1.0.4)
matrix (0.4.2)
method_source (1.1.0)
Expand All @@ -321,7 +324,7 @@ GEM
rake
mini_mime (1.1.5)
mini_portile2 (2.8.8)
minitest (5.25.1)
minitest (5.25.4)
minitest-stub_any_instance (1.0.3)
monetize (1.9.4)
money (~> 6.12)
Expand All @@ -333,12 +336,17 @@ GEM
money (~> 6.13.2)
railties (>= 3.0)
msgpack (1.7.2)
mutex_m (0.2.0)
mutex_m (0.3.0)
net-ftp (0.3.7)
net-protocol
time
net-http (0.6.0)
uri
net-imap (0.4.18)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.1.3)
timeout
net-smtp (0.3.3)
Expand Down Expand Up @@ -452,7 +460,7 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.3.9)
rexml (3.4.0)
rubyzip (2.3.2)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
Expand Down Expand Up @@ -534,7 +542,7 @@ GEM
simpleidn
warden (1.2.9)
rack (>= 2.0.9)
wasabi (5.0.3)
wasabi (5.1.0)
addressable
faraday (>= 1.9, < 3)
nokogiri (>= 1.13.9)
Expand Down Expand Up @@ -571,6 +579,7 @@ DEPENDENCIES
capybara (~> 3.40.0)
coffee-rails (>= 5.0)
company_register!
concurrent-ruby (= 1.3.4)
countries
data_migrate (~> 9.0)
database_cleaner
Expand Down
93 changes: 93 additions & 0 deletions app/jobs/org_registrant_phone_checker_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
class OrgRegistrantPhoneCheckerJob < ApplicationJob
queue_as :default

def perform(type: 'bulk', registrant_user_code: nil, spam_delay: 1 )
case type
when 'bulk'
execute_bulk_checker(spam_delay)
when 'single'
execute_single_checker(registrant_user_code)
else
raise "Invalid type: #{type}. Allowed types: 'bulk', 'single'"
end
end

def execute_bulk_checker(spam_delay)
log("Bulk checker started")

Contact.where(ident_type: 'org', ident_country_code: 'EE').joins(:registrant_domains).each do |registrant_user|
is_phone_number_matching = check_the_registrant_phone_number(registrant_user)

call_disclosure_action(is_phone_number_matching, registrant_user)
sleep(spam_delay)
end

log("Bulk checker finished")
end

def execute_single_checker(registrant_user_code)
registrant_user = RegistrantUser.find_by(code: registrant_user_code)
is_phone_number_matching = check_the_registrant_phone_number(registrant_user)

call_disclosure_action(is_phone_number_matching, registrant_user)
end

private

def call_disclosure_action(is_phone_number_matching, contact)
if is_phone_number_matching
disclose_phone_number(contact)
log("Phone number disclosed for registrant user #{contact.code}. Phone number: #{contact.phone}")
elsif contact.disclosed_attributes.include?('phone')
log("Removing phone number from disclosed attributes for registrant user #{contact.code}. Phone number: #{contact.phone}")
contact.disclosed_attributes.delete('phone')
contact.save!
else
log("Phone number not disclosed for registrant user #{contact.code}. Phone number: #{contact.phone}")
end
end

def log(message)
Rails.logger.info(message)
end

def disclose_phone_number(contact)
contact.disclosed_attributes << 'phone'
contact.save!
end

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

def check_the_registrant_phone_number(registrant_user)
phone_numbers = fetch_phone_number_from_company_register(registrant_user.ident)

# TODO: implement phone number check
# If phone number is matching with registrant phone number, then return return true, else return false

phone_numbers.any? do |phone_number|
puts '---- business registry phone number ----'
puts phone_number
puts '---- registrant phone number ----'
puts registrant_user.phone
puts '---- format phone number ----'
puts format_phone_number(phone_number)
puts '---- format registrant phone number ----'
puts format_phone_number(registrant_user.phone)

format_phone_number(phone_number) == format_phone_number(registrant_user.phone)
end
end

def format_phone_number(phone_number)
# phone number from business registry is "+3725655662"
# we need to format it to "+3725655662"
phone_number.gsub(/\D/, '')
end

def fetch_phone_number_from_company_register(company_code)
data = company_register.company_details(registration_number: company_code.to_s)
data[0].phone_numbers
end
end

0 comments on commit d3d91b5

Please sign in to comment.