mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 17:53:35 +02:00
Story#107279016 - admin shows all reserved domains line by line
This commit is contained in:
parent
34363ca878
commit
46e502080f
2 changed files with 32 additions and 6 deletions
|
@ -2,9 +2,9 @@ class Admin::ReservedDomainsController < AdminController
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
def index
|
def index
|
||||||
rd = ReservedDomain.first_or_initialize
|
names = ReservedDomain.pluck(:names).each_with_object({}){|e_h,h| h.merge!(e_h)}
|
||||||
rd.names = nil if rd.names.blank?
|
names.names = nil if names.blank?
|
||||||
@reserved_domains = rd.names.to_yaml.gsub(/---.?\n/, '').gsub(/\.\.\..?\n/, '')
|
@reserved_domains = names.to_yaml.gsub(/---.?\n/, '').gsub(/\.\.\..?\n/, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -20,9 +20,27 @@ class Admin::ReservedDomainsController < AdminController
|
||||||
render :index and return
|
render :index and return
|
||||||
end
|
end
|
||||||
|
|
||||||
rd = ReservedDomain.first_or_create
|
result = true
|
||||||
|
ReservedDomain.transaction do
|
||||||
|
# removing old ones
|
||||||
|
existing = ReservedDomain.any_of_domains(names.keys).pluck(:id)
|
||||||
|
ReservedDomain.where.not(id: existing).delete_all
|
||||||
|
|
||||||
if rd.update(names: names)
|
#updating and adding
|
||||||
|
names.each do |name, psw|
|
||||||
|
rec = ReservedDomain.by_domain(name).first
|
||||||
|
rec ||= ReservedDomain.new
|
||||||
|
rec.names = {name => psw}
|
||||||
|
|
||||||
|
unless rec.save
|
||||||
|
result = false
|
||||||
|
raise ActiveRecord::Rollback
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if result
|
||||||
flash[:notice] = I18n.t('record_updated')
|
flash[:notice] = I18n.t('record_updated')
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
else
|
else
|
||||||
|
|
|
@ -9,7 +9,15 @@ class ReservedDomain < ActiveRecord::Base
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def pw_for(domain_name)
|
def pw_for(domain_name)
|
||||||
select("names -> '#{domain_name}' AS pw").first.try(:pw)
|
by_domain(domain_name).select("names -> '#{domain_name}' AS pw").first.try(:pw)
|
||||||
|
end
|
||||||
|
|
||||||
|
def by_domain name
|
||||||
|
where("names ? '#{name}'")
|
||||||
|
end
|
||||||
|
|
||||||
|
def any_of_domains names
|
||||||
|
where("names ?| ARRAY['#{names.join("','")}']")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue