2018-09-23 19:44:14 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-30 17:06:18 +00:00
|
|
|
class Dashboard::ProjectsController < Dashboard::ApplicationController
|
2017-03-03 10:35:04 +00:00
|
|
|
include ParamsBackwardCompatibility
|
2017-12-07 09:11:41 +00:00
|
|
|
include RendersMemberAccess
|
2020-07-09 15:08:59 +00:00
|
|
|
include RendersProjectsList
|
2019-08-21 10:13:45 +00:00
|
|
|
include SortingHelper
|
|
|
|
include SortingPreference
|
2020-06-19 18:08:39 +00:00
|
|
|
include FiltersEvents
|
2017-03-03 10:35:04 +00:00
|
|
|
|
2018-11-28 19:06:02 +00:00
|
|
|
prepend_before_action(only: [:index]) { authenticate_sessionless_user!(:rss) }
|
2020-07-28 00:10:23 +00:00
|
|
|
before_action :set_non_archived_param, only: [:index, :starred]
|
2019-08-21 10:13:45 +00:00
|
|
|
before_action :set_sorting
|
2019-07-04 09:29:06 +00:00
|
|
|
before_action :projects, only: [:index]
|
2017-12-11 14:21:06 +00:00
|
|
|
skip_cross_project_access_check :index, :starred
|
2016-03-04 15:11:33 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
feature_category :projects
|
|
|
|
|
2015-09-08 13:49:20 +00:00
|
|
|
def index
|
|
|
|
respond_to do |format|
|
2019-02-25 03:15:43 +00:00
|
|
|
format.html do
|
2019-06-05 00:10:24 +00:00
|
|
|
render_projects
|
2019-02-25 03:15:43 +00:00
|
|
|
end
|
2015-09-08 13:49:20 +00:00
|
|
|
format.atom do
|
|
|
|
load_events
|
2017-06-12 17:21:13 +00:00
|
|
|
render layout: 'xml.atom'
|
2015-09-08 13:49:20 +00:00
|
|
|
end
|
2016-02-03 21:33:01 +00:00
|
|
|
format.json do
|
|
|
|
render json: {
|
2019-03-19 00:01:49 +00:00
|
|
|
html: view_to_html_string("dashboard/projects/_projects", projects: @projects)
|
2016-02-03 21:33:01 +00:00
|
|
|
}
|
|
|
|
end
|
2015-09-08 13:49:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2015-03-09 21:12:03 +00:00
|
|
|
def starred
|
2017-06-21 13:48:12 +00:00
|
|
|
@projects = load_projects(params.merge(starred: true))
|
2020-03-11 12:09:26 +00:00
|
|
|
.includes(:forked_from_project, :tags)
|
2016-02-03 23:21:14 +00:00
|
|
|
|
2015-03-09 21:12:03 +00:00
|
|
|
@groups = []
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
2016-02-03 23:21:14 +00:00
|
|
|
render json: {
|
2019-03-19 00:01:49 +00:00
|
|
|
html: view_to_html_string("dashboard/projects/_projects", projects: @projects)
|
2016-02-03 23:21:14 +00:00
|
|
|
}
|
2015-03-09 21:12:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2015-03-09 21:12:03 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-06-05 00:10:24 +00:00
|
|
|
def projects
|
2020-03-11 12:09:26 +00:00
|
|
|
@projects ||= load_projects(params.merge(non_public: true))
|
2019-06-05 00:10:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def render_projects
|
2019-09-18 14:02:45 +00:00
|
|
|
# n+1: https://gitlab.com/gitlab-org/gitlab-foss/issues/40260
|
2019-06-05 00:10:24 +00:00
|
|
|
Gitlab::GitalyClient.allow_n_plus_1_calls do
|
|
|
|
render
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-03 10:35:04 +00:00
|
|
|
def load_projects(finder_params)
|
2020-08-31 21:10:19 +00:00
|
|
|
@total_user_projects_count = ProjectsFinder.new(params: { non_public: true, without_deleted: true }, current_user: current_user).execute
|
|
|
|
@total_starred_projects_count = ProjectsFinder.new(params: { starred: true, without_deleted: true }, current_user: current_user).execute
|
2018-12-07 10:05:17 +00:00
|
|
|
|
2020-02-05 00:08:41 +00:00
|
|
|
finder_params[:use_cte] = true if use_cte_for_finder?
|
2020-08-31 21:10:19 +00:00
|
|
|
finder_params[:without_deleted] = true
|
2020-01-27 21:08:47 +00:00
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
projects = ProjectsFinder.new(params: finder_params, current_user: current_user).execute
|
|
|
|
|
|
|
|
projects = preload_associations(projects)
|
|
|
|
projects = projects.page(finder_params[:page])
|
2017-12-07 09:11:41 +00:00
|
|
|
|
|
|
|
prepare_projects_for_rendering(projects)
|
2017-02-13 14:19:03 +00:00
|
|
|
end
|
2020-04-21 15:21:10 +00:00
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def preload_associations(projects)
|
|
|
|
projects.includes(:route, :creator, :group, namespace: [:route, :owner]).preload(:project_feature)
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-02-13 14:19:03 +00:00
|
|
|
|
2020-02-05 00:08:41 +00:00
|
|
|
def use_cte_for_finder?
|
|
|
|
# The starred action loads public projects, which causes the CTE to be less efficient
|
2020-04-21 15:21:10 +00:00
|
|
|
action_name == 'index'
|
2020-02-05 00:08:41 +00:00
|
|
|
end
|
|
|
|
|
2015-03-09 21:12:03 +00:00
|
|
|
def load_events
|
2020-04-21 15:21:10 +00:00
|
|
|
projects = ProjectsFinder
|
2020-08-31 21:10:19 +00:00
|
|
|
.new(params: params.merge(non_public: true, without_deleted: true), current_user: current_user)
|
2020-04-21 15:21:10 +00:00
|
|
|
.execute
|
2017-07-27 17:42:15 +00:00
|
|
|
|
|
|
|
@events = EventCollection
|
|
|
|
.new(projects, offset: params[:offset].to_i, filter: event_filter)
|
|
|
|
.to_a
|
2017-11-06 16:52:56 +00:00
|
|
|
|
|
|
|
Events::RenderService.new(current_user).execute(@events, atom_request: request.format.atom?)
|
2015-03-09 21:12:03 +00:00
|
|
|
end
|
2019-08-21 10:13:45 +00:00
|
|
|
|
|
|
|
def set_sorting
|
|
|
|
params[:sort] = set_sort_order
|
|
|
|
@sort = params[:sort]
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_sort_order
|
2020-12-11 00:09:41 +00:00
|
|
|
sort_value_name
|
2019-08-21 10:13:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def sorting_field
|
|
|
|
Project::SORTING_PREFERENCE_FIELD
|
|
|
|
end
|
2015-03-09 21:12:03 +00:00
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
|
|
|
Dashboard::ProjectsController.prepend_if_ee('EE::Dashboard::ProjectsController')
|