diff --git a/app/controllers/aaaas_controller.rb b/app/controllers/aaaas_controller.rb index 21fbe01..dd224c4 100644 --- a/app/controllers/aaaas_controller.rb +++ b/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 \ No newline at end of file +end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f8b5552..09f9d75 100644 --- a/app/controllers/application_controller.rb +++ b/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 diff --git a/app/controllers/as_controller.rb b/app/controllers/as_controller.rb index 207624b..5557496 100644 --- a/app/controllers/as_controller.rb +++ b/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 \ No newline at end of file +end \ No newline at end of file diff --git a/app/controllers/cnames_controller.rb b/app/controllers/cnames_controller.rb index 0423465..c3c6cb6 100644 --- a/app/controllers/cnames_controller.rb +++ b/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 \ No newline at end of file +end \ No newline at end of file diff --git a/app/controllers/mxes_controller.rb b/app/controllers/mxes_controller.rb index a8bed14..10a6ce3 100644 --- a/app/controllers/mxes_controller.rb +++ b/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 \ No newline at end of file diff --git a/app/controllers/ns_controller.rb b/app/controllers/ns_controller.rb index 51da3f4..aa1247d 100644 --- a/app/controllers/ns_controller.rb +++ b/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 \ No newline at end of file diff --git a/app/controllers/records_controller.rb b/app/controllers/records_controller.rb index c7e0d87..b70d00d 100644 --- a/app/controllers/records_controller.rb +++ b/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 \ No newline at end of file diff --git a/app/controllers/records_controller_common.rb b/app/controllers/records_controller_common.rb new file mode 100644 index 0000000..e00fb1c --- /dev/null +++ b/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 \ No newline at end of file diff --git a/app/controllers/soas_controller.rb b/app/controllers/soas_controller.rb index 816b061..ff26cd3 100644 --- a/app/controllers/soas_controller.rb +++ b/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 \ No newline at end of file diff --git a/app/controllers/srvs_controller.rb b/app/controllers/srvs_controller.rb index dfedc2b..b9bd901 100644 --- a/app/controllers/srvs_controller.rb +++ b/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 \ No newline at end of file diff --git a/app/controllers/txts_controller.rb b/app/controllers/txts_controller.rb index e7f96b8..f54011b 100644 --- a/app/controllers/txts_controller.rb +++ b/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 \ No newline at end of file