Commit 0f0b9a84 authored by Toon Claes's avatar Toon Claes

Use helper to construct Finder params

The ProjectsFinder and GroupFinder both support the same set of params. And the
`/api/v4/projects` and `/api/v4/group/:id/projects` also support the same set of
params. But they do not match the Finder params. So use a helper method to
transform them.
parent 01c6323d
...@@ -151,7 +151,7 @@ module API ...@@ -151,7 +151,7 @@ module API
end end
get ":id/projects" do get ":id/projects" do
group = find_group!(params[:id]) group = find_group!(params[:id])
projects = GroupProjectsFinder.new(group: group, current_user: current_user).execute projects = GroupProjectsFinder.new(group: group, current_user: current_user, params: project_finder_params).execute
projects = filter_projects(projects) projects = filter_projects(projects)
entity = params[:simple] ? Entities::BasicProjectDetails : Entities::Project entity = params[:simple] ? Entities::BasicProjectDetails : Entities::Project
present paginate(projects), with: entity, current_user: current_user present paginate(projects), with: entity, current_user: current_user
......
...@@ -264,6 +264,16 @@ module API ...@@ -264,6 +264,16 @@ module API
projects.reorder(params[:order_by] => params[:sort]) projects.reorder(params[:order_by] => params[:sort])
end end
def project_finder_params
finder_params = {}
finder_params[:non_public] = true if params[:membership].present?
finder_params[:starred] = true if params[:starred].present?
finder_params[:visibility_level] = Gitlab::VisibilityLevel.level_value(params[:visibility]) if params[:visibility]
finder_params[:archived] = params[:archived]
finder_params[:search] = params[:search] if params[:search]
finder_params
end
# file helpers # file helpers
def uploaded_file(field, uploads_path) def uploaded_file(field, uploads_path)
......
...@@ -68,14 +68,7 @@ module API ...@@ -68,14 +68,7 @@ module API
end end
def present_projects(options = {}) def present_projects(options = {})
finder_params = {} projects = ProjectsFinder.new(current_user: current_user, params: project_finder_params).execute
finder_params[:non_public] = true if params[:membership].present?
finder_params[:starred] = true if params[:starred].present?
finder_params[:visibility_level] = Gitlab::VisibilityLevel.level_value(params[:visibility]) if params[:visibility]
finder_params[:archived] = params[:archived]
finder_params[:search] = params[:search] if params[:search]
projects = ProjectsFinder.new(current_user: current_user, params: finder_params).execute
projects = filter_projects(projects) projects = filter_projects(projects)
projects = projects.with_statistics if params[:statistics] projects = projects.with_statistics if params[:statistics]
projects = projects.with_issues_enabled if params[:with_issues_enabled] projects = projects.with_issues_enabled if params[:with_issues_enabled]
......
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