Commit 2621790e authored by James Lopez's avatar James Lopez

Merge branch '323418-update-terraform-module-path' into 'master'

Return new infrastructure registry path for package details

See merge request gitlab-org/gitlab!63685
parents 3b1d5351 4390e6a2
......@@ -269,6 +269,10 @@ class Packages::Package < ApplicationRecord
tags.pluck(:name)
end
def infrastructure_package?
terraform_module?
end
def debian_incoming?
debian? && version.nil?
end
......
......@@ -25,8 +25,12 @@ module API
expose :status
expose :_links do
expose :web_path do |package|
::Gitlab::Routing.url_helpers.project_package_path(package.project, package)
expose :web_path do |package, opts|
if package.infrastructure_package?
::Gitlab::Routing.url_helpers.namespace_project_infrastructure_registry_path(opts[:namespace], package.project, package)
else
::Gitlab::Routing.url_helpers.project_package_path(package.project, package)
end
end
expose :delete_api_path, if: can_destroy(:package, &:project) do |package|
......
......@@ -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
present paginate(packages), with: ::API::Entities::Package, user: current_user, group: true, namespace: user_group.root_ancestor
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
present paginate(packages), with: ::API::Entities::Package, user: current_user, namespace: user_project.root_ancestor
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
present package, with: ::API::Entities::Package, user: current_user, namespace: user_project.root_ancestor
end
desc 'Remove a package' do
......
......@@ -897,6 +897,26 @@ RSpec.describe Packages::Package, type: :model do
end
end
describe '#infrastructure_package?' do
let(:package) { create(:package) }
subject { package.infrastructure_package? }
it { is_expected.to eq(false) }
context 'with generic package' do
let(:package) { create(:generic_package) }
it { is_expected.to eq(false) }
end
context 'with terraform module package' do
let(:package) { create(:terraform_module_package) }
it { is_expected.to eq(true) }
end
end
describe 'plan_limits' do
Packages::Package.package_types.keys.without('composer').each do |pt|
plan_limit_name = if pt == 'generic'
......
......@@ -40,10 +40,36 @@ RSpec.describe API::ProjectPackages do
context 'with terraform module package' do
let_it_be(:terraform_module_package) { create(:terraform_module_package, project: project) }
it 'filters out terraform module packages when no package_type filter is set' do
subject
context 'when no package_type filter is set' do
let(:params) { {} }
it 'filters out terraform module packages' do
subject
expect(json_response).not_to include(a_hash_including('package_type' => 'terraform_module'))
end
it 'returns packages with the package registry web_path' do
subject
expect(json_response).to include(a_hash_including('_links' => a_hash_including('web_path' => include('packages'))))
end
end
context 'when package_type filter is set to terraform_module' do
let(:params) { { package_type: :terraform_module } }
expect(json_response).not_to include(a_hash_including('package_type' => 'terraform_module'))
it 'returns the terraform module package' do
subject
expect(json_response).to include(a_hash_including('package_type' => 'terraform_module'))
end
it 'returns the terraform module package with the infrastructure registry web_path' do
subject
expect(json_response).to include(a_hash_including('_links' => a_hash_including('web_path' => include('infrastructure_registry'))))
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