Browse Source

DRY up records controllers

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
83e5b44254
  1. 14
      app/controllers/aaaas_controller.rb
  2. 4
      app/controllers/application_controller.rb
  3. 14
      app/controllers/as_controller.rb
  4. 13
      app/controllers/cnames_controller.rb
  5. 15
      app/controllers/mxes_controller.rb
  6. 15
      app/controllers/ns_controller.rb
  7. 10
      app/controllers/records_controller.rb
  8. 25
      app/controllers/records_controller_common.rb
  9. 15
      app/controllers/soas_controller.rb
  10. 14
      app/controllers/srvs_controller.rb
  11. 12
      app/controllers/txts_controller.rb

14
app/controllers/aaaas_controller.rb

@ -9,7 +9,7 @@ class AaaasController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show
end
before_filter :ensure_nested_under_domain
include RecordsControllerCommon
protected
@ -25,14 +25,4 @@ class AaaasController < ApplicationController
before_create_save(record)
record
end
def before_create_save(record)
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end
end
end

4
app/controllers/application_controller.rb

@ -40,8 +40,4 @@ class ApplicationController < ActionController::Base
render :nothing => true if params[Settings.honeypot].present?
end
def nested_via_records?
nested? && nested.association && nested.association.collection? && nested.association.name == :records
end
end

14
app/controllers/as_controller.rb

@ -9,7 +9,7 @@ class AsController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show
end
before_filter :ensure_nested_under_domain
include RecordsControllerCommon
protected
@ -26,14 +26,4 @@ class AsController < ApplicationController
before_create_save(record)
record
end
def before_create_save(record)
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end
end
end

13
app/controllers/cnames_controller.rb

@ -10,7 +10,7 @@ class CnamesController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show
end
before_filter :ensure_nested_under_domain
include RecordsControllerCommon
protected
@ -26,13 +26,4 @@ class CnamesController < ApplicationController
record
end
def before_create_save(record)
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end
end
end

15
app/controllers/mxes_controller.rb

@ -9,7 +9,7 @@ class MxesController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show
end
before_filter :ensure_nested_under_domain
include RecordsControllerCommon
protected
@ -33,15 +33,4 @@ class MxesController < ApplicationController
before_create_save(record)
record
end
def before_create_save(record)
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end
end
end

15
app/controllers/ns_controller.rb

@ -9,7 +9,7 @@ class NsController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show
end
before_filter :ensure_nested_under_domain
include RecordsControllerCommon
protected
@ -27,16 +27,6 @@ class NsController < ApplicationController
record
end
def before_create_save(record)
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end
def after_update_save(record)
domain = @record.domain
soa_record = domain.soa_record
@ -51,5 +41,4 @@ class NsController < ApplicationController
flash[:warning] = "All NS records deleted, no other nameservers are associated with this domain!"
end
end
end
end

10
app/controllers/records_controller.rb

@ -26,7 +26,8 @@ class RecordsController < ApplicationController
# conf.create.link.label = "Add Record"
conf.actions.exclude :show
end
before_filter :ensure_nested_under_domain, :except => 'modify'
include RecordsControllerCommon
skip_before_filter :ensure_nested_under_domain, :only => 'modify'
skip_before_filter :authenticate_user!, :only => 'modify'
protect_from_forgery :except => 'modify'
skip_authorize_resource :only => :modify
@ -49,14 +50,7 @@ class RecordsController < ApplicationController
def new_model
record = super
record.user_id = current_user.id
before_create_save(record)
record
end
def before_create_save(record)
record.domain = nested_parent_record
record.user = record.domain_user
end
end

25
app/controllers/records_controller_common.rb

@ -0,0 +1,25 @@
# some common bits of code for records related controllers
module RecordsControllerCommon
extend ActiveSupport::Concern
included do
before_filter :ensure_nested_under_domain
end
protected
def before_create_save(record)
record.domain = nested_parent_record
record.user = record.domain_user
end
def nested_via_records?
nested? && nested.association && nested.association.collection? && nested.association.name == :records
end
# override to close create form after success
# RecordsController is the only one that does not really need this
def render_parent?
nested_singular_association? # || params[:parent_sti]
end
end

15
app/controllers/soas_controller.rb

@ -7,7 +7,7 @@ class SoasController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :delete, :show
end
before_filter :ensure_nested_under_domain
include RecordsControllerCommon
protected
@ -22,20 +22,9 @@ class SoasController < ApplicationController
record
end
def before_create_save(record)
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end
def after_update_save(record)
unless @record.domain.ns_records.any? {|ns_record| @record.primary_ns == ns_record.content}
flash.now[:warning] = "SOA record's primary NS is no longer among this domain's NS records"
end
end
end
end

14
app/controllers/srvs_controller.rb

@ -9,7 +9,7 @@ class SrvsController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show
end
before_filter :ensure_nested_under_domain
include RecordsControllerCommon
protected
@ -31,14 +31,4 @@ class SrvsController < ApplicationController
record
end
def before_create_save(record)
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end
end
end

12
app/controllers/txts_controller.rb

@ -9,7 +9,7 @@ class TxtsController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show
end
before_filter :ensure_nested_under_domain
include RecordsControllerCommon
protected
@ -25,14 +25,4 @@ class TxtsController < ApplicationController
before_create_save(record)
record
end
def before_create_save(record)
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end
end
Loading…
Cancel
Save