Browse Source

updates

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
bbbdf3f237
  1. 2
      Gemfile
  2. 8
      Gemfile.lock
  3. 15
      app/controllers/domains_controller.rb
  4. 4
      app/controllers/soas_controller.rb
  5. 4
      app/models/ability.rb
  6. 25
      app/models/domain.rb
  7. 8
      app/models/record.rb
  8. 17
      app/views/domains/_horizontal_subform_header.html.erb
  9. 41
      app/views/domains/_horizontal_subform_record.html.erb
  10. 2
      config/environments/production.rb
  11. 9
      config/settings.yml

2
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'

8
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)

15
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

4
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

4
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.

25
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

8
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

17
app/views/domains/_horizontal_subform_header.html.erb

@ -0,0 +1,17 @@
<%# diferentiate create/update subform columns %>
<thead>
<tr>
<%
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)
-%>
<th class="<%= "#{'required' if column.required?} #{'hidden' if hidden}" %>"><label><%= column.label unless hidden %></label></th>
<% end -%>
</tr>
</thead>

41
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]}"
%>
<tr id="<%= tr_id %>" class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>">
<% columns = @record.new_record? ? config.create.columns : config.update.columns %>
<% columns.each :for => @record.class, :crud_type => crud_type, :flatten => true do |column| %>
<%
next unless in_subform?(column, parent_record)
show_actions = true
column = column.clone
column.form_ui ||= :select if column.association
-%>
<td<%= ' class="hidden"'.html_safe if column_renders_as(column) == :hidden %>>
<% unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) -%>
<%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%>
<% else -%>
<p><%= get_column_value(@record, column) -%></p>
<% end -%>
</td>
<% end -%>
<% if show_actions -%>
<td class="actions">
<% if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %>
<% destroy_id = "#{options[:id]}-destroy" %>
<%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.delete_subform_record(\"#{tr_id}\"); return false;", :style=> "display: none;" %>
<%= javascript_tag("ActiveScaffold.show('#{destroy_id}');") if !locked %>
<% end %>
<% unless @record.new_record? %>
<input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= @record.id -%>" />
<% end -%>
</td>
<% end -%>
</tr>

2
config/environments/production.rb

@ -15,7 +15,7 @@ Simpledns::Application.configure do
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
config.assets.compile = true # TODO: false, all assets should be served by httpd
# Generate digests for assets URLs
config.assets.digest = true

9
config/settings.yml

@ -1 +1,8 @@
master: 1.1.1.1
master: 1.1.1.1
default_ttl: 2000
min_ttl: 1000
ns:
- ns1.ourdomain.com
- ns2.ourdomain.com
- ns3.ourdomain.com
- ns4.ourdomain.com
Loading…
Cancel
Save