From 97bac7482e9781e81b7325bedc97dfd53c6864e9 Mon Sep 17 00:00:00 2001 From: Drew Blessing Date: Tue, 19 Dec 2023 09:40:51 -0600 Subject: [PATCH] Add params and sorting to group users API Adds the optional active param and adds default descending ID sorting to the Groups Users API. Changelog: changed EE: true --- ee/app/finders/groups/users_finder.rb | 3 ++- ee/lib/ee/api/groups.rb | 5 +++-- ee/spec/finders/groups/users_finder_spec.rb | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ee/app/finders/groups/users_finder.rb b/ee/app/finders/groups/users_finder.rb index 67285f2310cbdc..597c01fa4f5b8c 100644 --- a/ee/app/finders/groups/users_finder.rb +++ b/ee/app/finders/groups/users_finder.rb @@ -25,7 +25,8 @@ def base_scope return relations.first if relations.size == 1 - ::User.from_union(relations) # rubocop:disable CodeReuse/ActiveRecord -- Simple union of existing relations/scopes + union = ::User.from_union(relations) # rubocop:disable CodeReuse/ActiveRecord -- Simple union of existing relations/scopes + union.order_id_desc end def relations_to_join(users) diff --git a/ee/lib/ee/api/groups.rb b/ee/lib/ee/api/groups.rb index 845b0220e99c63..a6067f3732eb96 100644 --- a/ee/lib/ee/api/groups.rb +++ b/ee/lib/ee/api/groups.rb @@ -268,6 +268,9 @@ def delete_group(group) ] end params do + optional :search, type: String, desc: 'Search users by name, email or username' + optional :active, type: ::Grape::API::Boolean, default: false, desc: 'Filters only active users' + optional :include_saml_users, type: Grape::API::Boolean, desc: 'Return users with a SAML identity in this group' @@ -276,8 +279,6 @@ def delete_group(group) desc: 'Return service accounts owned by this group' at_least_one_of :include_saml_users, :include_service_accounts - optional :search, type: String, desc: 'Search users by name, email or username' - use :pagination end # rubocop: disable CodeReuse/ActiveRecord diff --git a/ee/spec/finders/groups/users_finder_spec.rb b/ee/spec/finders/groups/users_finder_spec.rb index 6e36df500d7ae4..d2d501a2c4248e 100644 --- a/ee/spec/finders/groups/users_finder_spec.rb +++ b/ee/spec/finders/groups/users_finder_spec.rb @@ -38,6 +38,10 @@ it 'finds both saml users and service accounts' do expect(finder.execute).to match_array([saml_user1, saml_user2, service_account1, service_account2]) end + + it 'orders by id descending' do + expect(finder.execute).to eq([service_account2, service_account1, saml_user2, saml_user1]) + end end context 'when params includes only saml users' do @@ -46,6 +50,18 @@ it 'finds only saml users' do expect(finder.execute).to match_array([saml_user1, saml_user2]) end + + context 'when active param is true' do + let(:params) { { active: true, include_saml_users: true } } + + before do + saml_user2.block! + end + + it 'includes only active users' do + expect(finder.execute).to match_array([saml_user1]) + end + end end context 'when params includes only service accounts' do -- GitLab