mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 17:28:18 +02:00
Update company_register gem and fix logger dependency
- 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
This commit is contained in:
parent
c81aed0c62
commit
d3d91b5294
3 changed files with 117 additions and 12 deletions
93
app/jobs/org_registrant_phone_checker_job.rb
Normal file
93
app/jobs/org_registrant_phone_checker_job.rb
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue