Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
a0aaf93f
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,发现更多精彩内容 >>
未验证
提交
a0aaf93f
编写于
10月 25, 2016
作者:
Y
Yatish Mehta
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add query param to filter users on 'external' & 'blocked' type on API
上级
c6d01098
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
1 deletion
+45
-1
changelogs/unreleased/23731-add-param-to-user-api.yml
changelogs/unreleased/23731-add-param-to-user-api.yml
+4
-0
doc/api/users.md
doc/api/users.md
+14
-0
lib/api/users.rb
lib/api/users.rb
+6
-1
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+21
-0
未找到文件。
changelogs/unreleased/23731-add-param-to-user-api.yml
0 → 100644
浏览文件 @
a0aaf93f
---
title
:
Add query param to filter users by external & blocked type
merge_request
:
7109
author
:
Yatish Mehta
doc/api/users.md
浏览文件 @
a0aaf93f
...
...
@@ -33,6 +33,18 @@ GET /users
]
```
In addition, you can filter users based on states eg.
`blocked`
,
`active`
This works only to filter users who are
`blocked`
or
`active`
.
It does not support
`active=false`
or
`blocked=false`
.
```
GET /users?active=true
```
```
GET /users?blocked=true
```
### For admins
```
...
...
@@ -120,6 +132,8 @@ For example:
GET /users?username=jack_smith
```
You can search for users who are external with:
`/users?external=true`
## Single user
Get a single user.
...
...
lib/api/users.rb
浏览文件 @
a0aaf93f
...
...
@@ -10,6 +10,9 @@ module API
# GET /users
# GET /users?search=Admin
# GET /users?username=root
# GET /users?active=true
# GET /users?external=true
# GET /users?blocked=true
get
do
unless
can?
(
current_user
,
:read_users_list
,
nil
)
render_api_error!
(
"Not authorized."
,
403
)
...
...
@@ -19,8 +22,10 @@ module API
@users
=
User
.
where
(
username:
params
[
:username
])
else
@users
=
User
.
all
@users
=
@users
.
active
if
params
[
:active
].
present?
@users
=
@users
.
active
if
to_boolean
(
params
[
:active
])
@users
=
@users
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
@users
=
@users
.
blocked
if
to_boolean
(
params
[
:blocked
])
@users
=
@users
.
external
if
to_boolean
(
params
[
:external
])
&&
current_user
.
is_admin?
@users
=
paginate
@users
end
...
...
spec/requests/api/users_spec.rb
浏览文件 @
a0aaf93f
...
...
@@ -48,6 +48,17 @@ describe API::API, api: true do
end
[
'username'
]).
to
eq
(
username
)
end
it
"returns an array of blocked users"
do
ldap_blocked_user
create
(
:user
,
state:
'blocked'
)
get
api
(
"/users?blocked=true"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
).
to
all
(
include
(
'state'
=>
/(blocked|ldap_blocked)/
))
end
it
"returns one user"
do
get
api
(
"/users?username=
#{
omniauth_user
.
username
}
"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
...
...
@@ -69,6 +80,16 @@ describe API::API, api: true do
expect
(
json_response
.
first
.
keys
).
to
include
'last_sign_in_at'
expect
(
json_response
.
first
.
keys
).
to
include
'confirmed_at'
end
it
"returns an array of external users"
do
create
(
:user
,
external:
true
)
get
api
(
"/users?external=true"
,
admin
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
).
to
all
(
include
(
'external'
=>
true
))
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录