BigW Consortium Gitlab

root_controller.rb 1.7 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 20
    super
  end

  private

21 22 23 24 25 26 27
  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
28

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

  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
55
end