Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
28ef8cc5
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
28ef8cc5
编写于
2月 06, 2018
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add sorting options for /users API (admin only)
Signed-off-by:
N
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
上级
1a430836
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
46 addition
and
1 deletion
+46
-1
changelogs/unreleased/42669-allow-order_by-users-in-gitlab-api.yml
...s/unreleased/42669-allow-order_by-users-in-gitlab-api.yml
+5
-0
doc/api/users.md
doc/api/users.md
+5
-0
lib/api/users.rb
lib/api/users.rb
+18
-1
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+18
-0
未找到文件。
changelogs/unreleased/42669-allow-order_by-users-in-gitlab-api.yml
0 → 100644
浏览文件 @
28ef8cc5
---
title
:
Add sorting options for /users API (admin only)
merge_request
:
16945
author
:
type
:
added
doc/api/users.md
浏览文件 @
28ef8cc5
...
...
@@ -51,6 +51,11 @@ GET /users?blocked=true
GET /users
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
|
`order_by`
| string | no | Return projects ordered by
`id`
,
`name`
,
`username`
,
`created_at`
, or
`updated_at`
fields. Default is
`id`
|
|
`sort`
| string | no | Return projects sorted in
`asc`
or
`desc`
order. Default is
`desc`
|
```
json
[
{
...
...
lib/api/users.rb
浏览文件 @
28ef8cc5
...
...
@@ -18,6 +18,14 @@ module API
User
.
find_by
(
id:
id
)
||
not_found!
(
'User'
)
end
def
reorder_users
(
users
)
if
params
[
:order_by
]
&&
params
[
:sort
]
users
.
reorder
(
params
[
:order_by
]
=>
params
[
:sort
])
else
users
end
end
params
:optional_attributes
do
optional
:skype
,
type:
String
,
desc:
'The Skype username'
optional
:linkedin
,
type:
String
,
desc:
'The LinkedIn username'
...
...
@@ -35,6 +43,13 @@ module API
optional
:avatar
,
type:
File
,
desc:
'Avatar image for user'
all_or_none_of
:extern_uid
,
:provider
end
params
:sort_params
do
optional
:order_by
,
type:
String
,
values:
%w[id name username created_at updated_at]
,
default:
'id'
,
desc:
'Return users ordered by a field'
optional
:sort
,
type:
String
,
values:
%w[asc desc]
,
default:
'desc'
,
desc:
'Return users sorted in ascending and descending order'
end
end
desc
'Get the list of users'
do
...
...
@@ -53,16 +68,18 @@ module API
optional
:created_before
,
type:
DateTime
,
desc:
'Return users created before the specified time'
all_or_none_of
:extern_uid
,
:provider
use
:sort_params
use
:pagination
end
get
do
authenticated_as_admin!
if
params
[
:external
].
present?
||
(
params
[
:extern_uid
].
present?
&&
params
[
:provider
].
present?
)
unless
current_user
&
.
admin?
params
.
except!
(
:created_after
,
:created_before
)
params
.
except!
(
:created_after
,
:created_before
,
:order_by
,
:sort
)
end
users
=
UsersFinder
.
new
(
current_user
,
params
).
execute
users
=
reorder_users
(
users
)
authorized
=
can?
(
current_user
,
:read_users_list
)
...
...
spec/requests/api/users_spec.rb
浏览文件 @
28ef8cc5
...
...
@@ -199,6 +199,24 @@ describe API::Users do
expect
(
json_response
.
size
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'username'
]).
to
eq
(
user
.
username
)
end
it
'returns the correct order when sorted by id'
do
admin
user
get
api
(
'/users'
,
admin
),
{
order_by:
'id'
,
sort:
'asc'
}
expect
(
response
).
to
match_response_schema
(
'public_api/v4/user/admins'
)
expect
(
json_response
.
size
).
to
eq
(
2
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
admin
.
id
)
expect
(
json_response
.
last
[
'id'
]).
to
eq
(
user
.
id
)
end
it
'returns 400 when provided incorrect sort params'
do
get
api
(
'/users'
,
admin
),
{
order_by:
'magic'
,
sort:
'asc'
}
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录