debian-mirror-gitlab/app/controllers/root_controller.rb

77 lines
2.5 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
# 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-25 12:07:36 +05:30
class RootController < Dashboard::ProjectsController
2017-08-17 22:00:37 +05:30
skip_before_action :authenticate_user!, only: [:index]
before_action :redirect_unlogged_user, if: -> { current_user.nil? }
before_action :redirect_logged_user, if: -> { current_user.present? }
2020-10-24 23:57:45 +05:30
before_action :customize_homepage, only: :index, if: -> { current_user.present? }
2020-07-28 23:09:34 +05:30
# 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-09-11 14:41:01 +05:30
2015-09-25 12:07:36 +05:30
def index
2019-12-04 20:38:33 +05:30
# n+1: https://gitlab.com/gitlab-org/gitlab-foss/issues/40260
2018-03-17 18:26:18 +05:30
Gitlab::GitalyClient.allow_n_plus_1_calls do
2020-07-28 23:09:34 +05:30
projects
2018-03-17 18:26:18 +05:30
super
end
2015-09-11 14:41:01 +05:30
end
private
2017-08-17 22:00:37 +05:30
def redirect_unlogged_user
if redirect_to_home_page_url?
2018-03-17 18:26:18 +05:30
redirect_to(Gitlab::CurrentSettings.home_page_url)
2017-08-17 22:00:37 +05:30
else
redirect_to(new_user_session_path)
end
end
2015-09-11 14:41:01 +05:30
2017-08-17 22:00:37 +05:30
def redirect_logged_user
2015-09-11 14:41:01 +05:30
case current_user.dashboard
when 'stars'
2015-09-25 12:07:36 +05:30
flash.keep
2017-08-17 22:00:37 +05:30
redirect_to(starred_dashboard_projects_path)
2015-10-24 18:46:33 +05:30
when 'project_activity'
2017-08-17 22:00:37 +05:30
redirect_to(activity_dashboard_path)
2015-10-24 18:46:33 +05:30
when 'starred_project_activity'
2017-08-17 22:00:37 +05:30
redirect_to(activity_dashboard_path(filter: 'starred'))
2016-06-02 11:05:42 +05:30
when 'groups'
2017-08-17 22:00:37 +05:30
redirect_to(dashboard_groups_path)
2016-06-02 11:05:42 +05:30
when 'todos'
2017-08-17 22:00:37 +05:30
redirect_to(dashboard_todos_path)
2018-05-09 12:01:36 +05:30
when 'issues'
2019-02-15 15:39:39 +05:30
redirect_to(issues_dashboard_path(assignee_username: current_user.username))
2018-05-09 12:01:36 +05:30
when 'merge_requests'
2019-02-15 15:39:39 +05:30
redirect_to(merge_requests_dashboard_path(assignee_username: current_user.username))
2015-09-11 14:41:01 +05:30
end
end
2017-08-17 22:00:37 +05:30
def redirect_to_home_page_url?
2020-03-13 15:44:24 +05:30
# If user is not signed-in and tries to access root_path - redirect them to landing page
2017-08-17 22:00:37 +05:30
# Don't redirect to the default URL to prevent endless redirections
2018-03-17 18:26:18 +05:30
return false unless Gitlab::CurrentSettings.home_page_url.present?
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
home_page_url = Gitlab::CurrentSettings.home_page_url.chomp('/')
2017-08-17 22:00:37 +05:30
root_urls = [Gitlab.config.gitlab['url'].chomp('/'), root_url.chomp('/')]
root_urls.exclude?(home_page_url)
end
2020-10-24 23:57:45 +05:30
def customize_homepage
@customize_homepage = experiment_enabled?(:customize_homepage)
end
2015-09-11 14:41:01 +05:30
end
2019-12-04 20:38:33 +05:30
RootController.prepend_if_ee('EE::RootController')