Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/projects.rb')
-rw-r--r--lib/api/projects.rb48
1 files changed, 42 insertions, 6 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 3b1d239398f..28bcb382ecf 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -45,6 +45,20 @@ module API
end
end
+ def support_order_by_similarity!(attrs)
+ return unless params[:order_by] == 'similarity'
+
+ if order_by_similarity?(allow_unauthorized: false)
+ # Limit to projects the current user is a member of.
+ # Do not include all public projects because it
+ # could cause long running queries
+ attrs[:non_public] = true
+ attrs[:sort] = params['order_by']
+ else
+ params[:order_by] = route.params['order_by'][:default]
+ end
+ end
+
def delete_project(user_project)
destroy_conditionally!(user_project) do
::Projects::DestroyService.new(user_project, current_user, {}).async_execute
@@ -93,8 +107,8 @@ module API
params :sort_params do
optional :order_by, type: String,
- values: %w[id name path created_at updated_at last_activity_at] + Helpers::ProjectsHelpers::STATISTICS_SORT_PARAMS,
- default: 'created_at', desc: "Return projects ordered by field. #{Helpers::ProjectsHelpers::STATISTICS_SORT_PARAMS.join(', ')} are only available to admins."
+ values: %w[id name path created_at updated_at last_activity_at similarity] + Helpers::ProjectsHelpers::STATISTICS_SORT_PARAMS,
+ default: 'created_at', desc: "Return projects ordered by field. #{Helpers::ProjectsHelpers::STATISTICS_SORT_PARAMS.join(', ')} are only available to admins. Similarity is available when searching and is limited to projects the user has access to."
optional :sort, type: String, values: %w[asc desc], default: 'desc',
desc: 'Return projects sorted in ascending and descending order'
end
@@ -131,16 +145,17 @@ module API
end
def load_projects
- params = project_finder_params
- verify_project_filters!(params)
+ project_params = project_finder_params
+ support_order_by_similarity!(project_params)
+ verify_project_filters!(project_params)
- ProjectsFinder.new(current_user: current_user, params: params).execute
+ ProjectsFinder.new(current_user: current_user, params: project_params).execute
end
def present_projects(projects, options = {})
verify_statistics_order_by_projects!
- projects = reorder_projects(projects)
+ projects = reorder_projects(projects) unless order_by_similarity?(allow_unauthorized: false)
projects = apply_filters(projects)
records, options = paginate_with_strategies(projects, options[:request_scope]) do |projects|
@@ -572,6 +587,27 @@ module API
end
# rubocop: enable CodeReuse/ActiveRecord
+ desc 'Import members from another project' do
+ detail 'This feature was introduced in GitLab 14.2'
+ end
+ params do
+ requires :project_id, type: Integer, desc: 'The ID of the source project to import the members from.'
+ end
+ post ":id/import_project_members/:project_id", feature_category: :experimentation_expansion do
+ authorize! :admin_project, user_project
+
+ source_project = Project.find_by_id(params[:project_id])
+ not_found!('Project') unless source_project && can?(current_user, :read_project, source_project)
+
+ result = ::Members::ImportProjectTeamService.new(current_user, params).execute
+
+ if result
+ { status: result, message: 'Successfully imported' }
+ else
+ render_api_error!('Import failed', :unprocessable_entity)
+ end
+ end
+
desc 'Workhorse authorize the file upload' do
detail 'This feature was introduced in GitLab 13.11'
end