mirror of
https://github.com/internetee/registry.git
synced 2025-07-31 23:16:23 +02:00
Merge pull request #2741 from internetee/disclose-phone-num-for-org-registrants
Update company_register gem and fix logger dependency
This commit is contained in:
commit
268b942042
9 changed files with 282 additions and 19 deletions
|
@ -94,7 +94,6 @@ module Repp
|
|||
action = Actions::ContactUpdate.new(@contact, contact_params_with_address(required: false),
|
||||
contact_params[:legal_document],
|
||||
contact_ident_params(required: false), current_user)
|
||||
|
||||
unless action.call
|
||||
handle_errors(@contact)
|
||||
return
|
||||
|
|
|
@ -12,11 +12,12 @@ module Actions
|
|||
def call
|
||||
maybe_remove_address
|
||||
maybe_attach_legal_doc
|
||||
validate_ident
|
||||
maybe_validate_ident
|
||||
maybe_change_email
|
||||
# maybe_company_is_relevant
|
||||
commit
|
||||
validate_contact
|
||||
maybe_validate_phone_number
|
||||
maybe_validate_contact
|
||||
end
|
||||
|
||||
def maybe_change_email
|
||||
|
@ -45,7 +46,7 @@ module Actions
|
|||
contact.country_code = nil
|
||||
end
|
||||
|
||||
def validate_ident
|
||||
def maybe_validate_ident
|
||||
validate_ident_integrity
|
||||
validate_ident_birthday
|
||||
|
||||
|
@ -102,12 +103,16 @@ module Actions
|
|||
contact.save
|
||||
end
|
||||
|
||||
def validate_contact
|
||||
def maybe_validate_contact
|
||||
return if @error || !contact.valid?
|
||||
|
||||
[:regex, :mx].each do |m|
|
||||
contact.verify_email(check_level: m, single_email: true)
|
||||
end
|
||||
end
|
||||
|
||||
def maybe_validate_phone_number
|
||||
OrgRegistrantPhoneCheckerJob.perform_later(type: 'single', registrant_user_code: contact.code)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,8 @@ module Actions
|
|||
maybe_change_email if new_attributes[:email].present?
|
||||
maybe_filtering_old_failed_records
|
||||
commit
|
||||
validate_contact
|
||||
maybe_validate_phone_number
|
||||
maybe_validate_contact
|
||||
end
|
||||
|
||||
def maybe_change_email
|
||||
|
@ -125,7 +126,7 @@ module Actions
|
|||
updated
|
||||
end
|
||||
|
||||
def validate_contact
|
||||
def maybe_validate_contact
|
||||
return if @error || !contact.valid?
|
||||
|
||||
[:regex, :mx].each do |m|
|
||||
|
@ -134,5 +135,9 @@ module Actions
|
|||
|
||||
@contact.remove_force_delete_for_valid_contact
|
||||
end
|
||||
|
||||
def maybe_validate_phone_number
|
||||
OrgRegistrantPhoneCheckerJob.perform_later(type: 'single', registrant_user_code: contact.code)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
78
app/jobs/org_registrant_phone_checker_job.rb
Normal file
78
app/jobs/org_registrant_phone_checker_job.rb
Normal file
|
@ -0,0 +1,78 @@
|
|||
class OrgRegistrantPhoneCheckerJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(type: 'bulk', registrant_user_code: nil, spam_delay: 1)
|
||||
puts '??? PERFROMED ???'
|
||||
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 = Contact.where(ident_type: 'org', ident_country_code: 'EE').joins(:registrant_domains).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)
|
||||
phone_numbers.any? do |phone_number|
|
||||
format_phone_number(phone_number) == format_phone_number(registrant_user.phone)
|
||||
end
|
||||
end
|
||||
|
||||
def format_phone_number(phone_number)
|
||||
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