Commit 5a265126 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'bvl-api-feature-categories-3' into 'master'

Add feature categories to the API G -> Discussions

See merge request gitlab-org/gitlab!46438
parents ca790a62 342e8cf8
......@@ -9,9 +9,9 @@ module EE
class_methods do
extend ::Gitlab::Utils::Override
override :noteable_types
def noteable_types
[::Epic, *super]
override :feature_category_per_noteable_type
def feature_category_per_noteable_type
super.merge!(::Epic => :issue_tracking)
end
end
end
......
......@@ -9,9 +9,12 @@ module EE
class_methods do
extend ::Gitlab::Utils::Override
override :noteable_types
def noteable_types
[::Epic, ::Vulnerability, *super]
override :feature_category_per_noteable_type
def feature_category_per_noteable_type
super.merge!(
::Epic => :issue_tracking,
::Vulnerability => :vulnerability_management
)
end
end
......
......@@ -8,7 +8,7 @@ module API
before { authenticate! }
Helpers::DiscussionsHelpers.noteable_types.each do |noteable_type|
Helpers::DiscussionsHelpers.feature_category_per_noteable_type.each do |noteable_type, feature_category|
parent_type = noteable_type.parent_class.to_s.underscore
noteables_str = noteable_type.to_s.underscore.pluralize
noteables_path = noteable_type == Commit ? "repository/#{noteables_str}" : noteables_str
......@@ -25,7 +25,7 @@ module API
use :pagination
end
get ":id/#{noteables_path}/:noteable_id/discussions" do
get ":id/#{noteables_path}/:noteable_id/discussions", feature_category: feature_category do
noteable = find_noteable(noteable_type, params[:noteable_id])
discussion_ids = paginate(noteable.discussion_ids_relation)
......@@ -41,7 +41,7 @@ module API
requires :discussion_id, type: String, desc: 'The ID of a discussion'
requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable'
end
get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id" do
get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id", feature_category: feature_category do
noteable = find_noteable(noteable_type, params[:noteable_id])
notes = readable_discussion_notes(noteable, params[:discussion_id])
......@@ -91,7 +91,7 @@ module API
end
end
end
post ":id/#{noteables_path}/:noteable_id/discussions" do
post ":id/#{noteables_path}/:noteable_id/discussions", feature_category: feature_category do
noteable = find_noteable(noteable_type, params[:noteable_id])
type = params[:position] ? 'DiffNote' : 'DiscussionNote'
id_key = noteable.is_a?(Commit) ? :commit_id : :noteable_id
......@@ -121,7 +121,7 @@ module API
requires :discussion_id, type: String, desc: 'The ID of a discussion'
requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable'
end
get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes" do
get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes", feature_category: feature_category do
noteable = find_noteable(noteable_type, params[:noteable_id])
notes = readable_discussion_notes(noteable, params[:discussion_id])
......@@ -141,7 +141,7 @@ module API
requires :body, type: String, desc: 'The content of a note'
optional :created_at, type: String, desc: 'The creation date of the note'
end
post ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes" do
post ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes", feature_category: feature_category do
noteable = find_noteable(noteable_type, params[:noteable_id])
notes = readable_discussion_notes(noteable, params[:discussion_id])
first_note = notes.first
......@@ -175,7 +175,7 @@ module API
requires :discussion_id, type: String, desc: 'The ID of a discussion'
requires :note_id, type: Integer, desc: 'The ID of a note'
end
get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes/:note_id" do
get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes/:note_id", feature_category: feature_category do
noteable = find_noteable(noteable_type, params[:noteable_id])
get_note(noteable, params[:note_id])
......@@ -192,7 +192,7 @@ module API
optional :resolved, type: Boolean, desc: 'Mark note resolved/unresolved'
exactly_one_of :body, :resolved
end
put ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes/:note_id" do
put ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes/:note_id", feature_category: feature_category do
noteable = find_noteable(noteable_type, params[:noteable_id])
if params[:resolved].nil?
......@@ -210,7 +210,7 @@ module API
requires :discussion_id, type: String, desc: 'The ID of a discussion'
requires :note_id, type: Integer, desc: 'The ID of a note'
end
delete ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes/:note_id" do
delete ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes/:note_id", feature_category: feature_category do
noteable = find_noteable(noteable_type, params[:noteable_id])
delete_note(noteable, params[:note_id])
......@@ -225,7 +225,7 @@ module API
requires :discussion_id, type: String, desc: 'The ID of a discussion'
requires :resolved, type: Boolean, desc: 'Mark discussion resolved/unresolved'
end
put ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id" do
put ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id", feature_category: feature_category do
noteable = find_noteable(noteable_type, params[:noteable_id])
resolve_discussion(noteable, params[:discussion_id], params[:resolved])
......
......@@ -3,10 +3,15 @@
module API
module Helpers
module DiscussionsHelpers
def self.noteable_types
def self.feature_category_per_noteable_type
# This is a method instead of a constant, allowing EE to more easily
# extend it.
[Issue, Snippet, MergeRequest, Commit]
{
Issue => :issue_tracking,
Snippet => :snippets,
MergeRequest => :code_review,
Commit => :code_review
}
end
end
end
......
......@@ -5,10 +5,12 @@ module API
module NotesHelpers
include ::RendersNotes
def self.noteable_types
# This is a method instead of a constant, allowing EE to more easily
# extend it.
[Issue, MergeRequest, Snippet]
def self.feature_category_per_noteable_type
{
Issue => :issue_tracking,
MergeRequest => :code_review,
Snippet => :snippets
}
end
def update_note(noteable, note_id)
......
......@@ -2,6 +2,8 @@
module API
class ImportBitbucketServer < ::API::Base
feature_category :importers
helpers do
def client
@client ||= BitbucketServer::Client.new(credentials)
......
......@@ -2,6 +2,8 @@
module API
class ImportGithub < ::API::Base
feature_category :importers
rescue_from Octokit::Unauthorized, with: :provider_unauthorized
before do
......
......@@ -6,6 +6,8 @@ module API
before { authenticate! }
feature_category :issue_tracking
params do
requires :id, type: String, desc: 'The ID of a project'
requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue'
......
......@@ -6,10 +6,10 @@ module API
helpers Helpers::IssuesHelpers
helpers Helpers::RateLimiter
feature_category :issue_tracking
before { authenticate_non_get! }
feature_category :issue_tracking
helpers do
params :negatable_issue_filter_params do
optional :labels, type: Array[String], coerce_with: ::API::Validations::Types::CommaSeparatedToArray.coerce, desc: 'Comma-separated list of label names'
......
......@@ -4,6 +4,8 @@ module API
class JobArtifacts < ::API::Base
before { authenticate_non_get! }
feature_category :continuous_integration
# EE::API::JobArtifacts would override the following helpers
helpers do
def authorize_download_artifacts!
......
......@@ -6,6 +6,8 @@ module API
before { authenticate! }
feature_category :continuous_integration
params do
requires :id, type: String, desc: 'The ID of a project'
end
......
......@@ -5,6 +5,8 @@ module API
class Keys < ::API::Base
before { authenticate! }
feature_category :authentication_and_authorization
resource :keys do
desc 'Get single ssh key by id. Only available to admin users' do
success Entities::SSHKeyWithUser
......
......@@ -7,6 +7,8 @@ module API
before { authenticate! }
feature_category :issue_tracking
params do
requires :id, type: String, desc: 'The ID of a project'
end
......
......@@ -2,6 +2,8 @@
module API
class Lint < ::API::Base
feature_category :pipeline_authoring
namespace :ci do
desc 'Validation of .gitlab-ci.yml content'
params do
......
......@@ -2,6 +2,8 @@
module API
class Markdown < ::API::Base
feature_category :not_owned
params do
requires :text, type: String, desc: "The markdown text to render"
optional :gfm, type: Boolean, desc: "Render text using GitLab Flavored Markdown"
......
......@@ -6,6 +6,8 @@ module API
before { authenticate! }
feature_category :authentication_and_authorization
helpers ::API::Helpers::MembersHelpers
%w[group project].each do |source_type|
......
......@@ -4,6 +4,8 @@ module API
class MergeRequestApprovals < ::API::Base
before { authenticate_non_get! }
feature_category :code_review
helpers do
params :ee_approval_params do
end
......
......@@ -7,6 +7,8 @@ module API
before { authenticate! }
feature_category :code_review
params do
requires :id, type: String, desc: 'The ID of a project'
end
......
......@@ -8,6 +8,8 @@ module API
before { authenticate_non_get! }
feature_category :code_review
helpers Helpers::MergeRequestsHelpers
# EE::API::MergeRequests would override the following helpers
......
......@@ -4,6 +4,8 @@ module API
module Metrics
module Dashboard
class Annotations < ::API::Base
feature_category :metrics
desc 'Create a new monitoring dashboard annotation' do
success Entities::Metrics::Dashboard::Annotation
end
......
......@@ -3,6 +3,8 @@
module API
module Metrics
class UserStarredDashboards < ::API::Base
feature_category :metrics
resource :projects do
desc 'Marks selected metrics dashboard as starred' do
success Entities::Metrics::UserStarredDashboard
......
......@@ -6,6 +6,8 @@ module API
before { authenticate! }
feature_category :subgroups
helpers do
params :optional_list_params_ee do
# EE::API::Namespaces would override this helper
......
......@@ -7,7 +7,7 @@ module API
before { authenticate! }
Helpers::NotesHelpers.noteable_types.each do |noteable_type|
Helpers::NotesHelpers.feature_category_per_noteable_type.each do |noteable_type, feature_category|
parent_type = noteable_type.parent_class.to_s.underscore
noteables_str = noteable_type.to_s.underscore.pluralize
......@@ -29,7 +29,7 @@ module API
use :pagination
end
# rubocop: disable CodeReuse/ActiveRecord
get ":id/#{noteables_str}/:noteable_id/notes" do
get ":id/#{noteables_str}/:noteable_id/notes", feature_category: feature_category do
noteable = find_noteable(noteable_type, params[:noteable_id])
# We exclude notes that are cross-references and that cannot be viewed
......@@ -57,7 +57,7 @@ module API
requires :note_id, type: Integer, desc: 'The ID of a note'
requires :noteable_id, type: Integer, desc: 'The ID of the noteable'
end
get ":id/#{noteables_str}/:noteable_id/notes/:note_id" do
get ":id/#{noteables_str}/:noteable_id/notes/:note_id", feature_category: feature_category do
noteable = find_noteable(noteable_type, params[:noteable_id])
get_note(noteable, params[:note_id])
end
......@@ -71,7 +71,7 @@ module API
optional :confidential, type: Boolean, desc: 'Confidentiality note flag, default is false'
optional :created_at, type: String, desc: 'The creation date of the note'
end
post ":id/#{noteables_str}/:noteable_id/notes" do
post ":id/#{noteables_str}/:noteable_id/notes", feature_category: feature_category do
noteable = find_noteable(noteable_type, params[:noteable_id])
opts = {
......@@ -104,7 +104,7 @@ module API
optional :body, type: String, allow_blank: false, desc: 'The content of a note'
optional :confidential, type: Boolean, desc: 'Confidentiality note flag'
end
put ":id/#{noteables_str}/:noteable_id/notes/:note_id" do
put ":id/#{noteables_str}/:noteable_id/notes/:note_id", feature_category: feature_category do
noteable = find_noteable(noteable_type, params[:noteable_id])
update_note(noteable, params[:note_id])
......
......@@ -31,8 +31,13 @@ RSpec.describe 'Every API endpoint' do
::API::FeatureFlagsUserLists, ::API::Features, ::API::Files, ::API::FreezePeriods,
::API::GroupBoards, ::API::GroupClusters, ::API::GroupExport, ::API::GroupImport,
::API::GroupLabels, ::API::GroupMilestones, ::API::Groups,
::API::GroupContainerRepositories, ::API::GroupVariables
::API::GroupContainerRepositories, ::API::GroupVariables,
::API::ImportBitbucketServer, ::API::ImportGithub, ::API::IssueLinks,
::API::Issues, ::API::JobArtifacts, ::API::Jobs, ::API::Keys, ::API::Labels,
::API::Lint, ::API::Markdown, ::API::Members, ::API::MergeRequestDiffs,
::API::MergeRequests, ::API::MergeRequestApprovals, ::API::Metrics::Dashboard::Annotations,
::API::Metrics::UserStarredDashboards, ::API::Namespaces, ::API::Notes,
::API::Discussions
]
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