Skip to content

Commit

Permalink
Merge pull request #1873 from internetee/1872-zeitwerk-migration
Browse files Browse the repository at this point in the history
Introduce Zeitwerk class loader
  • Loading branch information
vohmar committed Mar 9, 2021
2 parents 32634c7 + 43b3033 commit f47f1a9
Show file tree
Hide file tree
Showing 78 changed files with 626 additions and 664 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
12 changes: 6 additions & 6 deletions app/controllers/admin/contact_versions_controller.rb
Expand Up @@ -2,12 +2,12 @@ module Admin
class ContactVersionsController < BaseController
include ObjectVersionsHelper

load_and_authorize_resource
load_and_authorize_resource class: Version::ContactVersion

def index
params[:q] ||= {}

@q = ContactVersion.search(params[:q])
@q = Version::ContactVersion.search(params[:q])
@versions = @q.result.page(params[:page])
search_params = params[:q].deep_dup

Expand All @@ -23,7 +23,7 @@ def index
end
end

versions = ContactVersion.includes(:item).where(whereS).order(created_at: :desc, id: :desc)
versions = Version::ContactVersion.includes(:item).where(whereS).order(created_at: :desc, id: :desc)
@q = versions.search(params[:q])
@versions = @q.result.page(params[:page])
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
Expand All @@ -32,8 +32,8 @@ def index

def show
per_page = 7
@version = ContactVersion.find(params[:id])
@versions = ContactVersion.where(item_id: @version.item_id).order(created_at: :desc, id: :desc)
@version = Version::ContactVersion.find(params[:id])
@versions = Version::ContactVersion.where(item_id: @version.item_id).order(created_at: :desc, id: :desc)
@versions_map = @versions.all.map(&:id)

# what we do is calc amount of results until needed version
Expand All @@ -49,7 +49,7 @@ def show
end

def search
render json: ContactVersion.search_by_query(params[:q])
render json: Version::ContactVersion.search_by_query(params[:q])
end

def create_where_string(key, value)
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/admin/domain_versions_controller.rb
Expand Up @@ -2,12 +2,12 @@ module Admin
class DomainVersionsController < BaseController
include ObjectVersionsHelper

load_and_authorize_resource
load_and_authorize_resource class: Version::DomainVersion

def index
params[:q] ||= {}

@q = DomainVersion.includes(:item).search(params[:q])
@q = Version::DomainVersion.includes(:item).search(params[:q])
@versions = @q.result.page(params[:page])
search_params = params[:q].deep_dup

Expand Down Expand Up @@ -40,7 +40,7 @@ def index
whereS += " AND object->>'registrar_id' IN (#{registrars.map { |r| "'#{r.id.to_s}'" }.join ','})" if registrars.present?
whereS += " AND 1=0" if registrars == []

versions = DomainVersion.includes(:item).where(whereS).order(created_at: :desc, id: :desc)
versions = Version::DomainVersion.includes(:item).where(whereS).order(created_at: :desc, id: :desc)
@q = versions.search(params[:q])
@versions = @q.result.page(params[:page])
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
Expand All @@ -50,8 +50,8 @@ def index

def show
per_page = 7
@version = DomainVersion.find(params[:id])
@versions = DomainVersion.where(item_id: @version.item_id).order(created_at: :desc, id: :desc)
@version = Version::DomainVersion.find(params[:id])
@versions = Version::DomainVersion.where(item_id: @version.item_id).order(created_at: :desc, id: :desc)
@versions_map = @versions.all.map(&:id)

# what we do is calc amount of results until needed version
Expand All @@ -67,7 +67,7 @@ def show
end

def search
render json: DomainVersion.search_by_query(params[:q])
render json: Version::DomainVersion.search_by_query(params[:q])
end

def create_where_string(key, value)
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

0 comments on commit f47f1a9

Please sign in to comment.