debian-mirror-gitlab/app/controllers/dashboard/projects_controller.rb

120 lines
3.3 KiB
Ruby
Raw Normal View History

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