Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
cf2058c0
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,发现更多精彩内容 >>
提交
cf2058c0
编写于
4月 23, 2014
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6781 from thekid/master
Complete admin APIs for SSH Keys
上级
7b4a7625
05e792b4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
127 addition
and
0 deletion
+127
-0
doc/api/users.md
doc/api/users.md
+27
-0
lib/api/users.rb
lib/api/users.rb
+39
-0
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+61
-0
未找到文件。
doc/api/users.md
浏览文件 @
cf2058c0
...
...
@@ -220,6 +220,18 @@ Parameters:
+
**none**
## List SSH keys for user
Get a list of a specified user's SSH keys. Available only for admin
```
GET /users/:uid/keys
```
Parameters:
+
`uid`
(required) - id of specified user
## Single SSH key
...
...
@@ -286,3 +298,18 @@ Parameters:
+
`id`
(required) - SSH key ID
## Delete SSH key
Deletes key owned by a specified user. Available only for admin.
```
DELETE /users/:uid/keys/:id
```
Parameters:
+
`uid`
(required) - id of specified user
+
`id`
(required) - SSH key ID
Will return
`200 Ok`
on success, or
`404 Not found`
if either user or key cannot be found.
lib/api/users.rb
浏览文件 @
cf2058c0
...
...
@@ -113,6 +113,45 @@ module API
end
end
# Get ssh keys of a specified user. Only available to admin users.
#
# Parameters:
# uid (required) - The ID of a user
# Example Request:
# GET /users/:uid/keys
get
':uid/keys'
do
authenticated_as_admin!
user
=
User
.
find_by
(
id:
params
[
:uid
])
if
user
present
user
.
keys
,
with:
Entities
::
SSHKey
else
not_found!
end
end
# Delete existing ssh key of a specified user. Only available to admin
# users.
#
# Parameters:
# uid (required) - The ID of a user
# id (required) - SSH Key ID
# Example Request:
# DELETE /users/:uid/keys/:id
delete
':uid/keys/:id'
do
authenticated_as_admin!
user
=
User
.
find_by
(
id:
params
[
:uid
])
if
user
begin
key
=
user
.
keys
.
find
params
[
:id
]
key
.
destroy
rescue
ActiveRecord
::
RecordNotFound
not_found!
end
else
not_found!
end
end
# Delete user. Available only for admin
#
# Example Request:
...
...
spec/requests/api/users_spec.rb
浏览文件 @
cf2058c0
...
...
@@ -242,6 +242,67 @@ describe API::API, api: true do
end
end
describe
'GET /user/:uid/keys'
do
before
{
admin
}
context
'when unauthenticated'
do
it
'should return authentication error'
do
get
api
(
"/users/
#{
user
.
id
}
/keys"
)
response
.
status
.
should
==
401
end
end
context
'when authenticated'
do
it
'should return 404 for non-existing user'
do
get
api
(
'/users/999999/keys'
,
admin
)
response
.
status
.
should
==
404
end
it
'should return array of ssh keys'
do
user
.
keys
<<
key
user
.
save
get
api
(
"/users/
#{
user
.
id
}
/keys"
,
admin
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
first
[
'title'
].
should
==
key
.
title
end
end
end
describe
'DELETE /user/:uid/keys/:id'
do
before
{
admin
}
context
'when unauthenticated'
do
it
'should return authentication error'
do
delete
api
(
"/users/
#{
user
.
id
}
/keys/42"
)
response
.
status
.
should
==
401
end
end
context
'when authenticated'
do
it
'should delete existing key'
do
user
.
keys
<<
key
user
.
save
expect
{
delete
api
(
"/users/
#{
user
.
id
}
/keys/
#{
key
.
id
}
"
,
admin
)
}.
to
change
{
user
.
keys
.
count
}.
by
(
-
1
)
response
.
status
.
should
==
200
end
it
'should return 404 error if user not found'
do
user
.
keys
<<
key
user
.
save
delete
api
(
"/users/999999/keys/
#{
key
.
id
}
"
,
admin
)
response
.
status
.
should
==
404
end
it
'should return 404 error if key not foud'
do
delete
api
(
"/users/
#{
user
.
id
}
/keys/42"
,
admin
)
response
.
status
.
should
==
404
end
end
end
describe
"DELETE /users/:id"
do
before
{
admin
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录