From 788af6cc5f41357bd19fb2a0853513931f586050 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 9 Sep 2021 21:34:56 +0300 Subject: [PATCH] fixed codeclimate errors --- app/controllers/epp/base_controller.rb | 2 +- app/controllers/registrar/sessions_controller.rb | 14 ++++++-------- app/jobs/csync_job.rb | 4 ++-- app/jobs/send_e_invoice_job.rb | 2 +- app/jobs/verify_emails_job.rb | 2 +- app/models/certificate.rb | 10 +++++----- app/models/contact.rb | 2 +- app/models/depp/contact.rb | 2 +- app/models/domain.rb | 4 ++-- app/models/epp/domain.rb | 3 ++- app/models/invoice.rb | 8 +++++--- app/models/registrar.rb | 2 +- app/models/reserved_domain.rb | 2 +- lib/xsd/schema.rb | 4 ++-- test/jobs/send_e_invoice_job_test.rb | 2 +- 15 files changed, 32 insertions(+), 31 deletions(-) diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index 179b80b0e..44e38fe1c 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -1,5 +1,5 @@ module Epp - class BaseController < ActionController::Base + class BaseController < ApplicationController class AuthorizationError < StandardError; end skip_before_action :verify_authenticity_token check_authorization diff --git a/app/controllers/registrar/sessions_controller.rb b/app/controllers/registrar/sessions_controller.rb index 4db217574..c73ed799b 100644 --- a/app/controllers/registrar/sessions_controller.rb +++ b/app/controllers/registrar/sessions_controller.rb @@ -35,15 +35,13 @@ class Registrar @depp_user.errors.add(:base, :invalid_cert) end - if @depp_user.errors.none? - if @api_user.active? - sign_in_and_redirect(:registrar_user, @api_user) - else - @depp_user.errors.add(:base, :not_active) - show_error and return - end + show_error and return unless @depp_user.errors.none? + + if @api_user.active? + sign_in_and_redirect(:registrar_user, @api_user) else - show_error and return + @depp_user.errors.add(:base, :not_active) + show_error end end diff --git a/app/jobs/csync_job.rb b/app/jobs/csync_job.rb index 609e750f6..2cbada3de 100644 --- a/app/jobs/csync_job.rb +++ b/app/jobs/csync_job.rb @@ -45,7 +45,7 @@ class CsyncJob < ApplicationJob def process_scanner_results scanner_results - @results.keys.each do |domain| + @results.each_key do |domain| begin next unless qualified_for_monitoring?(domain, @results[domain]) @@ -132,7 +132,7 @@ class CsyncJob < ApplicationJob end def create_input_lines(out_file, state) - @input_store[state].keys.each do |nameserver| + @input_store[state].each_key do |nameserver| domains = @input_store[state][nameserver].join(' ') next unless domains.length.positive? diff --git a/app/jobs/send_e_invoice_job.rb b/app/jobs/send_e_invoice_job.rb index 4ef503d59..33a2745c6 100644 --- a/app/jobs/send_e_invoice_job.rb +++ b/app/jobs/send_e_invoice_job.rb @@ -1,7 +1,7 @@ class SendEInvoiceJob < ApplicationJob discard_on HTTPClient::TimeoutError - def perform(invoice_id, payable = true) + def perform(invoice_id, payable: true) logger.info "Started to process e-invoice for invoice_id #{invoice_id}" invoice = Invoice.find_by(id: invoice_id) return unless need_to_process_invoice?(invoice: invoice, payable: payable) diff --git a/app/jobs/verify_emails_job.rb b/app/jobs/verify_emails_job.rb index 0d3ec2078..1de244221 100644 --- a/app/jobs/verify_emails_job.rb +++ b/app/jobs/verify_emails_job.rb @@ -26,7 +26,7 @@ class VerifyEmailsJob < ApplicationJob end def logger - @logger ||= Logger.new(Rails.root.join('log', 'email_verification.log')) + @logger ||= Logger.new(Rails.root.join('log/email_verification.log')) end def log_success(verification) diff --git a/app/models/certificate.rb b/app/models/certificate.rb index 16908d4fd..767576d42 100644 --- a/app/models/certificate.rb +++ b/app/models/certificate.rb @@ -81,11 +81,11 @@ class Certificate < ApplicationRecord csr_file.rewind crt_file = Tempfile.new('client_crt') - _out, err, _st = Open3.capture3("openssl ca -config #{ENV['openssl_config_path']} \ - -keyfile #{ENV['ca_key_path']} \ - -cert #{ENV['ca_cert_path']} \ - -extensions usr_cert -notext -md sha256 \ - -in #{csr_file.path} -out #{crt_file.path} -key '#{ENV['ca_key_password']}' -batch") + _out, err, _st = Open3.capture3("openssl", "ca", "-config", ENV['openssl_config_path'], + "-keyfile", ENV['ca_key_path'], + "-cert", ENV['ca_cert_path'], + "-extensions", "usr_cert", "-notext", "-md sha256", + "-in", csr_file.path, "-out", crt_file.path, "-key", ENV['ca_key_password'], "-batch") if err.match?(/Data Base Updated/) crt_file.rewind diff --git a/app/models/contact.rb b/app/models/contact.rb index 997a396c3..f33c22c74 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -11,7 +11,7 @@ class Contact < ApplicationRecord include Contact::Archivable include EmailVerifable - belongs_to :original, class_name: name + belongs_to :original, class_name: 'Contact' belongs_to :registrar, required: true has_many :domain_contacts has_many :domains, through: :domain_contacts diff --git a/app/models/depp/contact.rb b/app/models/depp/contact.rb index c9e628a35..7deb36562 100644 --- a/app/models/depp/contact.rb +++ b/app/models/depp/contact.rb @@ -241,7 +241,7 @@ module Depp ident = ident_xml[:_anonymus].try(:first) when :update # detect if any ident has changed, nb! ident and self.ident is not always same - unless ident == self.ident && ident == ident_type && ident_country_code == ident_country_code + unless ident == self.ident && ident == ident_type && ident_country_code == self.ident_country_code ident = ident_xml[:_anonymus].try(:first) end end diff --git a/app/models/domain.rb b/app/models/domain.rb index 67ef5d32f..9312a9a54 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -343,10 +343,10 @@ class Domain < ApplicationRecord # find by internationalized domain name # internet domain name => ascii or puny, but db::domains.name is unicode def self.find_by_idn(name) - domain = find_by_name name + domain = find_by(name: name) if domain.blank? && name.include?('-') unicode = SimpleIDN.to_unicode name # we have no index on domains.name_puny - domain = find_by_name unicode + domain = find_by(name: unicode) end domain end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 4ff478fb2..d434c843c 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -216,7 +216,8 @@ class Epp::Domain < Domain return transfers.last if transfers.any? when 'request' return pending_transfer if pending_transfer - return query_transfer(frame, current_user) + + query_transfer(frame, current_user) when 'approve' return approve_transfer(frame, current_user) if pending_transfer when 'reject' diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 06407a8bf..df8b7aff8 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -17,13 +17,15 @@ class Invoice < ApplicationRecord scope :all_columns, -> { select("invoices.*") } scope :sort_due_date_column, -> { all_columns.select("CASE WHEN invoices.cancelled_at is not null THEN (invoices.cancelled_at + interval '100 year') ELSE - invoices.due_date END AS sort_due_date") } + invoices.due_date END AS sort_due_date") + } scope :sort_by_sort_due_date_asc, -> { sort_due_date_column.order("sort_due_date ASC") } scope :sort_by_sort_due_date_desc, -> { sort_due_date_column.order("sort_due_date DESC") } - scope :sort_receipt_date_column, -> { all_columns.includes(:account_activity).references(:account_activity).select(%Q{ + scope :sort_receipt_date_column, -> { all_columns.includes(:account_activity).references(:account_activity).select(%( CASE WHEN account_activities.created_at is not null THEN account_activities.created_at WHEN invoices.cancelled_at is not null THEN invoices.cancelled_at + interval '100 year' - ELSE NULL END AS sort_receipt_date })} + ELSE NULL END AS sort_receipt_date )) + } scope :sort_by_sort_receipt_date_asc, -> { sort_receipt_date_column.order("sort_receipt_date ASC") } scope :sort_by_sort_receipt_date_desc, -> { sort_receipt_date_column.order("sort_receipt_date DESC") } diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 2401e20fb..18c549e41 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -105,7 +105,7 @@ class Registrar < ApplicationRecord .deliver_later(wait: 1.minute) end - SendEInvoiceJob.set(wait: 1.minute).perform_now(invoice.id, payable) + SendEInvoiceJob.set(wait: 1.minute).perform_now(invoice.id, payable: payable) invoice end diff --git a/app/models/reserved_domain.rb b/app/models/reserved_domain.rb index 97fe84b72..5d585e5d9 100644 --- a/app/models/reserved_domain.rb +++ b/app/models/reserved_domain.rb @@ -37,7 +37,7 @@ class ReservedDomain < ApplicationRecord end def fill_empty_passwords - regenerate_password if self.password.blank? + regenerate_password if password.blank? end def regenerate_password diff --git a/lib/xsd/schema.rb b/lib/xsd/schema.rb index 4fe2ed553..2f409c55b 100644 --- a/lib/xsd/schema.rb +++ b/lib/xsd/schema.rb @@ -82,8 +82,8 @@ module Xsd end def schemas_by_name - prefixes.each_with_object({}) do |prefix, hash| - hash[prefix] = xsd_schemas.select { |filename| prefix_check(prefix, filename) }.uniq.sort + prefixes.index_with do |prefix| + xsd_schemas.select { |filename| prefix_check(prefix, filename) }.uniq.sort end end diff --git a/test/jobs/send_e_invoice_job_test.rb b/test/jobs/send_e_invoice_job_test.rb index ca1e50eb7..0f2c683f2 100644 --- a/test/jobs/send_e_invoice_job_test.rb +++ b/test/jobs/send_e_invoice_job_test.rb @@ -15,7 +15,7 @@ class SendEInvoiceJobTest < ActiveJob::TestCase assert_nothing_raised do perform_enqueued_jobs do - SendEInvoiceJob.perform_now(@invoice.id, true) + SendEInvoiceJob.perform_now(@invoice.id, payable: true) end end @invoice.reload