2012-03-15 23:14:39 +00:00
|
|
|
class SearchController < ApplicationController
|
|
|
|
def show
|
2013-01-25 08:07:21 +00:00
|
|
|
project_id = params[:project_id]
|
|
|
|
group_id = params[:group_id]
|
|
|
|
|
2013-10-23 20:27:40 +00:00
|
|
|
project_ids = find_project_ids(group_id, project_id)
|
2013-01-25 08:07:21 +00:00
|
|
|
|
2013-11-06 15:13:21 +00:00
|
|
|
result = SearchContext.new(project_ids, current_user, params).execute
|
2012-07-31 05:32:49 +00:00
|
|
|
|
2012-10-09 19:09:46 +00:00
|
|
|
@projects = result[:projects]
|
|
|
|
@merge_requests = result[:merge_requests]
|
|
|
|
@issues = result[:issues]
|
2012-10-16 19:05:11 +00:00
|
|
|
@wiki_pages = result[:wiki_pages]
|
2013-05-14 17:25:16 +00:00
|
|
|
@blobs = Kaminari.paginate_array(result[:blobs]).page(params[:page]).per(20)
|
|
|
|
@total_results = @projects.count + @merge_requests.count + @issues.count + @wiki_pages.count + @blobs.total_count
|
2012-03-15 23:14:39 +00:00
|
|
|
end
|
2013-10-23 20:27:40 +00:00
|
|
|
|
2014-01-09 08:29:55 +00:00
|
|
|
private
|
2013-11-13 20:07:53 +00:00
|
|
|
|
2013-10-23 20:27:40 +00:00
|
|
|
def find_project_ids(group_id, project_id)
|
|
|
|
project_ids = current_user.authorized_projects.map(&:id)
|
|
|
|
|
|
|
|
if group_id.present?
|
|
|
|
@group = Group.find(group_id)
|
|
|
|
group_project_ids = @group.projects.map(&:id)
|
|
|
|
project_ids.select! { |id| group_project_ids.include?(id) }
|
|
|
|
elsif project_id.present?
|
|
|
|
@project = Project.find(project_id)
|
2014-01-09 08:29:55 +00:00
|
|
|
project_ids = @project.public? ? [@project.id] : project_ids.select { |id| id == project_id.to_i }
|
2013-10-23 20:27:40 +00:00
|
|
|
end
|
|
|
|
project_ids
|
|
|
|
end
|
2012-03-15 23:14:39 +00:00
|
|
|
end
|