Updated dependency ransack to v4

This commit is contained in:
Sergei Tsoganov 2023-03-16 11:28:25 +02:00
parent a78f5b901f
commit 37c16a067d
16 changed files with 139 additions and 36 deletions

View file

@ -56,7 +56,7 @@ module Admin
private
def sortable_dispute_query_for(disputes, query, closed: false)
@q = disputes.order(:domain_name).search(query)
@q = disputes.order(:domain_name).ransack(query)
disputes = @q.result.page(closed ? params[:closed_page] : params[:page])
return disputes.per(params[:results_per_page]) if params[:results_per_page].present?

View file

@ -6,7 +6,7 @@ class Account < ApplicationRecord
validates :account_type, presence: true
CASH = 'cash'
CASH = 'cash'.freeze
def activities
account_activities
@ -16,7 +16,15 @@ class Account < ApplicationRecord
[id, balance, currency, registrar]
end
def self.ransackable_associations(auth_object = nil)
super
end
def self.ransackable_attributes(auth_object = nil)
super
end
def self.csv_header
['Id', 'Balance', 'Currency', 'Registrar']
%w[Id Balance Currency Registrar]
end
end

View file

@ -25,6 +25,14 @@ class AccountActivity < ApplicationRecord
end
class << self
def ransackable_attributes(auth_object = nil)
super
end
def ransackable_associations(auth_object = nil)
super
end
def types_for_select
[CREATE, RENEW, ADD_CREDIT, UPDATE_CREDIT].map { |x| [I18n.t(x), x] }
end

View file

@ -4,5 +4,13 @@ module ApiLog
# to_sym is needed because passing a string to ActiveRecord::Base.establish_connection
# for a configuration lookup is deprecated
establish_connection "api_log_#{Rails.env}".to_sym
def self.ransackable_associations(auth_object = nil)
super
end
def self.ransackable_attributes(auth_object = nil)
super
end
end
end

View file

@ -33,6 +33,14 @@ class Auction < ApplicationRecord
where('domain ilike ?', "%#{domain_name.strip}%") if domain_name.present?
}
def self.ransackable_attributes(auth_object = nil)
super
end
def self.ransackable_associations(auth_object = nil)
super
end
def self.pending(domain_name)
find_by(domain: domain_name.to_s, status: PENDING_STATUSES)
end

View file

@ -10,6 +10,10 @@ class BankStatement < ApplicationRecord
PARTIALLY_BINDED = 'partially_binded'.freeze
NOT_BINDED = 'not_binded'.freeze
def self.ransackable_attributes(auth_object = nil)
super
end
# TODO: Cache this to database so it can be used for searching
def status
if bank_transactions.unbinded.count == bank_transactions.count

View file

@ -21,6 +21,10 @@ module Billing
new_record? || duration_changed?
end
def self.ransackable_attributes(auth_object = nil)
super
end
def self.operation_categories
%w[create renew]
end

View file

@ -5,14 +5,21 @@ class BlockedDomain < ApplicationRecord
validates :name, domain_name: true, uniqueness: true
class << self
def ransackable_attributes(auth_object = nil)
super
end
def ransackable_associations(auth_object = nil)
super
end
def by_domain(name)
where(name: name)
end
end
def name= val
def name=(val)
super SimpleIDN.to_unicode(val)
end

View file

@ -183,6 +183,14 @@ class Contact < ApplicationRecord
#
class << self
def ransackable_associations(auth_object = nil)
super
end
def ransackable_attributes(auth_object = nil)
super
end
def search_by_query(query)
res = search(code_cont: query).result
res.reduce([]) { |o, v| o << { id: v[:id], display_key: "#{v.name} (#{v.code})" } }

View file

@ -21,6 +21,14 @@ class Dispute < ApplicationRecord
Domain.find_by(name: domain_name)
end
def self.ransackable_associations(auth_object = nil)
super
end
def self.ransackable_attributes(auth_object = nil)
super
end
def self.close_by_domain(domain_name)
dispute = Dispute.active.find_by(domain_name: domain_name)
return false unless dispute

View file

@ -245,6 +245,14 @@ class Domain < ApplicationRecord
end
class << self
def ransackable_associations(auth_object = nil)
super
end
def ransackable_attributes(auth_object = nil)
super
end
def nameserver_required?
Setting.nameserver_required
end

View file

@ -144,6 +144,14 @@ class Invoice < ApplicationRecord
]
end
def self.ransackable_associations(auth_object = nil)
super
end
def self.ransackable_attributes(auth_object = nil)
super
end
def self.csv_header
['Number', 'Buyer', 'Due Date', 'Receipt Date', 'Issue Date', 'Total', 'Currency', 'Seller Name']
end

View file

@ -13,16 +13,24 @@ class ReservedDomain < ApplicationRecord
self.ignored_columns = %w[legacy_id]
class << self
def ransackable_attributes(auth_object = nil)
super
end
def ransackable_associations(auth_object = nil)
super
end
def pw_for(domain_name)
name_in_ascii = SimpleIDN.to_ascii(domain_name)
by_domain(domain_name).first.try(:password) || by_domain(name_in_ascii).first.try(:password)
end
def by_domain name
def by_domain(name)
where(name: name)
end
def new_password_for name
def new_password_for(name)
record = by_domain(name).first
return unless record
@ -31,7 +39,7 @@ class ReservedDomain < ApplicationRecord
end
end
def name= val
def name=(val)
super SimpleIDN.to_unicode(val)
end

View file

@ -13,10 +13,18 @@ class Version::ContactVersion < PaperTrail::Version
contact.ident_human_description,
contact.registrar,
event,
created_at.to_formatted_s(:db)
created_at.to_formatted_s(:db),
]
end
def self.ransackable_attributes(auth_object = nil)
super
end
def self.ransackable_associations(auth_object = nil)
super
end
def self.csv_header
['Name', 'ID', 'Ident', 'Registrar', 'Action', 'Created at']
end

View file

@ -18,6 +18,14 @@ class Version::DomainVersion < PaperTrail::Version
]
end
def self.ransackable_attributes(auth_object = nil)
super
end
def self.ransackable_associations(auth_object = nil)
super
end
def self.was_contact_linked?(contact_id)
sql = <<-SQL
SELECT

View file

@ -8,7 +8,7 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
@auth_headers = { 'Authorization' => token }
adapter = ENV["shunter_default_adapter"].constantize.new
adapter = ENV['shunter_default_adapter'].constantize.new
adapter&.clear!
end
@ -60,8 +60,8 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
street: 'Wismari 13',
zip: '12345',
country_code: 'EE',
}
}
},
},
}
post '/repp/v1/contacts', headers: @auth_headers, params: request_body
@ -85,15 +85,15 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
request_body = {
"contact": {
"name": "Donald Trump",
"phone": "+372.51111112",
"email": "donald@trumptower.com",
"name": 'Donald Trump',
"phone": '+372.51111112',
"email": 'donald@trumptower.com',
"ident": {
"ident_type": "priv",
"ident_country_code": "EE",
"ident": "39708290069"
}
}
'ident_type': 'priv',
'ident_country_code': 'EE',
'ident': '39708290069',
},
},
}
post '/repp/v1/contacts', headers: @auth_headers, params: request_body
@ -109,15 +109,15 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
def test_validates_ident_code
request_body = {
"contact": {
"name": "Donald Trump",
"phone": "+372.51111112",
"email": "donald@trumptower.com",
"name": 'Donald Trump',
"phone": '+372.51111112',
"email": 'donald@trumptower.com',
"ident": {
"ident_type": "priv",
"ident_country_code": "EE",
"ident": "123123123"
}
}
"ident_type": 'priv',
"ident_country_code": 'EE',
"ident": '123123123',
},
},
}
post '/repp/v1/contacts', headers: @auth_headers, params: request_body
@ -158,8 +158,8 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
end
def test_returns_error_response_if_throttled
ENV["shunter_default_threshold"] = '1'
ENV["shunter_enabled"] = 'true'
ENV['shunter_default_threshold'] = '1'
ENV['shunter_enabled'] = 'true'
request_body = {
contact: {
@ -181,7 +181,7 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
assert_response :bad_request
assert_equal json[:code], 2502
assert response.body.include?(Shunter.default_error_message)
ENV["shunter_default_threshold"] = '10000'
ENV["shunter_enabled"] = 'false'
ENV['shunter_default_threshold'] = '10000'
ENV['shunter_enabled'] = 'false'
end
end