mirror of
https://github.com/internetee/registry.git
synced 2025-08-27 03:23:37 +02:00
fix issue with idents with special character
This commit is contained in:
parent
549c390b2e
commit
8e7bef39d7
3 changed files with 55 additions and 3 deletions
|
@ -412,7 +412,7 @@ GEM
|
||||||
request_store (~> 1.4)
|
request_store (~> 1.4)
|
||||||
pdfkit (0.8.7.2)
|
pdfkit (0.8.7.2)
|
||||||
pg (1.5.9)
|
pg (1.5.9)
|
||||||
pg_query (2.1.2)
|
pg_query (0.9.0)
|
||||||
google-protobuf (>= 3.17.1)
|
google-protobuf (>= 3.17.1)
|
||||||
pghero (3.1.0)
|
pghero (3.1.0)
|
||||||
activerecord (>= 6)
|
activerecord (>= 6)
|
||||||
|
|
|
@ -282,6 +282,54 @@ class Domain < ApplicationRecord
|
||||||
authorizable_ransackable_attributes
|
authorizable_ransackable_attributes
|
||||||
end
|
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?
|
def nameserver_required?
|
||||||
Setting.nameserver_required
|
Setting.nameserver_required
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ class PartialSearchFormatter
|
||||||
search_params.each do |key, value|
|
search_params.each do |key, value|
|
||||||
next unless should_format?(key, value)
|
next unless should_format?(key, value)
|
||||||
|
|
||||||
search_params[key] = format_value(value)
|
search_params[key] = format_value(value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
search_params
|
search_params
|
||||||
|
@ -15,9 +15,13 @@ class PartialSearchFormatter
|
||||||
key.include?('matches') && value.present?
|
key.include?('matches') && value.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.format_value(value)
|
def self.format_value(value, key)
|
||||||
if value =~ /\A\*.*\*\z/
|
if value =~ /\A\*.*\*\z/
|
||||||
value.gsub(/\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
|
else
|
||||||
"%#{value}%"
|
"%#{value}%"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue