Commit c7787f44 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ce-return-entity-type-for-project-autocomplete-sources-members' into 'master'

Add a type property to project autocomplete members

Closes #57771

See merge request gitlab-org/gitlab-ce!25296
parents 3928328c aa464800
...@@ -11,7 +11,7 @@ module Users ...@@ -11,7 +11,7 @@ module Users
def noteable_owner def noteable_owner
return [] unless noteable && return [] unless noteable &&
[as_hash(] [user_as_hash(]
end end
def participants_in_noteable def participants_in_noteable
...@@ -23,21 +23,24 @@ module Users ...@@ -23,21 +23,24 @@ module Users
def sorted(users) def sorted(users)
users.uniq.to_a.compact.sort_by(&:username).map do |user| users.uniq.to_a.compact.sort_by(&:username).map do |user|
as_hash(user) user_as_hash(user)
end end
end end
def groups def groups
current_user.authorized_groups.sort_by(&:path).map do |group| current_user.authorized_groups.sort_by(&:path).map do |group|
count = group.users.count group_as_hash(group)
{ username: group.full_path, name: group.full_name, count: count, avatar_url: group.avatar_url }
end end
end end
private private
def as_hash(user) def user_as_hash(user)
{ username: user.username, name:, avatar_url: user.avatar_url } { type:, username: user.username, name:, avatar_url: user.avatar_url }
def group_as_hash(group)
{ type:, username: group.full_path, name: group.full_name, avatar_url: group.avatar_url, count: group.users.count }
end end
end end
end end
# frozen_string_literal: true
require 'spec_helper'
describe Projects::AutocompleteSourcesController do
set(:group) { create(:group) }
set(:project) { create(:project, namespace: group) }
set(:issue) { create(:issue, project: project) }
set(:user) { create(:user) }
describe 'GET members' do
before do
it 'returns an array of member object' do
get :members, format: :json, params: { namespace_id: group.path, project_id: project.path, type:, type_id: }
all = json_response.find {|member| member["username"] == 'all'}
the_group = json_response.find {|member| member["username"] == group.full_path}
the_user = json_response.find {|member| member["username"] == user.username}
expect(all.symbolize_keys).to include(username: 'all',
name: 'All Project and Group Members',
count: 1)
expect(the_group.symbolize_keys).to include(type:,
name: group.full_name,
avatar_url: group.avatar_url,
count: 1)
expect(the_user.symbolize_keys).to include(type:,
avatar_url: user.avatar_url)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment