Ticket #5949: simple_filter_canceling_fix.2.diff
| File simple_filter_canceling_fix.2.diff, 3.9 kB (added by martin, 2 years ago) |
|---|
-
actionpack/lib/action_controller/filters.rb
old new 248 248 # The passed <tt>filters</tt> will be appended to the filter_chain and 249 249 # will execute before the action on this controller is performed. 250 250 def append_before_filter(*filters, &block) 251 new_filters, existing_filters = look_for_existing_filters(filters, :before) 252 253 append_filter_to_chain(new_filters, :before, &block) 254 skip_before_filter(existing_filters) unless existing_filters.empty? 251 append_filter_to_chain(filters, :before, &block) 255 252 end 256 253 257 254 # The passed <tt>filters</tt> will be prepended to the filter_chain and … … 266 263 # The passed <tt>filters</tt> will be appended to the array of filters 267 264 # that run _after_ actions on this controller are performed. 268 265 def append_after_filter(*filters, &block) 269 new_filters, existing_filters = look_for_existing_filters(filters, :after) 270 271 prepend_filter_to_chain(new_filters, :after, &block) 272 skip_after_filter(existing_filters) unless existing_filters.empty? 266 prepend_filter_to_chain(filters, :after, &block) 273 267 end 274 268 275 269 # The passed <tt>filters</tt> will be prepended to the array of filters … … 411 405 false 412 406 end 413 407 408 def around? 409 true 410 end 411 414 412 def call(controller, &block) 415 413 raise(ActionControllerError, 'No filter type: Nothing to do here.') 416 414 end … … 422 420 def filter 423 421 @filter.filter 424 422 end 423 424 def around? 425 false 426 end 425 427 end 426 428 427 429 class BeforeFilterProxy < FilterProxy #:nodoc: … … 494 496 495 497 def create_filters(filters, position, &block) #:nodoc: 496 498 filters, conditions = extract_conditions(filters, &block) 499 filters.map! { |filter| find_or_create_filter(filter,position) } 500 update_conditions(filters, conditions) 501 filters 502 end 497 503 498 filters.map! do |filter| 499 # change all the filters into instances of Filter derived classes 500 class_for_filter(filter).new(filter) 501 end 502 503 filters.map! do |filter| 504 def find_or_create_filter(filter,position) 505 if found_filter = find_filter(filter) { |f| f.send("#{position}?") } 506 found_filter 507 else 508 f = class_for_filter(filter).new(filter) 504 509 # apply proxy to filter if necessary 505 510 case position 506 511 when :before 507 BeforeFilterProxy.new(f ilter)512 BeforeFilterProxy.new(f) 508 513 when :after 509 AfterFilterProxy.new(f ilter)514 AfterFilterProxy.new(f) 510 515 else 511 f ilter516 f 512 517 end 513 518 end 514 515 update_conditions(filters, conditions)516 517 filters518 519 end 519 520 520 521 # The determination of the filter type was once done at run time. … … 603 604 end 604 605 end 605 606 end 606 607 def look_for_existing_filters(filters, which)608 filters, options = extract_conditions(filters)609 old_filters = []610 611 filter_chain.select(&"#{which}?".to_sym).each do |f|612 old_filters << f.filter if filters.include?(f.filter)613 end614 615 new_filters = filters - old_filters + [options]616 617 if options[:except]618 old_filters << { :only => options[:except] }619 elsif options[:only]620 old_filters << { :except => options[:only] }621 else622 old_filters = []623 end624 625 [new_filters, old_filters]626 end627 607 end 628 608 629 609 module InstanceMethods # :nodoc: