This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

Commit 626e79b6 authored by Robert Schilling's avatar Robert Schilling
Browse files

Split V3 entities into a separate file

parent 10ce4a511898
......@@ -694,19 +694,5 @@ class BroadcastMessage < Grape::Entity
expose :id, :message, :starts_at, :ends_at, :color, :font
expose :active?, as: :active
end
# Entities for the deprecated V3 API
class ProjectSnippetV3 < Grape::Entity
expose :id, :title, :file_name
expose :author, using: Entities::UserBasic
expose :updated_at, :created_at
# TODO (rspeicher): Deprecated; remove in 9.0
expose(:expires_at) { |snippet| nil }
expose :web_url do |snippet, options|
Gitlab::UrlBuilder.build(snippet)
end
end
end
end
module API
module V3
module Entities
class ProjectSnippet < Grape::Entity
expose :id, :title, :file_name
expose :author, using: ::API::Entities::UserBasic
expose :updated_at, :created_at
expose(:expires_at) { |snippet| nil }
expose :web_url do |snippet, options|
Gitlab::UrlBuilder.build(snippet)
end
end
end
end
end
......@@ -50,7 +50,7 @@ def find_issues(args = {})
resource :issues do
desc "Get currently authenticated user's issues" do
success Entities::Issue
success ::API::Entities::Issue
end
params do
optional :state, type: String, values: %w[opened closed all], default: 'all',
......@@ -60,7 +60,7 @@ def find_issues(args = {})
get do
issues = find_issues(scope: 'authored')
present paginate(issues), with: Entities::Issue, current_user: current_user
present paginate(issues), with: ::API::Entities::Issue, current_user: current_user
end
end
......@@ -69,7 +69,7 @@ def find_issues(args = {})
end
resource :groups do
desc 'Get a list of group issues' do
success Entities::Issue
success ::API::Entities::Issue
end
params do
optional :state, type: String, values: %w[opened closed all], default: 'opened',
......@@ -81,7 +81,7 @@ def find_issues(args = {})
issues = find_issues(group_id: group.id, state: params[:state] || 'opened', match_all_labels: true)
present paginate(issues), with: Entities::Issue, current_user: current_user
present paginate(issues), with: ::API::Entities::Issue, current_user: current_user
end
end
......@@ -93,7 +93,7 @@ def find_issues(args = {})
desc 'Get a list of project issues' do
detail 'iid filter is deprecated have been removed on V4'
success Entities::Issue
success ::API::Entities::Issue
end
params do
optional :state, type: String, values: %w[opened closed all], default: 'all',
......@@ -106,22 +106,22 @@ def find_issues(args = {})
issues = find_issues(project_id: project.id)
present paginate(issues), with: Entities::Issue, current_user: current_user, project: user_project
present paginate(issues), with: ::API::Entities::Issue, current_user: current_user, project: user_project
end
desc 'Get a single project issue' do
success Entities::Issue
success ::API::Entities::Issue
end
params do
requires :issue_id, type: Integer, desc: 'The ID of a project issue'
end
get ":id/issues/:issue_id" do
issue = find_project_issue(params[:issue_id])
present issue, with: Entities::Issue, current_user: current_user, project: user_project
present issue, with: ::API::Entities::Issue, current_user: current_user, project: user_project
end
desc 'Create a new project issue' do
success Entities::Issue
success ::API::Entities::Issue
end
params do
requires :title, type: String, desc: 'The title of an issue'
......@@ -153,14 +153,14 @@ def find_issues(args = {})
end
if issue.valid?
present issue, with: Entities::Issue, current_user: current_user, project: user_project
present issue, with: ::API::Entities::Issue, current_user: current_user, project: user_project
else
render_validation_error!(issue)
end
end
desc 'Update an existing issue' do
success Entities::Issue
success ::API::Entities::Issue
end
params do
requires :issue_id, type: Integer, desc: 'The ID of a project issue'
......@@ -186,14 +186,14 @@ def find_issues(args = {})
declared_params(include_missing: false)).execute(issue)
if issue.valid?
present issue, with: Entities::Issue, current_user: current_user, project: user_project
present issue, with: ::API::Entities::Issue, current_user: current_user, project: user_project
else
render_validation_error!(issue)
end
end
desc 'Move an existing issue' do
success Entities::Issue
success ::API::Entities::Issue
end
params do
requires :issue_id, type: Integer, desc: 'The ID of a project issue'
......@@ -208,7 +208,7 @@ def find_issues(args = {})
begin
issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project)
present issue, with: Entities::Issue, current_user: current_user, project: user_project
present issue, with: ::API::Entities::Issue, current_user: current_user, project: user_project
rescue ::Issues::MoveService::MoveError => error
render_api_error!(error.message, 400)
end
......
......@@ -39,7 +39,7 @@ def handle_merge_request_errors!(errors)
desc 'List merge requests' do
detail 'iid filter is deprecated have been removed on V4'
success Entities::MergeRequest
success ::API::Entities::MergeRequest
end
params do
optional :state, type: String, values: %w[opened closed merged all], default: 'all',
......@@ -66,11 +66,11 @@ def handle_merge_request_errors!(errors)
end
merge_requests = merge_requests.reorder(params[:order_by] => params[:sort])
present paginate(merge_requests), with: Entities::MergeRequest, current_user: current_user, project: user_project
present paginate(merge_requests), with: ::API::Entities::MergeRequest, current_user: current_user, project: user_project
end
desc 'Create a merge request' do
success Entities::MergeRequest
success ::API::Entities::MergeRequest
end
params do
requires :title, type: String, desc: 'The title of the merge request'
......@@ -89,7 +89,7 @@ def handle_merge_request_errors!(errors)
merge_request = ::MergeRequests::CreateService.new(user_project, current_user, mr_params).execute
if merge_request.valid?
present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project
present merge_request, with: ::API::Entities::MergeRequest, current_user: current_user, project: user_project
else
handle_merge_request_errors! merge_request.errors
end
......@@ -114,34 +114,34 @@ def handle_merge_request_errors!(errors)
if status == :deprecated
detail DEPRECATION_MESSAGE
end
success Entities::MergeRequest
success ::API::Entities::MergeRequest
end
get path do
merge_request = find_merge_request_with_access(params[:merge_request_id])
present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project
present merge_request, with: ::API::Entities::MergeRequest, current_user: current_user, project: user_project
end
desc 'Get the commits of a merge request' do
success Entities::RepoCommit
success ::API::Entities::RepoCommit
end
get "#{path}/commits" do
merge_request = find_merge_request_with_access(params[:merge_request_id])
present merge_request.commits, with: Entities::RepoCommit
present merge_request.commits, with: ::API::Entities::RepoCommit
end
desc 'Show the merge request changes' do
success Entities::MergeRequestChanges
success ::API::Entities::MergeRequestChanges
end
get "#{path}/changes" do
merge_request = find_merge_request_with_access(params[:merge_request_id])
present merge_request, with: Entities::MergeRequestChanges, current_user: current_user
present merge_request, with: ::API::Entities::MergeRequestChanges, current_user: current_user
end
desc 'Update a merge request' do
success Entities::MergeRequest
success ::API::Entities::MergeRequest
end
params do
optional :title, type: String, allow_blank: false, desc: 'The title of the merge request'
......@@ -162,14 +162,14 @@ def handle_merge_request_errors!(errors)
merge_request = ::MergeRequests::UpdateService.new(user_project, current_user, mr_params).execute(merge_request)
if merge_request.valid?
present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project
present merge_request, with: ::API::Entities::MergeRequest, current_user: current_user, project: user_project
else
handle_merge_request_errors! merge_request.errors
end
end
desc 'Merge a merge request' do
success Entities::MergeRequest
success ::API::Entities::MergeRequest
end
params do
optional :merge_commit_message, type: String, desc: 'Custom merge commit message'
......@@ -209,11 +209,11 @@ def handle_merge_request_errors!(errors)
.execute(merge_request)
end
present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project
present merge_request, with: ::API::Entities::MergeRequest, current_user: current_user, project: user_project
end
desc 'Cancel merge if "Merge When Pipeline Succeeds" is enabled' do
success Entities::MergeRequest
success ::API::Entities::MergeRequest
end
post "#{path}/cancel_merge_when_build_succeeds" do
merge_request = find_project_merge_request(params[:merge_request_id])
......@@ -227,19 +227,19 @@ def handle_merge_request_errors!(errors)
desc 'Get the comments of a merge request' do
detail 'Duplicate. DEPRECATED and HAS BEEN REMOVED in V4'
success Entities::MRNote
success ::API::Entities::MRNote
end
params do
use :pagination
end
get "#{path}/comments" do
merge_request = find_merge_request_with_access(params[:merge_request_id])
present paginate(merge_request.notes.fresh), with: Entities::MRNote
present paginate(merge_request.notes.fresh), with: ::API::Entities::MRNote
end
desc 'Post a comment to a merge request' do
detail 'Duplicate. DEPRECATED and HAS BEEN REMOVED in V4'
success Entities::MRNote
success ::API::Entities::MRNote
end
params do
requires :note, type: String, desc: 'The text of the comment'
......@@ -256,14 +256,14 @@ def handle_merge_request_errors!(errors)
note = ::Notes::CreateService.new(user_project, current_user, opts).execute
if note.save
present note, with: Entities::MRNote
present note, with: ::API::Entities::MRNote
else
render_api_error!("Failed to save note #{note.errors.messages}", 400)
end
end
desc 'List issues that will be closed on merge' do
success Entities::MRNote
success ::API::Entities::MRNote
end
params do
use :pagination
......
......@@ -24,28 +24,28 @@ def snippets_for_current_user
end
desc 'Get all project snippets' do
success Entities::ProjectSnippetV3
success ::API::V3::Entities::ProjectSnippet
end
params do
use :pagination
end
get ":id/snippets" do
present paginate(snippets_for_current_user), with: Entities::ProjectSnippetV3
present paginate(snippets_for_current_user), with: ::API::V3::Entities::ProjectSnippet
end
desc 'Get a single project snippet' do
success Entities::ProjectSnippetV3
success ::API::V3::Entities::ProjectSnippet
end
params do
requires :snippet_id, type: Integer, desc: 'The ID of a project snippet'
end
get ":id/snippets/:snippet_id" do
snippet = snippets_for_current_user.find(params[:snippet_id])
present snippet, with: Entities::ProjectSnippetV3
present snippet, with: ::API::V3::Entities::ProjectSnippet
end
desc 'Create a new project snippet' do
success Entities::ProjectSnippetV3
success ::API::V3::Entities::ProjectSnippet
end
params do
requires :title, type: String, desc: 'The title of the snippet'
......@@ -65,14 +65,14 @@ def snippets_for_current_user
snippet = CreateSnippetService.new(user_project, current_user, snippet_params).execute
if snippet.persisted?
present snippet, with: Entities::ProjectSnippetV3
present snippet, with: ::API::V3::Entities::ProjectSnippet
else
render_validation_error!(snippet)
end
end
desc 'Update an existing project snippet' do
success Entities::ProjectSnippetV3
success ::API::V3::Entities::ProjectSnippet
end
params do
requires :snippet_id, type: Integer, desc: 'The ID of a project snippet'
......@@ -99,7 +99,7 @@ def snippets_for_current_user
snippet_params).execute
if snippet.persisted?
present snippet, with: Entities::ProjectSnippetV3
present snippet, with: ::API::V3::Entities::ProjectSnippet
else
render_validation_error!(snippet)
end
......
......@@ -74,32 +74,32 @@ def map_public_to_visibility_level(attrs)
def present_projects(projects, options = {})
options = options.reverse_merge(
with: Entities::Project,
with: ::API::Entities::Project,
current_user: current_user,
simple: params[:simple],
)
projects = filter_projects(projects)
projects = projects.with_statistics if options[:statistics]
options[:with] = Entities::BasicProjectDetails if options[:simple]
options[:with] = ::API::Entities::BasicProjectDetails if options[:simple]
present paginate(projects), options
end
end
desc 'Get a list of visible projects for authenticated user' do
success Entities::BasicProjectDetails
success ::API::Entities::BasicProjectDetails
end
params do
use :collection_params
end
get '/visible' do
entity = current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails
entity = current_user ? ::API::Entities::ProjectWithAccess : ::API::Entities::BasicProjectDetails
present_projects ProjectsFinder.new.execute(current_user), with: entity
end
desc 'Get a projects list for authenticated user' do
success Entities::BasicProjectDetails
success ::API::Entities::BasicProjectDetails
end
params do
use :collection_params
......@@ -108,11 +108,11 @@ def present_projects(projects, options = {})
authenticate!
present_projects current_user.authorized_projects,
with: Entities::ProjectWithAccess
with: ::API::Entities::ProjectWithAccess
end
desc 'Get an owned projects list for authenticated user' do
success Entities::BasicProjectDetails
success ::API::Entities::BasicProjectDetails
end
params do
use :collection_params
......@@ -122,12 +122,12 @@ def present_projects(projects, options = {})
authenticate!
present_projects current_user.owned_projects,
with: Entities::ProjectWithAccess,
with: ::API::Entities::ProjectWithAccess,
statistics: params[:statistics]
end
desc 'Gets starred project for the authenticated user' do
success Entities::BasicProjectDetails
success ::API::Entities::BasicProjectDetails
end
params do
use :collection_params
......@@ -139,7 +139,7 @@ def present_projects(projects, options = {})
end
desc 'Get all projects for admin user' do
success Entities::BasicProjectDetails
success ::API::Entities::BasicProjectDetails
end
params do
use :collection_params
......@@ -148,11 +148,11 @@ def present_projects(projects, options = {})
get '/all' do
authenticated_as_admin!
present_projects Project.all, with: Entities::ProjectWithAccess, statistics: params[:statistics]
present_projects Project.all, with: ::API::Entities::ProjectWithAccess, statistics: params[:statistics]
end
desc 'Search for projects the current user has access to' do
success Entities::Project
success ::API::Entities::Project
end
params do
requires :query, type: String, desc: 'The project name to be searched'
......@@ -164,11 +164,11 @@ def present_projects(projects, options = {})
projects = search_service.objects('projects', params[:page])
projects = projects.reorder(params[:order_by] => params[:sort])
present paginate(projects), with: Entities::Project
present paginate(projects), with: ::API::Entities::Project
end
desc 'Create new project' do
success Entities::Project
success ::API::Entities::Project
end
params do
requires :name, type: String, desc: 'The name of the project'
......@@ -181,7 +181,7 @@ def present_projects(projects, options = {})
project = ::Projects::CreateService.new(current_user, attrs).execute
if project.saved?
present project, with: Entities::Project,
present project, with: ::API::Entities::Project,
user_can_admin_project: can?(current_user, :admin_project, project)
else
if project.errors[:limit_reached].present?
......@@ -192,7 +192,7 @@ def present_projects(projects, options = {})
end
desc 'Create new project for a specified user. Only available to admin users.' do
success Entities::Project
success ::API::Entities::Project
end
params do
requires :name, type: String, desc: 'The name of the project'
......@@ -210,7 +210,7 @@ def present_projects(projects, options = {})
project = ::Projects::CreateService.new(user, attrs).execute
if project.saved?
present project, with: Entities::Project,
present project, with: ::API::Entities::Project,
user_can_admin_project: can?(current_user, :admin_project, project)
else
render_validation_error!(project)
......@@ -223,26 +223,26 @@ def present_projects(projects, options = {})
end
resource :projects, requirements: { id: /[^\/]+/ } do
desc 'Get a single project' do
success Entities::ProjectWithAccess
success ::API::Entities::ProjectWithAccess
end
get ":id" do
entity = current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails
entity = current_user ? ::API::Entities::ProjectWithAccess : ::API::Entities::BasicProjectDetails
present user_project, with: entity, current_user: current_user,
user_can_admin_project: can?(current_user, :admin_project, user_project)
end
desc 'Get events for a single project' do
success Entities::Event
success ::API::Entities::Event
end
params do
use :pagination
end
get ":id/events" do
present paginate(user_project.events.recent), with: Entities::Event
present paginate(user_project.events.recent), with: ::API::Entities::Event
end
desc 'Fork new project for the current user or provided namespace.' do
success Entities::Project
success ::API::Entities::Project
end
params do
optional :namespace, type: String, desc: 'The ID or name of the namespace that the project will be forked into'
......@@ -268,13 +268,13 @@ def present_projects(projects, options = {})
if forked_project.errors.any?
conflict!(forked_project.errors.messages)
else
present forked_project, with: Entities::Project,
present forked_project, with: ::API::Entities::Project,
user_can_admin_project: can?(current_user, :admin_project, forked_project)
end
end
desc 'Update an existing project' do
success Entities::Project
success ::API::Entities::Project
end
params do
optional :name, type: String, desc: 'The name of the project'
......@@ -298,7 +298,7 @@ def present_projects(projects, options = {})
result = ::Projects::UpdateService.new(user_project, current_user, attrs).execute
if result[:status] == :success
present user_project, with: Entities::Project,
present user_project, with: ::API::Entities::Project,
user_can_admin_project: can?(current_user, :admin_project, user_project)
else
render_validation_error!(user_project)
......@@ -306,29 +306,29 @@ def present_projects(projects, options = {})
end
desc 'Archive a project' do
success Entities::Project
success ::API::Entities::Project
end
post ':id/archive' do
authorize!(:archive_project, user_project)
user_project.archive!
present user_project, with: Entities::Project
present user_project, with: ::API::Entities::Project
end
desc 'Unarchive a project' do
success Entities::Project
success ::API::Entities::Project
end
post ':id/unarchive' do
authorize!(:archive_project, user_project)
user_project.unarchive!
present user_project, with: Entities::Project
present user_project, with: ::API::Entities::Project
end
desc 'Star a project' do
success Entities::Project
success ::API::Entities::Project
end
post ':id/star' do
if current_user.starred?(user_project)
......@@ -337,19 +337,19 @@ def present_projects(projects, options = {})
current_user.toggle_star(user_project)
user_project.reload
present user_project, with: Entities::Project
present user_project, with: ::API::Entities::Project
end
end
desc 'Unstar a project' do
success Entities::Project
success ::API::Entities::Project
end
delete ':id/star' do
if current_user.starred?(user_project)
current_user.toggle_star(user_project)
user_project.reload
present user_project, with: Entities::Project
present user_project, with: ::API::Entities::Project
else
not_modified!
end
......@@ -390,7 +390,7 @@ def present_projects(projects, options = {})
end
desc 'Share the project with a group' do
success Entities::ProjectGroupLink
success ::API::Entities::ProjectGroupLink
end
params do
requires :group_id, type: Integer, desc: 'The ID of a group'
......@@ -412,7 +412,7 @@ def present_projects(projects, options = {})
link = user_project.project_group_links.new(declared_params(include_missing: false))
if link.save
present link, with: Entities::ProjectGroupLink
present link, with: ::API::Entities::ProjectGroupLink
else
render_api_error!(link.errors.full_messages.first, 409)
end
......@@ -440,7 +440,7 @@ def present_projects(projects, options = {})
end
desc 'Get the users list of a project' do
success Entities::UserBasic
success ::API::Entities::UserBasic
end
params do
optional :search, type: String, desc: 'Return list of users matching the search criteria'
......@@ -450,7 +450,7 @@ def present_projects(projects, options = {})
users = user_project.team.users
users = users.search(params[:search]) if params[:search].present?