Commit f6453690 authored by Jacopo's avatar Jacopo

Fixes members api spec error

parent 29d84b61
......@@ -19,7 +19,10 @@ module API
def find_all_members_for_project(project)
shared_group_ids = project.project_group_links.pluck(:group_id)
source_ids = [project.id, project.group&.id].concat(shared_group_ids).compact
project_group_ids = project.group&.self_and_ancestors&.pluck(:id)
source_ids = [project.id, project_group_ids, shared_group_ids]
.flatten
.compact
Member.includes(:user)
.joins(user: :project_authorizations)
.where(project_authorizations: { project_id: project.id })
......
......@@ -39,7 +39,7 @@ module API
source = find_source(source_type, params[:id])
members = find_all_members(source_type, source)
members = members.references(:user).merge(User.search(params[:query])) if params[:query].present?
members = members.includes(:user).references(:user).merge(User.search(params[:query])) if params[:query].present?
members = paginate(members)
present members, with: Entities::Member
......
......@@ -61,7 +61,7 @@ describe API::Members do
project.add_developer(create(:user))
expect do
get api(members_url, master)
get api(members_url, maintainer)
end.not_to exceed_query_limit(control)
end
......@@ -112,8 +112,8 @@ describe API::Members do
end
let(:linked_group) do
create(:group) do |group|
group.add_developer(linked_group_user)
create(:group) do |linked_group|
linked_group.add_developer(linked_group_user)
end
end
......@@ -129,7 +129,7 @@ describe API::Members do
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.map { |u| u['id'] }).to match_array [master.id, developer.id, nested_user.id, project_user.id, linked_group_user.id]
expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id, nested_user.id, project_user.id, linked_group_user.id]
end
it 'finds all group members including inherited members' do
......@@ -138,7 +138,7 @@ describe API::Members do
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.map { |u| u['id'] }).to match_array [master.id, developer.id, nested_user.id]
expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id, nested_user.id]
end
end
......
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