mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 08:43:37 +02:00
Domain name improvements
This commit is contained in:
parent
c5355ca8f5
commit
51091679c4
6 changed files with 34 additions and 6 deletions
5
Gemfile
5
Gemfile
|
@ -31,9 +31,12 @@ gem 'jbuilder', '~> 2.0'
|
||||||
# Replacement for erb
|
# Replacement for erb
|
||||||
gem 'haml-rails', '~> 0.5.3'
|
gem 'haml-rails', '~> 0.5.3'
|
||||||
|
|
||||||
#For XML parsing
|
# For XML parsing
|
||||||
gem 'nokogiri', '~> 1.6.2.1'
|
gem 'nokogiri', '~> 1.6.2.1'
|
||||||
|
|
||||||
|
# For punycode
|
||||||
|
gem 'simpleidn', '~> 0.0.5'
|
||||||
|
|
||||||
group :assets do
|
group :assets do
|
||||||
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
||||||
gem 'therubyracer', platforms: :ruby
|
gem 'therubyracer', platforms: :ruby
|
||||||
|
|
|
@ -141,6 +141,7 @@ GEM
|
||||||
rdoc (~> 4.0, < 5.0)
|
rdoc (~> 4.0, < 5.0)
|
||||||
shoulda-matchers (2.6.1)
|
shoulda-matchers (2.6.1)
|
||||||
activesupport (>= 3.0.0)
|
activesupport (>= 3.0.0)
|
||||||
|
simpleidn (0.0.5)
|
||||||
slop (3.5.0)
|
slop (3.5.0)
|
||||||
spring (1.1.3)
|
spring (1.1.3)
|
||||||
sprockets (2.11.0)
|
sprockets (2.11.0)
|
||||||
|
@ -195,6 +196,7 @@ DEPENDENCIES
|
||||||
sass-rails (~> 4.0.3)
|
sass-rails (~> 4.0.3)
|
||||||
sdoc (~> 0.4.0)
|
sdoc (~> 0.4.0)
|
||||||
shoulda-matchers (~> 2.6.1)
|
shoulda-matchers (~> 2.6.1)
|
||||||
|
simpleidn (~> 0.0.5)
|
||||||
spring
|
spring
|
||||||
therubyracer
|
therubyracer
|
||||||
turbolinks
|
turbolinks
|
||||||
|
|
|
@ -2,7 +2,6 @@ class Domain < ActiveRecord::Base
|
||||||
#TODO whois requests ip whitelist for full info for own domains and partial info for other domains
|
#TODO whois requests ip whitelist for full info for own domains and partial info for other domains
|
||||||
#TODO most inputs should be trimmed before validatation, probably some global logic?
|
#TODO most inputs should be trimmed before validatation, probably some global logic?
|
||||||
|
|
||||||
|
|
||||||
belongs_to :registrar
|
belongs_to :registrar
|
||||||
belongs_to :ns_set
|
belongs_to :ns_set
|
||||||
belongs_to :owner_contact, class_name: 'Contact'
|
belongs_to :owner_contact, class_name: 'Contact'
|
||||||
|
@ -11,6 +10,13 @@ class Domain < ActiveRecord::Base
|
||||||
|
|
||||||
validates :name, domain_name: true
|
validates :name, domain_name: true
|
||||||
|
|
||||||
|
def name=(value)
|
||||||
|
value.strip!
|
||||||
|
write_attribute(:name, SimpleIDN.to_unicode(value))
|
||||||
|
write_attribute(:name_puny, SimpleIDN.to_ascii(value))
|
||||||
|
write_attribute(:name_dirty, value)
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def check_availability(domains)
|
def check_availability(domains)
|
||||||
res = []
|
res = []
|
||||||
|
|
|
@ -17,10 +17,19 @@ class DomainNameValidator < ActiveModel::EachValidator
|
||||||
value = value.mb_chars.downcase.strip
|
value = value.mb_chars.downcase.strip
|
||||||
|
|
||||||
general_domains = /(.pri.ee|.edu.ee|.aip.ee|.org.ee|.med.ee|.riik.ee|.ee)/ #TODO Add more general domains here
|
general_domains = /(.pri.ee|.edu.ee|.aip.ee|.org.ee|.med.ee|.riik.ee|.ee)/ #TODO Add more general domains here
|
||||||
unicode_chars = /\u00E4\u00F5\u00F6\u00FC\u0161\u017E/ #äõöüšž
|
|
||||||
ok = value =~ /\A[a-zA-Z0-9#{unicode_chars}][a-zA-Z0-9#{unicode_chars}-]{0,61}[a-zA-Z0-9#{unicode_chars}]#{general_domains}\z/
|
|
||||||
|
|
||||||
ok &&= !(value[2] == '-' && value[3] == '-')
|
# it's punycode
|
||||||
|
if value[2] == '-' && value[3] == '-'
|
||||||
|
regexp = /\Axn--[a-zA-Z0-9-]{0,61}#{general_domains}\z/
|
||||||
|
return false unless value =~ regexp
|
||||||
|
value = SimpleIDN.to_unicode(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unicode_chars = /\u00E4\u00F5\u00F6\u00FC\u0161\u017E/ #äõöüšž
|
||||||
|
regexp = /\A[a-zA-Z0-9#{unicode_chars}][a-zA-Z0-9#{unicode_chars}-]{0,61}[a-zA-Z0-9#{unicode_chars}]#{general_domains}\z/
|
||||||
|
|
||||||
|
value =~ regexp
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
6
db/migrate/20140701130945_add_name_dirty_to_domains.rb
Normal file
6
db/migrate/20140701130945_add_name_dirty_to_domains.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class AddNameDirtyToDomains < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :domains, :name_dirty, :string
|
||||||
|
add_column :domains, :name_puny, :string
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20140627082711) do
|
ActiveRecord::Schema.define(version: 20140701130945) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -59,6 +59,8 @@ ActiveRecord::Schema.define(version: 20140627082711) do
|
||||||
t.string "auth_info"
|
t.string "auth_info"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.string "name_dirty"
|
||||||
|
t.string "name_puny"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "epp_sessions", force: true do |t|
|
create_table "epp_sessions", force: true do |t|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue