Upgrade to Rails 5.0

Closes #377
This commit is contained in:
Artur Beljajev 2019-09-15 15:38:52 +03:00
parent bb108efedd
commit fa52001be6
141 changed files with 1388 additions and 1664 deletions

View file

@ -3,6 +3,7 @@ module Admin
load_and_authorize_resource
before_action :set_contact, only: [:show]
helper_method :ident_types
helper_method :domain_filter_params
def index
params[:q] ||= {}
@ -19,7 +20,7 @@ module Admin
normalize_search_parameters do
@q = contacts.search(search_params)
@contacts = @q.result.uniq.page(params[:page])
@contacts = @q.result.distinct.page(params[:page])
end
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
@ -84,5 +85,9 @@ module Admin
def ident_types
Contact::Ident.types
end
def domain_filter_params
params.permit(:domain_filter)
end
end
end

View file

@ -33,7 +33,7 @@ module Admin
end
def notify_by_email?
ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:notify_by_email])
ActiveRecord::Type::Boolean.new.cast(params[:notify_by_email])
end
end
end

View file

@ -5,7 +5,7 @@ module Api
def cors_preflight_check
set_access_control_headers
render text: ''
render plain: ''
end
def set_access_control_headers

View file

@ -1,5 +1,3 @@
require 'rails5_api_controller_backport'
module Api
module V1
class BaseController < ActionController::API

View file

@ -1,4 +1,3 @@
require 'rails5_api_controller_backport'
require 'auth_token/auth_token_creator'
module Api
@ -16,7 +15,7 @@ module Api
end
def eid
user = RegistrantUser.find_or_create_by_api_data(eid_params)
user = RegistrantUser.find_or_create_by_api_data(eid_params.to_h)
token = create_token(user)
if token

View file

@ -1,4 +1,3 @@
require 'rails5_api_controller_backport'
require 'auth_token/auth_token_decryptor'
module Api

View file

@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
protect_from_forgery with: :exception, prepend: true
before_action do
resource = controller_name.singularize.to_sym

View file

@ -3,7 +3,6 @@ module Epp
class AuthorizationError < StandardError; end
check_authorization
skip_before_action :verify_authenticity_token
layout false
before_action :ensure_session_id_passed

View file

@ -1,6 +1,7 @@
class Registrant::ContactsController < RegistrantController
helper_method :domain
helper_method :fax_enabled?
helper_method :domain_filter_params
skip_authorization_check only: %i[edit update]
def show
@ -99,4 +100,8 @@ class Registrant::ContactsController < RegistrantController
http.request(request)
end
end
def domain_filter_params
params.permit(:domain_filter)
end
end

View file

@ -3,6 +3,7 @@ class Registrar
before_action :init_epp_contact
helper_method :address_processing?
helper_method :ident_types
helper_method :domain_filter_params
def index
authorize! :view, Depp::Contact
@ -68,7 +69,7 @@ class Registrar
def create
authorize! :create, Depp::Contact
@contact = Depp::Contact.new(params[:depp_contact])
@contact = Depp::Contact.new(contact_params)
if @contact.save
redirect_to registrar_contact_url(@contact.id)
@ -79,9 +80,9 @@ class Registrar
def update
authorize! :edit, Depp::Contact
@contact = Depp::Contact.new(params[:depp_contact])
@contact = Depp::Contact.new(contact_params)
if @contact.update_attributes(params[:depp_contact])
if @contact.update_attributes(contact_params)
redirect_to registrar_contact_url(@contact.id)
else
render 'edit'
@ -95,7 +96,7 @@ class Registrar
def destroy
authorize! :delete, Depp::Contact
@contact = Depp::Contact.new(params[:depp_contact])
@contact = Depp::Contact.new(contact_params_for_delete)
if @contact.delete
redirect_to registrar_contacts_url, notice: t(:destroyed)
@ -104,6 +105,12 @@ class Registrar
end
end
protected
def domain_filter_params
params.permit(:domain_filter)
end
private
def init_epp_contact
@ -131,5 +138,22 @@ class Registrar
def ident_types
Contact::Ident.types
end
def contact_params
params.require(:depp_contact).permit(:id,
:name,
:email,
:phone,
:org_name,
:ident, :ident_type, :ident_country_code,
:street, :city, :zip, :state, :country_code,
:password,
:legal_document,
:code)
end
def contact_params_for_delete
params.require(:depp_contact).permit(:id, :password, :legal_document)
end
end
end

View file

@ -2,16 +2,17 @@ class Registrar
class DomainsController < DeppController
before_action :init_domain, except: :new
helper_method :contacts
helper_method :search_params
def index
authorize! :view, Depp::Domain
params[:q] ||= {}
params[:q].delete_if { |_k, v| v.blank? }
if params[:q].length == 1 && params[:q][:name_matches].present?
@domain = Domain.find_by(name: params[:q][:name_matches])
if @domain
redirect_to info_registrar_domains_url(domain_name: @domain.name) and return
if search_params.to_h.delete_if { |_key, value| value.blank? }.length == 1 &&
search_params[:name_matches].present?
domain = Domain.find_by(name: search_params[:name_matches])
if domain
redirect_to info_registrar_domains_url(domain_name: domain.name) and return
end
end
@ -24,15 +25,15 @@ class Registrar
end
normalize_search_parameters do
@q = domains.search(params[:q])
@q = domains.search(search_params)
@domains = @q.result.page(params[:page])
if @domains.count == 0 && params[:q][:name_matches] !~ /^%.+%$/
# if we do not get any results, add wildcards to the name field and search again
n_cache = params[:q][:name_matches]
params[:q][:name_matches] = "%#{params[:q][:name_matches]}%"
@q = domains.search(params[:q])
# if we do not get any results, add wildcards to the name field and search again
if @domains.count == 0 && search_params[:name_matches] !~ /^%.+%$/
new_search_params = search_params.to_h
new_search_params[:name_matches] = "%#{new_search_params[:name_matches]}%"
@q = domains.search(new_search_params)
@domains = @q.result.page(params[:page])
params[:q][:name_matches] = n_cache # we don't want to show wildcards in search form
end
end
@ -164,17 +165,26 @@ class Registrar
end
def normalize_search_parameters
ca_cache = params[:q][:valid_to_lteq]
ca_cache = search_params[:valid_to_lteq]
begin
end_time = params[:q][:valid_to_lteq].try(:to_date)
params[:q][:valid_to_lteq] = end_time.try(:end_of_day)
end_time = search_params[:valid_to_lteq].try(:to_date)
search_params[:valid_to_lteq] = end_time.try(:end_of_day)
rescue
logger.warn('Invalid date')
end
yield
params[:q][:valid_to_lteq] = ca_cache
search_params[:valid_to_lteq] = ca_cache
end
def search_params
params.fetch(:q, {}).permit(:name_matches,
:registrant_ident_eq,
:contacts_ident_eq,
:nameservers_hostname_eq,
:valid_to_gteq,
:valid_to_lteq)
end
end
end

View file

@ -55,7 +55,7 @@ class Registrar
ip_allowed = restricted_ip.can_access_registrar_area?(resource.registrar)
unless ip_allowed
render text: t('registrar.authorization.ip_not_allowed', ip: request.ip)
render plain: t('registrar.authorization.ip_not_allowed', ip: request.ip)
warden.logout(:registrar_user)
return
end
@ -171,7 +171,7 @@ class Registrar
return if allowed
render text: t('registrar.authorization.ip_not_allowed', ip: request.ip)
render plain: t('registrar.authorization.ip_not_allowed', ip: request.ip)
end
def current_ability

View file

@ -19,7 +19,7 @@ class Registrar
xml_dir_path = Rails.root + 'app/views/registrar/xml_consoles/epp_requests'
xml = File.read("#{xml_dir_path}/#{params[:obj]}/#{params[:epp_action]}.xml")
xml.gsub!('<clTRID>ABC-12345</clTRID>', "<clTRID>#{cl_trid}</clTRID>")
render text: xml
render plain: xml
end
end
end

View file

@ -1,4 +1,4 @@
class Account < ActiveRecord::Base
class Account < ApplicationRecord
include Versions
belongs_to :registrar, required: true

View file

@ -1,4 +1,4 @@
class AccountActivity < ActiveRecord::Base
class AccountActivity < ApplicationRecord
include Versions
belongs_to :account, required: true
belongs_to :bank_transaction

View file

@ -1,4 +1,4 @@
class Action < ActiveRecord::Base
class Action < ApplicationRecord
has_paper_trail class_name: 'ActionVersion'
belongs_to :user

View file

@ -1,5 +1,5 @@
module ApiLog
class Db < ActiveRecord::Base
class Db < ApplicationRecord
self.abstract_class = true
# to_sym is needed because passing a string to ActiveRecord::Base.establish_connection
# for a configuration lookup is deprecated

View file

@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View file

@ -1,4 +1,4 @@
class Auction < ActiveRecord::Base
class Auction < ApplicationRecord
enum status: {
started: 'started',
awaiting_payment: 'awaiting_payment',

View file

@ -1,4 +1,4 @@
class BankStatement < ActiveRecord::Base
class BankStatement < ApplicationRecord
include Versions
has_many :bank_transactions

View file

@ -1,4 +1,4 @@
class BankTransaction < ActiveRecord::Base
class BankTransaction < ApplicationRecord
include Versions
belongs_to :bank_statement
has_one :account_activity

View file

@ -1,5 +1,5 @@
module Billing
class Price < ActiveRecord::Base
class Price < ApplicationRecord
include Concerns::Billing::Price::Expirable
belongs_to :zone, class_name: 'DNS::Zone', required: true

View file

@ -1,4 +1,4 @@
class BlockedDomain < ActiveRecord::Base
class BlockedDomain < ApplicationRecord
include Versions
before_save :generate_data
after_destroy :remove_data

View file

@ -1,6 +1,6 @@
require 'open3'
class Certificate < ActiveRecord::Base
class Certificate < ApplicationRecord
include Versions
belongs_to :api_user

View file

@ -35,7 +35,7 @@ module Concerns::Domain::ForceDelete
end
def preserve_current_statuses_for_force_delete
self.statuses_before_force_delete = statuses
self.statuses_before_force_delete = statuses.clone
end
def restore_statuses_before_force_delete

View file

@ -20,7 +20,7 @@ module EppErrors
epp_errors << collect_parent_errors(attr, errors)
end
errors[:epp_errors] = epp_errors
errors.add(:epp_errors, epp_errors)
errors[:epp_errors].flatten!
end

View file

@ -1,4 +1,4 @@
class Contact < ActiveRecord::Base
class Contact < ApplicationRecord
include Versions # version/contact_version.rb
include EppErrors
include UserEvents
@ -246,10 +246,8 @@ class Contact < ActiveRecord::Base
end
def registrant_user_contacts(registrant_user)
# In Rails 5, can be replaced with a much simpler `or` query method and the raw SQL parts can
# be removed.
from("(#{registrant_user_direct_contacts(registrant_user).to_sql} UNION " \
"#{registrant_user_indirect_contacts(registrant_user).to_sql}) AS contacts")
registrant_user_direct_contacts(registrant_user)
.or(registrant_user_indirect_contacts(registrant_user))
end
def registrant_user_direct_contacts(registrant_user)
@ -415,7 +413,7 @@ class Contact < ActiveRecord::Base
# if total is smaller than needed, the load more
# we also need to sort by valid_to
# todo: extract to drapper. Then we can remove Domain#roles
def all_domains(page: nil, per: nil, params: {})
def all_domains(page: nil, per: nil, params:)
# compose filter sql
filter_sql = case params[:domain_filter]
when "Registrant".freeze

View file

@ -1,4 +1,4 @@
class Directo < ActiveRecord::Base
class Directo < ApplicationRecord
DOMAIN_TO_PRODUCT = {"ee" => "01EE", "com.ee" => "02COM", "pri.ee" => "03PRI", "fie.ee"=>"04FIE", "med.ee" => "05MED"}.freeze
belongs_to :item, polymorphic: true

View file

@ -1,11 +1,11 @@
module DNS
class Zone < ActiveRecord::Base
class Zone < ApplicationRecord
validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, :master_nameserver, presence: true
validates :ttl, :refresh, :retry, :expire, :minimum_ttl, numericality: { only_integer: true }
validates :origin, uniqueness: true
before_destroy do
!used?
throw(:abort) if used?
end
def self.generate_zonefiles

View file

@ -1,4 +1,4 @@
class Dnskey < ActiveRecord::Base
class Dnskey < ApplicationRecord
include Versions # version/dnskey_version.rb
include EppErrors

View file

@ -1,4 +1,4 @@
class Domain < ActiveRecord::Base
class Domain < ApplicationRecord
include UserEvents
include Versions # version/domain_version.rb
include Concerns::Domain::Expirable
@ -191,8 +191,6 @@ class Domain < ActiveRecord::Base
end
def registrant_user_domains(registrant_user)
# In Rails 5, can be replaced with a much simpler `or` query method and the raw SQL parts can
# be removed.
from(
"(#{registrant_user_domains_by_registrant(registrant_user).to_sql} UNION " \
"#{registrant_user_domains_by_contact(registrant_user).to_sql}) AS domains"
@ -200,8 +198,6 @@ class Domain < ActiveRecord::Base
end
def registrant_user_direct_domains(registrant_user)
# In Rails 5, can be replaced with a much simpler `or` query method and the raw SQL parts can
# be removed.
from(
"(#{registrant_user_direct_domains_by_registrant(registrant_user).to_sql} UNION " \
"#{registrant_user_direct_domains_by_contact(registrant_user).to_sql}) AS domains"
@ -209,8 +205,6 @@ class Domain < ActiveRecord::Base
end
def registrant_user_administered_domains(registrant_user)
# In Rails 5, can be replaced with a much simpler `or` query method and the raw SQL parts can
# be removed.
from(
"(#{registrant_user_domains_by_registrant(registrant_user).to_sql} UNION " \
"#{registrant_user_domains_by_admin_contact(registrant_user).to_sql}) AS domains"
@ -229,7 +223,7 @@ class Domain < ActiveRecord::Base
def registrant_user_domains_by_admin_contact(registrant_user)
joins(:domain_contacts).where(domain_contacts: { contact_id: registrant_user.contacts,
type: [AdminDomainContact] })
type: [AdminDomainContact.name] })
end
def registrant_user_direct_domains_by_registrant(registrant_user)

View file

@ -1,4 +1,4 @@
class DomainContact < ActiveRecord::Base
class DomainContact < ApplicationRecord
# STI: tech_domain_contact
# STI: admin_domain_contact
include Versions # version/domain_contact_version.rb

View file

@ -1,4 +1,4 @@
class DomainStatus < ActiveRecord::Base
class DomainStatus < ApplicationRecord
include Versions # version/domain_status_version.rb
include EppErrors

View file

@ -1,4 +1,4 @@
class DomainTransfer < ActiveRecord::Base
class DomainTransfer < ApplicationRecord
belongs_to :domain
belongs_to :old_registrar, class_name: 'Registrar'

View file

@ -9,7 +9,7 @@ class Epp::Contact < Contact
def manage_permissions
return unless update_prohibited? || delete_prohibited?
add_epp_error('2304', nil, nil, I18n.t(:object_status_prohibits_operation))
false
throw(:abort)
end
class << self

View file

@ -12,7 +12,7 @@ class Epp::Domain < Domain
return unless update_prohibited? || delete_prohibited?
stat = (statuses & (DomainStatus::UPDATE_PROHIBIT_STATES + DomainStatus::DELETE_PROHIBIT_STATES)).first
add_epp_error('2304', 'status', stat, I18n.t(:object_status_prohibits_operation))
false
throw(:abort)
end
after_validation :validate_contacts

View file

@ -1,4 +1,4 @@
class EppSession < ActiveRecord::Base
class EppSession < ApplicationRecord
belongs_to :user, required: true
validates :session_id, uniqueness: true, presence: true

View file

@ -1,4 +1,4 @@
class Invoice < ActiveRecord::Base
class Invoice < ApplicationRecord
include Versions
include Concerns::Invoice::Cancellable
include Concerns::Invoice::Payable
@ -47,7 +47,7 @@ class Invoice < ActiveRecord::Base
errors.add(:base, I18n.t('failed_to_generate_invoice_invoice_number_limit_reached'))
logger.error('INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE')
false
throw(:abort)
end
def to_s

View file

@ -1,4 +1,4 @@
class InvoiceItem < ActiveRecord::Base
class InvoiceItem < ApplicationRecord
include Versions
belongs_to :invoice

View file

@ -1,4 +1,4 @@
class LegalDocument < ActiveRecord::Base
class LegalDocument < ApplicationRecord
cattr_accessor :explicitly_write_file
include EppErrors
MIN_BODY_SIZE = (1.37 * 3.kilobytes).ceil

View file

@ -1,4 +1,4 @@
class Nameserver < ActiveRecord::Base
class Nameserver < ApplicationRecord
include Versions # version/nameserver_version.rb
include EppErrors

View file

@ -1,4 +1,4 @@
class Notification < ActiveRecord::Base
class Notification < ApplicationRecord
include Versions # version/notification_version.rb
belongs_to :registrar

View file

@ -1,4 +1,4 @@
# To be able to remove existing jobs
class QueJob < ActiveRecord::Base
class QueJob < ApplicationRecord
self.primary_key = 'job_id'
end

View file

@ -1,10 +1,10 @@
# Used in Registrant portal to collect registrant verifications
# Registrant postgres user can access this table directly.
class RegistrantVerification < ActiveRecord::Base
class RegistrantVerification < ApplicationRecord
# actions
CONFIRMED = 'confirmed'
REJECTED = 'rejected'
# action types
DOMAIN_REGISTRANT_CHANGE = 'domain_registrant_change'
DOMAIN_DELETE = 'domain_delete'

View file

@ -1,4 +1,4 @@
class Registrar < ActiveRecord::Base
class Registrar < ApplicationRecord
include Versions # version/registrar_version.rb
has_many :domains, dependent: :restrict_with_error

View file

@ -1,4 +1,4 @@
class ReservedDomain < ActiveRecord::Base
class ReservedDomain < ApplicationRecord
include Versions # version/reserved_domain_version.rb
before_save :fill_empty_passwords
before_save :generate_data

View file

@ -1,10 +1,10 @@
module Type
class VATRate < ActiveRecord::Type::Decimal
def type_cast_from_database(value)
def deserialize(value)
super * 100 if value
end
def type_cast_for_database(value)
def serialize(value)
super / 100.0 if value
end
end

View file

@ -1,4 +1,4 @@
class User < ActiveRecord::Base
class User < ApplicationRecord
include Versions # version/user_version.rb
has_many :actions, dependent: :restrict_with_exception

View file

@ -1,4 +1,4 @@
class WhiteIp < ActiveRecord::Base
class WhiteIp < ApplicationRecord
include Versions
belongs_to :registrar

View file

@ -1,5 +1,5 @@
module Whois
class Server < ActiveRecord::Base
class Server < ApplicationRecord
self.abstract_class = true
establish_connection :"whois_#{Rails.env}"
end

View file

@ -1,5 +1,5 @@
require "erb"
class WhoisRecord < ActiveRecord::Base
class WhoisRecord < ApplicationRecord
belongs_to :domain
belongs_to :registrar

View file

@ -1,4 +1,5 @@
- domains = contact.all_domains(page: params[:domain_page], per: 20, params: params)
- domains = contact.all_domains(page: params[:domain_page], per: 20,
params: domain_filter_params.to_h)
.panel.panel-default
.panel-heading
.pull-left

View file

@ -1,4 +1,5 @@
<% domains = contact.all_domains(page: params[:domain_page], per: 20, params: params) %>
<% domains = contact.all_domains(page: params[:domain_page], per: 20,
params: domain_filter_params.to_h) %>
<div class="panel panel-default">
<div class="panel-heading">
@ -50,4 +51,4 @@
<div class="panel-footer">
<%= paginate domains, param_name: :domain_page %>
</div>
</div>
</div>

View file

@ -1,4 +1,5 @@
- domains = contact.all_domains(page: params[:domain_page], per: 20, params: params)
- domains = contact.all_domains(page: params[:domain_page], per: 20,
params: domain_filter_params.to_h)
.panel.panel-default
.panel-heading
.pull-left

View file

@ -3,7 +3,7 @@
<div class="col-md-3">
<div class="form-group">
<%= f.label :name, for: nil %>
<%= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control',
<%= f.search_field :name_matches, value: search_params[:name_matches], class: 'form-control',
placeholder: t(:name) %>
</div>
</div>
@ -44,7 +44,7 @@
<div class="col-md-3">
<div class="form-group">
<%= f.label :valid_to_from, for: nil %>
<%= f.search_field :valid_to_gteq, value: params[:q][:valid_to_gteq],
<%= f.search_field :valid_to_gteq, value: search_params[:valid_to_gteq],
class: 'form-control js-datepicker',
placeholder: t(:valid_to_from) %>
</div>
@ -53,7 +53,7 @@
<div class="col-md-3">
<div class="form-group">
<%= f.label :valid_to_until, for: nil %>
<%= f.search_field :valid_to_lteq, value: params[:q][:valid_to_lteq],
<%= f.search_field :valid_to_lteq, value: search_params[:valid_to_lteq],
class: 'form-control js-datepicker',
placeholder: t(:valid_to_until) %>
</div>