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

79 lines
2.2 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
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) }
2017-08-17 22:00:37 +05:30
before_action :set_non_archived_param
before_action :default_sorting
2018-03-27 19:54:05 +05:30
skip_cross_project_access_check :index, :starred
2015-04-26 12:48:37 +05:30
2015-09-25 12:07:36 +05:30
def index
2018-11-08 19:23:39 +05:30
@projects = load_projects(params.merge(non_public: true))
2015-09-25 12:07:36 +05:30
respond_to do |format|
2017-09-10 17:25:29 +05:30
format.html
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: {
html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
}
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))
2018-11-08 19:23:39 +05:30
.includes(:forked_from_project, :tags)
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: {
html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
}
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
2017-08-17 22:00:37 +05:30
def default_sorting
params[:sort] ||= 'latest_activity_desc'
@sort = params[:sort]
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
def load_projects(finder_params)
2019-03-02 22:35:43 +05:30
@total_user_projects_count = ProjectsFinder.new(params: { non_public: true }, current_user: current_user).execute
@total_starred_projects_count = ProjectsFinder.new(params: { starred: true }, current_user: current_user).execute
2018-03-17 18:26:18 +05:30
projects = ProjectsFinder
.new(params: finder_params, current_user: current_user)
.execute
2019-02-15 15:39:39 +05:30
.includes(:route, :creator, :group, namespace: [:route, :owner])
2018-11-08 19:23:39 +05:30
.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
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
2015-04-26 12:48:37 +05:30
def load_events
2017-09-10 17:25:29 +05:30
projects = load_projects(params.merge(non_public: true))
@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
end