fix issue with idents with special character

This commit is contained in:
mmeest 2025-06-09 10:31:33 +03:00
parent 549c390b2e
commit 8e7bef39d7
3 changed files with 55 additions and 3 deletions

View file

@ -412,7 +412,7 @@ GEM
request_store (~> 1.4)
pdfkit (0.8.7.2)
pg (1.5.9)
pg_query (2.1.2)
pg_query (0.9.0)
google-protobuf (>= 3.17.1)
pghero (3.1.0)
activerecord (>= 6)

View file

@ -282,6 +282,54 @@ class Domain < ApplicationRecord
authorizable_ransackable_attributes
end
def ransackable_scopes(*)
[:registrant_ident_cont_any, :contacts_ident_cont_any]
end
def registrant_ident_cont_any(value)
return all if value.blank?
# Split the value into parts and create search conditions
parts = value.split('-')
conditions = []
# Add the original value
conditions << "contacts.ident ILIKE '%#{value}%'"
# Add conditions for each part
parts.each do |part|
conditions << "contacts.ident ILIKE '%#{part}%'"
end
# Add condition with hyphens removed
clean_value = value.gsub('-', '')
conditions << "REPLACE(contacts.ident, '-', '') ILIKE '%#{clean_value}%'"
joins(:registrant).where(conditions.join(' OR '))
end
def contacts_ident_cont_any(value)
return all if value.blank?
# Split the value into parts and create search conditions
parts = value.split('-')
conditions = []
# Add the original value
conditions << "contacts.ident ILIKE '%#{value}%'"
# Add conditions for each part
parts.each do |part|
conditions << "contacts.ident ILIKE '%#{part}%'"
end
# Add condition with hyphens removed
clean_value = value.gsub('-', '')
conditions << "REPLACE(contacts.ident, '-', '') ILIKE '%#{clean_value}%'"
joins(:contacts).where(conditions.join(' OR '))
end
def nameserver_required?
Setting.nameserver_required
end

View file

@ -5,7 +5,7 @@ class PartialSearchFormatter
search_params.each do |key, value|
next unless should_format?(key, value)
search_params[key] = format_value(value)
search_params[key] = format_value(value, key)
end
search_params
@ -15,9 +15,13 @@ class PartialSearchFormatter
key.include?('matches') && value.present?
end
def self.format_value(value)
def self.format_value(value, key)
if value =~ /\A\*.*\*\z/
value.gsub(/\A\*|\*\z/, '')
elsif key.include?('ident')
# For contact identifiers, return array of values
parts = value.split('-')
parts.map { |part| "%#{part}%" }
else
"%#{value}%"
end