Commit 19eaaf71 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Add feature categories to the API

This adds a feature category to API classes from
::API::ProjectSnapshots -> ::API::Wikis
parent 392094d3
...@@ -6,6 +6,8 @@ module API ...@@ -6,6 +6,8 @@ module API
before { authorize_read_git_snapshot! } before { authorize_read_git_snapshot! }
feature_category :source_code_management
resource :projects do resource :projects do
desc 'Download a (possibly inconsistent) snapshot of a repository' do desc 'Download a (possibly inconsistent) snapshot of a repository' do
detail 'This feature was introduced in GitLab 10.7' detail 'This feature was introduced in GitLab 10.7'
......
...@@ -6,6 +6,8 @@ module API ...@@ -6,6 +6,8 @@ module API
before { check_snippets_enabled } before { check_snippets_enabled }
feature_category :snippets
params do params do
requires :id, type: String, desc: 'The ID of a project' requires :id, type: String, desc: 'The ID of a project'
end end
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
module API module API
class ProjectStatistics < ::API::Base class ProjectStatistics < ::API::Base
feature_category :source_code_management
before do before do
authenticate! authenticate!
authorize! :daily_statistics, user_project authorize! :daily_statistics, user_project
......
...@@ -12,6 +12,8 @@ module API ...@@ -12,6 +12,8 @@ module API
before { authenticate_non_get! } before { authenticate_non_get! }
feature_category :templates
params do params do
requires :id, type: String, desc: 'The ID of a project' requires :id, type: String, desc: 'The ID of a project'
requires :type, type: String, values: TEMPLATE_TYPES, desc: 'The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses|metrics_dashboard_ymls|issues|merge_requests) of the template' requires :type, type: String, values: TEMPLATE_TYPES, desc: 'The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses|metrics_dashboard_ymls|issues|merge_requests) of the template'
......
...@@ -8,6 +8,8 @@ module API ...@@ -8,6 +8,8 @@ module API
before { authorize_admin_project } before { authorize_admin_project }
feature_category :source_code_management
helpers Helpers::ProtectedBranchesHelpers helpers Helpers::ProtectedBranchesHelpers
params do params do
......
...@@ -8,6 +8,8 @@ module API ...@@ -8,6 +8,8 @@ module API
before { authorize_admin_project } before { authorize_admin_project }
feature_category :source_code_management
params do params do
requires :id, type: String, desc: 'The ID of a project' requires :id, type: String, desc: 'The ID of a project'
end end
......
...@@ -10,6 +10,8 @@ module API ...@@ -10,6 +10,8 @@ module API
before { authorize! :read_release, user_project } before { authorize! :read_release, user_project }
feature_category :release_orchestration
params do params do
requires :id, type: String, desc: 'The ID of a project' requires :id, type: String, desc: 'The ID of a project'
end end
......
...@@ -9,6 +9,8 @@ module API ...@@ -9,6 +9,8 @@ module API
before { authorize_read_releases! } before { authorize_read_releases! }
feature_category :release_orchestration
params do params do
requires :id, type: String, desc: 'The ID of a project' requires :id, type: String, desc: 'The ID of a project'
end end
......
...@@ -4,6 +4,8 @@ module API ...@@ -4,6 +4,8 @@ module API
class RemoteMirrors < ::API::Base class RemoteMirrors < ::API::Base
include PaginationParams include PaginationParams
feature_category :source_code_management
before do before do
unauthorized! unless can?(current_user, :admin_remote_mirror, user_project) unauthorized! unless can?(current_user, :admin_remote_mirror, user_project)
end end
......
...@@ -12,6 +12,8 @@ module API ...@@ -12,6 +12,8 @@ module API
before { authorize! :download_code, user_project } before { authorize! :download_code, user_project }
feature_category :source_code_management
params do params do
requires :id, type: String, desc: 'The ID of a project' requires :id, type: String, desc: 'The ID of a project'
end end
......
...@@ -6,6 +6,8 @@ module API ...@@ -6,6 +6,8 @@ module API
before { authenticate! } before { authenticate! }
feature_category :global_search
helpers do helpers do
SCOPE_ENTITY = { SCOPE_ENTITY = {
merge_requests: Entities::MergeRequestBasic, merge_requests: Entities::MergeRequestBasic,
......
# frozen_string_literal: true # frozen_string_literal: true
module API module API
class Services < ::API::Base class Services < ::API::Base
feature_category :integrations
services = Helpers::ServicesHelpers.services services = Helpers::ServicesHelpers.services
service_classes = Helpers::ServicesHelpers.service_classes service_classes = Helpers::ServicesHelpers.service_classes
......
...@@ -4,6 +4,8 @@ module API ...@@ -4,6 +4,8 @@ module API
class Settings < ::API::Base class Settings < ::API::Base
before { authenticated_as_admin! } before { authenticated_as_admin! }
feature_category :not_owned
helpers Helpers::SettingsHelpers helpers Helpers::SettingsHelpers
helpers do helpers do
......
...@@ -6,6 +6,8 @@ module API ...@@ -6,6 +6,8 @@ module API
class SidekiqMetrics < ::API::Base class SidekiqMetrics < ::API::Base
before { authenticated_as_admin! } before { authenticated_as_admin! }
feature_category :not_owned
helpers do helpers do
def queue_metrics def queue_metrics
Sidekiq::Queue.all.each_with_object({}) do |queue, hash| Sidekiq::Queue.all.each_with_object({}) do |queue, hash|
......
...@@ -5,6 +5,8 @@ module API ...@@ -5,6 +5,8 @@ module API
class Snippets < ::API::Base class Snippets < ::API::Base
include PaginationParams include PaginationParams
feature_category :snippets
resource :snippets do resource :snippets do
helpers Helpers::SnippetsHelpers helpers Helpers::SnippetsHelpers
helpers do helpers do
......
...@@ -4,6 +4,8 @@ module API ...@@ -4,6 +4,8 @@ module API
class Statistics < ::API::Base class Statistics < ::API::Base
before { authenticated_as_admin! } before { authenticated_as_admin! }
feature_category :instance_statistics
COUNTED_ITEMS = [Project, User, Group, ForkNetworkMember, ForkNetwork, Issue, COUNTED_ITEMS = [Project, User, Group, ForkNetworkMember, ForkNetwork, Issue,
MergeRequest, Note, Snippet, Key, Milestone].freeze MergeRequest, Note, Snippet, Key, Milestone].freeze
......
...@@ -4,6 +4,8 @@ module API ...@@ -4,6 +4,8 @@ module API
class Submodules < ::API::Base class Submodules < ::API::Base
before { authenticate! } before { authenticate! }
feature_category :source_code_management
helpers do helpers do
def commit_params(attrs) def commit_params(attrs)
{ {
......
...@@ -11,25 +11,29 @@ module API ...@@ -11,25 +11,29 @@ module API
type: 'merge_requests', type: 'merge_requests',
entity: Entities::MergeRequest, entity: Entities::MergeRequest,
source: Project, source: Project,
finder: ->(id) { find_merge_request_with_access(id, :update_merge_request) } finder: ->(id) { find_merge_request_with_access(id, :update_merge_request) },
feature_category: :code_review
}, },
{ {
type: 'issues', type: 'issues',
entity: Entities::Issue, entity: Entities::Issue,
source: Project, source: Project,
finder: ->(id) { find_project_issue(id) } finder: ->(id) { find_project_issue(id) },
feature_category: :issue_tracking
}, },
{ {
type: 'labels', type: 'labels',
entity: Entities::ProjectLabel, entity: Entities::ProjectLabel,
source: Project, source: Project,
finder: ->(id) { find_label(user_project, id) } finder: ->(id) { find_label(user_project, id) },
feature_category: :issue_tracking
}, },
{ {
type: 'labels', type: 'labels',
entity: Entities::GroupLabel, entity: Entities::GroupLabel,
source: Group, source: Group,
finder: ->(id) { find_label(user_group, id) } finder: ->(id) { find_label(user_group, id) },
feature_category: :issue_tracking
} }
] ]
...@@ -44,7 +48,7 @@ module API ...@@ -44,7 +48,7 @@ module API
desc 'Subscribe to a resource' do desc 'Subscribe to a resource' do
success subscribable[:entity] success subscribable[:entity]
end end
post ":id/#{subscribable[:type]}/:subscribable_id/subscribe" do post ":id/#{subscribable[:type]}/:subscribable_id/subscribe", subscribable.slice(:feature_category) do
parent = parent_resource(source_type) parent = parent_resource(source_type)
resource = instance_exec(params[:subscribable_id], &subscribable[:finder]) resource = instance_exec(params[:subscribable_id], &subscribable[:finder])
...@@ -59,7 +63,7 @@ module API ...@@ -59,7 +63,7 @@ module API
desc 'Unsubscribe from a resource' do desc 'Unsubscribe from a resource' do
success subscribable[:entity] success subscribable[:entity]
end end
post ":id/#{subscribable[:type]}/:subscribable_id/unsubscribe" do post ":id/#{subscribable[:type]}/:subscribable_id/unsubscribe", subscribable.slice(:feature_category) do
parent = parent_resource(source_type) parent = parent_resource(source_type)
resource = instance_exec(params[:subscribable_id], &subscribable[:finder]) resource = instance_exec(params[:subscribable_id], &subscribable[:finder])
......
...@@ -4,6 +4,8 @@ module API ...@@ -4,6 +4,8 @@ module API
class Suggestions < ::API::Base class Suggestions < ::API::Base
before { authenticate! } before { authenticate! }
feature_category :code_review
resource :suggestions do resource :suggestions do
desc 'Apply suggestion patch in the Merge Request it was created' do desc 'Apply suggestion patch in the Merge Request it was created' do
success Entities::Suggestion success Entities::Suggestion
......
...@@ -4,6 +4,8 @@ module API ...@@ -4,6 +4,8 @@ module API
class SystemHooks < ::API::Base class SystemHooks < ::API::Base
include PaginationParams include PaginationParams
feature_category :integrations
before do before do
authenticate! authenticate!
authenticated_as_admin! authenticated_as_admin!
......
...@@ -23,7 +23,7 @@ module API ...@@ -23,7 +23,7 @@ module API
optional :search, type: String, desc: 'Return list of tags matching the search criteria' optional :search, type: String, desc: 'Return list of tags matching the search criteria'
use :pagination use :pagination
end end
get ':id/repository/tags' do get ':id/repository/tags', feature_category: :source_code_management do
tags = ::TagsFinder.new(user_project.repository, tags = ::TagsFinder.new(user_project.repository,
sort: "#{params[:order_by]}_#{params[:sort]}", sort: "#{params[:order_by]}_#{params[:sort]}",
search: params[:search]).execute search: params[:search]).execute
...@@ -37,7 +37,7 @@ module API ...@@ -37,7 +37,7 @@ module API
params do params do
requires :tag_name, type: String, desc: 'The name of the tag' requires :tag_name, type: String, desc: 'The name of the tag'
end end
get ':id/repository/tags/:tag_name', requirements: TAG_ENDPOINT_REQUIREMENTS do get ':id/repository/tags/:tag_name', requirements: TAG_ENDPOINT_REQUIREMENTS, feature_category: :source_code_management do
tag = user_project.repository.find_tag(params[:tag_name]) tag = user_project.repository.find_tag(params[:tag_name])
not_found!('Tag') unless tag not_found!('Tag') unless tag
...@@ -54,7 +54,7 @@ module API ...@@ -54,7 +54,7 @@ module API
optional :message, type: String, desc: 'Specifying a message creates an annotated tag' optional :message, type: String, desc: 'Specifying a message creates an annotated tag'
optional :release_description, type: String, desc: 'Specifying release notes stored in the GitLab database (deprecated in GitLab 11.7)' optional :release_description, type: String, desc: 'Specifying release notes stored in the GitLab database (deprecated in GitLab 11.7)'
end end
post ':id/repository/tags' do post ':id/repository/tags', :release_orchestration do
authorize_admin_tag authorize_admin_tag
result = ::Tags::CreateService.new(user_project, current_user) result = ::Tags::CreateService.new(user_project, current_user)
...@@ -86,7 +86,7 @@ module API ...@@ -86,7 +86,7 @@ module API
params do params do
requires :tag_name, type: String, desc: 'The name of the tag' requires :tag_name, type: String, desc: 'The name of the tag'
end end
delete ':id/repository/tags/:tag_name', requirements: TAG_ENDPOINT_REQUIREMENTS do delete ':id/repository/tags/:tag_name', requirements: TAG_ENDPOINT_REQUIREMENTS, feature_category: :source_code_management do
authorize_admin_tag authorize_admin_tag
tag = user_project.repository.find_tag(params[:tag_name]) tag = user_project.repository.find_tag(params[:tag_name])
...@@ -112,7 +112,7 @@ module API ...@@ -112,7 +112,7 @@ module API
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
requires :description, type: String, desc: 'Release notes with markdown support' requires :description, type: String, desc: 'Release notes with markdown support'
end end
post ':id/repository/tags/:tag_name/release', requirements: TAG_ENDPOINT_REQUIREMENTS do post ':id/repository/tags/:tag_name/release', requirements: TAG_ENDPOINT_REQUIREMENTS, feature_category: :release_orchestration do
authorize_create_release! authorize_create_release!
## ##
...@@ -144,7 +144,7 @@ module API ...@@ -144,7 +144,7 @@ module API
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
requires :description, type: String, desc: 'Release notes with markdown support' requires :description, type: String, desc: 'Release notes with markdown support'
end end
put ':id/repository/tags/:tag_name/release', requirements: TAG_ENDPOINT_REQUIREMENTS do put ':id/repository/tags/:tag_name/release', requirements: TAG_ENDPOINT_REQUIREMENTS, feature_category: :release_orchestration do
authorize_update_release! authorize_update_release!
result = ::Releases::UpdateService result = ::Releases::UpdateService
......
...@@ -4,6 +4,8 @@ module API ...@@ -4,6 +4,8 @@ module API
class Templates < ::API::Base class Templates < ::API::Base
include PaginationParams include PaginationParams
feature_category :templates
GLOBAL_TEMPLATE_TYPES = { GLOBAL_TEMPLATE_TYPES = {
gitignores: { gitignores: {
gitlab_version: 8.8 gitlab_version: 8.8
......
...@@ -7,6 +7,8 @@ module API ...@@ -7,6 +7,8 @@ module API
class State < ::API::Base class State < ::API::Base
include ::Gitlab::Utils::StrongMemoize include ::Gitlab::Utils::StrongMemoize
feature_category :infrastructure_as_code
default_format :json default_format :json
before do before do
......
...@@ -5,6 +5,8 @@ module API ...@@ -5,6 +5,8 @@ module API
class StateVersion < ::API::Base class StateVersion < ::API::Base
default_format :json default_format :json
feature_category :infrastructure_as_code
before do before do
authenticate! authenticate!
authorize! :read_terraform_state, user_project authorize! :read_terraform_state, user_project
......
...@@ -6,6 +6,8 @@ module API ...@@ -6,6 +6,8 @@ module API
before { authenticate! } before { authenticate! }
feature_category :issue_tracking
ISSUABLE_TYPES = { ISSUABLE_TYPES = {
'merge_requests' => ->(iid) { find_merge_request_with_access(iid) }, 'merge_requests' => ->(iid) { find_merge_request_with_access(iid) },
'issues' => ->(iid) { find_project_issue(iid) } 'issues' => ->(iid) { find_project_issue(iid) }
......
...@@ -6,6 +6,8 @@ module API ...@@ -6,6 +6,8 @@ module API
HTTP_GITLAB_EVENT_HEADER = "HTTP_#{WebHookService::GITLAB_EVENT_HEADER}".underscore.upcase HTTP_GITLAB_EVENT_HEADER = "HTTP_#{WebHookService::GITLAB_EVENT_HEADER}".underscore.upcase
feature_category :continuous_integration
params do params do
requires :id, type: String, desc: 'The ID of a project' requires :id, type: String, desc: 'The ID of a project'
end end
......
...@@ -4,6 +4,8 @@ module API ...@@ -4,6 +4,8 @@ module API
class Unleash < ::API::Base class Unleash < ::API::Base
include PaginationParams include PaginationParams
feature_category :feature_flags
namespace :feature_flags do namespace :feature_flags do
resource :unleash, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do resource :unleash, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
params do params do
......
...@@ -4,6 +4,8 @@ module API ...@@ -4,6 +4,8 @@ module API
class UsageData < ::API::Base class UsageData < ::API::Base
before { authenticate! } before { authenticate! }
feature_category :collection
namespace 'usage_data' do namespace 'usage_data' do
before do before do
not_found! unless Feature.enabled?(:usage_data_api, default_enabled: true) not_found! unless Feature.enabled?(:usage_data_api, default_enabled: true)
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
module API module API
class UserCounts < ::API::Base class UserCounts < ::API::Base
feature_category :navigation
resource :user_counts do resource :user_counts do
desc 'Return the user specific counts' do desc 'Return the user specific counts' do
detail 'Open MR Count' detail 'Open MR Count'
......
...@@ -7,6 +7,8 @@ module API ...@@ -7,6 +7,8 @@ module API
before { authenticate! } before { authenticate! }
before { authorize! :admin_build, user_project } before { authorize! :admin_build, user_project }
feature_category :continuous_integration
helpers do helpers do
def filter_variable_parameters(params) def filter_variable_parameters(params)
# This method exists so that EE can more easily filter out certain # This method exists so that EE can more easily filter out certain
......
...@@ -9,6 +9,8 @@ module API ...@@ -9,6 +9,8 @@ module API
before { authenticate! } before { authenticate! }
feature_category :not_owned
METADATA_QUERY = <<~EOF METADATA_QUERY = <<~EOF
{ {
metadata { metadata {
......
...@@ -4,6 +4,8 @@ module API ...@@ -4,6 +4,8 @@ module API
class Wikis < ::API::Base class Wikis < ::API::Base
helpers ::API::Helpers::WikisHelpers helpers ::API::Helpers::WikisHelpers
feature_category :wiki
helpers do helpers do
attr_reader :container attr_reader :container
......
...@@ -45,7 +45,16 @@ RSpec.describe 'Every API endpoint' do ...@@ -45,7 +45,16 @@ RSpec.describe 'Every API endpoint' do
::API::NpmPackages, ::API::GenericPackages, ::API::GoProxy, ::API::Pages, ::API::NpmPackages, ::API::GenericPackages, ::API::GoProxy, ::API::Pages,
::API::PagesDomains, ::API::ProjectClusters, ::API::ProjectContainerRepositories, ::API::PagesDomains, ::API::ProjectClusters, ::API::ProjectContainerRepositories,
::API::ProjectEvents, ::API::ProjectExport, ::API::ProjectImport, ::API::ProjectHooks, ::API::ProjectEvents, ::API::ProjectExport, ::API::ProjectImport, ::API::ProjectHooks,
::API::ProjectMilestones, ::API::ProjectRepositoryStorageMoves, ::API::Projects ::API::ProjectMilestones, ::API::ProjectRepositoryStorageMoves, ::API::Projects,
::API::ProjectSnapshots, ::API::ProjectSnippets, ::API::ProjectStatistics,
::API::ProjectTemplates, ::API::Terraform::State, ::API::Terraform::StateVersion,
::API::ProtectedBranches, ::API::ProtectedTags, ::API::Releases, ::API::Release::Links,
::API::RemoteMirrors, ::API::Repositories, ::API::Search, ::API::Services,
::API::Settings, ::API::SidekiqMetrics, ::API::Snippets, ::API::Statistics,
::API::Submodules, ::API::Subscriptions, ::API::Suggestions, ::API::SystemHooks,
::API::Tags, ::API::Templates, ::API::Todos, ::API::Triggers, ::API::Unleash,
::API::UsageData, ::API::UserCounts, ::API::Variables, ::API::Version,
::API::Wikis
] ]
next unless completed_classes.include?(klass) next unless completed_classes.include?(klass)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment