2018-09-14 05:42:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-06-10 07:59:39 +00:00
|
|
|
# RootController
|
|
|
|
#
|
|
|
|
# This controller exists solely to handle requests to `root_url`. When a user is
|
|
|
|
# logged in and has customized their `dashboard` setting, they will be
|
|
|
|
# redirected to their preferred location.
|
|
|
|
#
|
|
|
|
# For users who haven't customized the setting, we simply delegate to
|
|
|
|
# `DashboardController#show`, which is the default.
|
2015-09-08 13:49:20 +00:00
|
|
|
class RootController < Dashboard::ProjectsController
|
2017-01-29 02:22:13 +00:00
|
|
|
skip_before_action :authenticate_user!, only: [:index]
|
2017-02-24 17:55:32 +00:00
|
|
|
|
|
|
|
before_action :redirect_unlogged_user, if: -> { current_user.nil? }
|
|
|
|
before_action :redirect_logged_user, if: -> { current_user.present? }
|
2020-07-09 15:08:59 +00:00
|
|
|
# We only need to load the projects when the user is logged in but did not
|
|
|
|
# configure a dashboard. In which case we render projects. We can do that straight
|
|
|
|
# from the #index action.
|
|
|
|
skip_before_action :projects
|
2015-06-13 00:53:58 +00:00
|
|
|
|
2015-09-08 13:49:20 +00:00
|
|
|
def index
|
2019-09-18 14:02:45 +00:00
|
|
|
# n+1: https://gitlab.com/gitlab-org/gitlab-foss/issues/40260
|
2018-02-20 15:07:54 +00:00
|
|
|
Gitlab::GitalyClient.allow_n_plus_1_calls do
|
2020-07-09 15:08:59 +00:00
|
|
|
projects
|
2018-02-20 15:07:54 +00:00
|
|
|
super
|
|
|
|
end
|
2015-06-13 00:53:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-02-24 17:55:32 +00:00
|
|
|
def redirect_unlogged_user
|
|
|
|
if redirect_to_home_page_url?
|
2018-02-02 18:39:55 +00:00
|
|
|
redirect_to(Gitlab::CurrentSettings.home_page_url)
|
2017-02-24 17:55:32 +00:00
|
|
|
else
|
|
|
|
redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
end
|
2015-06-13 00:53:58 +00:00
|
|
|
|
2017-02-24 17:55:32 +00:00
|
|
|
def redirect_logged_user
|
2015-06-13 00:53:58 +00:00
|
|
|
case current_user.dashboard
|
2015-06-10 07:59:39 +00:00
|
|
|
when 'stars'
|
2015-09-08 13:49:20 +00:00
|
|
|
flash.keep
|
2017-02-24 17:55:32 +00:00
|
|
|
redirect_to(starred_dashboard_projects_path)
|
2015-09-26 00:04:20 +00:00
|
|
|
when 'project_activity'
|
2017-02-24 17:55:32 +00:00
|
|
|
redirect_to(activity_dashboard_path)
|
2015-09-26 00:04:20 +00:00
|
|
|
when 'starred_project_activity'
|
2017-02-24 17:55:32 +00:00
|
|
|
redirect_to(activity_dashboard_path(filter: 'starred'))
|
2021-03-03 18:11:16 +00:00
|
|
|
when 'followed_user_activity'
|
|
|
|
redirect_to(activity_dashboard_path(filter: 'followed'))
|
2016-03-24 10:12:45 +00:00
|
|
|
when 'groups'
|
2017-02-24 17:55:32 +00:00
|
|
|
redirect_to(dashboard_groups_path)
|
2016-03-24 10:12:45 +00:00
|
|
|
when 'todos'
|
2017-02-24 17:55:32 +00:00
|
|
|
redirect_to(dashboard_todos_path)
|
2018-03-27 12:16:12 +00:00
|
|
|
when 'issues'
|
2018-10-29 03:03:43 +00:00
|
|
|
redirect_to(issues_dashboard_path(assignee_username: current_user.username))
|
2018-03-27 12:16:12 +00:00
|
|
|
when 'merge_requests'
|
2018-10-29 03:03:43 +00:00
|
|
|
redirect_to(merge_requests_dashboard_path(assignee_username: current_user.username))
|
2015-06-10 07:59:39 +00:00
|
|
|
end
|
|
|
|
end
|
2017-02-24 17:55:32 +00:00
|
|
|
|
|
|
|
def redirect_to_home_page_url?
|
2020-02-07 15:09:52 +00:00
|
|
|
# If user is not signed-in and tries to access root_path - redirect them to landing page
|
2017-02-24 17:55:32 +00:00
|
|
|
# Don't redirect to the default URL to prevent endless redirections
|
2018-02-02 18:39:55 +00:00
|
|
|
return false unless Gitlab::CurrentSettings.home_page_url.present?
|
2017-02-24 17:55:32 +00:00
|
|
|
|
2018-02-02 18:39:55 +00:00
|
|
|
home_page_url = Gitlab::CurrentSettings.home_page_url.chomp('/')
|
2017-02-24 17:55:32 +00:00
|
|
|
root_urls = [Gitlab.config.gitlab['url'].chomp('/'), root_url.chomp('/')]
|
|
|
|
|
|
|
|
root_urls.exclude?(home_page_url)
|
|
|
|
end
|
2015-06-10 07:59:39 +00:00
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
RootController.prepend_mod_with('RootController')
|