From 4e9dd03afcfbc8f5ec7d02b12a6cf4ef1c84b466 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius Date: Thu, 29 Sep 2011 04:18:29 -0700 Subject: [PATCH] filter records nesting, wire in AS core --- app/controllers/domains_controller.rb | 18 ------------------ app/controllers/records_controller.rb | 5 +++++ 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/app/controllers/domains_controller.rb b/app/controllers/domains_controller.rb index 0576ba2..a1ad33c 100644 --- a/app/controllers/domains_controller.rb +++ b/app/controllers/domains_controller.rb @@ -16,23 +16,5 @@ class DomainsController < ApplicationController def before_create_save(record) record.type = 'NATIVE' end - - # TODO: move to core - def do_edit_associated - @parent_record = params[:id].nil? ? new_model : find_if_allowed(params[:id], :update) - @column = active_scaffold_config.columns[params[:association]] - - # NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all. - @record = @column.association.klass.find(params[:associated_id]) if params[:associated_id] - @record ||= @column.singular_association? ? @parent_record.send(:"build_#{@column.name}") : @parent_record.send(@column.name).build - reflection = @parent_record.class.reflect_on_association(@column.name) - if reflection && reflection.reverse - reverse_macro = @record.class.reflect_on_association(reflection.reverse).macro - @record.send(:"#{reflection.reverse}=", @parent_record) if [:has_one, :belongs_to].include?(reverse_macro) - end - @scope = "[#{@column.name}]" - @scope += (@record.new_record?) ? "[#{(Time.now.to_f*1000).to_i.to_s}]" : "[#{@record.id}]" if @column.plural_association? - end - end diff --git a/app/controllers/records_controller.rb b/app/controllers/records_controller.rb index c15e829..6f97f2f 100644 --- a/app/controllers/records_controller.rb +++ b/app/controllers/records_controller.rb @@ -3,10 +3,15 @@ class RecordsController < ApplicationController conf.sti_children = [:SOA, :NS] conf.columns = [:name, :type, :content, :ttl, :prio, :change_date] end + before_filter :ensure_nested_under_domain protected def beginning_of_chain super.readonly(false) end + + def ensure_nested_under_domain + raise CanCan::AccessDenied, "not found" unless nested? and nested_parent_record.is_a?(Domain) + end end