Skip to content

Commit

Permalink
Fix namespaces for Zeitwerk class loader
Browse files Browse the repository at this point in the history
  • Loading branch information
yulgolem committed Mar 5, 2021
1 parent 32634c7 commit 57da745
Show file tree
Hide file tree
Showing 70 changed files with 595 additions and 647 deletions.
3 changes: 3 additions & 0 deletions .codeclimate.yml
Expand Up @@ -31,6 +31,9 @@ plugins:
rubocop:
enabled: true
channel: rubocop-0-74
checks:
Rubocop/Style/ClassAndModuleChildren:
enabled: false
checks:
method-lines:
config:
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/registrar/base_controller.rb
Expand Up @@ -17,7 +17,7 @@ def current_ability
private

def check_ip_restriction
ip_restriction = Authorization::RestrictedIP.new(request.ip)
ip_restriction = Authorization::RestrictedIp.new(request.ip)
allowed = ip_restriction.can_access_registrar_area?(current_registrar_user.registrar)

return if allowed
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/registrar/domains_controller.rb
Expand Up @@ -49,7 +49,7 @@ def index
domain_presenters << ::DomainPresenter.new(domain: domain, view: view_context)
end

raw_csv = Registrar::DomainListCSVPresenter.new(domains: domain_presenters,
raw_csv = Registrar::DomainListCsvPresenter.new(domains: domain_presenters,
view: view_context).to_s
filename = "Domains_#{l(Time.zone.now, format: :filename)}.csv"
send_data raw_csv, filename: filename, type: "#{Mime[:csv]}; charset=utf-8"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/registrar/sessions_controller.rb
Expand Up @@ -72,7 +72,7 @@ def find_user_by_idc_and_allowed(idc)
end

def check_ip_restriction
ip_restriction = Authorization::RestrictedIP.new(request.ip)
ip_restriction = Authorization::RestrictedIp.new(request.ip)
allowed = ip_restriction.can_access_registrar_area_sign_in_page?

return if allowed
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/interceptors/punycode_interceptor.rb
@@ -1,4 +1,4 @@
class PunycodeInterceptor
class Interceptors::PunycodeInterceptor
class << self
def delivering_email(message)
message.from = encode_addresses_as_punycode(message.from)
Expand All @@ -21,4 +21,4 @@ def encode_domain_part_as_punycode(domain_part)
SimpleIDN.to_ascii(domain_part)
end
end
end
end
4 changes: 2 additions & 2 deletions app/models/ability.rb
Expand Up @@ -89,8 +89,8 @@ def admin # Admin/admin_user dynamic role
can :manage, BlockedDomain
can :manage, ReservedDomain
can :manage, DNS::Zone
can :manage, DomainVersion
can :manage, ContactVersion
can :manage, Version::DomainVersion
can :manage, Version::ContactVersion
can :manage, Billing::Price
can :manage, User
can :manage, ApiUser
Expand Down
2 changes: 1 addition & 1 deletion app/models/action.rb
@@ -1,5 +1,5 @@
class Action < ApplicationRecord
has_paper_trail versions: { class_name: 'ActionVersion' }
has_paper_trail versions: { class_name: 'Version::ActionVersion' }

belongs_to :user
belongs_to :contact
Expand Down
2 changes: 1 addition & 1 deletion app/models/authorization/restricted_ip.rb
@@ -1,5 +1,5 @@
module Authorization
class RestrictedIP
class RestrictedIp
def initialize(ip)
@ip = ip
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/billing/price.rb
@@ -1,6 +1,6 @@
module Billing
class Price < ApplicationRecord
include Concerns::Billing::Price::Expirable
include Billing::Price::Expirable
include Versions

belongs_to :zone, class_name: 'DNS::Zone', required: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/billing/price/expirable.rb
@@ -1,4 +1,4 @@
module Concerns::Billing::Price::Expirable
module Billing::Price::Expirable
extend ActiveSupport::Concern

class_methods do
Expand Down
100 changes: 48 additions & 52 deletions app/models/concerns/contact/archivable.rb
@@ -1,68 +1,64 @@
module Concerns
module Contact
module Archivable
extend ActiveSupport::Concern
module Contact::Archivable
extend ActiveSupport::Concern

class_methods do
def archivable
unlinked.find_each.select(&:archivable?)
end
end
class_methods do
def archivable
unlinked.find_each.select(&:archivable?)
end
end

def archivable?(post: false)
inactive = inactive?
def archivable?(post: false)
inactive = inactive?

log("Found archivable contact id(#{id}), code (#{code})") if inactive && !post
log("Found archivable contact id(#{id}), code (#{code})") if inactive && !post

inactive
end
inactive
end

def archive(verified: false, notify: true, extra_log: false)
unless verified
raise 'Contact cannot be archived' unless archivable?(post: true)
end
def archive(verified: false, notify: true, extra_log: false)
unless verified
raise 'Contact cannot be archived' unless archivable?(post: true)
end

notify_registrar_about_archivation if notify
write_to_registrar_log if extra_log
destroy!
end
notify_registrar_about_archivation if notify
write_to_registrar_log if extra_log
destroy!
end

private
private

def notify_registrar_about_archivation
registrar.notifications.create!(
text: I18n.t('contact_has_been_archived',
contact_code: code, orphan_months: Setting.orphans_contacts_in_months)
)
end
def notify_registrar_about_archivation
registrar.notifications.create!(
text: I18n.t('contact_has_been_archived',
contact_code: code, orphan_months: Setting.orphans_contacts_in_months)
)
end

def inactive?
if DomainVersion.contact_unlinked_more_than?(contact_id: id, period: inactivity_period)
return true
end
def inactive?
if Version::DomainVersion.contact_unlinked_more_than?(contact_id: id, period: inactivity_period)
return true
end

DomainVersion.was_contact_linked?(id) ? false : created_at <= inactivity_period.ago
end
Version::DomainVersion.was_contact_linked?(id) ? false : created_at <= inactivity_period.ago
end

def inactivity_period
Setting.orphans_contacts_in_months.months
end
def inactivity_period
Setting.orphans_contacts_in_months.months
end

def log(msg)
@log ||= Logger.new(STDOUT)
@log.info(msg)
end
def log(msg)
@log ||= Logger.new(STDOUT)
@log.info(msg)
end

def write_to_registrar_log
registrar_name = registrar.accounting_customer_code
archive_path = ENV['contact_archivation_log_file_dir']
registrar_log_path = "#{archive_path}/#{registrar_name}.txt"
FileUtils.mkdir_p(archive_path) unless Dir.exist?(archive_path)
def write_to_registrar_log
registrar_name = registrar.accounting_customer_code
archive_path = ENV['contact_archivation_log_file_dir']
registrar_log_path = "#{archive_path}/#{registrar_name}.txt"
FileUtils.mkdir_p(archive_path) unless Dir.exist?(archive_path)

f = File.new(registrar_log_path, 'a+')
f.write("#{code}\n")
f.close
end
end
f = File.new(registrar_log_path, 'a+')
f.write("#{code}\n")
f.close
end
end
34 changes: 15 additions & 19 deletions app/models/concerns/contact/disclosable.rb
@@ -1,26 +1,22 @@
module Concerns
module Contact
module Disclosable
extend ActiveSupport::Concern
module Contact::Disclosable
extend ActiveSupport::Concern

class_methods do
attr_accessor :disclosable_attributes
end
class_methods do
attr_accessor :disclosable_attributes
end

included do
self.disclosable_attributes = %w[name email]
validate :validate_disclosed_attributes
end
included do
self.disclosable_attributes = %w[name email]
validate :validate_disclosed_attributes
end

private
private

def validate_disclosed_attributes
return if disclosed_attributes.empty?
def validate_disclosed_attributes
return if disclosed_attributes.empty?

has_undisclosable_attributes = (disclosed_attributes - self.class.disclosable_attributes)
.any?
errors.add(:disclosed_attributes, :invalid) if has_undisclosable_attributes
end
end
has_undisclosable_attributes = (disclosed_attributes - self.class.disclosable_attributes)
.any?
errors.add(:disclosed_attributes, :invalid) if has_undisclosable_attributes
end
end
2 changes: 1 addition & 1 deletion app/models/concerns/contact/identical.rb
@@ -1,4 +1,4 @@
module Concerns::Contact::Identical
module Contact::Identical
extend ActiveSupport::Concern

IDENTIFIABLE_ATTRIBUTES = %w[
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/domain/activatable.rb
@@ -1,4 +1,4 @@
module Concerns::Domain::Activatable
module Domain::Activatable
extend ActiveSupport::Concern

def active?
Expand Down
22 changes: 9 additions & 13 deletions app/models/concerns/domain/bulk_updatable.rb
@@ -1,17 +1,13 @@
module Concerns
module Domain
module BulkUpdatable
extend ActiveSupport::Concern
module Domain::BulkUpdatable
extend ActiveSupport::Concern

def bulk_update_prohibited?
discarded? || statuses_blocks_update?
end
def bulk_update_prohibited?
discarded? || statuses_blocks_update?
end

def statuses_blocks_update?
prohibited_array = [DomainStatus::SERVER_UPDATE_PROHIBITED,
DomainStatus::CLIENT_UPDATE_PROHIBITED]
prohibited_array.any? { |block_status| statuses.include?(block_status) }
end
end
def statuses_blocks_update?
prohibited_array = [DomainStatus::SERVER_UPDATE_PROHIBITED,
DomainStatus::CLIENT_UPDATE_PROHIBITED]
prohibited_array.any? { |block_status| statuses.include?(block_status) }
end
end
2 changes: 1 addition & 1 deletion app/models/concerns/domain/deletable.rb
@@ -1,4 +1,4 @@
module Concerns::Domain::Deletable
module Domain::Deletable
extend ActiveSupport::Concern

DELETE_STATUSES = [
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/domain/discardable.rb
@@ -1,4 +1,4 @@
module Concerns::Domain::Discardable
module Domain::Discardable
extend ActiveSupport::Concern

def keep
Expand Down
59 changes: 27 additions & 32 deletions app/models/concerns/domain/disputable.rb
@@ -1,44 +1,39 @@
# frozen_string_literal: true
module Domain::Disputable
extend ActiveSupport::Concern

module Concerns
module Domain
module Disputable
extend ActiveSupport::Concern

included do
validate :validate_disputed
end
included do
validate :validate_disputed
end

def mark_as_disputed
statuses.push(DomainStatus::DISPUTED) unless statuses.include?(DomainStatus::DISPUTED)
save
end
def mark_as_disputed
statuses.push(DomainStatus::DISPUTED) unless statuses.include?(DomainStatus::DISPUTED)
save
end

def unmark_as_disputed
statuses.delete_if { |status| status == DomainStatus::DISPUTED }
save
end
def unmark_as_disputed
statuses.delete_if { |status| status == DomainStatus::DISPUTED }
save
end

def in_disputed_list?
@in_disputed_list ||= Dispute.active.find_by(domain_name: name).present?
end
def in_disputed_list?
@in_disputed_list ||= Dispute.active.find_by(domain_name: name).present?
end

def disputed?
Dispute.active.where(domain_name: name).any?
end
def disputed?
Dispute.active.where(domain_name: name).any?
end

def validate_disputed
return if persisted? || !in_disputed_list?
def validate_disputed
return if persisted? || !in_disputed_list?

if reserved_pw.blank?
errors.add(:base, :required_parameter_missing_disputed)
return false
end
if reserved_pw.blank?
errors.add(:base, :required_parameter_missing_disputed)
return false
end

return if Dispute.valid_auth?(name, reserved_pw)
return if Dispute.valid_auth?(name, reserved_pw)

errors.add(:base, :invalid_auth_information_reserved)
end
end
errors.add(:base, :invalid_auth_information_reserved)
end
end
2 changes: 1 addition & 1 deletion app/models/concerns/domain/expirable.rb
@@ -1,4 +1,4 @@
module Concerns::Domain::Expirable
module Domain::Expirable
extend ActiveSupport::Concern

included do
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/domain/force_delete.rb
@@ -1,4 +1,4 @@
module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
module Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
extend ActiveSupport::Concern

included do
Expand Down

0 comments on commit 57da745

Please sign in to comment.