2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
require_dependency 'declarative_policy'
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
module API
|
|
|
|
class Projects < Grape::API
|
2017-08-17 22:00:37 +05:30
|
|
|
include PaginationParams
|
2018-03-27 19:54:05 +05:30
|
|
|
include Helpers::CustomAttributes
|
2018-05-09 12:01:36 +05:30
|
|
|
include Helpers::ProjectsHelpers
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
before { authenticate_non_get! }
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
helpers do
|
2019-05-18 00:54:41 +05:30
|
|
|
if Gitlab.ee?
|
|
|
|
params :optional_filter_params_ee do
|
|
|
|
optional :wiki_checksum_failed, type: Grape::API::Boolean, default: false, desc: 'Limit by projects where wiki checksum is failed'
|
|
|
|
optional :repository_checksum_failed, type: Grape::API::Boolean, default: false, desc: 'Limit by projects where repository checksum is failed'
|
|
|
|
end
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2019-05-18 00:54:41 +05:30
|
|
|
params :optional_update_params_ee do
|
|
|
|
optional :mirror_user_id, type: Integer, desc: 'User responsible for all the activity surrounding a pull mirror event'
|
|
|
|
optional :only_mirror_protected_branches, type: Grape::API::Boolean, desc: 'Only mirror protected branches'
|
|
|
|
optional :mirror_overwrites_diverged_branches, type: Grape::API::Boolean, desc: 'Pull mirror overwrites diverged branches'
|
|
|
|
optional :import_url, type: String, desc: 'URL from which the project is imported'
|
|
|
|
optional :packages_enabled, type: Grape::API::Boolean, desc: 'Enable project packages feature'
|
|
|
|
optional :fallback_approvals_required, type: Integer, desc: 'Overall approvals required when no rule is present'
|
|
|
|
end
|
2018-11-18 11:00:15 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
# EE::API::Projects would override this method
|
|
|
|
def apply_filters(projects)
|
|
|
|
projects = projects.with_issues_available_for_user(current_user) if params[:with_issues_enabled]
|
|
|
|
projects = projects.with_merge_requests_enabled if params[:with_merge_requests_enabled]
|
|
|
|
projects = projects.with_statistics if params[:statistics]
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
lang = params[:with_programming_language]
|
|
|
|
projects = projects.with_programming_language(lang) if lang
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
projects
|
|
|
|
end
|
|
|
|
|
|
|
|
def verify_update_project_attrs!(project, attrs)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
helpers do
|
|
|
|
params :statistics_params do
|
|
|
|
optional :statistics, type: Boolean, default: false, desc: 'Include project statistics'
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
params :collection_params do
|
|
|
|
use :sort_params
|
|
|
|
use :filter_params
|
|
|
|
use :pagination
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
optional :simple, type: Boolean, default: false,
|
|
|
|
desc: 'Return only the ID, URL, name, and path of each project'
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
params :sort_params do
|
|
|
|
optional :order_by, type: String, values: %w[id name path created_at updated_at last_activity_at],
|
|
|
|
default: 'created_at', desc: 'Return projects ordered by field'
|
|
|
|
optional :sort, type: String, values: %w[asc desc], default: 'desc',
|
|
|
|
desc: 'Return projects sorted in ascending and descending order'
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
params :filter_params do
|
2018-11-18 11:00:15 +05:30
|
|
|
optional :archived, type: Boolean, desc: 'Limit by archived status'
|
2017-09-10 17:25:29 +05:30
|
|
|
optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values,
|
|
|
|
desc: 'Limit by visibility'
|
|
|
|
optional :search, type: String, desc: 'Return list of projects matching the search criteria'
|
|
|
|
optional :owned, type: Boolean, default: false, desc: 'Limit by owned by authenticated user'
|
|
|
|
optional :starred, type: Boolean, default: false, desc: 'Limit by starred status'
|
|
|
|
optional :membership, type: Boolean, default: false, desc: 'Limit by projects that the current user is a member of'
|
|
|
|
optional :with_issues_enabled, type: Boolean, default: false, desc: 'Limit by enabled issues feature'
|
|
|
|
optional :with_merge_requests_enabled, type: Boolean, default: false, desc: 'Limit by enabled merge requests feature'
|
2019-03-02 22:35:43 +05:30
|
|
|
optional :with_programming_language, type: String, desc: 'Limit to repositories which use the given programming language'
|
2018-11-18 11:00:15 +05:30
|
|
|
optional :min_access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'Limit by minimum access level of authenticated user'
|
|
|
|
|
2019-05-18 00:54:41 +05:30
|
|
|
use :optional_filter_params_ee if Gitlab.ee?
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
params :create_params do
|
|
|
|
optional :namespace_id, type: Integer, desc: 'Namespace ID for the new project. Default to the user namespace.'
|
|
|
|
optional :import_url, type: String, desc: 'URL from which the project is imported'
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def load_projects
|
|
|
|
ProjectsFinder.new(current_user: current_user, params: project_finder_params).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
def present_projects(projects, options = {})
|
2017-09-10 17:25:29 +05:30
|
|
|
projects = reorder_projects(projects)
|
2018-11-18 11:00:15 +05:30
|
|
|
projects = apply_filters(projects)
|
2018-03-17 18:26:18 +05:30
|
|
|
projects = paginate(projects)
|
2018-03-27 19:54:05 +05:30
|
|
|
projects, options = with_custom_attributes(projects, options)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
options = options.reverse_merge(
|
|
|
|
with: current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails,
|
|
|
|
statistics: params[:statistics],
|
2018-12-13 13:39:08 +05:30
|
|
|
current_user: current_user,
|
|
|
|
license: false
|
2017-09-10 17:25:29 +05:30
|
|
|
)
|
|
|
|
options[:with] = Entities::BasicProjectDetails if params[:simple]
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
present options[:with].prepare_relation(projects, options), options
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
def translate_params_for_compatibility(params)
|
|
|
|
params[:builds_enabled] = params.delete(:jobs_enabled) if params.key?(:jobs_enabled)
|
|
|
|
params
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
resource :users, requirements: API::USER_REQUIREMENTS do
|
2017-09-10 17:25:29 +05:30
|
|
|
desc 'Get a user projects' do
|
|
|
|
success Entities::BasicProjectDetails
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :user_id, type: String, desc: 'The ID or username of the user'
|
|
|
|
use :collection_params
|
|
|
|
use :statistics_params
|
2018-03-27 19:54:05 +05:30
|
|
|
use :with_custom_attributes
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
get ":user_id/projects" do
|
|
|
|
user = find_user(params[:user_id])
|
|
|
|
not_found!('User') unless user
|
|
|
|
|
|
|
|
params[:user] = user
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
present_projects load_projects
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
resource :projects do
|
2018-03-17 18:26:18 +05:30
|
|
|
include CustomAttributesEndpoints
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Get a list of visible projects for authenticated user' do
|
|
|
|
success Entities::BasicProjectDetails
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
use :collection_params
|
|
|
|
use :statistics_params
|
2018-03-27 19:54:05 +05:30
|
|
|
use :with_custom_attributes
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
get do
|
2018-03-17 18:26:18 +05:30
|
|
|
present_projects load_projects
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Create new project' do
|
|
|
|
success Entities::Project
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
optional :name, type: String, desc: 'The name of the project'
|
|
|
|
optional :path, type: String, desc: 'The path of the repository'
|
|
|
|
at_least_one_of :name, :path
|
2018-05-09 12:01:36 +05:30
|
|
|
use :optional_project_params
|
2017-08-17 22:00:37 +05:30
|
|
|
use :create_params
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
post do
|
2017-08-17 22:00:37 +05:30
|
|
|
attrs = declared_params(include_missing: false)
|
2018-10-15 14:42:47 +05:30
|
|
|
attrs = translate_params_for_compatibility(attrs)
|
2017-08-17 22:00:37 +05:30
|
|
|
project = ::Projects::CreateService.new(current_user, attrs).execute
|
|
|
|
|
|
|
|
if project.saved?
|
|
|
|
present project, with: Entities::Project,
|
2019-03-13 22:55:13 +05:30
|
|
|
user_can_admin_project: can?(current_user, :admin_project, project),
|
|
|
|
current_user: current_user
|
2014-09-02 18:07:02 +05:30
|
|
|
else
|
2017-08-17 22:00:37 +05:30
|
|
|
if project.errors[:limit_reached].present?
|
|
|
|
error!(project.errors[:limit_reached], 403)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
render_validation_error!(project)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Create new project for a specified user. Only available to admin users.' do
|
|
|
|
success Entities::Project
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :name, type: String, desc: 'The name of the project'
|
|
|
|
requires :user_id, type: Integer, desc: 'The ID of a user'
|
2017-09-10 17:25:29 +05:30
|
|
|
optional :path, type: String, desc: 'The path of the repository'
|
2017-08-17 22:00:37 +05:30
|
|
|
optional :default_branch, type: String, desc: 'The default branch of the project'
|
2018-05-09 12:01:36 +05:30
|
|
|
use :optional_project_params
|
2017-08-17 22:00:37 +05:30
|
|
|
use :create_params
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2014-09-02 18:07:02 +05:30
|
|
|
post "user/:user_id" do
|
|
|
|
authenticated_as_admin!
|
2017-08-17 22:00:37 +05:30
|
|
|
user = User.find_by(id: params.delete(:user_id))
|
|
|
|
not_found!('User') unless user
|
|
|
|
|
|
|
|
attrs = declared_params(include_missing: false)
|
2018-10-15 14:42:47 +05:30
|
|
|
attrs = translate_params_for_compatibility(attrs)
|
2017-08-17 22:00:37 +05:30
|
|
|
project = ::Projects::CreateService.new(user, attrs).execute
|
|
|
|
|
|
|
|
if project.saved?
|
|
|
|
present project, with: Entities::Project,
|
2019-03-13 22:55:13 +05:30
|
|
|
user_can_admin_project: can?(current_user, :admin_project, project),
|
|
|
|
current_user: current_user
|
2014-09-02 18:07:02 +05:30
|
|
|
else
|
2017-08-17 22:00:37 +05:30
|
|
|
render_validation_error!(project)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
params do
|
|
|
|
requires :id, type: String, desc: 'The ID of a project'
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Get a single project' do
|
|
|
|
success Entities::ProjectWithAccess
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
use :statistics_params
|
2018-03-27 19:54:05 +05:30
|
|
|
use :with_custom_attributes
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
optional :license, type: Boolean, default: false,
|
|
|
|
desc: 'Include project license data'
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
get ":id" do
|
2018-03-27 19:54:05 +05:30
|
|
|
options = {
|
|
|
|
with: current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails,
|
|
|
|
current_user: current_user,
|
|
|
|
user_can_admin_project: can?(current_user, :admin_project, user_project),
|
2018-12-13 13:39:08 +05:30
|
|
|
statistics: params[:statistics],
|
|
|
|
license: params[:license]
|
2018-03-27 19:54:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
project, options = with_custom_attributes(user_project, options)
|
|
|
|
|
|
|
|
present project, options
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Fork new project for the current user or provided namespace.' do
|
|
|
|
success Entities::Project
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
optional :namespace, type: String, desc: 'The ID or name of the namespace that the project will be forked into'
|
2019-05-18 00:54:41 +05:30
|
|
|
optional :path, type: String, desc: 'The path that will be assigned to the fork'
|
|
|
|
optional :name, type: String, desc: 'The name that will be assigned to the fork'
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
post ':id/fork' do
|
2018-03-17 18:26:18 +05:30
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42284')
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
fork_params = declared_params(include_missing: false)
|
|
|
|
namespace_id = fork_params[:namespace]
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
if namespace_id.present?
|
2018-05-09 12:01:36 +05:30
|
|
|
fork_params[:namespace] = find_namespace(namespace_id)
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
unless fork_params[:namespace] && can?(current_user, :create_projects, fork_params[:namespace])
|
2016-09-29 09:46:39 +05:30
|
|
|
not_found!('Target Namespace')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
forked_project = ::Projects::ForkService.new(user_project, current_user, fork_params).execute
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
if forked_project.errors.any?
|
|
|
|
conflict!(forked_project.errors.messages)
|
2015-04-26 12:48:37 +05:30
|
|
|
else
|
2017-08-17 22:00:37 +05:30
|
|
|
present forked_project, with: Entities::Project,
|
2019-03-13 22:55:13 +05:30
|
|
|
user_can_admin_project: can?(current_user, :admin_project, forked_project),
|
|
|
|
current_user: current_user
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
desc 'List forks of this project' do
|
|
|
|
success Entities::Project
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
use :collection_params
|
2018-03-27 19:54:05 +05:30
|
|
|
use :with_custom_attributes
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
get ':id/forks' do
|
|
|
|
forks = ForkProjectsFinder.new(user_project, params: project_finder_params, current_user: current_user).execute
|
|
|
|
|
|
|
|
present_projects forks
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
desc 'Check pages access of this project'
|
|
|
|
get ':id/pages_access' do
|
|
|
|
authorize! :read_pages_content, user_project unless user_project.public_pages?
|
|
|
|
status 200
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Update an existing project' do
|
|
|
|
success Entities::Project
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
optional :name, type: String, desc: 'The name of the project'
|
|
|
|
optional :default_branch, type: String, desc: 'The default branch of the project'
|
|
|
|
optional :path, type: String, desc: 'The path of the repository'
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
use :optional_project_params
|
2019-05-18 00:54:41 +05:30
|
|
|
use :optional_update_params_ee if Gitlab.ee?
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2019-05-18 00:54:41 +05:30
|
|
|
at_least_one_of(*Helpers::ProjectsHelpers.update_params_at_least_one_of)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
put ':id' do
|
|
|
|
authorize_admin_project
|
2017-08-17 22:00:37 +05:30
|
|
|
attrs = declared_params(include_missing: false)
|
2015-04-26 12:48:37 +05:30
|
|
|
authorize! :rename_project, user_project if attrs[:name].present?
|
2017-08-17 22:00:37 +05:30
|
|
|
authorize! :change_visibility_level, user_project if attrs[:visibility].present?
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
attrs = translate_params_for_compatibility(attrs)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
verify_update_project_attrs!(user_project, attrs)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
result = ::Projects::UpdateService.new(user_project, current_user, attrs).execute
|
|
|
|
|
|
|
|
if result[:status] == :success
|
2016-01-19 16:12:03 +05:30
|
|
|
present user_project, with: Entities::Project,
|
2019-03-13 22:55:13 +05:30
|
|
|
user_can_admin_project: can?(current_user, :admin_project, user_project),
|
|
|
|
current_user: current_user
|
2017-08-17 22:00:37 +05:30
|
|
|
else
|
|
|
|
render_validation_error!(user_project)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Archive a project' do
|
|
|
|
success Entities::Project
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
post ':id/archive' do
|
|
|
|
authorize!(:archive_project, user_project)
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
::Projects::UpdateService.new(user_project, current_user, archived: true).execute
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
present user_project, with: Entities::Project, current_user: current_user
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Unarchive a project' do
|
|
|
|
success Entities::Project
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
post ':id/unarchive' do
|
|
|
|
authorize!(:archive_project, user_project)
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
::Projects::UpdateService.new(@project, current_user, archived: false).execute
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
present user_project, with: Entities::Project, current_user: current_user
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Star a project' do
|
|
|
|
success Entities::Project
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
post ':id/star' do
|
|
|
|
if current_user.starred?(user_project)
|
|
|
|
not_modified!
|
|
|
|
else
|
|
|
|
current_user.toggle_star(user_project)
|
|
|
|
user_project.reload
|
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
present user_project, with: Entities::Project, current_user: current_user
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Unstar a project' do
|
|
|
|
success Entities::Project
|
|
|
|
end
|
|
|
|
post ':id/unstar' do
|
2016-06-02 11:05:42 +05:30
|
|
|
if current_user.starred?(user_project)
|
|
|
|
current_user.toggle_star(user_project)
|
|
|
|
user_project.reload
|
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
present user_project, with: Entities::Project, current_user: current_user
|
2016-06-02 11:05:42 +05:30
|
|
|
else
|
|
|
|
not_modified!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
desc 'Get languages in project repository'
|
|
|
|
get ':id/languages' do
|
2019-05-18 00:54:41 +05:30
|
|
|
::Projects::RepositoryLanguagesService
|
|
|
|
.new(user_project, current_user)
|
|
|
|
.execute.map { |lang| [lang.name, lang.share] }.to_h
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Remove a project'
|
2014-09-02 18:07:02 +05:30
|
|
|
delete ":id" do
|
|
|
|
authorize! :remove_project, user_project
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
destroy_conditionally!(user_project) do
|
|
|
|
::Projects::DestroyService.new(user_project, current_user, {}).async_execute
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
accepted!
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Mark this project as forked from another'
|
|
|
|
params do
|
|
|
|
requires :forked_from_id, type: String, desc: 'The ID of the project it was forked from'
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
post ":id/fork/:forked_from_id" do
|
2018-11-20 20:47:30 +05:30
|
|
|
authorize! :admin_project, user_project
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
fork_from_project = find_project!(params[:forked_from_id])
|
|
|
|
|
|
|
|
not_found!("Source Project") unless fork_from_project
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
result = ::Projects::ForkService.new(fork_from_project, current_user).execute(user_project)
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
if result
|
2019-03-13 22:55:13 +05:30
|
|
|
present user_project.reload, with: Entities::Project, current_user: current_user
|
2014-09-02 18:07:02 +05:30
|
|
|
else
|
2018-03-17 18:26:18 +05:30
|
|
|
render_api_error!("Project already forked", 409) if user_project.forked?
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Remove a forked_from relationship'
|
2014-09-02 18:07:02 +05:30
|
|
|
delete ":id/fork" do
|
2015-11-26 14:37:03 +05:30
|
|
|
authorize! :remove_fork_project, user_project
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
result = destroy_conditionally!(user_project) do
|
|
|
|
::Projects::UnlinkForkService.new(user_project, current_user).execute
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
result ? status(204) : not_modified!
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2016-01-14 18:37:52 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Share the project with a group' do
|
|
|
|
success Entities::ProjectGroupLink
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :group_id, type: Integer, desc: 'The ID of a group'
|
2019-03-13 22:55:13 +05:30
|
|
|
requires :group_access, type: Integer, values: Gitlab::Access.values, as: :link_group_access, desc: 'The group access level'
|
2017-08-17 22:00:37 +05:30
|
|
|
optional :expires_at, type: Date, desc: 'Share expiration date'
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
post ":id/share" do
|
|
|
|
authorize! :admin_project, user_project
|
2017-08-17 22:00:37 +05:30
|
|
|
group = Group.find_by_id(params[:group_id])
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
unless user_project.allowed_to_share_with_group?
|
2018-10-15 14:42:47 +05:30
|
|
|
break render_api_error!("The project sharing with group is disabled", 400)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
result = ::Projects::GroupLinks::CreateService.new(user_project, current_user, declared_params(include_missing: false))
|
|
|
|
.execute(group)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
if result[:status] == :success
|
|
|
|
present result[:link], with: Entities::ProjectGroupLink
|
2016-06-02 11:05:42 +05:30
|
|
|
else
|
2019-03-13 22:55:13 +05:30
|
|
|
render_api_error!(result[:message], result[:http_status])
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
params do
|
|
|
|
requires :group_id, type: Integer, desc: 'The ID of the group'
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
delete ":id/share/:group_id" do
|
|
|
|
authorize! :admin_project, user_project
|
2016-01-14 18:37:52 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
link = user_project.project_group_links.find_by(group_id: params[:group_id])
|
|
|
|
not_found!('Group Link') unless link
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
destroy_conditionally!(link)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
desc 'Upload a file'
|
|
|
|
params do
|
|
|
|
requires :file, type: File, desc: 'The file to be uploaded'
|
|
|
|
end
|
|
|
|
post ":id/uploads" do
|
2019-02-15 15:39:39 +05:30
|
|
|
UploadService.new(user_project, params[:file]).execute.to_h
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Get the users list of a project' do
|
|
|
|
success Entities::UserBasic
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
optional :search, type: String, desc: 'Return list of users matching the search criteria'
|
|
|
|
use :pagination
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
get ':id/users' do
|
2017-09-10 17:25:29 +05:30
|
|
|
users = DeclarativePolicy.subject_scope { user_project.team.users }
|
2017-08-17 22:00:37 +05:30
|
|
|
users = users.search(params[:search]) if params[:search].present?
|
|
|
|
|
|
|
|
present paginate(users), with: Entities::UserBasic
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Start the housekeeping task for a project' do
|
|
|
|
detail 'This feature was introduced in GitLab 9.0.'
|
|
|
|
end
|
|
|
|
post ':id/housekeeping' do
|
|
|
|
authorize_admin_project
|
|
|
|
|
|
|
|
begin
|
|
|
|
::Projects::HousekeepingService.new(user_project).execute
|
|
|
|
rescue ::Projects::HousekeepingService::LeaseTaken => error
|
|
|
|
conflict!(error.message)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
desc 'Transfer a project to a new namespace'
|
|
|
|
params do
|
|
|
|
requires :namespace, type: String, desc: 'The ID or path of the new namespace'
|
|
|
|
end
|
|
|
|
put ":id/transfer" do
|
|
|
|
authorize! :change_namespace, user_project
|
|
|
|
|
|
|
|
namespace = find_namespace!(params[:namespace])
|
|
|
|
result = ::Projects::TransferService.new(user_project, current_user).execute(namespace)
|
|
|
|
|
|
|
|
if result
|
2019-03-13 22:55:13 +05:30
|
|
|
present user_project, with: Entities::Project, current_user: current_user
|
2018-11-08 19:23:39 +05:30
|
|
|
else
|
|
|
|
render_api_error!("Failed to transfer project #{user_project.errors.messages}", 400)
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|