Browse Source

updates, refactor

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
e5858a4174
  1. 1
      app/controllers/ns_controller.rb
  2. 1
      app/controllers/records_controller.rb
  3. 3
      app/controllers/soas_controller.rb
  4. 1
      app/models/ability.rb
  5. 9
      app/models/domain.rb
  6. 2
      app/models/record.rb

1
app/controllers/ns_controller.rb

@ -2,6 +2,7 @@ class NsController < ApplicationController
active_scaffold :ns do |conf|
conf.columns = [:name, :content, :ttl]
conf.columns[:content].label = 'Hostname'
conf.actions.exclude :show
end
protected

1
app/controllers/records_controller.rb

@ -2,6 +2,7 @@ class RecordsController < ApplicationController
active_scaffold :record do |conf|
conf.sti_children = [:SOA, :NS]
conf.columns = [:name, :type, :content, :ttl, :prio, :change_date]
conf.actions.exclude :show
end
before_filter :ensure_nested_under_domain

3
app/controllers/soas_controller.rb

@ -1,6 +1,9 @@
class SoasController < ApplicationController
active_scaffold :soa do |conf|
conf.columns = [:name, :primary_ns, :contact, :ttl]
conf.update.columns = [:contact, :ttl]
conf.actions.exclude :delete
conf.actions.exclude :show
end
protected

1
app/models/ability.rb

@ -7,6 +7,7 @@ class Ability
if user.persisted?
can :manage, Domain, :user_id => user.id
can :manage, Record, :domain => {:user_id => user.id}
cannot :delete, SOA
end
# The first argument to `can` is the action you are giving the user permission to do.

9
app/models/domain.rb

@ -10,8 +10,6 @@ class Domain < ActiveRecord::Base
has_one :soa_record, :class_name => 'SOA', :conditions => {:type => 'SOA'}
# Handle relations and validations for all resource records on this zone
validates_associated :records
for type in Record.types
has_many :"#{type.downcase}_records", :class_name => type, :conditions => {:type => type}
validates_associated :"#{type.downcase}_records"
@ -19,15 +17,12 @@ class Domain < ActiveRecord::Base
validates :name, :presence => true, :uniqueness => true, :domainname => {:require_valid_tld => false}
validates :master, :presence => true, :if => :slave?
validates :master, :ip => true, :if => :slave?, :allow_nil => true
validates :master, :ip => true, :allow_nil => true, :if => :slave?
validates :type, :inclusion => { :in => @@types, :message => "Unknown domain type" }
validates :soa_record, :presence => {:unless => :slave?}
validates_associated :soa_record, :allow_nil => true
validates :ns_records, :presence => true, :length => {:minimum => 2, :message => "must have be at least 2"}
MASTER_FORMAT = /\A(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\z/
validate :master, :presence => {:if => :slave?},
:format => {:with => MASTER_FORMAT, :allow_blank => true, :if => :slave?}
validates_associated :records
# Are we a slave domain
def slave?; self.type == 'SLAVE' end
end

2
app/models/record.rb

@ -2,7 +2,7 @@ class Record < ActiveRecord::Base
belongs_to :domain
cattr_reader :types
@@types = ['SOA', 'NS', 'A', 'MX', 'TXT', 'CNAME']
@@types = %w(SOA NS A MX TXT CNAME)
validates :domain_id, :name, :presence => true
validates :type, :inclusion => {:in => @@types, :message => "Unknown record type"}

Loading…
Cancel
Save