BigW Consortium Gitlab

root_controller.rb 1.82 KB
Newer Older
Robert Speicher committed
1 2 3 4 5 6 7 8
# 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.
9
class RootController < Dashboard::ProjectsController
10
  skip_before_action :authenticate_user!, only: [:index]
11 12 13

  before_action :redirect_unlogged_user, if: -> { current_user.nil? }
  before_action :redirect_logged_user, if: -> { current_user.present? }
14

15
  def index
16 17 18 19
    # n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/37434
    Gitlab::GitalyClient.allow_n_plus_1_calls do
      super
    end
20 21 22 23
  end

  private

24 25 26 27 28 29 30
  def redirect_unlogged_user
    if redirect_to_home_page_url?
      redirect_to(current_application_settings.home_page_url)
    else
      redirect_to(new_user_session_path)
    end
  end
31

32
  def redirect_logged_user
33
    case current_user.dashboard
Robert Speicher committed
34
    when 'stars'
35
      flash.keep
36
      redirect_to(starred_dashboard_projects_path)
37
    when 'project_activity'
38
      redirect_to(activity_dashboard_path)
39
    when 'starred_project_activity'
40
      redirect_to(activity_dashboard_path(filter: 'starred'))
41
    when 'groups'
42
      redirect_to(dashboard_groups_path)
43
    when 'todos'
44
      redirect_to(dashboard_todos_path)
Robert Speicher committed
45 46
    end
  end
47 48 49 50 51 52 53 54 55 56 57

  def redirect_to_home_page_url?
    # If user is not signed-in and tries to access root_path - redirect him to landing page
    # Don't redirect to the default URL to prevent endless redirections
    return false unless current_application_settings.home_page_url.present?

    home_page_url = current_application_settings.home_page_url.chomp('/')
    root_urls = [Gitlab.config.gitlab['url'].chomp('/'), root_url.chomp('/')]

    root_urls.exclude?(home_page_url)
  end
Robert Speicher committed
58
end