Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
b50b5a44
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
b50b5a44
编写于
2月 24, 2017
作者:
R
Rémy Coutable
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the redirect to custom home page URL and move it to RootController
Signed-off-by:
N
Rémy Coutable
<
remy@rymai.me
>
上级
c72c8e9a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
62 addition
and
36 deletion
+62
-36
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+0
-21
app/controllers/root_controller.rb
app/controllers/root_controller.rb
+27
-10
changelogs/unreleased/28609-fix-redirect-to-home-page-url.yml
...gelogs/unreleased/28609-fix-redirect-to-home-page-url.yml
+4
-0
spec/controllers/root_controller_spec.rb
spec/controllers/root_controller_spec.rb
+31
-5
未找到文件。
app/controllers/application_controller.rb
浏览文件 @
b50b5a44
...
...
@@ -72,14 +72,6 @@ class ApplicationController < ActionController::Base
end
end
def
authenticate_user!
(
*
args
)
if
redirect_to_home_page_url?
return
redirect_to
current_application_settings
.
home_page_url
end
super
(
*
args
)
end
def
log_exception
(
exception
)
application_trace
=
ActionDispatch
::
ExceptionWrapper
.
new
(
env
,
exception
).
application_trace
application_trace
.
map!
{
|
t
|
"
#{
t
}
\n
"
}
...
...
@@ -287,19 +279,6 @@ class ApplicationController < ActionController::Base
session
[
:skip_tfa
]
&&
session
[
:skip_tfa
]
>
Time
.
current
end
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
(
'/'
)]
return
false
if
root_urls
.
include?
(
home_page_url
)
current_user
.
nil?
&&
root_path
==
request
.
path
end
# U2F (universal 2nd factor) devices need a unique identifier for the application
# to perform authentication.
# https://developers.yubico.com/U2F/App_ID.html
...
...
app/controllers/root_controller.rb
浏览文件 @
b50b5a44
...
...
@@ -8,7 +8,9 @@
# `DashboardController#show`, which is the default.
class
RootController
<
Dashboard
::
ProjectsController
skip_before_action
:authenticate_user!
,
only:
[
:index
]
before_action
:redirect_to_custom_dashboard
,
only:
[
:index
]
before_action
:redirect_unlogged_user
,
if:
->
{
current_user
.
nil?
}
before_action
:redirect_logged_user
,
if:
->
{
current_user
.
present?
}
def
index
super
...
...
@@ -16,23 +18,38 @@ class RootController < Dashboard::ProjectsController
private
def
redirect_to_custom_dashboard
return
redirect_to
new_user_session_path
unless
current_user
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
def
redirect_logged_user
case
current_user
.
dashboard
when
'stars'
flash
.
keep
redirect_to
starred_dashboard_projects_path
redirect_to
(
starred_dashboard_projects_path
)
when
'project_activity'
redirect_to
activity_dashboard_path
redirect_to
(
activity_dashboard_path
)
when
'starred_project_activity'
redirect_to
activity_dashboard_path
(
filter:
'starred'
)
redirect_to
(
activity_dashboard_path
(
filter:
'starred'
)
)
when
'groups'
redirect_to
dashboard_groups_path
redirect_to
(
dashboard_groups_path
)
when
'todos'
redirect_to
dashboard_todos_path
else
return
redirect_to
(
dashboard_todos_path
)
end
end
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
end
changelogs/unreleased/28609-fix-redirect-to-home-page-url.yml
0 → 100644
浏览文件 @
b50b5a44
---
title
:
Fix the redirect to custom home page URL
merge_request
:
9518
author
:
spec/controllers/root_controller_spec.rb
浏览文件 @
b50b5a44
...
...
@@ -2,6 +2,26 @@ require 'spec_helper'
describe
RootController
do
describe
'GET index'
do
context
'when user is not logged in'
do
it
'redirects to the sign-in page'
do
get
:index
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
end
context
'when a custom home page URL is defined'
do
before
do
stub_application_setting
(
home_page_url:
'https://gitlab.com'
)
end
it
'redirects the user to the custom home page URL'
do
get
:index
expect
(
response
).
to
redirect_to
(
'https://gitlab.com'
)
end
end
end
context
'with a user'
do
let
(
:user
)
{
create
(
:user
)
}
...
...
@@ -12,55 +32,60 @@ describe RootController do
context
'who has customized their dashboard setting for starred projects'
do
before
do
user
.
update_attribute
(
:dashboard
,
'stars'
)
user
.
dashboard
=
'stars'
end
it
'redirects to their specified dashboard'
do
get
:index
expect
(
response
).
to
redirect_to
starred_dashboard_projects_path
end
end
context
'who has customized their dashboard setting for project activities'
do
before
do
user
.
update_attribute
(
:dashboard
,
'project_activity'
)
user
.
dashboard
=
'project_activity'
end
it
'redirects to the activity list'
do
get
:index
expect
(
response
).
to
redirect_to
activity_dashboard_path
end
end
context
'who has customized their dashboard setting for starred project activities'
do
before
do
user
.
update_attribute
(
:dashboard
,
'starred_project_activity'
)
user
.
dashboard
=
'starred_project_activity'
end
it
'redirects to the activity list'
do
get
:index
expect
(
response
).
to
redirect_to
activity_dashboard_path
(
filter:
'starred'
)
end
end
context
'who has customized their dashboard setting for groups'
do
before
do
user
.
update_attribute
(
:dashboard
,
'groups'
)
user
.
dashboard
=
'groups'
end
it
'redirects to their group list'
do
get
:index
expect
(
response
).
to
redirect_to
dashboard_groups_path
end
end
context
'who has customized their dashboard setting for todos'
do
before
do
user
.
update_attribute
(
:dashboard
,
'todos'
)
user
.
dashboard
=
'todos'
end
it
'redirects to their todo list'
do
get
:index
expect
(
response
).
to
redirect_to
dashboard_todos_path
end
end
...
...
@@ -68,6 +93,7 @@ describe RootController do
context
'who uses the default dashboard setting'
do
it
'renders the default dashboard'
do
get
:index
expect
(
response
).
to
render_template
'dashboard/projects/index'
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录