Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c87c55bb
Commit
c87c55bb
authored
Apr 20, 2018
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add 2FA filter to users API for admins only
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
c212908a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
1 deletion
+26
-1
app/finders/users_finder.rb
app/finders/users_finder.rb
+12
-0
doc/api/users.md
doc/api/users.md
+1
-0
lib/api/users.rb
lib/api/users.rb
+1
-1
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+12
-0
No files found.
app/finders/users_finder.rb
View file @
c87c55bb
...
...
@@ -32,6 +32,7 @@ class UsersFinder
users
=
by_active
(
users
)
users
=
by_external_identity
(
users
)
users
=
by_external
(
users
)
users
=
by_2fa
(
users
)
users
=
by_created_at
(
users
)
users
=
by_custom_attributes
(
users
)
...
...
@@ -76,4 +77,15 @@ class UsersFinder
users
.
external
end
def
by_2fa
(
users
)
case
params
[
:two_factor
]
when
'enabled'
users
.
with_two_factor
when
'disabled'
users
.
without_two_factor
else
users
end
end
end
doc/api/users.md
View file @
c87c55bb
...
...
@@ -55,6 +55,7 @@ GET /users
| --------- | ---- | -------- | ----------- |
|
`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`
|
|
`two_factor`
| string | no | Filter users by Two-factor authentication. Filter values are
`enabled`
or
`disabled`
. By default it returns all users |
```
json
[
...
...
lib/api/users.rb
View file @
c87c55bb
...
...
@@ -77,7 +77,7 @@ module API
authenticated_as_admin!
if
params
[
:external
].
present?
||
(
params
[
:extern_uid
].
present?
&&
params
[
:provider
].
present?
)
unless
current_user
&
.
admin?
params
.
except!
(
:created_after
,
:created_before
,
:order_by
,
:sort
)
params
.
except!
(
:created_after
,
:created_before
,
:order_by
,
:sort
,
:two_factor
)
end
users
=
UsersFinder
.
new
(
current_user
,
params
).
execute
...
...
spec/requests/api/users_spec.rb
View file @
c87c55bb
...
...
@@ -212,6 +212,18 @@ describe API::Users do
expect
(
json_response
.
last
[
'id'
]).
to
eq
(
user
.
id
)
end
it
'returns users with 2fa enabled'
do
admin
user
user_with_2fa
=
create
(
:user
,
:two_factor_via_otp
)
get
api
(
'/users'
,
admin
),
{
two_factor:
'enabled'
}
expect
(
response
).
to
match_response_schema
(
'public_api/v4/user/admins'
)
expect
(
json_response
.
size
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
user_with_2fa
.
id
)
end
it
'returns 400 when provided incorrect sort params'
do
get
api
(
'/users'
,
admin
),
{
order_by:
'magic'
,
sort:
'asc'
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment