diff options
Diffstat (limited to 'lib/api/projects.rb')
-rw-r--r-- | lib/api/projects.rb | 170 |
1 files changed, 85 insertions, 85 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb index b23fe6cd4e7..3be654dcdc7 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_dependency 'declarative_policy' +require_dependency "declarative_policy" module API class Projects < Grape::API @@ -59,13 +59,13 @@ module API :tag_list, :visibility, :wiki_enabled, - :avatar + :avatar, ] end helpers do params :statistics_params do - optional :statistics, type: Boolean, default: false, desc: 'Include project statistics' + optional :statistics, type: Boolean, default: false, desc: "Include project statistics" end params :collection_params do @@ -74,35 +74,35 @@ module API use :pagination optional :simple, type: Boolean, default: false, - desc: 'Return only the ID, URL, name, and path of each project' + desc: "Return only the ID, URL, name, and path of each project" end 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' + 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 params :filter_params do - optional :archived, type: Boolean, desc: 'Limit by archived status' + optional :archived, type: Boolean, desc: "Limit by archived status" 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' - optional :with_programming_language, type: String, desc: 'Limit to repositories which use the given programming language' - optional :min_access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'Limit by minimum access level of authenticated user' + 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" + optional :with_programming_language, type: String, desc: "Limit to repositories which use the given programming language" + optional :min_access_level, type: Integer, values: Gitlab::Access.all_values, desc: "Limit by minimum access level of authenticated user" use :optional_filter_params_ee end 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' + 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 def load_projects @@ -133,18 +133,18 @@ module API end resource :users, requirements: API::USER_REQUIREMENTS do - desc 'Get a user projects' do + 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' + requires :user_id, type: String, desc: "The ID or username of the user" use :collection_params use :statistics_params use :with_custom_attributes end get ":user_id/projects" do user = find_user(params[:user_id]) - not_found!('User') unless user + not_found!("User") unless user params[:user] = user @@ -155,7 +155,7 @@ module API resource :projects do include CustomAttributesEndpoints - desc 'Get a list of visible projects for authenticated user' do + desc "Get a list of visible projects for authenticated user" do success Entities::BasicProjectDetails end params do @@ -167,12 +167,12 @@ module API present_projects load_projects end - desc 'Create new project' do + 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' + 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 use :optional_project_params use :create_params @@ -194,14 +194,14 @@ module API end end - desc 'Create new project for a specified user. Only available to admin users.' do + 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' - optional :path, type: String, desc: 'The path of the repository' - optional :default_branch, type: String, desc: 'The default branch of the project' + requires :name, type: String, desc: "The name of the project" + requires :user_id, type: Integer, desc: "The ID of a user" + optional :path, type: String, desc: "The path of the repository" + optional :default_branch, type: String, desc: "The default branch of the project" use :optional_project_params use :create_params end @@ -209,7 +209,7 @@ module API post "user/:user_id" do authenticated_as_admin! user = User.find_by(id: params.delete(:user_id)) - not_found!('User') unless user + not_found!("User") unless user attrs = declared_params(include_missing: false) attrs = translate_params_for_compatibility(attrs) @@ -226,10 +226,10 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get a single project' do + desc "Get a single project" do success Entities::ProjectWithAccess end params do @@ -237,7 +237,7 @@ module API use :with_custom_attributes optional :license, type: Boolean, default: false, - desc: 'Include project license data' + desc: "Include project license data" end get ":id" do options = { @@ -245,7 +245,7 @@ module API current_user: current_user, user_can_admin_project: can?(current_user, :admin_project, user_project), statistics: params[:statistics], - license: params[:license] + license: params[:license], } project, options = with_custom_attributes(user_project, options) @@ -253,16 +253,16 @@ module API present project, options end - desc 'Fork new project for the current user or provided namespace.' do + 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' - 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' + optional :namespace, type: String, desc: "The ID or name of the namespace that the project will be forked into" + 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" end - post ':id/fork' do - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42284') + post ":id/fork" do + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/42284") fork_params = declared_params(include_missing: false) namespace_id = fork_params[:namespace] @@ -271,7 +271,7 @@ module API fork_params[:namespace] = find_namespace(namespace_id) unless fork_params[:namespace] && can?(current_user, :create_projects, fork_params[:namespace]) - not_found!('Target Namespace') + not_found!("Target Namespace") end end @@ -285,38 +285,38 @@ module API end end - desc 'List forks of this project' do + desc "List forks of this project" do success Entities::Project end params do use :collection_params use :with_custom_attributes end - get ':id/forks' do + get ":id/forks" do forks = ForkProjectsFinder.new(user_project, params: project_finder_params, current_user: current_user).execute present_projects forks end - desc 'Check pages access of this project' - get ':id/pages_access' do + 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 - desc 'Update an existing project' do + 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' + 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" use :optional_project_params at_least_one_of(*::API::Projects.update_params_at_least_one_of) end - put ':id' do + put ":id" do authorize_admin_project attrs = declared_params(include_missing: false) authorize! :rename_project, user_project if attrs[:name].present? @@ -336,10 +336,10 @@ module API end end - desc 'Archive a project' do + desc "Archive a project" do success Entities::Project end - post ':id/archive' do + post ":id/archive" do authorize!(:archive_project, user_project) ::Projects::UpdateService.new(user_project, current_user, archived: true).execute @@ -347,10 +347,10 @@ module API present user_project, with: Entities::Project end - desc 'Unarchive a project' do + desc "Unarchive a project" do success Entities::Project end - post ':id/unarchive' do + post ":id/unarchive" do authorize!(:archive_project, user_project) ::Projects::UpdateService.new(@project, current_user, archived: false).execute @@ -358,10 +358,10 @@ module API present user_project, with: Entities::Project end - desc 'Star a project' do + desc "Star a project" do success Entities::Project end - post ':id/star' do + post ":id/star" do if current_user.starred?(user_project) not_modified! else @@ -372,10 +372,10 @@ module API end end - desc 'Unstar a project' do + desc "Unstar a project" do success Entities::Project end - post ':id/unstar' do + post ":id/unstar" do if current_user.starred?(user_project) current_user.toggle_star(user_project) user_project.reload @@ -386,8 +386,8 @@ module API end end - desc 'Get languages in project repository' - get ':id/languages' do + desc "Get languages in project repository" + get ":id/languages" do if user_project.repository_languages.present? user_project.repository_languages.map { |l| [l.name, l.share] }.to_h else @@ -395,7 +395,7 @@ module API end end - desc 'Remove a project' + desc "Remove a project" delete ":id" do authorize! :remove_project, user_project @@ -406,9 +406,9 @@ module API accepted! end - desc 'Mark this project as forked from another' + 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' + requires :forked_from_id, type: String, desc: "The ID of the project it was forked from" end post ":id/fork/:forked_from_id" do authorize! :admin_project, user_project @@ -426,31 +426,31 @@ module API end end - desc 'Remove a forked_from relationship' + desc "Remove a forked_from relationship" delete ":id/fork" do authorize! :remove_fork_project, user_project - result = destroy_conditionally!(user_project) do + result = destroy_conditionally!(user_project) { ::Projects::UnlinkForkService.new(user_project, current_user).execute - end + } result ? status(204) : not_modified! end - desc 'Share the project with a group' do + 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' - requires :group_access, type: Integer, values: Gitlab::Access.values, desc: 'The group access level' - optional :expires_at, type: Date, desc: 'Share expiration date' + requires :group_id, type: Integer, desc: "The ID of a group" + requires :group_access, type: Integer, values: Gitlab::Access.values, desc: "The group access level" + optional :expires_at, type: Date, desc: "Share expiration date" end post ":id/share" do authorize! :admin_project, user_project group = Group.find_by_id(params[:group_id]) unless group && can?(current_user, :read_group, group) - not_found!('Group') + not_found!("Group") end unless user_project.allowed_to_share_with_group? @@ -467,45 +467,45 @@ module API end params do - requires :group_id, type: Integer, desc: 'The ID of the group' + requires :group_id, type: Integer, desc: "The ID of the group" end # rubocop: disable CodeReuse/ActiveRecord delete ":id/share/:group_id" do authorize! :admin_project, user_project link = user_project.project_group_links.find_by(group_id: params[:group_id]) - not_found!('Group Link') unless link + not_found!("Group Link") unless link destroy_conditionally!(link) end # rubocop: enable CodeReuse/ActiveRecord - desc 'Upload a file' + desc "Upload a file" params do - requires :file, type: File, desc: 'The file to be uploaded' + requires :file, type: File, desc: "The file to be uploaded" end post ":id/uploads" do UploadService.new(user_project, params[:file]).execute.to_h end - desc 'Get the users list of a project' do + 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' + optional :search, type: String, desc: "Return list of users matching the search criteria" use :pagination end - get ':id/users' do + get ":id/users" do users = DeclarativePolicy.subject_scope { user_project.team.users } 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.' + desc "Start the housekeeping task for a project" do + detail "This feature was introduced in GitLab 9.0." end - post ':id/housekeeping' do + post ":id/housekeeping" do authorize_admin_project begin @@ -515,9 +515,9 @@ module API end end - desc 'Transfer a project to a new namespace' + desc "Transfer a project to a new namespace" params do - requires :namespace, type: String, desc: 'The ID or path of the new namespace' + requires :namespace, type: String, desc: "The ID or path of the new namespace" end put ":id/transfer" do authorize! :change_namespace, user_project |