class SearchController < ApplicationController

  skip_before_filter :load_project
  before_filter :load_project_search, :only => :results
  before_filter :permission_to_search, :only => :results

  def results
    @search = params[:search]

    unless @search.blank?
      @comments = Comment.search @search,
        :retry_stale => true, :order => 'created_at DESC',
        :with => { :project_id => project_ids },
        :page => params[:page]
    end
  end
  
  protected

    def load_project_search
      @current_project = Project.find_by_permalink(params[:project_id]) if params[:project_id]
    end

    def permission_to_search
      unless user_can_search? or (@current_project and project_owner.can_search?)
        flash[:notice] = "Search is disabled"
        redirect_to root_path
      end
    end
    
    def user_can_search?
      current_user.can_search?
    end
    
    def project_owner
      @current_project.user
    end
  
    def project_ids
      if @current_project
        @current_project.id
      else
        current_user.projects.collect { |p| p.id }
      end
    end

end

class SearchController < ApplicationController
  
  before_filter :permission_to_search, :only => :results
  
  def results
    @search = params[:search]
    
    unless @search.blank?
      @comments = Comment.search @search,
        :retry_stale => true, :order => 'created_at DESC',
        :with => { :project_id => project_ids },
        :page => params[:page]
    end
  end
  
  protected
  
    def permission_to_search
      unless user_can_search? or (@current_project and project_owner.can_search?)
        flash[:notice] = "Search is disabled"
        redirect_to root_path
      end
    end
    
    def user_can_search?
      current_user.can_search?
    end
    
    def project_owner
      @current_project.user
    end
  
    def project_ids
      if @current_project
        @current_project.id
      else
        current_user.projects.collect { |p| p.id }
      end
    end

end

Revert before_filter tampering in SearchController
Revert before_filter tampering in SearchController

These "fixes" are no longer necessary and they broke some
permissions features of searching across all projects.

This reverts commits:
 - 04a7f9b8358a5c053c4b76a91993e920f820d5e6
 - 04a5479a4291a39801d6bfd05d8cd09ece361e74
