Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
915dac00
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,发现更多精彩内容 >>
提交
915dac00
编写于
9月 10, 2012
作者:
A
Alex Denisov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Error throwing moved to api_helper
上级
a839cb42
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
34 addition
and
13 deletion
+34
-13
lib/api/helpers.rb
lib/api/helpers.rb
+24
-3
lib/api/issues.rb
lib/api/issues.rb
+3
-3
lib/api/milestones.rb
lib/api/milestones.rb
+2
-2
lib/api/projects.rb
lib/api/projects.rb
+5
-5
未找到文件。
lib/api/helpers.rb
浏览文件 @
915dac00
...
@@ -8,7 +8,7 @@ module Gitlab
...
@@ -8,7 +8,7 @@ module Gitlab
if
@project
||=
current_user
.
projects
.
find_by_id
(
params
[
:id
])
||
if
@project
||=
current_user
.
projects
.
find_by_id
(
params
[
:id
])
||
current_user
.
projects
.
find_by_code
(
params
[
:id
])
current_user
.
projects
.
find_by_code
(
params
[
:id
])
else
else
error!
({
'message'
=>
'404 Not found'
},
404
)
not_found!
end
end
@project
@project
...
@@ -19,15 +19,36 @@ module Gitlab
...
@@ -19,15 +19,36 @@ module Gitlab
end
end
def
authenticate!
def
authenticate!
error!
({
'message'
=>
'401 Unauthorized'
},
401
)
unless
current_user
unauthorized!
unless
current_user
end
end
def
authorize!
action
,
subject
def
authorize!
action
,
subject
unless
abilities
.
allowed?
(
current_user
,
action
,
subject
)
unless
abilities
.
allowed?
(
current_user
,
action
,
subject
)
error!
({
'message'
=>
'403 Forbidden'
},
403
)
forbidden!
end
end
end
end
# error helpers
def
forbidden!
error!
({
'message'
=>
'403 Forbidden'
},
403
)
end
def
not_found!
(
resource
=
nil
)
message
=
[
"404"
]
message
<<
resource
if
resource
message
<<
"Not Found"
error!
({
'message'
=>
message
.
join
(
' '
)},
404
)
end
def
unauthorized!
error!
({
'message'
=>
'401 Unauthorized'
},
401
)
end
def
not_allowed!
error!
({
'message'
=>
'method not allowed'
},
405
)
end
private
private
def
abilities
def
abilities
...
...
lib/api/issues.rb
浏览文件 @
915dac00
...
@@ -60,7 +60,7 @@ module Gitlab
...
@@ -60,7 +60,7 @@ module Gitlab
if
@issue
.
save
if
@issue
.
save
present
@issue
,
with:
Entities
::
Issue
present
@issue
,
with:
Entities
::
Issue
else
else
error!
({
'message'
=>
'404 Not found'
},
404
)
not_found!
end
end
end
end
...
@@ -93,7 +93,7 @@ module Gitlab
...
@@ -93,7 +93,7 @@ module Gitlab
if
@issue
.
update_attributes
(
parameters
)
if
@issue
.
update_attributes
(
parameters
)
present
@issue
,
with:
Entities
::
Issue
present
@issue
,
with:
Entities
::
Issue
else
else
error!
({
'message'
=>
'404 Not found'
},
404
)
not_found!
end
end
end
end
...
@@ -105,7 +105,7 @@ module Gitlab
...
@@ -105,7 +105,7 @@ module Gitlab
# Example Request:
# Example Request:
# DELETE /projects/:id/issues/:issue_id
# DELETE /projects/:id/issues/:issue_id
delete
":id/issues/:issue_id"
do
delete
":id/issues/:issue_id"
do
error!
({
'message'
=>
'method not allowed'
},
405
)
not_allowed!
end
end
end
end
end
end
...
...
lib/api/milestones.rb
浏览文件 @
915dac00
...
@@ -45,7 +45,7 @@ module Gitlab
...
@@ -45,7 +45,7 @@ module Gitlab
if
@milestone
.
save
if
@milestone
.
save
present
@milestone
,
with:
Entities
::
Milestone
present
@milestone
,
with:
Entities
::
Milestone
else
else
error!
({
'message'
=>
'404 Not found'
},
404
)
not_found!
end
end
end
end
...
@@ -74,7 +74,7 @@ module Gitlab
...
@@ -74,7 +74,7 @@ module Gitlab
if
@milestone
.
update_attributes
(
parameters
)
if
@milestone
.
update_attributes
(
parameters
)
present
@milestone
,
with:
Entities
::
Milestone
present
@milestone
,
with:
Entities
::
Milestone
else
else
error!
({
'message'
=>
'404 Not found'
},
404
)
not_found!
end
end
end
end
end
end
...
...
lib/api/projects.rb
浏览文件 @
915dac00
...
@@ -50,7 +50,7 @@ module Gitlab
...
@@ -50,7 +50,7 @@ module Gitlab
if
@project
.
saved?
if
@project
.
saved?
present
@project
,
with:
Entities
::
Project
present
@project
,
with:
Entities
::
Project
else
else
error!
({
'message'
=>
'404 Not found'
},
404
)
not_found!
end
end
end
end
...
@@ -172,7 +172,7 @@ module Gitlab
...
@@ -172,7 +172,7 @@ module Gitlab
if
@snippet
.
save
if
@snippet
.
save
present
@snippet
,
with:
Entities
::
ProjectSnippet
present
@snippet
,
with:
Entities
::
ProjectSnippet
else
else
error!
({
'message'
=>
'404 Not found'
},
404
)
not_found!
end
end
end
end
...
@@ -201,7 +201,7 @@ module Gitlab
...
@@ -201,7 +201,7 @@ module Gitlab
if
@snippet
.
update_attributes
(
parameters
)
if
@snippet
.
update_attributes
(
parameters
)
present
@snippet
,
with:
Entities
::
ProjectSnippet
present
@snippet
,
with:
Entities
::
ProjectSnippet
else
else
error!
({
'message'
=>
'404 Not found'
},
404
)
not_found!
end
end
end
end
...
@@ -244,10 +244,10 @@ module Gitlab
...
@@ -244,10 +244,10 @@ module Gitlab
ref
=
params
[
:sha
]
ref
=
params
[
:sha
]
commit
=
user_project
.
commit
ref
commit
=
user_project
.
commit
ref
error!
(
'404 Commit Not Found'
,
404
)
unless
commit
not_found!
"Commit"
unless
commit
tree
=
Tree
.
new
commit
.
tree
,
user_project
,
ref
,
params
[
:filepath
]
tree
=
Tree
.
new
commit
.
tree
,
user_project
,
ref
,
params
[
:filepath
]
error!
(
'404 File Not Found'
,
404
)
unless
tree
.
try
(
:tree
)
not_found!
"File"
unless
tree
.
try
(
:tree
)
if
tree
.
text?
if
tree
.
text?
encoding
=
Gitlab
::
Encode
.
detect_encoding
(
tree
.
data
)
encoding
=
Gitlab
::
Encode
.
detect_encoding
(
tree
.
data
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录