Browse Source

more refinement

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
5250dc4815
  1. 10
      app/controllers/domains_controller.rb
  2. 6
      app/controllers/mxes_controller.rb
  3. 6
      app/models/domain.rb
  4. 3
      app/models/ns.rb
  5. 1
      app/models/record.rb

10
app/controllers/domains_controller.rb

@ -5,7 +5,7 @@ class DomainsController < ApplicationController
conf.list.columns = [:name, :soa_record, :ns_records, :records] conf.list.columns = [:name, :soa_record, :ns_records, :records]
conf.create.columns = [:name, :soa_record, :ns_records] conf.create.columns = [:name, :soa_record, :ns_records]
conf.update.columns = [:name, :soa_record, :ns_records] conf.update.columns = [:name, :soa_record, :ns_records]
conf.columns[:name].description = 'yourdomain.com' conf.columns[:name].description = 'domain.com'
conf.columns[:ns_records].show_blank_record = false conf.columns[:ns_records].show_blank_record = false
conf.actions.exclude :show conf.actions.exclude :show
conf.list.sorting = { :name => :asc } conf.list.sorting = { :name => :asc }
@ -18,8 +18,7 @@ class DomainsController < ApplicationController
def do_new def do_new
super super
session[:sample_ns] = nil @record.setup(current_user.email)
@record.setup(current_user.email, sample_ns)
end end
def before_create_save(record) def before_create_save(record)
@ -27,12 +26,7 @@ class DomainsController < ApplicationController
end end
def after_create_save(record) def after_create_save(record)
session[:sample_ns] = nil
@record.reload @record.reload
end end
def sample_ns
session[:sample_ns] ||= Settings.ns.sample(2)
end
end end

6
app/controllers/mxes_controller.rb

@ -1,10 +1,10 @@
class MxesController < ApplicationController class MxesController < ApplicationController
active_scaffold :mx do |conf| active_scaffold :mx do |conf|
conf.list.columns = [:name, :type, :content, :ttl, :prio, :change_date] conf.list.columns = [:name, :type, :content, :ttl, :prio, :change_date]
conf.create.columns = [:name, :content, :ttl, :prio] conf.create.columns = [:content, :ttl, :prio]
conf.update.columns = [:name, :content, :ttl, :prio] conf.update.columns = [:content, :ttl, :prio]
conf.columns[:content].label = 'MX' conf.columns[:content].label = 'MX'
conf.columns[:name].description = 'Ex: mail or mx etc' conf.columns[:content].description = 'Ex. mail.domain.com'
conf.columns[:change_date].list_ui = :timestamp conf.columns[:change_date].list_ui = :timestamp
conf.actions.exclude :show conf.actions.exclude :show
end end

6
app/models/domain.rb

@ -28,7 +28,7 @@ class Domain < ActiveRecord::Base
def slave?; self.type == 'SLAVE' end def slave?; self.type == 'SLAVE' end
def setup(email, sample_ns) def setup(email)
build_soa_record build_soa_record
soa = soa_record soa = soa_record
soa.contact ||= email soa.contact ||= email
@ -36,7 +36,7 @@ class Domain < ActiveRecord::Base
ns_records.build ns_records.build
ns_records.build ns_records.build
ns1, ns2 = ns_records ns1, ns2 = ns_records
ns1.content = sample_ns.first ns1.content = Settings.ns.first
ns2.content = sample_ns.second ns2.content = (Settings.ns - [ns1.content]).sample
end end
end end

3
app/models/ns.rb

@ -20,10 +20,9 @@
# Obtained from http://www.zytrax.com/books/dns/ch8/ns.html # Obtained from http://www.zytrax.com/books/dns/ch8/ns.html
# #
class NS < Record class NS < Record
validates :content, :presence => true, :hostname => true validates :content, :presence => true, :hostname => true, :inclusion => {:in => Settings.ns}
def to_label; "#{content}" end def to_label; "#{content}" end
end end
Ns = NS Ns = NS

1
app/models/record.rb

@ -6,6 +6,7 @@ class Record < ActiveRecord::Base
validates :domain, :name, :presence => true validates :domain, :name, :presence => true
validates :type, :inclusion => {:in => @@types, :message => "Unknown record type"} validates :type, :inclusion => {:in => @@types, :message => "Unknown record type"}
validates :content, :uniqueness => {:scope => [:domain_id, :type]}
# RFC 2181, 8 # RFC 2181, 8
validates :ttl, :numericality => { validates :ttl, :numericality => {
# :greater_than_or_equal_to => 0, # :greater_than_or_equal_to => 0,

Loading…
Cancel
Save