diff --git a/app/controllers/admin/account_activities_controller.rb b/app/controllers/admin/account_activities_controller.rb index cb34d1645..ac93802cc 100644 --- a/app/controllers/admin/account_activities_controller.rb +++ b/app/controllers/admin/account_activities_controller.rb @@ -25,13 +25,12 @@ module Admin @account_activities = @q.result.page(params[:page]).per(params[:results_per_page]) @count = @q.result.count - if params[:page] && params[:page].to_i > 1 - @sum = @q.result.limit(@account_activities.offset_value).sum(:sum) + - @b.result.where("account_activities.id NOT IN (#{@q.result.select(:id).to_sql})") - .sum(:sum) - else - @sum = @b.result.where("account_activities.id NOT IN (#{@q.result.select(:id).to_sql})").sum(:sum) - end + @sum = if params[:page] && params[:page].to_i > 1 + @q.result.limit(@account_activities.offset_value).sum(:sum) + + @b.result.where("account_activities.id NOT IN (#{@q.result.select(:id).to_sql})").sum(:sum) + else + @b.result.where("account_activities.id NOT IN (#{@q.result.select(:id).to_sql})").sum(:sum) + end respond_to do |format| format.html diff --git a/app/controllers/admin/epp_logs_controller.rb b/app/controllers/admin/epp_logs_controller.rb index 5aea411e2..279ff1ab8 100644 --- a/app/controllers/admin/epp_logs_controller.rb +++ b/app/controllers/admin/epp_logs_controller.rb @@ -3,6 +3,7 @@ module Admin load_and_authorize_resource class: ApiLog::EppLog before_action :set_default_dates, only: [:index] + # rubocop:disable Metrics/MethodLength def index @q = ApiLog::EppLog.ransack(params[:q]) @q.sorts = 'id desc' if @q.sorts.empty? @@ -20,6 +21,7 @@ module Admin render_by_format('admin/epp_logs/index', 'epp_logs') end + # rubocop:enable Metrics/MethodLength def show @epp_log = ApiLog::EppLog.find(params[:id]) diff --git a/app/controllers/admin/repp_logs_controller.rb b/app/controllers/admin/repp_logs_controller.rb index 3a8ee6c4a..b957c52c2 100644 --- a/app/controllers/admin/repp_logs_controller.rb +++ b/app/controllers/admin/repp_logs_controller.rb @@ -3,6 +3,7 @@ module Admin load_and_authorize_resource class: ApiLog::ReppLog before_action :set_default_dates, only: [:index] + # rubocop:disable Metrics/MethodLength def index @q = ApiLog::ReppLog.search(params[:q]) @q.sorts = 'id desc' if @q.sorts.empty? @@ -22,6 +23,7 @@ module Admin render_by_format('admin/repp_logs/index', 'repp_logs') end + # rubocop:enable Metrics/MethodLength def show @repp_log = ApiLog::ReppLog.find(params[:id]) diff --git a/app/controllers/api/v1/registrant/confirms_controller.rb b/app/controllers/api/v1/registrant/confirms_controller.rb index a1750f47a..c500019ea 100644 --- a/app/controllers/api/v1/registrant/confirms_controller.rb +++ b/app/controllers/api/v1/registrant/confirms_controller.rb @@ -15,9 +15,7 @@ module Api current_registrant: serialized_registrant(@domain.registrant), } - unless delete_action? - res[:new_registrant] = serialized_registrant(@domain.pending_registrant) - end + res[:new_registrant] = serialized_registrant(@domain.pending_registrant) unless delete_action? render json: res, status: :ok end diff --git a/app/controllers/concerns/deliverable.rb b/app/controllers/concerns/deliverable.rb index 0ceae0067..28ef23d8a 100644 --- a/app/controllers/concerns/deliverable.rb +++ b/app/controllers/concerns/deliverable.rb @@ -23,4 +23,4 @@ module Deliverable def find_invoice @invoice = Invoice.find(params[:invoice_id]) end -end \ No newline at end of file +end diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index 3ce5486f3..179b80b0e 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -312,7 +312,12 @@ module Epp request: trimmed_request, request_command: request_command, request_successful: epp_errors.empty?, - request_object: resource ? "#{params[:epp_object_type]}: #{resource.class} - #{resource.id} - #{resource.name}" : params[:epp_object_type], + request_object: if resource + "#{params[:epp_object_type]}: #{resource.class} - "\ + "#{resource.id} - #{resource.name}" + else + params[:epp_object_type] + end, response: @response, api_user_name: @api_user.try(:username) || current_user.try(:username) || 'api-public', api_user_registrar: @api_user.try(:registrar).try(:to_s) || diff --git a/app/controllers/epp/sessions_controller.rb b/app/controllers/epp/sessions_controller.rb index c7eddeecf..8d8b56e62 100644 --- a/app/controllers/epp/sessions_controller.rb +++ b/app/controllers/epp/sessions_controller.rb @@ -14,16 +14,13 @@ module Epp webclient_request = ENV['webclient_ips'].split(',').map(&:strip).include?(request.ip) if webclient_request && !Rails.env.test? && !Rails.env.development? client_md5 = Certificate.parse_md_from_string(request.env['HTTP_SSL_CLIENT_CERT']) - if ENV['cert_path'].blank? - raise 'webclient cert (cert_path) missing, registrar (r)epp disabled' - end + raise 'webclient cert (cert_path) missing, registrar (r)epp disabled' if ENV['cert_path'].blank? server_md5 = Certificate.parse_md_from_string(File.read(ENV['cert_path'])) if client_md5 != server_md5 msg = 'Authentication error; server closing connection (certificate is not valid)' epp_errors.add(:epp_errors, - msg: msg, - code: '2501') + msg: msg, code: '2501') success = false end @@ -33,10 +30,10 @@ module Epp !@api_user.pki_ok?(request.env['HTTP_SSL_CLIENT_CERT'], request.env['HTTP_SSL_CLIENT_S_DN_CN']) msg = 'Authentication error; server closing connection (certificate is not valid)' epp_errors.add(:epp_errors, - msg: msg,code: '2501') + msg: msg, code: '2501') success = false - end + end if success && !@api_user msg = 'Authentication error; server closing connection (API user not found)' @@ -109,9 +106,8 @@ module Epp def ip_white? webclient_request = ENV['webclient_ips'].split(',').map(&:strip).include?(request.ip) return true if webclient_request - if @api_user && !@api_user.registrar.api_ip_white?(request.ip) - return false - end + return false if @api_user && !@api_user.registrar.api_ip_white?(request.ip) + true end diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index d477c2c27..278bd4812 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -21,9 +21,7 @@ class Registrar current_domain_scope end - if params[:contacts_ident_eq] - domains = domains.where(contacts: { ident: params[:contacts_ident_eq] }) - end + domains = domains.where(contacts: { ident: params[:contacts_ident_eq] }) if params[:contacts_ident_eq] normalize_search_parameters do @q = domains.search(search_params.except(:contacts_ident_eq)) diff --git a/app/controllers/registrar/nameservers_controller.rb b/app/controllers/registrar/nameservers_controller.rb index cc3c27ad7..37d95dbe2 100644 --- a/app/controllers/registrar/nameservers_controller.rb +++ b/app/controllers/registrar/nameservers_controller.rb @@ -35,9 +35,7 @@ class Registrar notices = ["#{t('.replaced')}. #{t('.affected_domains')}: " \ "#{res[:data][:affected_domains].join(', ')}"] - if res[:data][:skipped_domains] - notices << "#{t('.skipped_domains')}: #{res[:data][:skipped_domains].join(', ')}" - end + notices << "#{t('.skipped_domains')}: #{res[:data][:skipped_domains].join(', ')}" if res[:data][:skipped_domains] notices.join(', ') end diff --git a/app/controllers/registrar/xml_consoles_controller.rb b/app/controllers/registrar/xml_consoles_controller.rb index 60406b539..f4aba12ed 100644 --- a/app/controllers/registrar/xml_consoles_controller.rb +++ b/app/controllers/registrar/xml_consoles_controller.rb @@ -22,7 +22,7 @@ class Registrar def load_xml cl_trid = "#{depp_current_user.tag}-#{Time.zone.now.to_i}" - xml_dir_path = "#{Rails.root}/app/views/registrar/xml_consoles/epp_requests" + xml_dir_path = Rails.root.join('app', 'views', 'registrar', 'xml_consoles', 'epp_requests').to_s xml = File.read("#{xml_dir_path}/#{params[:obj]}/#{params[:epp_action]}.xml") xml = prepare_payload(xml, cl_trid) @@ -54,7 +54,7 @@ class Registrar end def insert_prefix_and_version(xml, pref, version) - xml.gsub!("\"#{pref.to_s}\"", + xml.gsub!("\"#{pref}\"", "\"#{Xsd::Schema.filename(for_prefix: pref.to_s, for_version: version)}\"") xml end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6ecb4fa42..ed7942f44 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -6,7 +6,7 @@ module ApplicationHelper def env_style return '' if unstable_env.nil? - "background-image: url(#{image_path("#{unstable_env.to_s}.png")});" + "background-image: url(#{image_path("#{unstable_env}.png")});" end def ident_for(contact) diff --git a/app/interactions/actions/do_request.rb b/app/interactions/actions/do_request.rb index ca38140f1..96fa37544 100644 --- a/app/interactions/actions/do_request.rb +++ b/app/interactions/actions/do_request.rb @@ -13,7 +13,6 @@ module Actions else do_live_request(@request, @uri) end - rescue StandardError, OpenURI::HTTPError => e Rails.logger.debug e.message end diff --git a/app/interactions/actions/domain_update.rb b/app/interactions/actions/domain_update.rb index 5165a68c8..40b7876f6 100644 --- a/app/interactions/actions/domain_update.rb +++ b/app/interactions/actions/domain_update.rb @@ -43,9 +43,7 @@ module Actions end def assign_new_registrant - unless params[:registrant][:code] - domain.add_epp_error('2306', nil, nil, %i[registrant cannot_be_missing]) - end + domain.add_epp_error('2306', nil, nil, %i[registrant cannot_be_missing]) unless params[:registrant][:code] regt = Registrant.find_by(code: params[:registrant][:code]) unless regt diff --git a/app/interactions/domains/bulk_renew/single_domain_renew.rb b/app/interactions/domains/bulk_renew/single_domain_renew.rb index 7ab4f928c..290d585f6 100644 --- a/app/interactions/domains/bulk_renew/single_domain_renew.rb +++ b/app/interactions/domains/bulk_renew/single_domain_renew.rb @@ -37,11 +37,11 @@ module Domains price: domain_pricelist) end - def in_transaction_with_retries + def in_transaction_with_retries(&block) if Rails.env.test? yield else - transaction_wrapper { yield } + transaction_wrapper(&block) end rescue ActiveRecord::StatementInvalid => e log_error e diff --git a/app/interactions/domains/update_confirm/process_update_confirmed.rb b/app/interactions/domains/update_confirm/process_update_confirmed.rb index 734dbf5d8..62d3e4651 100644 --- a/app/interactions/domains/update_confirm/process_update_confirmed.rb +++ b/app/interactions/domains/update_confirm/process_update_confirmed.rb @@ -38,7 +38,7 @@ module Domains private def user_id - @user_id ||= domain.pending_json.dig('current_user_id') + @user_id ||= domain.pending_json['current_user_id'] end end end diff --git a/app/jobs/csync_job.rb b/app/jobs/csync_job.rb index a8a4bcea9..609e750f6 100644 --- a/app/jobs/csync_job.rb +++ b/app/jobs/csync_job.rb @@ -37,9 +37,7 @@ class CsyncJob < ApplicationJob def unqualification_reason(nss, key, result_types) return 'no CDNSKEY / nameservers reported different CDNSKEYs' unless key - if result_types.include? 'untrustworthy' - return 'current DNSSEC config invalid (required for rollover/delete)' - end + return 'current DNSSEC config invalid (required for rollover/delete)' if result_types.include? 'untrustworthy' "Nameserver(s) not reachable / invalid data (#{result_types.join(', ')})" unless nss end diff --git a/app/jobs/directo_invoice_forward_job.rb b/app/jobs/directo_invoice_forward_job.rb index e52caac20..43a537ade 100644 --- a/app/jobs/directo_invoice_forward_job.rb +++ b/app/jobs/directo_invoice_forward_job.rb @@ -44,9 +44,7 @@ class DirectoInvoiceForwardJob < ApplicationJob end def assign_monthly_numbers - if directo_counter_exceedable?(@client.invoices.count) - raise 'Directo Counter is going to be out of period!' - end + raise 'Directo Counter is going to be out of period!' if directo_counter_exceedable?(@client.invoices.count) min_directo = Setting.directo_monthly_number_min.presence.try(:to_i) directo_number = [Setting.directo_monthly_number_last.presence.try(:to_i), diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb index d8d722844..81d215386 100644 --- a/app/mailers/contact_mailer.rb +++ b/app/mailers/contact_mailer.rb @@ -14,4 +14,4 @@ class ContactMailer < ApplicationMailer def address_processing Contact.address_processing? end -end \ No newline at end of file +end diff --git a/app/models/api_user.rb b/app/models/api_user.rb index 61dd12387..8ae131a6e 100644 --- a/app/models/api_user.rb +++ b/app/models/api_user.rb @@ -44,6 +44,7 @@ class ApiUser < User after_initialize :set_defaults def set_defaults return unless new_record? + self.active = true unless saved_change_to_active? end @@ -76,7 +77,7 @@ class ApiUser < User end def linked_with?(another_api_user) - another_api_user.identity_code == self.identity_code + another_api_user.identity_code == identity_code end private diff --git a/app/models/billing/reference_no.rb b/app/models/billing/reference_no.rb index d164f7565..fbb9218c4 100644 --- a/app/models/billing/reference_no.rb +++ b/app/models/billing/reference_no.rb @@ -1,7 +1,7 @@ module Billing class ReferenceNo - REGEXP = /\A\d{2,20}\z/.freeze - MULTI_REGEXP = /(\d{2,20})/.freeze + REGEXP = /\A\d{2,20}\z/ + MULTI_REGEXP = /(\d{2,20})/ def self.generate base = Base.generate diff --git a/app/models/blocked_domain.rb b/app/models/blocked_domain.rb index 286345ea4..fb50a8b52 100644 --- a/app/models/blocked_domain.rb +++ b/app/models/blocked_domain.rb @@ -8,7 +8,7 @@ class BlockedDomain < ApplicationRecord class << self - def by_domain name + def by_domain(name) where(name: name) end end @@ -29,7 +29,7 @@ class BlockedDomain < ApplicationRecord def generate_json h = HashWithIndifferentAccess.new - h[:name] = self.name + h[:name] = name h[:status] = ['Blocked'] h end diff --git a/app/models/certificate.rb b/app/models/certificate.rb index e646999c9..16908d4fd 100644 --- a/app/models/certificate.rb +++ b/app/models/certificate.rb @@ -67,9 +67,7 @@ class Certificate < ApplicationRecord @cached_status = SIGNED - if parsed_crt.not_before > Time.zone.now.utc && parsed_crt.not_after < Time.zone.now.utc - @cached_status = EXPIRED - end + @cached_status = EXPIRED if parsed_crt.not_before > Time.zone.now.utc && parsed_crt.not_after < Time.zone.now.utc crl = OpenSSL::X509::CRL.new(File.open("#{ENV['crl_dir']}/crl.pem").read) return @cached_status unless crl.revoked.map(&:serial).include?(parsed_crt.serial) @@ -104,7 +102,7 @@ class Certificate < ApplicationRecord end logger.error(err) puts "Certificate sign issue: #{err.inspect}" if Rails.env.test? - return false + false end end diff --git a/app/models/certification_request.rb b/app/models/certification_request.rb index 1ea81c120..c3477ab35 100644 --- a/app/models/certification_request.rb +++ b/app/models/certification_request.rb @@ -1,3 +1,3 @@ class CertificationRequest extend ActiveModel::Translation -end \ No newline at end of file +end diff --git a/app/models/concerns/contact/archivable.rb b/app/models/concerns/contact/archivable.rb index 6c9581175..31f79395b 100644 --- a/app/models/concerns/contact/archivable.rb +++ b/app/models/concerns/contact/archivable.rb @@ -16,9 +16,7 @@ module Contact::Archivable end def archive(verified: false, notify: true, extra_log: false) - unless verified - raise 'Contact cannot be archived' unless archivable?(post: true) - end + raise 'Contact cannot be archived' if !verified && !archivable?(post: true) notify_registrar_about_archivation if notify write_to_registrar_log if extra_log @@ -35,9 +33,7 @@ module Contact::Archivable end def inactive? - if Version::DomainVersion.contact_unlinked_more_than?(contact_id: id, period: inactivity_period) - return true - end + return true if Version::DomainVersion.contact_unlinked_more_than?(contact_id: id, period: inactivity_period) Version::DomainVersion.was_contact_linked?(id) ? false : created_at <= inactivity_period.ago end diff --git a/app/models/concerns/domain/expirable.rb b/app/models/concerns/domain/expirable.rb index 1710f9dcd..f8e06f89f 100644 --- a/app/models/concerns/domain/expirable.rb +++ b/app/models/concerns/domain/expirable.rb @@ -22,9 +22,7 @@ module Domain::Expirable def expirable? return false if expire_time > Time.zone.now - if statuses.include?(DomainStatus::EXPIRED) && outzone_at.present? && delete_date.present? - return false - end + return false if statuses.include?(DomainStatus::EXPIRED) && outzone_at.present? && delete_date.present? true end diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index b31b02eac..0d6b44a05 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -16,10 +16,8 @@ module Domain::ForceDelete where("(force_delete_data->>'contact_notification_sent_date') is null") } - HOLD_STATUSES = [ - DomainStatus::SERVER_HOLD, - DomainStatus::CLIENT_HOLD, - ].freeze + HOLD_STATUSES = [DomainStatus::SERVER_HOLD, + DomainStatus::CLIENT_HOLD].freeze end class_methods do diff --git a/app/models/concerns/epp_errors.rb b/app/models/concerns/epp_errors.rb index dc5a4d452..cdb3c5d80 100644 --- a/app/models/concerns/epp_errors.rb +++ b/app/models/concerns/epp_errors.rb @@ -121,7 +121,7 @@ module EppErrors err = { code: code, msg: t } val = check_for_status(code, obj, val) err[:value] = { val: val, obj: obj } if val.present? - self.errors.add(:epp_errors, **err) + errors.add(:epp_errors, **err) end def check_for_status(code, obj, val) diff --git a/app/models/concerns/user_events.rb b/app/models/concerns/user_events.rb index afce650fe..80775f256 100644 --- a/app/models/concerns/user_events.rb +++ b/app/models/concerns/user_events.rb @@ -5,26 +5,25 @@ module UserEvents # EPP requires a server defined creator ID, which should be registrar code if we have one def cr_id # try this, rebuild user for registrar before searching history? really? - registrar = self.creator.try(:registrar) + registrar = creator.try(:registrar) if registrar.present? # Did creator return a kind of User that has a registrar? registrar.code else - if self.versions.first.try(:object).nil? - changes = self.versions.first.try(:object_changes) + if versions.first.try(:object).nil? + changes = versions.first.try(:object_changes) cr_registrar_id = changes['registrar_id'].second if changes.present? else # untested, expected never to execute - cr_registrar_id = self.versions.first.object['registrar_id'] + cr_registrar_id = versions.first.object['registrar_id'] end if cr_registrar_id.present? Registrar.find(cr_registrar_id).code else # cr_id optional for domain, but required for contact; but we want something here anyway - self.creator_str || self.registrar.code # Fallback + creator_str || self.registrar.code # Fallback end end end end - end diff --git a/app/models/contact.rb b/app/models/contact.rb index cd7eb4add..997a396c3 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: self.name + belongs_to :original, class_name: name belongs_to :registrar, required: true has_many :domain_contacts has_many :domains, through: :domain_contacts @@ -20,6 +20,7 @@ class Contact < ApplicationRecord has_many :actions, dependent: :destroy attr_accessor :legal_document_id + alias_attribute :kind, :ident_type alias_attribute :copy_from_id, :original_id # Old attribute name; for PaperTrail @@ -29,7 +30,7 @@ class Contact < ApplicationRecord } NAME_REGEXP = /([\u00A1-\u00B3\u00B5-\u00BF\u0021-\u0026\u0028-\u002C\u003A-\u0040]| - [\u005B-\u005F\u007B-\u007E\u2040-\u206F\u20A0-\u20BF\u2100-\u218F])/x.freeze + [\u005B-\u005F\u007B-\u007E\u2040-\u206F\u20A0-\u20BF\u2100-\u218F])/x validates :name, :email, presence: true validates :name, format: { without: NAME_REGEXP, message: :invalid }, if: -> { priv? } diff --git a/app/models/depp/contact.rb b/app/models/depp/contact.rb index e32b08fae..c9e628a35 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 == self.ident_type && ident_country_code == self.ident_country_code + unless ident == self.ident && ident == ident_type && ident_country_code == ident_country_code ident = ident_xml[:_anonymus].try(:first) end end diff --git a/app/models/depp/user.rb b/app/models/depp/user.rb index e1d71091c..60c6f6c3d 100644 --- a/app/models/depp/user.rb +++ b/app/models/depp/user.rb @@ -11,7 +11,7 @@ module Depp validate :validate_existance_in_server def initialize(args = {}) - args.each { |k, v| send("#{k.to_s}=", v) } + args.each { |k, v| send("#{k}=", v) } end def server diff --git a/app/models/dnskey.rb b/app/models/dnskey.rb index 0f98dc162..5fa1243f6 100644 --- a/app/models/dnskey.rb +++ b/app/models/dnskey.rb @@ -76,15 +76,15 @@ class Dnskey < ApplicationRecord def validate_flags return if flags.blank? return if FLAGS.include?(flags.to_s) + errors.add(:flags, :invalid, values: "Valid flags are: #{FLAGS.join(', ')}") end def generate_digest return unless flags == 257 || flags == 256 # require ZoneFlag, but optional SecureEntryPoint + self.ds_alg = alg - if self.ds_digest_type.blank? || !DS_DIGEST_TYPE.include?(ds_digest_type) - self.ds_digest_type = Setting.ds_digest_type - end + self.ds_digest_type = Setting.ds_digest_type if ds_digest_type.blank? || !DS_DIGEST_TYPE.include?(ds_digest_type) flags_hex = self.class.int_to_hex(flags) protocol_hex = self.class.int_to_hex(protocol) @@ -93,7 +93,7 @@ class Dnskey < ApplicationRecord hex = [domain.name_in_wire_format, flags_hex, protocol_hex, alg_hex, public_key_hex].join bin = self.class.hex_to_bin(hex) - case self.ds_digest_type + case ds_digest_type when 1 self.ds_digest = Digest::SHA1.hexdigest(bin).upcase when 2 @@ -113,11 +113,11 @@ class Dnskey < ApplicationRecord c = 0 wire_format.each_byte.with_index do |b, i| - if i.even? - c += b << 8 - else - c += b - end + c += if i.even? + b << 8 + else + b + end end self.ds_key_tag = ((c & 0xFFFF) + (c >> 16)) & 0xFFFF @@ -150,21 +150,21 @@ class Dnskey < ApplicationRecord end class << self - def int_to_hex(s) - s = s.to_s(16) - s.prepend('0') if s.length.odd? + def int_to_hex(num) + num = num.to_s(16) + num.prepend('0') if num.length.odd? end - def hex_to_bin(s) - s.scan(/../).map(&:hex).pack('c*') + def hex_to_bin(num) + num.scan(/../).map(&:hex).pack('c*') end - def bin_to_hex(s) - s.each_byte.map { |b| format('%02X', b) }.join + def bin_to_hex(num) + num.each_byte.map { |b| format('%02X', b) }.join end def pub_key_base64?(pub) - return unless pub&.is_a?(String) + return unless pub.is_a?(String) Base64.strict_encode64(Base64.strict_decode64(pub)) == pub rescue ArgumentError diff --git a/app/models/domain.rb b/app/models/domain.rb index c0893e07f..67ef5d32f 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -121,10 +121,8 @@ class Domain < ApplicationRecord validate :status_is_consistant def status_is_consistant has_error = (hold_status? && statuses.include?(DomainStatus::SERVER_MANUAL_INZONE)) - unless has_error - if (statuses & DELETE_STATUSES).any? - has_error = statuses.include? DomainStatus::SERVER_DELETE_PROHIBITED - end + if !has_error && (statuses & DELETE_STATUSES).any? + has_error = statuses.include? DomainStatus::SERVER_DELETE_PROHIBITED end errors.add(:domains, I18n.t(:object_status_prohibits_operation)) if has_error end @@ -345,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 = self.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 = self.find_by_name unicode + domain = find_by_name unicode end domain end @@ -381,9 +379,7 @@ class Domain < ApplicationRecord return true unless Setting.days_to_renew_domain_before_expire != 0 # if you can renew domain at days_to_renew before domain expiration - if (expire_time.to_date - Time.zone.today) + 1 > Setting.days_to_renew_domain_before_expire - return false - end + return false if (expire_time.to_date - Time.zone.today) + 1 > Setting.days_to_renew_domain_before_expire true end @@ -592,14 +588,14 @@ class Domain < ApplicationRecord statuses.each do |s| unless update.include? s case s - when DomainStatus::PENDING_DELETE - self.delete_date = nil - when DomainStatus::SERVER_MANUAL_INZONE # removal causes server hold to set - self.outzone_at = Time.zone.now if force_delete_scheduled? - when DomainStatus::EXPIRED # removal causes server hold to set - self.outzone_at = self.expire_time + 15.day - when DomainStatus::SERVER_HOLD # removal causes server hold to set - self.outzone_at = nil + when DomainStatus::PENDING_DELETE + self.delete_date = nil + when DomainStatus::SERVER_MANUAL_INZONE # removal causes server hold to set + self.outzone_at = Time.zone.now if force_delete_scheduled? + when DomainStatus::EXPIRED # removal causes server hold to set + self.outzone_at = expire_time + 15.day + when DomainStatus::SERVER_HOLD # removal causes server hold to set + self.outzone_at = nil end end end diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 6bd5507b9..614be201b 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -98,8 +98,8 @@ class Epp::Contact < Contact return unless legal_document_data legal_documents.create( - document_type: legal_document_data[:type], - body: legal_document_data[:body] + document_type: legal_document_data[:type], + body: legal_document_data[:body] ) end @@ -108,9 +108,9 @@ class Epp::Contact < Contact return unless legal_document_data doc = LegalDocument.create( - documentable_type: Contact, - document_type: legal_document_data[:type], - body: legal_document_data[:body] + documentable_type: Contact, + document_type: legal_document_data[:type], + body: legal_document_data[:body] ) self.legal_documents = [doc] diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index d0949e35b..b9f93f255 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -144,8 +144,8 @@ class Epp::Domain < Domain return end - if doc = attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call) - frame.css("legalDocument").first.content = doc.path if doc&.persisted? + if doc = attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call) && doc&.persisted? + frame.css("legalDocument").first.content = doc.path end if Setting.request_confirmation_on_domain_deletion_enabled && @@ -325,11 +325,13 @@ class Epp::Domain < Domain return false end - begin - errors.add(:base, :domain_status_prohibits_operation) - return false - end if (statuses & + if (statuses & [DomainStatus::CLIENT_DELETE_PROHIBITED, DomainStatus::SERVER_DELETE_PROHIBITED]).any? + begin + errors.add(:base, :domain_status_prohibits_operation) + return false + end + end true end diff --git a/app/models/iban.rb b/app/models/iban.rb index 260aca827..395f61bfa 100644 --- a/app/models/iban.rb +++ b/app/models/iban.rb @@ -2,4 +2,4 @@ class Iban def self.max_length 34 end -end \ No newline at end of file +end diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 48d4def33..b8977e409 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -16,7 +16,7 @@ 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{ @@ -91,8 +91,8 @@ class Invoice < ApplicationRecord read_attribute(:total) end - def each - items.each { |item| yield item } + def each(&block) + items.each(&block) end def as_pdf diff --git a/app/models/user.rb b/app/models/user.rb index 18ab410d0..cca07ca14 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,7 +8,7 @@ class User < ApplicationRecord self.ignored_columns = %w[legacy_id] def id_role_username - "#{self.id}-#{self.class}: #{self.username}" + "#{id}-#{self.class}: #{username}" end def self.from_omniauth(omniauth_hash) diff --git a/app/models/white_ip.rb b/app/models/white_ip.rb index 38cee7b6b..7bbd8c18f 100644 --- a/app/models/white_ip.rb +++ b/app/models/white_ip.rb @@ -54,12 +54,8 @@ class WhiteIp < ApplicationRecord def ids_including(ip) ipv4 = ipv6 = [] - if check_ip4(ip).present? - ipv4 = select { |white_ip| check_ip4(white_ip.ipv4) === check_ip4(ip) } - end - if check_ip6(ip).present? - ipv6 = select { |white_ip| check_ip6(white_ip.ipv6) === check_ip6(ip) } - end + ipv4 = select { |white_ip| check_ip4(white_ip.ipv4) === check_ip4(ip) } if check_ip4(ip).present? + ipv6 = select { |white_ip| check_ip6(white_ip.ipv6) === check_ip6(ip) } if check_ip6(ip).present? (ipv4 + ipv6).pluck(:id).flatten.uniq end # rubocop:enable Style/CaseEquality diff --git a/app/views/epp/domains/info.xml.builder b/app/views/epp/domains/info.xml.builder index 01641af8e..b154752e9 100644 --- a/app/views/epp/domains/info.xml.builder +++ b/app/views/epp/domains/info.xml.builder @@ -29,13 +29,9 @@ xml.epp_head do @nameservers.each do |x| xml.tag!('domain:hostAttr') do xml.tag!('domain:hostName', x.hostname) - if x.ipv4.present? - x.ipv4.each { |ip| xml.tag!('domain:hostAddr', ip, 'ip' => 'v4') } - end + x.ipv4.each { |ip| xml.tag!('domain:hostAddr', ip, 'ip' => 'v4') } if x.ipv4.present? - if x.ipv6.present? - x.ipv6.each { |ip| xml.tag!('domain:hostAddr', ip, 'ip' => 'v6') } - end + x.ipv6.each { |ip| xml.tag!('domain:hostAddr', ip, 'ip' => 'v6') } if x.ipv6.present? end end end diff --git a/lib/deserializers/xml/dnssec.rb b/lib/deserializers/xml/dnssec.rb index 562d05c7a..d0564c89c 100644 --- a/lib/deserializers/xml/dnssec.rb +++ b/lib/deserializers/xml/dnssec.rb @@ -46,9 +46,7 @@ module Deserializers @ds_data = [] # schema validation prevents both in the same parent node - if frame.css('dsData').present? - frame.css('dsData').each { |k| @ds_data << key_from_params(k, dsa: true) } - end + frame.css('dsData').each { |k| @ds_data << key_from_params(k, dsa: true) } if frame.css('dsData').present? if frame.css('all')&.text == 'true' keys_from_domain_name(domain_name) diff --git a/lib/tasks/registrars/reload_balance.rake b/lib/tasks/registrars/reload_balance.rake index d08f7fee3..937af45f7 100644 --- a/lib/tasks/registrars/reload_balance.rake +++ b/lib/tasks/registrars/reload_balance.rake @@ -29,4 +29,4 @@ namespace :registrars do puts "Invoiced total: #{invoiced_registrar_count}" end -end \ No newline at end of file +end diff --git a/lib/validators/phone_validator.rb b/lib/validators/phone_validator.rb index a2a91e9f7..b4b004031 100644 --- a/lib/validators/phone_validator.rb +++ b/lib/validators/phone_validator.rb @@ -6,9 +6,7 @@ class PhoneValidator < ActiveModel::EachValidator country_code = phone_parts.first subscriber_no = phone_parts.second - if zeros_only?(country_code) || zeros_only?(subscriber_no) - record.errors.add(attribute, :invalid) - end + record.errors.add(attribute, :invalid) if zeros_only?(country_code) || zeros_only?(subscriber_no) end private diff --git a/lib/xsd/schema.rb b/lib/xsd/schema.rb index b48237053..4fe2ed553 100644 --- a/lib/xsd/schema.rb +++ b/lib/xsd/schema.rb @@ -3,8 +3,8 @@ module Xsd SCHEMA_PATH = 'lib/schemas/'.freeze BASE_URL = 'https://epp.tld.ee/schema/'.freeze - REGEX_PREFIX_WITH_DASH = /(?\w+-\w+)-(?\w.\w).xsd/.freeze - REGEX_PREFIX_WITHOUT_DASH = /(?\w+)-(?\w.\w).xsd/.freeze + REGEX_PREFIX_WITH_DASH = /(?\w+-\w+)-(?\w.\w).xsd/ + REGEX_PREFIX_WITHOUT_DASH = /(?\w+)-(?\w.\w).xsd/ PREFIXES = %w[ domain-ee