refactoring

This commit is contained in:
olegphenomenon 2021-09-20 15:30:30 +03:00
parent 4501463434
commit 419e5a587d
3 changed files with 29 additions and 9 deletions

View file

@ -16,19 +16,39 @@ class ReplaceUpdToObjUpdProhibitedJob < ApplicationJob
domain_batches.each do |domain| domain_batches.each do |domain|
if domain.locked_by_registrant? if domain.locked_by_registrant?
if rollback if rollback
domain.statuses = domain.statuses + ["serverUpdateProhibited"] if mode == 'add' and !domain.statuses.include? "serverUpdateProhibited" domain = rollback_actions(mode, domain)
domain.statuses = domain.statuses - ["serverObjUpdateProhibited"] if mode == 'remove' and domain.statuses.include? "serverObjUpdateProhibited"
else else
domain.statuses = domain.statuses + ["serverObjUpdateProhibited"] if mode == 'add' and !domain.statuses.include? "serverObjUpdateProhibited" domain = add_actions(mode, domain)
domain.statuses = domain.statuses - ["serverUpdateProhibited"] if mode == 'remove' and domain.statuses.include? "serverUpdateProhibited"
end end
domain.save! domain.save!
end end
end end
logger.info "Successfully proccesed #{count} domains of #{Domain.count}" logger.info "Successfully proccesed #{count} domains of #{Domain.count}"
end end
end end
def rollback_actions(mode, domain)
if mode == 'add' and !domain.statuses.include? 'serverUpdateProhibited'
domain.statuses = domain.statuses + ['serverUpdateProhibited']
elsif mode == 'remove' and domain.statuses.include? 'serverObjUpdateProhibited'
domain.statuses = domain.statuses - ['serverObjUpdateProhibited']
end
domain
end
def add_actions(mode, domain)
if mode == 'add' and !domain.statuses.include? 'serverObjUpdateProhibited'
domain.statuses = domain.statuses + ['serverObjUpdateProhibited']
elsif mode == 'remove' and domain.statuses.include? 'serverUpdateProhibited'
domain.statuses = domain.statuses - ['serverUpdateProhibited']
end
domain
end
def logger def logger
@logger ||= Logger.new(Rails.root.join('log/migrate_before_force_delete_statuses.log')) @logger ||= Logger.new(Rails.root.join('log/migrate_before_force_delete_statuses.log'))
end end

View file

@ -17,11 +17,11 @@ class RegistrantUser < User
Country.new(alpha2_code) Country.new(alpha2_code)
end end
def companies(company_register = nil) def companies(company_register = CompanyRegister::Client.new)
return [] if ident.include?('-') return [] if ident.include?('-')
[OpenStruct.new(registration_number: '43344412', company_name: 'TestFirma'), company_register.representation_rights(citizen_personal_code: ident,
OpenStruct.new(registration_number: '12345678', company_name: 'SuperFirma OU')] citizen_country_code: country.alpha3)
end end
def contacts(representable: true) def contacts(representable: true)