Commit 44fdf0a1 authored by Toon Claes's avatar Toon Claes

Move ProjectsFinder to `present_projects` for simplification

To avoid passing parameters double, move all filtering to the `present_projects`
helper.
parent 98043aee
...@@ -67,20 +67,18 @@ module API ...@@ -67,20 +67,18 @@ module API
optional :import_url, type: String, desc: 'URL from which the project is imported' optional :import_url, type: String, desc: 'URL from which the project is imported'
end end
def present_projects(projects, options = {}) def present_projects(options = {})
options = options.reverse_merge( options = options.reverse_merge(
with: Entities::Project, with: current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails,
current_user: current_user, current_user: current_user
simple: params[:simple],
with_issues_enabled: params[:with_issues_enabled],
with_merge_requests_enabled: params[:with_merge_requests_enabled]
) )
projects = ProjectsFinder.new(current_user: current_user).execute
projects = filter_projects(projects) projects = filter_projects(projects)
projects = projects.with_statistics if options[:statistics] projects = projects.with_statistics if params[:statistics]
projects = projects.with_issues_enabled if options[:with_issues_enabled] projects = projects.with_issues_enabled if params[:with_issues_enabled]
projects = projects.with_merge_requests_enabled if options[:with_merge_requests_enabled] projects = projects.with_merge_requests_enabled if params[:with_merge_requests_enabled]
options[:with] = Entities::BasicProjectDetails if options[:simple] options[:with] = Entities::BasicProjectDetails if params[:simple]
present paginate(projects), options present paginate(projects), options
end end
...@@ -94,8 +92,7 @@ module API ...@@ -94,8 +92,7 @@ module API
use :statistics_params use :statistics_params
end end
get do get do
entity = current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails present_projects
present_projects ProjectsFinder.new(current_user: current_user).execute, with: entity, statistics: params[:statistics]
end end
desc 'Create new project' do desc 'Create new project' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment