Commit fbdd411e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve npm packages code according to review

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 14e80d14
......@@ -3,7 +3,7 @@
> Introduced in [GitLab Premium](https://about.gitlab.com/pricing/) 11.7.
With the GitLab NPM Registry, every
project can have its own space to store its NPM packages.
project can have its own space to store NPM packages.
![GitLab NPM Registry](img/npm_package_view.png)
......@@ -40,7 +40,7 @@ Note that **only packages that have the same path as the project** are supported
## Authenticating to the GitLab NPM Registry
If a project is private or you want to upload NPM package to GitLab,
credentials will need to be provided for authorization. Support is available for
credentials will need to be provided for authentication. Support is available for
[oauth tokens](#authenticating-with-an-oauth-token) only.
### Authenticating with an oauth token
......
......@@ -15,7 +15,7 @@ class Packages::NpmPackagesFinder
def packages
project.packages
.only_npm
.npm
.with_name(package_name)
.last_of_each_version
.preload_files
......
......@@ -15,7 +15,6 @@ class Packages::Package < ActiveRecord::Base
enum package_type: { maven: 1, npm: 2 }
scope :with_name, ->(name) { where(name: name) }
scope :only_npm, -> { where(package_type: 'npm') }
scope :preload_files, -> { preload(:package_files) }
def self.for_projects(projects)
......@@ -29,7 +28,7 @@ class Packages::Package < ActiveRecord::Base
end
def self.by_name_and_file_name(name, file_name)
where(name: name)
with_name(name)
.joins(:package_files)
.where(packages_package_files: { file_name: file_name }).last!
end
......
......@@ -67,7 +67,7 @@ module API
get ':id/packages/npm/*package_name/-/*file_name', format: false do
authorize_download_package!
package = user_project.packages.only_npm
package = user_project.packages.npm
.by_name_and_file_name(params[:package_name], params[:file_name])
package_file = ::Packages::PackageFileFinder
......
......@@ -19,4 +19,16 @@ describe Gitlab::Regex do
it { is_expected.not_to match('my feature flag') }
it { is_expected.not_to match('!!()()') }
end
describe '.package_name_regex' do
subject { described_class.package_name_regex }
it { is_expected.to match('123') }
it { is_expected.to match('foo') }
it { is_expected.to match('foo/bar') }
it { is_expected.to match('@foo/bar') }
it { is_expected.not_to match('$foo/bar') }
it { is_expected.not_to match('my package name') }
it { is_expected.not_to match('!!()()') }
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