From ba6a53f8f3be2d31de0449de23a4bb69f228ed62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Mon, 13 Nov 2017 15:15:11 +0000 Subject: Merge branch 'fix-subgroup-autocomplete' into 'master' Fix users autocomplete in a subgroup Closes #39452 See merge request gitlab-org/gitlab-ce!15350 (cherry picked from commit 4a1e8188f96744103e51263c9bdc071c8e088690) cf6ff601 Fix users autocomplete in a subgroup --- app/finders/autocomplete_users_finder.rb | 2 +- changelogs/unreleased/fix-subgroup-autocomplete.yml | 5 +++++ spec/finders/autocomplete_users_finder_spec.rb | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/fix-subgroup-autocomplete.yml diff --git a/app/finders/autocomplete_users_finder.rb b/app/finders/autocomplete_users_finder.rb index b8f52e31926..c3f5358b577 100644 --- a/app/finders/autocomplete_users_finder.rb +++ b/app/finders/autocomplete_users_finder.rb @@ -45,7 +45,7 @@ class AutocompleteUsersFinder def find_users return users_from_project if project - return group.users if group + return group.users_with_parents if group return User.all if current_user User.none diff --git a/changelogs/unreleased/fix-subgroup-autocomplete.yml b/changelogs/unreleased/fix-subgroup-autocomplete.yml new file mode 100644 index 00000000000..4baa2b02f77 --- /dev/null +++ b/changelogs/unreleased/fix-subgroup-autocomplete.yml @@ -0,0 +1,5 @@ +--- +title: Fix user autocomplete in subgroups +merge_request: +author: +type: fixed diff --git a/spec/finders/autocomplete_users_finder_spec.rb b/spec/finders/autocomplete_users_finder_spec.rb index 684af74d750..dcf9111776e 100644 --- a/spec/finders/autocomplete_users_finder_spec.rb +++ b/spec/finders/autocomplete_users_finder_spec.rb @@ -42,6 +42,21 @@ describe AutocompleteUsersFinder do it { is_expected.to match_array([user1]) } end + context 'when passed a subgroup', :nested_groups do + let(:grandparent) { create(:group, :public) } + let(:parent) { create(:group, :public, parent: grandparent) } + let(:child) { create(:group, :public, parent: parent) } + let(:group) { parent } + + let!(:grandparent_user) { create(:group_member, :developer, group: grandparent).user } + let!(:parent_user) { create(:group_member, :developer, group: parent).user } + let!(:child_user) { create(:group_member, :developer, group: child).user } + + it 'includes users from parent groups as well' do + expect(subject).to match_array([grandparent_user, parent_user]) + end + end + it { is_expected.to match_array([user1, external_user, omniauth_user, current_user]) } context 'when filtered by search' do -- cgit v1.2.1