Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #5949: simple_filter_canceling_fix.2.diff

File simple_filter_canceling_fix.2.diff, 3.9 kB (added by martin, 2 years ago)

New version applied to trunk

  • actionpack/lib/action_controller/filters.rb

    old new  
    248248      # The passed <tt>filters</tt> will be appended to the filter_chain and 
    249249      # will execute before the action on this controller is performed. 
    250250      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) 
    255252      end 
    256253 
    257254      # The passed <tt>filters</tt> will be prepended to the filter_chain and 
     
    266263      # The passed <tt>filters</tt> will be appended to the array of filters 
    267264      # that run _after_ actions on this controller are performed. 
    268265      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) 
    273267      end 
    274268 
    275269      # The passed <tt>filters</tt> will be prepended to the array of filters 
     
    411405          false 
    412406        end 
    413407 
     408        def around? 
     409          true 
     410        end 
     411 
    414412        def call(controller, &block) 
    415413          raise(ActionControllerError, 'No filter type: Nothing to do here.') 
    416414        end 
     
    422420        def filter 
    423421          @filter.filter 
    424422        end 
     423 
     424        def around? 
     425          false 
     426        end 
    425427      end 
    426428 
    427429      class BeforeFilterProxy < FilterProxy #:nodoc: 
     
    494496 
    495497        def create_filters(filters, position, &block) #:nodoc: 
    496498          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 
    497503 
    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) 
    504509            # apply proxy to filter if necessary 
    505510            case position 
    506511            when :before 
    507               BeforeFilterProxy.new(filter
     512              BeforeFilterProxy.new(f
    508513            when :after 
    509               AfterFilterProxy.new(filter
     514              AfterFilterProxy.new(f
    510515            else 
    511               filter 
     516              f 
    512517            end 
    513518          end 
    514  
    515           update_conditions(filters, conditions) 
    516  
    517           filters 
    518519        end 
    519520 
    520521        # The determination of the filter type was once done at run time. 
     
    603604            end 
    604605          end 
    605606        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           end 
    614            
    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           else 
    622             old_filters = [] 
    623           end 
    624  
    625           [new_filters, old_filters] 
    626         end 
    627607    end 
    628608 
    629609    module InstanceMethods # :nodoc: