Commit ee4d038a authored by Giorgenes Gelatti's avatar Giorgenes Gelatti

Move package entities to core

Move package entities and specs
to core for the upcoming
move of package features to core.
parent c93986fe
......@@ -107,7 +107,7 @@ module API
conan_package_reference: params[:conan_package_reference]
)
present presenter, with: EE::API::Entities::ConanPackage::ConanPackageSnapshot
present presenter, with: ::API::Entities::ConanPackage::ConanPackageSnapshot
end
desc 'Recipe Snapshot' do
......@@ -119,7 +119,7 @@ module API
presenter = ::Packages::Conan::PackagePresenter.new(recipe, current_user, project)
present presenter, with: EE::API::Entities::ConanPackage::ConanRecipeSnapshot
present presenter, with: ::API::Entities::ConanPackage::ConanRecipeSnapshot
end
# Get the manifest
......@@ -191,7 +191,7 @@ module API
status 200
upload_urls = package_upload_urls(::Packages::Conan::FileMetadatum::PACKAGE_FILES)
present upload_urls, with: EE::API::Entities::ConanPackage::ConanUploadUrls
present upload_urls, with: ::API::Entities::ConanPackage::ConanUploadUrls
end
desc 'Recipe Upload Urls' do
......@@ -204,7 +204,7 @@ module API
status 200
upload_urls = recipe_upload_urls(::Packages::Conan::FileMetadatum::RECIPE_FILES)
present upload_urls, with: EE::API::Entities::ConanPackage::ConanUploadUrls
present upload_urls, with: ::API::Entities::ConanPackage::ConanUploadUrls
end
desc 'Delete Package' do
......
......@@ -17,7 +17,7 @@ module API
resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get all project packages within a group' do
detail 'This feature was introduced in GitLab 12.5'
success EE::API::Entities::Package
success ::API::Entities::Package
end
params do
use :pagination
......@@ -37,7 +37,7 @@ module API
declared(params).slice(:exclude_subgroups, :order_by, :sort, :package_type, :package_name)
).execute
present paginate(packages), with: EE::API::Entities::Package, user: current_user, group: true
present paginate(packages), with: ::API::Entities::Package, user: current_user, group: true
end
end
end
......
......@@ -21,11 +21,11 @@ module API
end
def present_package_download_urls
present_download_urls(EE::API::Entities::ConanPackage::ConanPackageManifest, &:package_urls)
present_download_urls(::API::Entities::ConanPackage::ConanPackageManifest, &:package_urls)
end
def present_recipe_download_urls
present_download_urls(EE::API::Entities::ConanPackage::ConanRecipeManifest, &:recipe_urls)
present_download_urls(::API::Entities::ConanPackage::ConanRecipeManifest, &:recipe_urls)
end
def recipe_upload_urls(file_names)
......
......@@ -27,7 +27,7 @@ module API
desc 'Get all tags for a given an NPM package' do
detail 'This feature was introduced in GitLab 12.7'
success EE::API::Entities::NpmPackageTag
success ::API::Entities::NpmPackageTag
end
params do
requires :package_name, type: String, desc: 'Package name'
......@@ -44,7 +44,7 @@ module API
.execute
present ::Packages::Npm::PackagePresenter.new(package_name, packages),
with: EE::API::Entities::NpmPackageTag
with: ::API::Entities::NpmPackageTag
end
params do
......@@ -118,7 +118,7 @@ module API
.new(project_by_package_name, package_name).execute
present ::Packages::Npm::PackagePresenter.new(package_name, packages),
with: EE::API::Entities::NpmPackage
with: ::API::Entities::NpmPackage
end
end
......
......@@ -72,7 +72,7 @@ module API
track_event('nuget_service_index')
present ::Packages::Nuget::ServiceIndexPresenter.new(authorized_user_project),
with: EE::API::Entities::Nuget::ServiceIndex
with: ::API::Entities::Nuget::ServiceIndex
end
# https://docs.microsoft.com/en-us/nuget/api/package-publish-resource
......@@ -127,7 +127,7 @@ module API
route_setting :authentication, deploy_token_allowed: true
get 'index', format: :json do
present ::Packages::Nuget::PackagesMetadataPresenter.new(find_packages),
with: EE::API::Entities::Nuget::PackagesMetadata
with: ::API::Entities::Nuget::PackagesMetadata
end
desc 'The NuGet Metadata Service - Package name and version level' do
......@@ -139,7 +139,7 @@ module API
route_setting :authentication, deploy_token_allowed: true
get '*package_version', format: :json do
present ::Packages::Nuget::PackageMetadataPresenter.new(find_package),
with: EE::API::Entities::Nuget::PackageMetadata
with: ::API::Entities::Nuget::PackageMetadata
end
end
......@@ -158,7 +158,7 @@ module API
route_setting :authentication, deploy_token_allowed: true
get 'index', format: :json do
present ::Packages::Nuget::PackagesVersionsPresenter.new(find_packages),
with: EE::API::Entities::Nuget::PackagesVersions
with: ::API::Entities::Nuget::PackagesVersions
end
desc 'The NuGet Content Service - content request' do
......@@ -212,7 +212,7 @@ module API
track_event('search_package')
present ::Packages::Nuget::SearchResultsPresenter.new(search),
with: EE::API::Entities::Nuget::SearchResults
with: ::API::Entities::Nuget::SearchResults
end
end
end
......
......@@ -17,7 +17,7 @@ module API
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get all package files' do
detail 'This feature was introduced in GitLab 11.8'
success EE::API::Entities::PackageFile
success ::API::Entities::PackageFile
end
params do
use :pagination
......@@ -26,7 +26,7 @@ module API
package = ::Packages::PackageFinder
.new(user_project, params[:package_id]).execute
present paginate(package.package_files), with: EE::API::Entities::PackageFile
present paginate(package.package_files), with: ::API::Entities::PackageFile
end
end
end
......
......@@ -16,7 +16,7 @@ module API
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get all project packages' do
detail 'This feature was introduced in GitLab 11.8'
success EE::API::Entities::Package
success ::API::Entities::Package
end
params do
use :pagination
......@@ -35,12 +35,12 @@ module API
declared_params.slice(:order_by, :sort, :package_type, :package_name)
).execute
present paginate(packages), with: EE::API::Entities::Package, user: current_user
present paginate(packages), with: ::API::Entities::Package, user: current_user
end
desc 'Get a single project package' do
detail 'This feature was introduced in GitLab 11.9'
success EE::API::Entities::Package
success ::API::Entities::Package
end
params do
requires :package_id, type: Integer, desc: 'The ID of a package'
......@@ -49,7 +49,7 @@ module API
package = ::Packages::PackageFinder
.new(user_project, params[:package_id]).execute
present package, with: EE::API::Entities::Package, user: current_user
present package, with: ::API::Entities::Package, user: current_user
end
desc 'Remove a package' do
......
# frozen_string_literal: true
module EE
module API
module Entities
module ConanPackage
class ConanPackageManifest < Grape::Entity
expose :package_urls, merge: true
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module ConanPackage
class ConanPackageSnapshot < Grape::Entity
expose :package_snapshot, merge: true
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module ConanPackage
class ConanRecipeManifest < Grape::Entity
expose :recipe_urls, merge: true
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module ConanPackage
class ConanRecipeSnapshot < Grape::Entity
expose :recipe_snapshot, merge: true
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module ConanPackage
class ConanUploadUrls < Grape::Entity
expose :upload_urls, merge: true
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module EntityHelpers
def can_read(attr, &block)
->(obj, opts) { Ability.allowed?(opts[:user], "read_#{attr}".to_sym, yield(obj)) }
end
def can_destroy(attr, &block)
->(obj, opts) { Ability.allowed?(opts[:user], "destroy_#{attr}".to_sym, yield(obj)) }
end
def expose_restricted(attr, &block)
expose attr, if: can_read(attr, &block)
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Nuget
class Dependency < Grape::Entity
expose :id, as: :@id
expose :type, as: :@type
expose :name, as: :id
expose :range
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Nuget
class DependencyGroup < Grape::Entity
expose :id, as: :@id
expose :type, as: :@type
expose :target_framework, as: :targetFramework, expose_nil: false
expose :dependencies, using: EE::API::Entities::Nuget::Dependency
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Nuget
class Metadatum < Grape::Entity
expose :project_url, as: :projectUrl, expose_nil: false
expose :license_url, as: :licenseUrl, expose_nil: false
expose :icon_url, as: :iconUrl, expose_nil: false
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Nuget
class PackageMetadata < Grape::Entity
expose :json_url, as: :@id
expose :archive_url, as: :packageContent
expose :catalog_entry, as: :catalogEntry, using: EE::API::Entities::Nuget::PackageMetadataCatalogEntry
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Nuget
class PackageMetadataCatalogEntry < Grape::Entity
expose :json_url, as: :@id
expose :authors
expose :dependency_groups, as: :dependencyGroups, using: EE::API::Entities::Nuget::DependencyGroup
expose :package_name, as: :id
expose :package_version, as: :version
expose :tags
expose :archive_url, as: :packageContent
expose :summary
expose :metadatum, using: EE::API::Entities::Nuget::Metadatum, merge: true
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Nuget
class PackagesMetadata < Grape::Entity
expose :count
expose :items, using: EE::API::Entities::Nuget::PackagesMetadataItem
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Nuget
class PackagesMetadataItem < Grape::Entity
expose :json_url, as: :@id
expose :lower_version, as: :lower
expose :upper_version, as: :upper
expose :packages_count, as: :count
expose :packages, as: :items, using: EE::API::Entities::Nuget::PackageMetadata
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Nuget
class PackagesVersions < Grape::Entity
expose :versions
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Nuget
class SearchResult < Grape::Entity
expose :type, as: :@type
expose :authors
expose :name, as: :id
expose :name, as: :title
expose :summary
expose :total_downloads, as: :totalDownloads
expose :verified
expose :version
expose :versions, using: EE::API::Entities::Nuget::SearchResultVersion
expose :tags
expose :metadatum, using: EE::API::Entities::Nuget::Metadatum, merge: true
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Nuget
class SearchResultVersion < Grape::Entity
expose :json_url, as: :@id
expose :version
expose :downloads
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Nuget
class SearchResults < Grape::Entity
expose :total_count, as: :totalHits
expose :data, using: EE::API::Entities::Nuget::SearchResult
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Nuget
class ServiceIndex < Grape::Entity
expose :version
expose :resources
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class Package < Grape::Entity
include ::API::Helpers::RelatedResourcesHelpers
extend EntityHelpers
expose :id
expose :name
expose :version
expose :package_type
expose :_links do
expose :web_path do |package|
::Gitlab::Routing.url_helpers.project_package_path(package.project, package)
end
expose :delete_api_path, if: can_destroy(:package, &:project) do |package|
expose_url api_v4_projects_packages_path(package_id: package.id, id: package.project_id)
end
end
expose :created_at
expose :project_id, if: ->(_, opts) { opts[:group] }
expose :project_path, if: ->(obj, opts) { opts[:group] && Ability.allowed?(opts[:user], :read_project, obj.project) }
expose :tags
expose :pipeline, if: ->(package) { package.build_info }, using: Package::Pipeline
expose :versions, using: ::EE::API::Entities::PackageVersion
private
def project_path
object.project.full_path
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class Package < Grape::Entity
class Pipeline < ::API::Entities::PipelineBasic
expose :user, using: ::API::Entities::UserBasic
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class PackageFile < Grape::Entity
expose :id, :package_id, :created_at
expose :file_name, :size
expose :file_md5, :file_sha1
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class PackageVersion < Grape::Entity
expose :id
expose :version
expose :created_at
expose :tags
expose :pipeline, if: ->(package) { package.build_info }, using: Package::Pipeline
end
end
end
end
......@@ -4,7 +4,7 @@ module EE
module API
module Entities
class ProjectPushRule < Grape::Entity
extend EntityHelpers
extend ::API::Entities::EntityHelpers
expose :id, :project_id, :created_at
expose :commit_message_regex, :commit_message_negative_regex, :branch_name_regex, :deny_delete_tag
expose :member_check, :prevent_secrets, :author_email_regex
......
# frozen_string_literal: true
module API
module Entities
module ConanPackage
class ConanPackageManifest < Grape::Entity
expose :package_urls, merge: true
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module ConanPackage
class ConanPackageSnapshot < Grape::Entity
expose :package_snapshot, merge: true
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module ConanPackage
class ConanRecipeManifest < Grape::Entity
expose :recipe_urls, merge: true
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module ConanPackage
class ConanRecipeSnapshot < Grape::Entity
expose :recipe_snapshot, merge: true
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module ConanPackage
class ConanUploadUrls < Grape::Entity
expose :upload_urls, merge: true
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module EntityHelpers
def can_read(attr, &block)
->(obj, opts) { Ability.allowed?(opts[:user], "read_#{attr}".to_sym, yield(obj)) }
end
def can_destroy(attr, &block)
->(obj, opts) { Ability.allowed?(opts[:user], "destroy_#{attr}".to_sym, yield(obj)) }
end
def expose_restricted(attr, &block)
expose attr, if: can_read(attr, &block)
end
end
end
end
# frozen_string_literal: true
module API
module Entities
class NpmPackage < Grape::Entity
expose :name
expose :versions
expose :dist_tags, as: 'dist-tags'
end
end
end
# frozen_string_literal: true
module API
module Entities
class NpmPackageTag < Grape::Entity
expose :dist_tags, merge: true
end
end
end
# frozen_string_literal: true
module API
module Entities
module Nuget
class Dependency < Grape::Entity
expose :id, as: :@id
expose :type, as: :@type
expose :name, as: :id
expose :range
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Nuget
class DependencyGroup < Grape::Entity
expose :id, as: :@id
expose :type, as: :@type
expose :target_framework, as: :targetFramework, expose_nil: false
expose :dependencies, using: ::API::Entities::Nuget::Dependency
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Nuget
class Metadatum < Grape::Entity
expose :project_url, as: :projectUrl, expose_nil: false
expose :license_url, as: :licenseUrl, expose_nil: false
expose :icon_url, as: :iconUrl, expose_nil: false
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Nuget
class PackageMetadata < Grape::Entity
expose :json_url, as: :@id
expose :archive_url, as: :packageContent
expose :catalog_entry, as: :catalogEntry, using: ::API::Entities::Nuget::PackageMetadataCatalogEntry
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Nuget
class PackageMetadataCatalogEntry < Grape::Entity
expose :json_url, as: :@id
expose :authors
expose :dependency_groups, as: :dependencyGroups, using: ::API::Entities::Nuget::DependencyGroup
expose :package_name, as: :id
expose :package_version, as: :version
expose :tags
expose :archive_url, as: :packageContent
expose :summary
expose :metadatum, using: ::API::Entities::Nuget::Metadatum, merge: true
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Nuget
class PackagesMetadata < Grape::Entity
expose :count
expose :items, using: ::API::Entities::Nuget::PackagesMetadataItem
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Nuget
class PackagesMetadataItem < Grape::Entity
expose :json_url, as: :@id
expose :lower_version, as: :lower
expose :upper_version, as: :upper
expose :packages_count, as: :count
expose :packages, as: :items, using: ::API::Entities::Nuget::PackageMetadata
end
end
end
end
# frozen_string_literal: true
module EE
module API
module API
module Entities
class NpmPackage < Grape::Entity
expose :name
module Nuget
class PackagesVersions < Grape::Entity
expose :versions
expose :dist_tags, as: 'dist-tags'
end
end
end
......
# frozen_string_literal: true
module API
module Entities
module Nuget
class SearchResult < Grape::Entity
expose :type, as: :@type
expose :authors
expose :name, as: :id
expose :name, as: :title
expose :summary
expose :total_downloads, as: :totalDownloads
expose :verified
expose :version
expose :versions, using: ::API::Entities::Nuget::SearchResultVersion
expose :tags
expose :metadatum, using: ::API::Entities::Nuget::Metadatum, merge: true
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Nuget
class SearchResultVersion < Grape::Entity
expose :json_url, as: :@id
expose :version
expose :downloads
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Nuget
class SearchResults < Grape::Entity
expose :total_count, as: :totalHits
expose :data, using: ::API::Entities::Nuget::SearchResult
end
end
end
end
# frozen_string_literal: true
module EE
module API
module API
module Entities
class NpmPackageTag < Grape::Entity
expose :dist_tags, merge: true
module Nuget
class ServiceIndex < Grape::Entity
expose :version
expose :resources
end
end
end
......
# frozen_string_literal: true
module API
module Entities
class Package < Grape::Entity
include ::API::Helpers::RelatedResourcesHelpers
extend ::API::Entities::EntityHelpers
expose :id
expose :name
expose :version
expose :package_type
expose :_links do
expose :web_path do |package|
::Gitlab::Routing.url_helpers.project_package_path(package.project, package)
end
expose :delete_api_path, if: can_destroy(:package, &:project) do |package|
expose_url api_v4_projects_packages_path(package_id: package.id, id: package.project_id)
end
end
expose :created_at
expose :project_id, if: ->(_, opts) { opts[:group] }
expose :project_path, if: ->(obj, opts) { opts[:group] && Ability.allowed?(opts[:user], :read_project, obj.project) }
expose :tags
expose :pipeline, if: ->(package) { package.build_info }, using: Package::Pipeline
expose :versions, using: ::API::Entities::PackageVersion
private
def project_path
object.project.full_path
end
end
end
end
# frozen_string_literal: true
module API
module Entities
class Package < Grape::Entity
class Pipeline < ::API::Entities::PipelineBasic
expose :user, using: ::API::Entities::UserBasic
end
end
end
end
# frozen_string_literal: true
module API
module Entities
class PackageFile < Grape::Entity
expose :id, :package_id, :created_at
expose :file_name, :size
expose :file_md5, :file_sha1
end
end
end
# frozen_string_literal: true
module API
module Entities
class PackageVersion < Grape::Entity
expose :id
expose :version
expose :created_at
expose :tags
expose :pipeline, if: ->(package) { package.build_info }, using: Package::Pipeline
end
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe EE::API::Entities::Nuget::DependencyGroup do
RSpec.describe API::Entities::Nuget::DependencyGroup do
let(:dependency_group) do
{
id: 'http://gitlab.com/Sandbox.App/1.0.0.json#dependencygroup',
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe EE::API::Entities::Nuget::Dependency do
RSpec.describe API::Entities::Nuget::Dependency do
let(:dependency) do
{
id: 'http://gitlab.com/Sandbox.App/1.0.0.json#dependency',
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe EE::API::Entities::Nuget::Metadatum do
RSpec.describe API::Entities::Nuget::Metadatum do
let(:metadatum) do
{
project_url: 'http://sandbox.com/project',
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe EE::API::Entities::Nuget::PackageMetadataCatalogEntry do
RSpec.describe API::Entities::Nuget::PackageMetadataCatalogEntry do
let(:entry) do
{
json_url: 'http://sandbox.com/json/package',
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe EE::API::Entities::Nuget::SearchResult do
RSpec.describe API::Entities::Nuget::SearchResult do
let(:search_result) do
{
type: 'Package',
......
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