Commit aa543116 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch...

Merge branch '334197-404-for-package-details-link-under-infrastructure-registry-for-projects-nested-under-2-group' into 'master'

Resolve "404 for package details link under Infrastructure Registry for projects nested under 2 group levels"

See merge request gitlab-org/gitlab!64553
parents 22067f14 49382b4c
......@@ -43,7 +43,7 @@ module API
declared(params).slice(:exclude_subgroups, :order_by, :sort, :package_type, :package_name, :include_versionless, :status)
).execute
present paginate(packages), with: ::API::Entities::Package, user: current_user, group: true, namespace: user_group.root_ancestor
present paginate(packages), with: ::API::Entities::Package, user: current_user, group: true, namespace: user_group
end
end
end
......
......@@ -41,7 +41,7 @@ module API
declared_params.slice(:order_by, :sort, :package_type, :package_name, :include_versionless, :status)
).execute
present paginate(packages), with: ::API::Entities::Package, user: current_user, namespace: user_project.root_ancestor
present paginate(packages), with: ::API::Entities::Package, user: current_user, namespace: user_project.namespace
end
desc 'Get a single project package' do
......@@ -55,7 +55,7 @@ module API
package = ::Packages::PackageFinder
.new(user_project, params[:package_id]).execute
present package, with: ::API::Entities::Package, user: current_user, namespace: user_project.root_ancestor
present package, with: ::API::Entities::Package, user: current_user, namespace: user_project.namespace
end
desc 'Remove a package' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::Entities::Package do
let(:package) { create(:generic_package) }
subject { described_class.new(package).as_json(namespace: package.project.namespace) }
it 'exposes correct attributes' do
expect(subject).to include(
:id,
:name,
:version,
:package_type,
:status,
:_links,
:created_at,
:tags,
:versions
)
end
it 'exposes correct web_path in _links' do
expect(subject[:_links][:web_path]).to match('/packages/')
end
context 'with a terraform_module' do
let(:package) { create(:terraform_module_package) }
it 'exposes correct web_path in _links' do
expect(subject[:_links][:web_path]).to match('/infrastructure_registry/')
end
end
end
......@@ -3,8 +3,9 @@
require 'spec_helper'
RSpec.describe API::ProjectPackages do
let(:user) { create(:user) }
let_it_be(:project) { create(:project, :public) }
let(:user) { create(:user) }
let!(:package1) { create(:npm_package, project: project, version: '3.1.0', name: "@#{project.root_namespace.path}/foo1") }
let(:package_url) { "/projects/#{project.id}/packages/#{package1.id}" }
let!(:package2) { create(:nuget_package, project: project, version: '2.0.4') }
......@@ -71,6 +72,20 @@ RSpec.describe API::ProjectPackages do
expect(json_response).to include(a_hash_including('_links' => a_hash_including('web_path' => include('infrastructure_registry'))))
end
end
context 'in nested group' do
let_it_be(:nested_project) { create(:project, :public, :in_subgroup) }
let_it_be(:nested_terraform_module_package) { create(:terraform_module_package, project: nested_project) }
let(:params) { { package_type: :terraform_module } }
let(:url) { "/projects/#{nested_project.id}/packages" }
it 'returns the nested terraform module package with the correct web_path' do
subject
expect(json_response).to include(a_hash_including('_links' => a_hash_including('web_path' => include(nested_project.namespace.full_path))))
end
end
end
context 'project is private' do
......
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