Verified Commit 63360ade authored by Rémy Coutable's avatar Rémy Coutable 🔴

Add `requirements: { id: %r{[^/]+} }` for all projects and groups namespaced API routes

Signed-off-by: Rémy Coutable's avatarRémy Coutable <remy@rymai.me>
parent c9abdadd
Pipeline #7062727 passed with stages
in 75 minutes and 49 seconds
---
title: 'Add `requirements: { id: /.+/ }` for all projects and groups namespaced API
routes'
merge_request: 9944
author:
......@@ -10,7 +10,7 @@ module API
params do
requires :id, type: String, desc: "The #{source_type} ID"
end
resource source_type.pluralize do
resource source_type.pluralize, requirements: { id: %r{[^/]+} } do
desc "Gets a list of access requests for a #{source_type}." do
detail 'This feature was introduced in GitLab 8.11.'
success Entities::AccessRequester
......
......@@ -9,13 +9,15 @@ module API
{ type: 'snippet', find_by: :id }
].freeze
resource :projects do
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: { id: %r{[^/]+} } do
AWARDABLES.each do |awardable_params|
awardable_string = awardable_params[:type].pluralize
awardable_id_string = "#{awardable_params[:type]}_#{awardable_params[:find_by]}"
params do
requires :id, type: String, desc: 'The ID of a project'
requires :"#{awardable_id_string}", type: Integer, desc: "The ID of an Issue, Merge Request or Snippet"
end
......
......@@ -7,7 +7,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get all project boards' do
detail 'This feature was introduced in 8.13'
success Entities::Board
......
......@@ -10,7 +10,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a project repository branches' do
success Entities::RepoBranch
end
......
......@@ -2,7 +2,10 @@ require 'mime/types'
module API
class CommitStatuses < Grape::API
resource :projects do
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: { id: %r{[^/]+} } do
include PaginationParams
before { authenticate! }
......@@ -11,7 +14,6 @@ module API
success Entities::CommitStatus
end
params do
requires :id, type: String, desc: 'The ID of a project'
requires :sha, type: String, desc: 'The commit hash'
optional :ref, type: String, desc: 'The ref'
optional :stage, type: String, desc: 'The stage'
......@@ -37,7 +39,6 @@ module API
success Entities::CommitStatus
end
params do
requires :id, type: String, desc: 'The ID of a project'
requires :sha, type: String, desc: 'The commit hash'
requires :state, type: String, desc: 'The state of the status',
values: %w(pending running success failed canceled)
......
......@@ -10,7 +10,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: { id: /.+/ } do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a project repository commits' do
success Entities::RepoCommit
end
......
......@@ -17,7 +17,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of the project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
before { authorize_admin_project }
desc "Get a specific project's deploy keys" do
......
......@@ -8,7 +8,7 @@ module API
params do
requires :id, type: String, desc: 'The project ID'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get all deployments of the project' do
detail 'This feature was introduced in GitLab 8.11.'
success Entities::Deployment
......
......@@ -9,7 +9,7 @@ module API
params do
requires :id, type: String, desc: 'The project ID'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get all environments of the project' do
detail 'This feature was introduced in GitLab 8.11.'
success Entities::Environment
......
......@@ -52,7 +52,7 @@ module API
params do
requires :id, type: String, desc: 'The project ID'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get raw file contents from the repository'
params do
requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
......
......@@ -84,7 +84,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a group'
end
resource :groups do
resource :groups, requirements: { id: %r{[^/]+} } do
desc 'Update a group. Available only for users who can administrate groups.' do
success Entities::Group
end
......@@ -154,7 +154,7 @@ module API
params do
requires :project_id, type: String, desc: 'The ID or path of the project'
end
post ":id/projects/:project_id" do
post ":id/projects/:project_id", requirements: { project_id: /.+/ } do
authenticated_as_admin!
group = find_group!(params[:id])
project = find_project!(params[:project_id])
......
......@@ -58,7 +58,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a group'
end
resource :groups do
resource :groups, requirements: { id: %r{[^/]+} } do
desc 'Get a list of group issues' do
success Entities::IssueBasic
end
......@@ -79,7 +79,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
include TimeTrackingEndpoints
desc 'Get a list of project issues' do
......
......@@ -7,7 +7,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
helpers do
params :optional_scope do
optional :scope, types: [String, Array[String]], desc: 'The scope of builds to show',
......
......@@ -7,7 +7,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get all labels of the project' do
success Entities::Label
end
......
......@@ -10,7 +10,7 @@ module API
params do
requires :id, type: String, desc: "The #{source_type} ID"
end
resource source_type.pluralize do
resource source_type.pluralize, requirements: { id: %r{[^/]+} } do
desc 'Gets a list of group or project members viewable by the authenticated user.' do
success Entities::Member
end
......
......@@ -5,14 +5,16 @@ module API
before { authenticate! }
resource :projects do
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a list of merge request diff versions' do
detail 'This feature was introduced in GitLab 8.12.'
success Entities::MergeRequestDiff
end
params do
requires :id, type: String, desc: 'The ID of a project'
requires :merge_request_iid, type: Integer, desc: 'The IID of a merge request'
use :pagination
end
......@@ -28,7 +30,6 @@ module API
end
params do
requires :id, type: String, desc: 'The ID of a project'
requires :merge_request_iid, type: Integer, desc: 'The IID of a merge request'
requires :version_id, type: Integer, desc: 'The ID of a merge request diff version'
end
......
......@@ -7,7 +7,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
include TimeTrackingEndpoints
helpers do
......
......@@ -23,7 +23,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a list of project milestones' do
success Entities::Milestone
end
......
......@@ -9,7 +9,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
NOTEABLE_TYPES.each do |noteable_type|
noteables_str = noteable_type.to_s.underscore.pluralize
......
......@@ -48,14 +48,14 @@ module API
end
%w[group project].each do |source_type|
resource source_type.pluralize do
params do
requires :id, type: String, desc: "The #{source_type} ID"
end
resource source_type.pluralize, requirements: { id: %r{[^/]+} } do
desc "Get #{source_type} level notification level settings, defaults to Global" do
detail 'This feature was introduced in GitLab 8.12'
success Entities::NotificationSetting
end
params do
requires :id, type: String, desc: 'The group ID or project ID or project NAMESPACE/PROJECT_NAME'
end
get ":id/notification_settings" do
source = find_source(source_type, params[:id])
......@@ -69,7 +69,6 @@ module API
success Entities::NotificationSetting
end
params do
requires :id, type: String, desc: 'The group ID or project ID or project NAMESPACE/PROJECT_NAME'
optional :level, type: String, desc: "The #{source_type} notification level"
NotificationSetting::EMAIL_EVENTS.each do |event|
optional event, type: Boolean, desc: 'Enable/disable this notification'
......
......@@ -7,7 +7,7 @@ module API
params do
requires :id, type: String, desc: 'The project ID'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get all Pipelines of the project' do
detail 'This feature was introduced in GitLab 8.11.'
success Entities::PipelineBasic
......
......@@ -24,7 +24,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get project hooks' do
success Entities::ProjectHook
end
......
......@@ -7,7 +7,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
helpers do
def handle_project_member_errors(errors)
if errors[:project_access].any?
......
......@@ -142,7 +142,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: { id: /[^\/]+/ } do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a single project' do
success Entities::ProjectWithAccess
end
......
......@@ -9,7 +9,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
helpers do
def handle_project_member_errors(errors)
if errors[:project_access].any?
......
......@@ -86,7 +86,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
before { authorize_admin_project }
desc 'Get runners available for project' do
......
......@@ -604,7 +604,10 @@ module API
]
}.freeze
resource :projects do
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: { id: %r{[^/]+} } do
before { authenticate! }
before { authorize_admin_project }
......@@ -692,7 +695,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc "Trigger a slash command for #{service_slug}" do
detail 'Added in GitLab 8.13'
end
......
......@@ -12,7 +12,7 @@ module API
requires :id, type: String, desc: 'The ID of a project'
requires :subscribable_id, type: String, desc: 'The ID of a resource'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
subscribable_types.each do |type, finder|
type_singularized = type.singularize
entity_class = Entities.const_get(type_singularized.camelcase)
......
......@@ -7,7 +7,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a project repository tags' do
success Entities::RepoTag
end
......
......@@ -12,7 +12,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
ISSUABLE_TYPES.each do |type, finder|
type_id_str = "#{type.singularize}_iid".to_sym
......
......@@ -5,7 +5,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Trigger a GitLab project pipeline' do
success Entities::Pipeline
end
......
......@@ -6,7 +6,7 @@ module API
before { authenticate! }
AWARDABLES = %w[issue merge_request snippet].freeze
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
AWARDABLES.each do |awardable_type|
awardable_string = awardable_type.pluralize
awardable_id_string = "#{awardable_type}_id"
......
......@@ -6,7 +6,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get all project boards' do
detail 'This feature was introduced in 8.13'
success ::API::Entities::Board
......
......@@ -9,7 +9,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a project repository branches' do
success ::API::Entities::RepoBranch
end
......
......@@ -11,7 +11,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: { id: /.+/ } do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a project repository commits' do
success ::API::Entities::RepoCommit
end
......
......@@ -13,7 +13,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of the project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
before { authorize_admin_project }
%w(keys deploy_keys).each do |path|
......
......@@ -9,7 +9,7 @@ module API
params do
requires :id, type: String, desc: 'The project ID'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get all deployments of the project' do
detail 'This feature was introduced in GitLab 8.11.'
success ::API::V3::Deployments
......
......@@ -9,7 +9,7 @@ module API
params do
requires :id, type: String, desc: 'The project ID'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get all environments of the project' do
detail 'This feature was introduced in GitLab 8.11.'
success Entities::Environment
......
......@@ -40,7 +40,7 @@ module API
params do
requires :id, type: String, desc: 'The project ID'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a file from repository'
params do
requires :file_path, type: String, desc: 'The path to the file. Ex. lib/class.rb'
......
......@@ -93,7 +93,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a group'
end
resource :groups do
resource :groups, requirements: { id: %r{[^/]+} } do
desc 'Update a group. Available only for users who can administrate groups.' do
success Entities::Group
end
......@@ -163,7 +163,7 @@ module API
params do
requires :project_id, type: String, desc: 'The ID or path of the project'
end
post ":id/projects/:project_id" do
post ":id/projects/:project_id", requirements: { project_id: /.+/ } do
authenticated_as_admin!
group = find_group!(params[:id])
project = find_project!(params[:project_id])
......
......@@ -68,7 +68,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a group'
end
resource :groups do
resource :groups, requirements: { id: %r{[^/]+} } do
desc 'Get a list of group issues' do
success ::API::Entities::Issue
end
......@@ -89,7 +89,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
include TimeTrackingEndpoints
desc 'Get a list of project issues' do
......
......@@ -6,7 +6,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get all labels of the project' do
success ::API::Entities::Label
end
......
......@@ -11,7 +11,7 @@ module API
params do
requires :id, type: String, desc: "The #{source_type} ID"
end
resource source_type.pluralize do
resource source_type.pluralize, requirements: { id: %r{[^/]+} } do
desc 'Gets a list of group or project members viewable by the authenticated user.' do
success ::API::Entities::Member
end
......
......@@ -4,14 +4,16 @@ module API
class MergeRequestDiffs < Grape::API
before { authenticate! }
resource :projects do
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a list of merge request diff versions' do
detail 'This feature was introduced in GitLab 8.12.'
success ::API::Entities::MergeRequestDiff
end
params do
requires :id, type: String, desc: 'The ID of a project'
requires :merge_request_id, type: Integer, desc: 'The ID of a merge request'
end
......@@ -27,7 +29,6 @@ module API
end
params do
requires :id, type: String, desc: 'The ID of a project'
requires :merge_request_id, type: Integer, desc: 'The ID of a merge request'
requires :version_id, type: Integer, desc: 'The ID of a merge request diff version'
end
......
......@@ -10,7 +10,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
include TimeTrackingEndpoints
helpers do
......
......@@ -18,7 +18,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a list of project milestones' do
success ::API::Entities::Milestone
end
......
......@@ -10,7 +10,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
NOTEABLE_TYPES.each do |noteable_type|
noteables_str = noteable_type.to_s.underscore.pluralize
......
......@@ -8,7 +8,7 @@ module API
params do
requires :id, type: String, desc: 'The project ID'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get all Pipelines of the project' do
detail 'This feature was introduced in GitLab 8.11.'
success ::API::Entities::Pipeline
......
......@@ -25,7 +25,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get project hooks' do
success ::API::V3::Entities::ProjectHook
end
......
......@@ -8,7 +8,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
helpers do
def handle_project_member_errors(errors)
if errors[:project_access].any?
......
......@@ -234,7 +234,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: { id: /[^\/]+/ } do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a single project' do
success ::API::V3::Entities::ProjectWithAccess
end
......
......@@ -8,7 +8,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
helpers do
def handle_project_member_errors(errors)
if errors[:project_access].any?
......
......@@ -26,7 +26,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
before { authorize_admin_project }
desc "Disable project's runner" do
......
......@@ -554,7 +554,10 @@ module API
]
}.freeze
resource :projects do
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: { id: %r{[^/]+} } do
before { authenticate! }
before { authorize_admin_project }
......@@ -609,7 +612,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc "Trigger a slash command for #{service_slug}" do
detail 'Added in GitLab 8.13'
end
......
......@@ -14,7 +14,7 @@ module API
requires :id, type: String, desc: 'The ID of a project'
requires :subscribable_id, type: String, desc: 'The ID of a resource'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
subscribable_types.each do |type, finder|
type_singularized = type.singularize
entity_class = ::API::Entities.const_get(type_singularized.camelcase)
......
......@@ -6,7 +6,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a project repository tags' do
success ::API::Entities::RepoTag
end
......
......@@ -6,7 +6,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Trigger a GitLab project build' do
success ::API::V3::Entities::TriggerRequest
end
......
......@@ -10,7 +10,7 @@ module API
requires :id, type: String, desc: 'The ID of a project'