Commit 2d45ec58 authored by Jonas Waelter's avatar Jonas Waelter

Add 'exclude_external' parameter to endpoint /api/v4/users

parent 19bdc419
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# active: boolean # active: boolean
# blocked: boolean # blocked: boolean
# external: boolean # external: boolean
# non_external: boolean
# without_projects: boolean # without_projects: boolean
# sort: string # sort: string
# id: integer # id: integer
...@@ -40,6 +41,7 @@ class UsersFinder ...@@ -40,6 +41,7 @@ class UsersFinder
users = by_active(users) users = by_active(users)
users = by_external_identity(users) users = by_external_identity(users)
users = by_external(users) users = by_external(users)
users = by_non_external(users)
users = by_2fa(users) users = by_2fa(users)
users = by_created_at(users) users = by_created_at(users)
users = by_without_projects(users) users = by_without_projects(users)
...@@ -103,6 +105,12 @@ class UsersFinder ...@@ -103,6 +105,12 @@ class UsersFinder
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def by_non_external(users)
return users unless params[:non_external]
users.non_external
end
def by_2fa(users) def by_2fa(users)
case params[:two_factor] case params[:two_factor]
when 'enabled' when 'enabled'
......
...@@ -360,6 +360,7 @@ class User < ApplicationRecord ...@@ -360,6 +360,7 @@ class User < ApplicationRecord
scope :blocked, -> { with_states(:blocked, :ldap_blocked) } scope :blocked, -> { with_states(:blocked, :ldap_blocked) }
scope :blocked_pending_approval, -> { with_states(:blocked_pending_approval) } scope :blocked_pending_approval, -> { with_states(:blocked_pending_approval) }
scope :external, -> { where(external: true) } scope :external, -> { where(external: true) }
scope :non_external, -> { where(external: false) }
scope :confirmed, -> { where.not(confirmed_at: nil) } scope :confirmed, -> { where.not(confirmed_at: nil) }
scope :active, -> { with_state(:active).non_internal } scope :active, -> { with_state(:active).non_internal }
scope :active_without_ghosts, -> { with_state(:active).without_ghosts } scope :active_without_ghosts, -> { with_state(:active).without_ghosts }
......
...@@ -53,6 +53,9 @@ For example: ...@@ -53,6 +53,9 @@ For example:
GET /users?username=jack_smith GET /users?username=jack_smith
``` ```
NOTE:
Username search is case insensitive.
In addition, you can filter users based on the states `blocked` and `active`. 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 It does not support `active=false` or `blocked=false`. The list of billable users
is the total number of users minus the blocked 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_ ...@@ -74,8 +77,11 @@ To exclude these users from the users' list, you can use the parameter `exclude_
GET /users?exclude_internal=true GET /users?exclude_internal=true
``` ```
NOTE: In addition, to exclude external users from the users' list, you can use the parameter `exclude_external=true`.
Username search is case insensitive.
```plaintext
GET /users?exclude_external=true
```
### For admins ### For admins
......
...@@ -82,6 +82,7 @@ module API ...@@ -82,6 +82,7 @@ module API
optional :search, type: String, desc: 'Search for a username' optional :search, type: String, desc: 'Search for a username'
optional :active, type: Boolean, default: false, desc: 'Filters only active users' optional :active, type: Boolean, default: false, desc: 'Filters only active users'
optional :external, type: Boolean, default: false, desc: 'Filters only external 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 :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_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 :created_before, type: DateTime, desc: 'Return users created before the specified time'
......
...@@ -51,6 +51,12 @@ RSpec.describe UsersFinder do ...@@ -51,6 +51,12 @@ RSpec.describe UsersFinder do
expect(users).to contain_exactly(user, normal_user, external_user, omniauth_user, admin_user) expect(users).to contain_exactly(user, normal_user, external_user, omniauth_user, admin_user)
end 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 it 'filters by created_at' do
filtered_user_before = create(:user, created_at: 3.days.ago) filtered_user_before = create(:user, created_at: 3.days.ago)
filtered_user_after = create(:user, created_at: Time.now + 3.days) filtered_user_after = create(:user, created_at: Time.now + 3.days)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment