diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /lib/api/groups.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) | |
download | gitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'lib/api/groups.rb')
-rw-r--r-- | lib/api/groups.rb | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/lib/api/groups.rb b/lib/api/groups.rb index 353c8b4b242..6e07bb46721 100644 --- a/lib/api/groups.rb +++ b/lib/api/groups.rb @@ -23,13 +23,20 @@ module API optional :order_by, type: String, values: %w[name path id], default: 'name', desc: 'Order by name, path or id' optional :sort, type: String, values: %w[asc desc], default: 'asc', desc: 'Sort by asc (ascending) or desc (descending)' optional :min_access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'Minimum access level of authenticated user' + optional :top_level_only, type: Boolean, desc: 'Only include top level groups' use :pagination end # rubocop: disable CodeReuse/ActiveRecord def find_groups(params, parent_id = nil) find_params = params.slice(:all_available, :custom_attributes, :owned, :min_access_level) - find_params[:parent] = find_group!(parent_id) if parent_id + + find_params[:parent] = if params[:top_level_only] + [nil] + elsif parent_id + find_group!(parent_id) + end + find_params[:all_available] = find_params.fetch(:all_available, current_user&.can_read_all_resources?) @@ -144,6 +151,7 @@ module API end group = create_group + group.preload_shared_group_links if group.persisted? present group, with: Entities::GroupDetail, current_user: current_user @@ -168,6 +176,8 @@ module API end put ':id' do group = find_group!(params[:id]) + group.preload_shared_group_links + authorize! :admin_group, group if update_group(group) @@ -186,6 +196,7 @@ module API end get ":id" do group = find_group!(params[:id]) + group.preload_shared_group_links options = { with: params[:with_projects] ? Entities::GroupDetail : Entities::Group, @@ -292,6 +303,7 @@ module API post ":id/projects/:project_id", requirements: { project_id: /.+/ } do authenticated_as_admin! group = find_group!(params[:id]) + group.preload_shared_group_links project = find_project!(params[:project_id]) result = ::Projects::TransferService.new(project, current_user).execute(group) @@ -301,6 +313,49 @@ module API render_api_error!("Failed to transfer project #{project.errors.messages}", 400) end end + + desc 'Share a group with a group' do + success Entities::GroupDetail + end + params do + requires :group_id, type: Integer, desc: 'The ID of the group to share' + requires :group_access, type: Integer, values: Gitlab::Access.all_values, desc: 'The group access level' + optional :expires_at, type: Date, desc: 'Share expiration date' + end + post ":id/share" do + shared_group = find_group!(params[:id]) + shared_with_group = find_group!(params[:group_id]) + + group_link_create_params = { + shared_group_access: params[:group_access], + expires_at: params[:expires_at] + } + + result = ::Groups::GroupLinks::CreateService.new(shared_with_group, current_user, group_link_create_params).execute(shared_group) + shared_group.preload_shared_group_links + + if result[:status] == :success + present shared_group, with: Entities::GroupDetail, current_user: current_user + else + render_api_error!(result[:message], result[:http_status]) + end + end + + params do + requires :group_id, type: Integer, desc: 'The ID of the shared group' + end + # rubocop: disable CodeReuse/ActiveRecord + delete ":id/share/:group_id" do + shared_group = find_group!(params[:id]) + + link = shared_group.shared_with_group_links.find_by(shared_with_group_id: params[:group_id]) + not_found!('Group Link') unless link + + ::Groups::GroupLinks::DestroyService.new(shared_group, current_user).execute(link) + + no_content! + end + # rubocop: enable CodeReuse/ActiveRecord end end end |