mirror of
https://github.com/internetee/registry.git
synced 2025-05-30 01:20:04 +02:00
Story#108091488 - Seems that now reserved domains will be in better table
This commit is contained in:
parent
3c33a44f38
commit
6415bfae38
4 changed files with 34 additions and 16 deletions
|
@ -2,7 +2,7 @@ class Admin::ReservedDomainsController < AdminController
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
def index
|
def index
|
||||||
names = ReservedDomain.pluck(:names).each_with_object({}){|e_h,h| h.merge!(e_h)}
|
names = ReservedDomain.pluck(:name, :password).each_with_object({}){|domain, hash| hash[domain[0]] = domain[1]}
|
||||||
names.names = nil if names.blank?
|
names.names = nil if names.blank?
|
||||||
@reserved_domains = names.to_yaml.gsub(/---.?\n/, '').gsub(/\.\.\..?\n/, '')
|
@reserved_domains = names.to_yaml.gsub(/---.?\n/, '').gsub(/\.\.\..?\n/, '')
|
||||||
end
|
end
|
||||||
|
@ -28,9 +28,8 @@ class Admin::ReservedDomainsController < AdminController
|
||||||
|
|
||||||
#updating and adding
|
#updating and adding
|
||||||
names.each do |name, psw|
|
names.each do |name, psw|
|
||||||
rec = ReservedDomain.by_domain(name).first
|
rec = ReservedDomain.find_or_initialize_by(name: name)
|
||||||
rec ||= ReservedDomain.new
|
rec.password = psw
|
||||||
rec.names = {name => psw}
|
|
||||||
|
|
||||||
unless rec.save
|
unless rec.save
|
||||||
result = false
|
result = false
|
||||||
|
@ -39,7 +38,6 @@ class Admin::ReservedDomainsController < AdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if result
|
if result
|
||||||
flash[:notice] = I18n.t('record_updated')
|
flash[:notice] = I18n.t('record_updated')
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
|
|
|
@ -2,24 +2,27 @@ class ReservedDomain < ActiveRecord::Base
|
||||||
include Versions # version/reserved_domain_version.rb
|
include Versions # version/reserved_domain_version.rb
|
||||||
before_save :fill_empty_passwords
|
before_save :fill_empty_passwords
|
||||||
|
|
||||||
def fill_empty_passwords
|
|
||||||
return unless names
|
|
||||||
names.each { |k, v| names[k] = SecureRandom.hex if v.blank? }
|
|
||||||
end
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def pw_for(domain_name)
|
def pw_for(domain_name)
|
||||||
name_in_unicode = SimpleIDN.to_ascii(domain_name)
|
name_in_ascii = SimpleIDN.to_ascii(domain_name)
|
||||||
by_domain(domain_name).select("names -> '#{domain_name}' AS pw").first.try(:pw) ||
|
by_domain(domain_name).first.try(:password) || by_domain(name_in_ascii).first.try(:password)
|
||||||
by_domain(name_in_unicode).select("names -> '#{name_in_unicode}' AS pw").first.try(:pw)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def by_domain name
|
def by_domain name
|
||||||
where("names ? '#{name}'")
|
where(name: name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def any_of_domains names
|
def any_of_domains names
|
||||||
where("names ?| ARRAY['#{names.join("','")}']")
|
where(name: names)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def fill_empty_passwords
|
||||||
|
self.password = SecureRandom.hex unless self.password
|
||||||
|
end
|
||||||
|
|
||||||
|
def name= val
|
||||||
|
super SimpleIDN.to_unicode(val)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
class NameAndPasswordForReservedDomain < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
add_column :reserved_domains, :name, :string
|
||||||
|
add_column :reserved_domains, :password, :string
|
||||||
|
|
||||||
|
ReservedDomain.find_each do |domain|
|
||||||
|
names = domain.names
|
||||||
|
domain.update_columns(name: names.keys.first, password: names.values.first)
|
||||||
|
end
|
||||||
|
|
||||||
|
remove_column :reserved_domains, :names
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -73,7 +73,7 @@ admin3 = {
|
||||||
[admin1, admin2, admin3].each do |at|
|
[admin1, admin2, admin3].each do |at|
|
||||||
admin = AdminUser.where(at)
|
admin = AdminUser.where(at)
|
||||||
next if admin.present?
|
next if admin.present?
|
||||||
admin = AdminUser.new(at.merge({ password_confirmation: 'testtest' }))
|
admin = AdminUser.new(at.merge({ password_confirmation: 'testtest', password: 'testtest' }))
|
||||||
admin.roles = ['admin']
|
admin.roles = ['admin']
|
||||||
admin.save
|
admin.save
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue