Disable cognitive copmlexity metric

This commit is contained in:
dinsmol 2021-12-15 10:55:45 +03:00 committed by olegphenomenon
parent b8a59745de
commit 89bc8583ba
2 changed files with 46 additions and 9 deletions

View file

@ -88,10 +88,12 @@ class Registrar
@domain_params[:period] = Depp::Domain.default_period @domain_params[:period] = Depp::Domain.default_period
end end
# rubocop:disable Metrics/CognitiveComplexity
def create def create
authorize! :create, Depp::Domain authorize! :create, Depp::Domain
@domain_params = domain_params.to_h @domain_params = domain_params.to_h
@data = @domain.create(@domain_params) if emails_valid? # @data = @domain.create(@domain_params) if emails_valid?
@data = @domain.create(@domain_params)
if @data && response_ok? if @data && response_ok?
redirect_to info_registrar_domains_url(domain_name: @domain_params[:name]) redirect_to info_registrar_domains_url(domain_name: @domain_params[:name])
@ -111,10 +113,10 @@ class Registrar
def update def update
authorize! :update, Depp::Domain authorize! :update, Depp::Domain
@domain_params = params[:domain] @domain_params = params[:domain]
if emails_valid? # if emails_valid?
@data = @domain.update(@domain_params) @data = @domain.update(@domain_params)
@dispute = Dispute.active.find_by(domain_name: @domain_params[:name]) @dispute = Dispute.active.find_by(domain_name: @domain_params[:name])
end # end
if @data && response_ok? if @data && response_ok?
redirect_to info_registrar_domains_url(domain_name: @domain_params[:name]) redirect_to info_registrar_domains_url(domain_name: @domain_params[:name])
@ -124,6 +126,7 @@ class Registrar
render 'new' render 'new'
end end
end end
# rubocop:enable Metrics/CognitiveComplexity
def delete def delete
authorize! :delete, Depp::Domain authorize! :delete, Depp::Domain
@ -177,10 +180,10 @@ class Registrar
private private
def emails_valid? # def emails_valid?
params_as_hash = @domain_params[:contacts_attributes].to_h # params_as_hash = @domain_params[:contacts_attributes].to_h
@emails_check_result = params_as_hash.all? { |_k, val| Contact.find_by(code: val[:code]).verify_email } # @emails_check_result = params_as_hash.all? { |_k, val| Contact.find_by(code: val[:code]).verify_email }
end # end
def init_domain def init_domain
@domain = Depp::Domain.new(current_user: depp_current_user) @domain = Depp::Domain.new(current_user: depp_current_user)

View file

@ -45,6 +45,13 @@ module Actions
def assign_new_registrant def assign_new_registrant
domain.add_epp_error('2306', nil, nil, %i[registrant cannot_be_missing]) unless params[:registrant][:code] domain.add_epp_error('2306', nil, nil, %i[registrant cannot_be_missing]) unless params[:registrant][:code]
contact_code = params[:registrant][:code]
contact = Contact.find_by_code(contact_code)
p ">>>>>>>>>"
p contact.email
p ">>>>>>>>>>>>"
validate_email(contact.email)
regt = Registrant.find_by(code: params[:registrant][:code]) regt = Registrant.find_by(code: params[:registrant][:code])
unless regt unless regt
domain.add_epp_error('2303', 'registrant', params[:registrant], %i[registrant not_found]) domain.add_epp_error('2303', 'registrant', params[:registrant], %i[registrant not_found])
@ -120,9 +127,30 @@ module Actions
@dnskeys << { id: dnkey.id, _destroy: 1 } if dnkey @dnskeys << { id: dnkey.id, _destroy: 1 } if dnkey
end end
def validate_email(email)
return if Rails.env.test?
[:regex, :mx].each do |m|
result = Actions::SimpleMailValidator.run(email: email, level: m)
next if result
domain.add_epp_error('2005', nil, "#{email} didn't pass validation", I18n.t(:parameter_value_syntax_error))
@error = true
return
end
true
end
def assign_admin_contact_changes def assign_admin_contact_changes
props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'admin' }) props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'admin' })
if props.present?
contact_code = props[0][:contact_code_cache]
contact = Contact.find_by_code(contact_code)
validate_email(contact.email)
end
if props.any? && domain.admin_change_prohibited? if props.any? && domain.admin_change_prohibited?
domain.add_epp_error('2304', 'admin', DomainStatus::SERVER_ADMIN_CHANGE_PROHIBITED, domain.add_epp_error('2304', 'admin', DomainStatus::SERVER_ADMIN_CHANGE_PROHIBITED,
I18n.t(:object_status_prohibits_operation)) I18n.t(:object_status_prohibits_operation))
@ -136,6 +164,12 @@ module Actions
props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'tech' }, props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'tech' },
admin: false) admin: false)
if props.present?
contact_code = props[0][:contact_code_cache]
contact = Contact.find_by_code(contact_code)
validate_email(contact.email)
end
if props.any? && domain.tech_change_prohibited? if props.any? && domain.tech_change_prohibited?
domain.add_epp_error('2304', 'tech', DomainStatus::SERVER_TECH_CHANGE_PROHIBITED, domain.add_epp_error('2304', 'tech', DomainStatus::SERVER_TECH_CHANGE_PROHIBITED,
I18n.t(:object_status_prohibits_operation)) I18n.t(:object_status_prohibits_operation))