From e5858a4174b8b20c921dc0801ab649610fb5f443 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius Date: Fri, 30 Sep 2011 11:56:50 -0700 Subject: [PATCH] updates, refactor --- app/controllers/ns_controller.rb | 1 + app/controllers/records_controller.rb | 1 + app/controllers/soas_controller.rb | 3 +++ app/models/ability.rb | 1 + app/models/domain.rb | 9 ++------- app/models/record.rb | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/ns_controller.rb b/app/controllers/ns_controller.rb index 69ccb52..ab5791b 100644 --- a/app/controllers/ns_controller.rb +++ b/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 diff --git a/app/controllers/records_controller.rb b/app/controllers/records_controller.rb index 6f97f2f..3ffd764 100644 --- a/app/controllers/records_controller.rb +++ b/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 diff --git a/app/controllers/soas_controller.rb b/app/controllers/soas_controller.rb index 87f24b0..6cc9e56 100644 --- a/app/controllers/soas_controller.rb +++ b/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 diff --git a/app/models/ability.rb b/app/models/ability.rb index 2b7bd8a..ddb0ded 100644 --- a/app/models/ability.rb +++ b/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. diff --git a/app/models/domain.rb b/app/models/domain.rb index a21c3da..e910254 100644 --- a/app/models/domain.rb +++ b/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 diff --git a/app/models/record.rb b/app/models/record.rb index 97071cb..ac20a92 100644 --- a/app/models/record.rb +++ b/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"}