Commit 36ca9057 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Hide packages without version from packages UI

Because almost all package managers require version to be present. The
only case when we have package without version is maven metadata one. So
we should be safe just by hiding one.
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 9465fbbe
......@@ -8,7 +8,7 @@ module Projects
before_action :authorize_destroy_package!, only: [:destroy]
def index
@packages = project.packages.all.page(params[:page])
@packages = project.packages.has_version.page(params[:page])
end
def show
......
......@@ -15,6 +15,7 @@ class Packages::Package < ActiveRecord::Base
enum package_type: { maven: 1, npm: 2 }
scope :with_name, ->(name) { where(name: name) }
scope :has_version, -> { where.not(version: nil) }
scope :preload_files, -> { preload(:package_files) }
scope :last_of_each_version, -> { where(id: all.select('MAX(id) AS id').group(:version)) }
......
---
title: Hide packages without version from UI
merge_request: 9151
author:
type: fixed
......@@ -56,6 +56,14 @@ describe 'Packages' do
expect(page).to have_content(package.version)
end
it 'hides a package without a version from the list' do
package.update!(version: nil)
visit_project_packages
expect(page).not_to have_content(package.name)
end
it 'shows a single package' do
click_on package.name
......
......@@ -44,4 +44,16 @@ RSpec.describe Packages::Package, type: :model do
is_expected.not_to include(package2)
end
end
describe '.has_version' do
let!(:package1) { create(:npm_package, version: '1.0.0') }
let!(:package2) { create(:npm_package, version: nil) }
let!(:package3) { create(:npm_package, version: '1.0.1') }
subject { described_class.has_version }
it 'includes only packages with version attribute' do
is_expected.to match_array([package1, package3])
end
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