Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #50 from databus23/add_type_to_template
Browse files Browse the repository at this point in the history
add support for specifying the domain type in the zone template.
  • Loading branch information
kennethkalmer committed Dec 6, 2014
2 parents 95fb977 + 7a6b3ba commit c1ce2c3
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 13 deletions.
16 changes: 13 additions & 3 deletions app/models/zone_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ class ZoneTemplate < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
validates_presence_of :ttl

validates_inclusion_of :type, :in => %w(NATIVE MASTER SLAVE), :message => "must be one of NATIVE, MASTER"
validates_presence_of :master, :if => :slave?
validates_format_of :master, :if => :slave?,
:allow_blank => true,
:with => /\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/
# Disable single table inheritence (STI)
self.inheritance_column = 'not_used_here'
# Scopes
scope :user, lambda { |user| user.admin? ? nil : where(:user_id => user.id) }
scope :with_soa, joins(:record_templates).where('record_templates.record_type = ?', 'SOA')
Expand Down Expand Up @@ -39,7 +45,8 @@ def find_with_validations( *args )
# This method will throw exceptions as it encounters errors, and will use a
# transaction to complete/rollback the operation.
def build( domain_name, user = nil )
domain = Domain.new( :name => domain_name, :ttl => self.ttl )
domain = Domain.new( :name => domain_name, :ttl => self.ttl, :type => self.type )
domain.master = self.master if slave?
domain.user = user if user.is_a?( User )

self.class.transaction do
Expand Down Expand Up @@ -74,5 +81,8 @@ def build( domain_name, user = nil )
def has_soa?
record_templates.count( :conditions => "record_type LIKE 'SOA'" ) == 1
end

# Are we a slave domain template
def slave?
self.type == 'SLAVE'
end
end
18 changes: 9 additions & 9 deletions app/views/domains/_new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
%td{:width => "300"}=t :label_domain_name
%td= f.text_field :name
%td= help_icon('help-domain')
%tr
%td=t :label_domain_type
%td
= f.select :type, ['NATIVE','MASTER','SLAVE']
%td= help_icon('help-type')
%tr#master-address{ :style => 'display: none' }
%td=t :label_domain_master_address
%td= f.text_field :master
%td= help_icon('help-master')
%tr#zone-templates
%td=t :label_domain_zone_template
%td
Expand All @@ -39,6 +30,15 @@
=link_to((t :label_create_zone_templates), new_zone_template_path)
=t :label_zone_for_eazy_management
%td &nbsp;
%tr#domain-type
%td=t :label_domain_type
%td
= f.select :type, ['NATIVE','MASTER','SLAVE']
%td= help_icon('help-type')
%tr#master-address{ :style => 'display: none' }
%td=t :label_domain_master_address
%td= f.text_field :master
%td= help_icon('help-master')


#no-template-input
Expand Down
8 changes: 8 additions & 0 deletions app/views/templates/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
%td= t :label_template_zone_ttl
%td &nbsp;
%td= f.text_field :ttl, :size => 6
%tr
%td= t :label_template_zone_type
%td &nbsp;
%td= f.select :type, ['NATIVE','MASTER','SLAVE']
%tr
%td= t :label_template_zone_master
%td &nbsp;
%td= f.text_field :master, :size => 15
- if User.active_owners.any?
%tr
%td= t :label_template_zone_owner
Expand Down
3 changes: 3 additions & 0 deletions app/views/templates/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
%tr
%td= t :label_template_zone_ttl
%td= @zone_template.ttl
%tr
%td= t :label_template_zone_type
%td= @zone_template.type.humanize
%tr
%td= t :label_template_zone_owner
%td
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ en:
The name by which our zone templates will be known.
label_template_zone_name: "Name"
label_template_zone_ttl: "TTL"
label_template_zone_type: "Type"
label_template_zone_master: "Master IP"
label_template_zone_owner: "Owner"

# Templates index
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20130429134229_add_type_master_to_zone_template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddTypeMasterToZoneTemplate < ActiveRecord::Migration
def change
add_column :zone_templates, :type, :string, :default => 'NATIVE'
add_column :zone_templates, :master, :string
end
end

4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20130419205056) do
ActiveRecord::Schema.define(:version => 20130429134229) do

create_table "audits", :force => true do |t|
t.integer "auditable_id"
Expand Down Expand Up @@ -139,6 +139,8 @@
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
t.string "type", :default => "NATIVE"
t.string "master"
end

end
2 changes: 2 additions & 0 deletions public/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ $(document).ready(function() {
$('#domain_zone_template_id').change(function() {
if ( $(this).val() == '' ) {
$('#no-template-input').show();
$('#domain-type').show();
} else {
$('#no-template-input').hide();
$('#domain-type').hide();
}
});

Expand Down

0 comments on commit c1ce2c3

Please sign in to comment.