diff --git a/Gemfile b/Gemfile
index 05d8885..36c154e 100644
--- a/Gemfile
+++ b/Gemfile
@@ -18,7 +18,7 @@ gem 'devise', '~> 1.4.5'
gem 'cancan', '~> 1.6.5'
# gem "meta_where", "~> 1.0" # squeel ?
gem 'sentient_user', '~> 0.3.2'
-gem 'active_scaffold', '~> 3.1.0', :git => 'https://github.com/activescaffold/active_scaffold.git'
+gem 'active_scaffold', '~> 3.1.0', :git => 'https://github.com/clyfe/active_scaffold.git' # :path => '/home/clyfe/dev/active_scaffold'
gem 'web-app-theme'
gem 'pjax_rails', '~> 0.1.10'
gem 'validates_hostname', '~> 1.0.0', :git => 'https://github.com/KimNorgaard/validates_hostname.git'
diff --git a/Gemfile.lock b/Gemfile.lock
index 62681bb..2bfe5f2 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -5,8 +5,8 @@ GIT
validates_hostname (1.0.0)
GIT
- remote: https://github.com/activescaffold/active_scaffold.git
- revision: 60bb1ffeb99e7d3b6b99ffb117a48a527afe2c51
+ remote: https://github.com/clyfe/active_scaffold.git
+ revision: 04a7e1d3333fcb86a5967b17b4e535beec6acc39
specs:
active_scaffold (3.1.2)
rails (~> 3.1.0)
@@ -45,7 +45,7 @@ GEM
arel (2.2.1)
bcrypt-ruby (3.0.1)
builder (3.0.0)
- cancan (1.6.5)
+ cancan (1.6.6)
capistrano (2.9.0)
highline
net-scp (>= 1.0.0)
@@ -161,7 +161,7 @@ GEM
rspec (~> 2.6.0)
rubyzip (0.9.4)
sass (3.1.7)
- sass-rails (3.1.2)
+ sass-rails (3.1.3)
actionpack (~> 3.1.0)
railties (~> 3.1.0)
sass (>= 3.1.4)
diff --git a/app/controllers/domains_controller.rb b/app/controllers/domains_controller.rb
index a1ad33c..ffba318 100644
--- a/app/controllers/domains_controller.rb
+++ b/app/controllers/domains_controller.rb
@@ -12,9 +12,22 @@ class DomainsController < ApplicationController
end
protected
+
+ def do_new
+ super
+ @record.setup(current_user.email, sample_ns)
+ end
def before_create_save(record)
record.type = 'NATIVE'
end
-
+
+ def after_create_save(record)
+ session[:sample_ns] = nil
+ end
+
+ def sample_ns
+ session[:sample_ns] ||= Settings.ns.sample(2)
+ end
+
end
diff --git a/app/controllers/soas_controller.rb b/app/controllers/soas_controller.rb
index 6cc9e56..cfef921 100644
--- a/app/controllers/soas_controller.rb
+++ b/app/controllers/soas_controller.rb
@@ -1,9 +1,9 @@
class SoasController < ApplicationController
active_scaffold :soa do |conf|
conf.columns = [:name, :primary_ns, :contact, :ttl]
+ conf.subform.columns = [:name, :primary_ns, :contact, :ttl]
conf.update.columns = [:contact, :ttl]
- conf.actions.exclude :delete
- conf.actions.exclude :show
+ conf.actions.exclude :delete, :show
end
protected
diff --git a/app/models/ability.rb b/app/models/ability.rb
index ddb0ded..5107afe 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -5,9 +5,11 @@ class Ability
user ||= User.new
if user.persisted?
+ can :create, Domain
can :manage, Domain, :user_id => user.id
+ can :create, Record
can :manage, Record, :domain => {:user_id => user.id}
- cannot :delete, SOA
+ cannot :delete, SOA # it's deleted with the parent domain
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 e910254..08df4d5 100644
--- a/app/models/domain.rb
+++ b/app/models/domain.rb
@@ -21,8 +21,31 @@ class Domain < ActiveRecord::Base
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"}
+ validates :ns_records, :presence => true, :length => {
+ :minimum => 2, :maximum => 10,
+ :message => "must have be at least 2, at most 10"}
validates_associated :records
def slave?; self.type == 'SLAVE' end
+
+ def setup(email, sample_ns)
+ build_soa_record
+ ns_records.build
+ ns_records.build
+
+ soa = soa_record
+ ns1, ns2 = ns_records
+
+ soa.domain = self
+ soa.contact ||= email
+ soa.ttl ||= Settings.default_ttl
+
+ ns1.domain = self
+ ns1.name = sample_ns.first
+ ns1.ttl ||= Settings.default_ttl
+
+ ns2.domain = self
+ ns2.name = sample_ns.second
+ ns2.ttl ||= Settings.default_ttl
+ end
end
diff --git a/app/models/record.rb b/app/models/record.rb
index ac20a92..799e454 100644
--- a/app/models/record.rb
+++ b/app/models/record.rb
@@ -4,10 +4,14 @@ class Record < ActiveRecord::Base
cattr_reader :types
@@types = %w(SOA NS A MX TXT CNAME)
- validates :domain_id, :name, :presence => true
+ validates :domain, :name, :presence => true
validates :type, :inclusion => {:in => @@types, :message => "Unknown record type"}
# RFC 2181, 8
- validates :ttl, :numericality => { :greater_than_or_equal_to => 0, :less_than => 2**31 }, :allow_blank => true
+ validates :ttl, :numericality => {
+ # :greater_than_or_equal_to => 0,
+ :greater_than_or_equal_to => Settings.min_ttl.to_i,
+ :less_than => 2**31
+ }, :allow_blank => true
before_validation :prepare_name!
before_save :update_change_date
diff --git a/app/views/domains/_horizontal_subform_header.html.erb b/app/views/domains/_horizontal_subform_header.html.erb
new file mode 100644
index 0000000..702fc46
--- /dev/null
+++ b/app/views/domains/_horizontal_subform_header.html.erb
@@ -0,0 +1,17 @@
+<%# diferentiate create/update subform columns %>
+
+
+
+ <%
+ readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update))
+ crud_type = @record.new_record? ? :create : (readonly ? :read : :update)
+ config = active_scaffold_config_for(record.class)
+ columns = @record.new_record? ? config.create.columns : config.update.columns
+ columns.each :for => record.class, :crud_type => crud_type, :flatten => true do |column|
+ hidden = column_renders_as(column) == :hidden
+ next unless in_subform?(column, parent_record)
+ -%>
+
+
diff --git a/app/views/domains/_horizontal_subform_record.html.erb b/app/views/domains/_horizontal_subform_record.html.erb
new file mode 100644
index 0000000..70d4eb2
--- /dev/null
+++ b/app/views/domains/_horizontal_subform_record.html.erb
@@ -0,0 +1,41 @@
+<%# diferentiate create/update subform columns %>
+
+<%
+ record_column = column
+ readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update))
+ crud_type = @record.new_record? ? :create : (readonly ? :read : :update)
+ show_actions = false
+ config = active_scaffold_config_for(@record.class)
+ options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope)
+ tr_id = "association-#{options[:id]}"
+%>
+">
+ <% end -%>
+
<%= get_column_value(@record, column) -%>
+ <% end -%> +