Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
0c866f4a
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,发现更多精彩内容 >>
提交
0c866f4a
编写于
5月 03, 2017
作者:
M
Michael Kozono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Resolve discussions
上级
fc061c2e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
42 addition
and
23 deletion
+42
-23
app/controllers/users_controller.rb
app/controllers/users_controller.rb
+10
-8
app/models/route.rb
app/models/route.rb
+11
-11
app/models/user.rb
app/models/user.rb
+1
-1
db/migrate/20170503184421_add_index_to_redirect_routes.rb
db/migrate/20170503184421_add_index_to_redirect_routes.rb
+2
-3
spec/controllers/users_controller_spec.rb
spec/controllers/users_controller_spec.rb
+18
-0
未找到文件。
app/controllers/users_controller.rb
浏览文件 @
0c866f4a
...
...
@@ -3,7 +3,6 @@ class UsersController < ApplicationController
skip_before_action
:authenticate_user!
before_action
:user
,
except:
[
:exists
]
before_action
:authorize_read_user!
,
except:
[
:exists
]
def
show
respond_to
do
|
format
|
...
...
@@ -93,14 +92,17 @@ class UsersController < ApplicationController
private
def
authorize_read_user!
render_404
unless
can?
(
current_user
,
:read_user
,
user
)
ensure_canonical_path
(
user
.
namespace
,
params
[
:username
])
end
def
user
@user
||=
User
.
find_by_full_path
(
params
[
:username
],
follow_redirects:
true
)
return
@user
if
@user
@user
=
User
.
find_by_full_path
(
params
[
:username
],
follow_redirects:
true
)
return
render_404
unless
@user
return
render_404
unless
can?
(
current_user
,
:read_user
,
@user
)
ensure_canonical_path
(
@user
.
namespace
,
params
[
:username
])
@user
end
def
contributed_projects
...
...
app/models/route.rb
浏览文件 @
0c866f4a
...
...
@@ -16,22 +16,22 @@ class Route < ActiveRecord::Base
scope
:direct_descendant_routes
,
->
(
path
)
{
where
(
'routes.path LIKE ? AND routes.path NOT LIKE ?'
,
"
#{
sanitize_sql_like
(
path
)
}
/%"
,
"
#{
sanitize_sql_like
(
path
)
}
/%/%"
)
}
def
rename_direct_descendant_routes
if
path_changed?
||
name_changed?
direct_descendant_routes
=
self
.
class
.
direct_descendant_routes
(
path_was
)
return
if
!
path_changed?
&&
!
name_changed?
direct_descendant_routes
.
each
do
|
route
|
attributes
=
{}
direct_descendant_routes
=
self
.
class
.
direct_descendant_routes
(
path_was
)
if
path_changed?
&&
route
.
path
.
present?
attributes
[
:path
]
=
route
.
path
.
sub
(
path_was
,
path
)
end
direct_descendant_routes
.
each
do
|
route
|
attributes
=
{}
if
name_changed?
&&
name_was
.
present?
&&
route
.
name
.
present?
attributes
[
:name
]
=
route
.
name
.
sub
(
name_was
,
name
)
end
if
path_changed?
&&
route
.
path
.
present?
attributes
[
:path
]
=
route
.
path
.
sub
(
path_was
,
path
)
end
route
.
update
(
attributes
)
unless
attributes
.
empty?
if
name_changed?
&&
name_was
.
present?
&&
route
.
name
.
present?
attributes
[
:name
]
=
route
.
name
.
sub
(
name_was
,
name
)
end
route
.
update
(
attributes
)
unless
attributes
.
empty?
end
end
...
...
app/models/user.rb
浏览文件 @
0c866f4a
...
...
@@ -335,7 +335,7 @@ class User < ActiveRecord::Base
def
find_by_full_path
(
path
,
follow_redirects:
false
)
namespace
=
Namespace
.
find_by_full_path
(
path
,
follow_redirects:
follow_redirects
)
namespace
.
owner
if
namespace
&&
namespace
.
owner
namespace
&
.
owner
end
def
reference_prefix
...
...
db/migrate/20170503184421_add_index_to_redirect_routes.rb
浏览文件 @
0c866f4a
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
# rubocop:disable RemoveIndex
class
AddIndexToRedirectRoutes
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
@@ -16,7 +15,7 @@ class AddIndexToRedirectRoutes < ActiveRecord::Migration
end
def
down
remove_index
(
:redirect_routes
,
:path
)
if
index_exists?
(
:redirect_routes
,
:path
)
remove_index
(
:redirect_routes
,
[
:source_type
,
:source_id
])
if
index_exists?
(
:redirect_routes
,
[
:source_type
,
:source_id
])
remove_
concurrent_
index
(
:redirect_routes
,
:path
)
if
index_exists?
(
:redirect_routes
,
:path
)
remove_
concurrent_
index
(
:redirect_routes
,
[
:source_type
,
:source_id
])
if
index_exists?
(
:redirect_routes
,
[
:source_type
,
:source_id
])
end
end
spec/controllers/users_controller_spec.rb
浏览文件 @
0c866f4a
...
...
@@ -84,6 +84,24 @@ describe UsersController do
expect
(
response
).
to
redirect_to
(
user
)
end
end
context
'when a user by that username does not exist'
do
context
'when logged out'
do
it
'renders 404 (does not redirect to login)'
do
get
:show
,
username:
'nonexistent'
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'when logged in'
do
before
{
sign_in
(
user
)
}
it
'renders 404'
do
get
:show
,
username:
'nonexistent'
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
end
describe
'GET #calendar'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录