Commit 49382b4c authored by Matt Kasa's avatar Matt Kasa

Fix infrastructure registry package details links

Changelog: fixed

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/334197
parent 36a6d04a
...@@ -43,7 +43,7 @@ module API ...@@ -43,7 +43,7 @@ module API
declared(params).slice(:exclude_subgroups, :order_by, :sort, :package_type, :package_name, :include_versionless, :status) declared(params).slice(:exclude_subgroups, :order_by, :sort, :package_type, :package_name, :include_versionless, :status)
).execute ).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 end
end end
......
...@@ -41,7 +41,7 @@ module API ...@@ -41,7 +41,7 @@ module API
declared_params.slice(:order_by, :sort, :package_type, :package_name, :include_versionless, :status) declared_params.slice(:order_by, :sort, :package_type, :package_name, :include_versionless, :status)
).execute ).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 end
desc 'Get a single project package' do desc 'Get a single project package' do
...@@ -55,7 +55,7 @@ module API ...@@ -55,7 +55,7 @@ module API
package = ::Packages::PackageFinder package = ::Packages::PackageFinder
.new(user_project, params[:package_id]).execute .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 end
desc 'Remove a package' do 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 @@ ...@@ -3,8 +3,9 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe API::ProjectPackages do RSpec.describe API::ProjectPackages do
let(:user) { create(:user) }
let_it_be(:project) { create(:project, :public) } 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!(: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(:package_url) { "/projects/#{project.id}/packages/#{package1.id}" }
let!(:package2) { create(:nuget_package, project: project, version: '2.0.4') } let!(:package2) { create(:nuget_package, project: project, version: '2.0.4') }
...@@ -71,6 +72,20 @@ RSpec.describe API::ProjectPackages do ...@@ -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')))) expect(json_response).to include(a_hash_including('_links' => a_hash_including('web_path' => include('infrastructure_registry'))))
end end
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 end
context 'project is private' do 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