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
57b30f05
Commit
57b30f05
authored
Apr 10, 2020
by
Blair Lunceford
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add api support
parent
3d50086e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
1 deletion
+27
-1
app/finders/users_finder.rb
app/finders/users_finder.rb
+8
-0
doc/api/users.md
doc/api/users.md
+3
-0
lib/api/users.rb
lib/api/users.rb
+2
-1
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+14
-0
No files found.
app/finders/users_finder.rb
View file @
57b30f05
...
...
@@ -14,6 +14,7 @@
# active: boolean
# blocked: boolean
# external: boolean
# without_projects: boolean
#
class
UsersFinder
include
CreatedAtFilter
...
...
@@ -36,6 +37,7 @@ class UsersFinder
users
=
by_external
(
users
)
users
=
by_2fa
(
users
)
users
=
by_created_at
(
users
)
users
=
by_without_projects
(
users
)
users
=
by_custom_attributes
(
users
)
users
...
...
@@ -94,6 +96,12 @@ class UsersFinder
users
end
end
def
by_without_projects
(
users
)
return
users
unless
params
[
:without_projects
]
users
.
without_projects
end
end
UsersFinder
.
prepend_if_ee
(
'EE::UsersFinder'
)
doc/api/users.md
View file @
57b30f05
...
...
@@ -75,6 +75,7 @@ GET /users
|
`order_by`
| string | no | Return users ordered by
`id`
,
`name`
,
`username`
,
`created_at`
, or
`updated_at`
fields. Default is
`id`
|
|
`sort`
| string | no | Return users 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 |
|
`without_projects`
| boolean | no | Filter users without projects |
```
json
[
...
...
@@ -207,6 +208,8 @@ You can search users by creation date time range with:
GET /users?created_before=2001-01-02T00:00:00.060Z&created_after=1999-01-02T00:00:00.060
```
You can search for users without projects with:
`/users?without_projects=true`
You can filter by
[
custom attributes
](
custom_attributes.md
)
with:
```
plaintext
...
...
lib/api/users.rb
View file @
57b30f05
...
...
@@ -82,6 +82,7 @@ module API
optional
:blocked
,
type:
Boolean
,
default:
false
,
desc:
'Filters only blocked users'
optional
:created_after
,
type:
DateTime
,
desc:
'Return users created after the specified time'
optional
:created_before
,
type:
DateTime
,
desc:
'Return users created before the specified time'
optional
:without_projects
,
type:
Boolean
,
desc:
'Filters only users without projects'
all_or_none_of
:extern_uid
,
:provider
use
:sort_params
...
...
@@ -94,7 +95,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
,
:two_factor
)
params
.
except!
(
:created_after
,
:created_before
,
:order_by
,
:sort
,
:two_factor
,
:without_projects
)
end
users
=
UsersFinder
.
new
(
current_user
,
params
).
execute
...
...
spec/requests/api/users_spec.rb
View file @
57b30f05
...
...
@@ -280,6 +280,20 @@ describe API::Users, :do_not_mock_admin_mode do
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
user_with_2fa
.
id
)
end
it
"returns users without projects"
do
admin
user
user_without_projects
=
create
(
:user
)
project
=
create
(
:project
,
:repository
,
namespace:
user
.
namespace
)
project2
=
create
(
:project
,
namespace:
admin
.
namespace
)
get
api
(
'/users'
,
admin
),
params:
{
without_projects:
true
}
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_without_projects
.
id
)
end
it
'returns 400 when provided incorrect sort params'
do
get
api
(
'/users'
,
admin
),
params:
{
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