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
2d45ec58
Commit
2d45ec58
authored
Feb 03, 2021
by
Jonas Waelter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add 'exclude_external' parameter to endpoint /api/v4/users
parent
19bdc419
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
2 deletions
+24
-2
app/finders/users_finder.rb
app/finders/users_finder.rb
+8
-0
app/models/user.rb
app/models/user.rb
+1
-0
doc/api/users.md
doc/api/users.md
+8
-2
lib/api/users.rb
lib/api/users.rb
+1
-0
spec/finders/users_finder_spec.rb
spec/finders/users_finder_spec.rb
+6
-0
No files found.
app/finders/users_finder.rb
View file @
2d45ec58
...
...
@@ -14,6 +14,7 @@
# active: boolean
# blocked: boolean
# external: boolean
# non_external: boolean
# without_projects: boolean
# sort: string
# id: integer
...
...
@@ -40,6 +41,7 @@ class UsersFinder
users
=
by_active
(
users
)
users
=
by_external_identity
(
users
)
users
=
by_external
(
users
)
users
=
by_non_external
(
users
)
users
=
by_2fa
(
users
)
users
=
by_created_at
(
users
)
users
=
by_without_projects
(
users
)
...
...
@@ -103,6 +105,12 @@ class UsersFinder
end
# rubocop: enable CodeReuse/ActiveRecord
def
by_non_external
(
users
)
return
users
unless
params
[
:non_external
]
users
.
non_external
end
def
by_2fa
(
users
)
case
params
[
:two_factor
]
when
'enabled'
...
...
app/models/user.rb
View file @
2d45ec58
...
...
@@ -360,6 +360,7 @@ class User < ApplicationRecord
scope
:blocked
,
->
{
with_states
(
:blocked
,
:ldap_blocked
)
}
scope
:blocked_pending_approval
,
->
{
with_states
(
:blocked_pending_approval
)
}
scope
:external
,
->
{
where
(
external:
true
)
}
scope
:non_external
,
->
{
where
(
external:
false
)
}
scope
:confirmed
,
->
{
where
.
not
(
confirmed_at:
nil
)
}
scope
:active
,
->
{
with_state
(
:active
).
non_internal
}
scope
:active_without_ghosts
,
->
{
with_state
(
:active
).
without_ghosts
}
...
...
doc/api/users.md
View file @
2d45ec58
...
...
@@ -53,6 +53,9 @@ For example:
GET /users?username=jack_smith
```
NOTE:
Username search is case insensitive.
In addition, you can filter users based on the states
`blocked`
and
`active`
.
It does not support
`active=false`
or
`blocked=false`
. The list of billable users
is the total number of users minus the blocked users.
...
...
@@ -74,8 +77,11 @@ To exclude these users from the users' list, you can use the parameter `exclude_
GET /users?exclude_internal=true
```
NOTE:
Username search is case insensitive.
In addition, to exclude external users from the users' list, you can use the parameter
`exclude_external=true`
.
```
plaintext
GET /users?exclude_external=true
```
### For admins
...
...
lib/api/users.rb
View file @
2d45ec58
...
...
@@ -82,6 +82,7 @@ module API
optional
:search
,
type:
String
,
desc:
'Search for a username'
optional
:active
,
type:
Boolean
,
default:
false
,
desc:
'Filters only active users'
optional
:external
,
type:
Boolean
,
default:
false
,
desc:
'Filters only external users'
optional
:exclude_external
,
as: :non_external
,
type:
Boolean
,
default:
false
,
desc:
'Filters only non external users'
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'
...
...
spec/finders/users_finder_spec.rb
View file @
2d45ec58
...
...
@@ -51,6 +51,12 @@ RSpec.describe UsersFinder do
expect
(
users
).
to
contain_exactly
(
user
,
normal_user
,
external_user
,
omniauth_user
,
admin_user
)
end
it
'filters by non external users'
do
users
=
described_class
.
new
(
user
,
non_external:
true
).
execute
expect
(
users
).
to
contain_exactly
(
user
,
normal_user
,
blocked_user
,
omniauth_user
,
internal_user
,
admin_user
)
end
it
'filters by created_at'
do
filtered_user_before
=
create
(
:user
,
created_at:
3
.
days
.
ago
)
filtered_user_after
=
create
(
:user
,
created_at:
Time
.
now
+
3
.
days
)
...
...
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