Browse Source

filter records nesting, wire in AS core

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
4e9dd03afc
  1. 18
      app/controllers/domains_controller.rb
  2. 5
      app/controllers/records_controller.rb

18
app/controllers/domains_controller.rb

@ -16,23 +16,5 @@ class DomainsController < ApplicationController
def before_create_save(record) def before_create_save(record)
record.type = 'NATIVE' record.type = 'NATIVE'
end 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 end

5
app/controllers/records_controller.rb

@ -3,10 +3,15 @@ class RecordsController < ApplicationController
conf.sti_children = [:SOA, :NS] conf.sti_children = [:SOA, :NS]
conf.columns = [:name, :type, :content, :ttl, :prio, :change_date] conf.columns = [:name, :type, :content, :ttl, :prio, :change_date]
end end
before_filter :ensure_nested_under_domain
protected protected
def beginning_of_chain def beginning_of_chain
super.readonly(false) super.readonly(false)
end end
def ensure_nested_under_domain
raise CanCan::AccessDenied, "not found" unless nested? and nested_parent_record.is_a?(Domain)
end
end end

Loading…
Cancel
Save