diff options
author | 🙈 jacopo beschi 🙉 <intrip@gmail.com> | 2018-07-25 21:45:42 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2018-07-25 21:45:42 +0000 |
commit | 046796cc3a98068e99abed152145e76c4636959c (patch) | |
tree | ab7061a86e9e69b56c27835682542a5bc2423942 /lib | |
parent | 7b6d3974d416bca12360327b147feefeeead01f6 (diff) | |
download | gitlab-ce-046796cc3a98068e99abed152145e76c4636959c.tar.gz |
Resolve "API endpoint that returns all members, including the inherited membership through ancestor group"
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/helpers/members_helpers.rb | 25 | ||||
-rw-r--r-- | lib/api/members.rb | 17 |
2 files changed, 42 insertions, 0 deletions
diff --git a/lib/api/helpers/members_helpers.rb b/lib/api/helpers/members_helpers.rb index a50ea0b52aa..fed8846e505 100644 --- a/lib/api/helpers/members_helpers.rb +++ b/lib/api/helpers/members_helpers.rb @@ -10,6 +10,31 @@ module API def authorize_admin_source!(source_type, source) authorize! :"admin_#{source_type}", source end + + def find_all_members(source_type, source) + members = source_type == 'project' ? find_all_members_for_project(source) : find_all_members_for_group(source) + members.non_invite + .non_request + end + + def find_all_members_for_project(project) + shared_group_ids = project.project_group_links.pluck(:group_id) + 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 }) + .where(source_id: source_ids) + end + + def find_all_members_for_group(group) + source_ids = group.self_and_ancestors.pluck(:id) + Member.includes(:user) + .where(source_id: source_ids) + .where(source_type: 'Namespace') + end end end end diff --git a/lib/api/members.rb b/lib/api/members.rb index 8b12986d09e..3d2220fed96 100644 --- a/lib/api/members.rb +++ b/lib/api/members.rb @@ -28,6 +28,23 @@ module API present members, with: Entities::Member end + desc 'Gets a list of group or project members viewable by the authenticated user, including those who gained membership through ancestor group.' do + success Entities::Member + end + params do + optional :query, type: String, desc: 'A query string to search for members' + use :pagination + end + get ":id/members/all" do + source = find_source(source_type, params[:id]) + + members = find_all_members(source_type, source) + members = members.includes(:user).references(:user).merge(User.search(params[:query])) if params[:query].present? + members = paginate(members) + + present members, with: Entities::Member + end + desc 'Gets a member of a group or project.' do success Entities::Member end |