diff options
author | Brian Neel <brian@gitlab.com> | 2017-08-24 01:20:40 +0300 |
---|---|---|
committer | Brian Neel <brian@gitlab.com> | 2017-08-24 01:20:40 +0300 |
commit | cb49a829e89e3409d41b1a5a83747b2edcd24d23 (patch) | |
tree | 103560b5f0fe4a1e48b1614bca386204e456fe45 | |
parent | cdf87fe890a589da2c73e2f758e98f1c014d7953 (diff) |
Add admin search option to API /users
-rw-r--r-- | app/finders/users_finder.rb | 8 | ||||
-rw-r--r-- | doc/api/users.md | 6 | ||||
-rw-r--r-- | lib/api/users.rb | 3 |
3 files changed, 16 insertions, 1 deletions
diff --git a/app/finders/users_finder.rb b/app/finders/users_finder.rb index 33f7ae90598..d8f0d55eb0e 100644 --- a/app/finders/users_finder.rb +++ b/app/finders/users_finder.rb @@ -12,6 +12,7 @@ # active: boolean # blocked: boolean # external: boolean +# admin: boolean # class UsersFinder include CreatedAtFilter @@ -32,6 +33,7 @@ class UsersFinder users = by_external_identity(users) users = by_external(users) users = by_created_at(users) + users = by_admin(users) users end @@ -74,4 +76,10 @@ class UsersFinder users.external end + + def by_admin(users) + return users if params[:admin].nil? + + users.where(admin: params[:admin]) + end end diff --git a/doc/api/users.md b/doc/api/users.md index 57a13eb477d..bf2f76a3c9e 100644 --- a/doc/api/users.md +++ b/doc/api/users.md @@ -152,6 +152,12 @@ 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 admin users: + +``` +GET /users?admin=true +``` + ## Single user Get a single user. diff --git a/lib/api/users.rb b/lib/api/users.rb index e2019d6d512..5201bb52c4d 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -50,6 +50,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 :admin, type: Boolean, desc: 'Filters on admin status' all_or_none_of :extern_uid, :provider use :pagination @@ -58,7 +59,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) + params.except!(:created_after, :created_before, :admin) end users = UsersFinder.new(current_user, params).execute |