Commit e0ca0ef3 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor npm related code based on review

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 7e619f68
...@@ -128,8 +128,8 @@ created in snippets, wikis, and repos. ...@@ -128,8 +128,8 @@ created in snippets, wikis, and repos.
- [Default labels](../user/admin_area/labels.html): Create labels that will be automatically added to every new project. - [Default labels](../user/admin_area/labels.html): Create labels that will be automatically added to every new project.
- [Restrict the use of public or internal projects](../public_access/public_access.md#restricting-the-use-of-public-or-internal-projects): Restrict the use of visibility levels for users when they create a project or a snippet. - [Restrict the use of public or internal projects](../public_access/public_access.md#restricting-the-use-of-public-or-internal-projects): Restrict the use of visibility levels for users when they create a project or a snippet.
- [Custom project templates](../user/admin_area/custom_project_templates.md): Configure a set of projects to be used as custom templates when creating a new project. **[PREMIUM ONLY]** - [Custom project templates](../user/admin_area/custom_project_templates.md): Configure a set of projects to be used as custom templates when creating a new project. **[PREMIUM ONLY]**
- [Maven Repository](maven_repository.md): Enable Maven Repository within GitLab. - [Maven Repository](maven_repository.md): Enable Maven Repository within GitLab. **[PREMIUM ONLY]**
- [NPM Registry](npm_registry.md): Enable NPM Registry within GitLab. - [NPM Registry](npm_registry.md): Enable NPM Registry within GitLab. **[PREMIUM ONLY]**
### Repository settings ### Repository settings
......
...@@ -16,6 +16,7 @@ class Packages::Package < ActiveRecord::Base ...@@ -16,6 +16,7 @@ class Packages::Package < ActiveRecord::Base
scope :with_name, ->(name) { where(name: name) } scope :with_name, ->(name) { where(name: name) }
scope :preload_files, -> { preload(:package_files) } scope :preload_files, -> { preload(:package_files) }
scope :last_of_each_version, -> { where(id: all.select('MAX(id) AS id').group(:version)) }
def self.for_projects(projects) def self.for_projects(projects)
return none unless projects.any? return none unless projects.any?
...@@ -32,8 +33,4 @@ class Packages::Package < ActiveRecord::Base ...@@ -32,8 +33,4 @@ class Packages::Package < ActiveRecord::Base
.joins(:package_files) .joins(:package_files)
.where(packages_package_files: { file_name: file_name }).last! .where(packages_package_files: { file_name: file_name }).last!
end end
def self.last_of_each_version
where(id: all.select('MAX(id) AS id').group(:version))
end
end end
# frozen_string_literal: true # frozen_string_literal: true
class NpmPackagePresenter class NpmPackagePresenter
include API::Helpers::RelatedResourcesHelpers
attr_reader :project, :name, :packages attr_reader :project, :name, :packages
def initialize(project, name, packages) def initialize(project, name, packages)
...@@ -37,8 +39,8 @@ class NpmPackagePresenter ...@@ -37,8 +39,8 @@ class NpmPackagePresenter
end end
def tarball_url(package, package_file) def tarball_url(package, package_file)
"#{Gitlab.config.gitlab.url}/api/v4/projects/" \ expose_url "#{api_v4_projects_path(id: package.project_id)}" \
"#{package.project_id}/packages/npm/#{package.name}" \ "/packages/npm/#{package.name}" \
"/-/#{package_file.file_name}" "/-/#{package_file.file_name}"
end end
end end
...@@ -81,6 +81,7 @@ module API ...@@ -81,6 +81,7 @@ module API
end end
params do params do
requires :package_name, type: String, desc: 'Package name' requires :package_name, type: String, desc: 'Package name'
requires :versions, type: Hash, desc: 'Package version info'
end end
put ':id/packages/npm/:package_name', requirements: NPM_ENDPOINT_REQUIREMENTS do put ':id/packages/npm/:package_name', requirements: NPM_ENDPOINT_REQUIREMENTS do
authorize_create_package! authorize_create_package!
......
...@@ -58,7 +58,7 @@ FactoryBot.define do ...@@ -58,7 +58,7 @@ FactoryBot.define do
trait(:npm) do trait(:npm) do
file { fixture_file_upload('ee/spec/fixtures/npm/foo-1.0.1.tgz') } file { fixture_file_upload('ee/spec/fixtures/npm/foo-1.0.1.tgz') }
file_name 'foo-1.0.1.tgz' file_name 'foo-1.0.1.tgz'
file_sha1 'f572d396fae9206628714fb2ce00f72e94f2258f' file_sha1 'be93151dc23ac34a82752444556fe79b32c7a1ad'
file_type 'tgz' file_type 'tgz'
end end
......
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