Skip to content
代码片段 群组 项目
提交 b591eb9c 编辑于 作者: Kassio Borges's avatar Kassio Borges
浏览文件

Merge branch '387822-add-public-package-field-to-package-details-graphql' into 'master'

No related branches found
No related tags found
无相关合并请求
......@@ -28,6 +28,8 @@ class PackageDetailsType < PackageType
field :last_downloaded_at, Types::TimeType, null: true, description: 'Last time that a file of this package was downloaded.'
field :public_package, GraphQL::Types::Boolean, null: true, description: 'Indicates if there is public access to the package.'
def versions
object.versions
end
......@@ -63,6 +65,10 @@ def pypi_setup_url
def pypi_url
pypi_registry_url(object.project.id)
end
def public_package
object.project.public? || object.project.project_feature.package_registry_access_level == ProjectFeature::PUBLIC
end
end
end
end
......@@ -17152,6 +17152,7 @@ Represents a package details in the Package Registry.
| <a id="packagedetailstypepackagetype"></a>`packageType` | [`PackageTypeEnum!`](#packagetypeenum) | Package type. |
| <a id="packagedetailstypepipelines"></a>`pipelines` | [`PipelineConnection`](#pipelineconnection) | Pipelines that built the package. Max page size 20. (see [Connections](#connections)) |
| <a id="packagedetailstypeproject"></a>`project` | [`Project!`](#project) | Project where the package is stored. |
| <a id="packagedetailstypepublicpackage"></a>`publicPackage` | [`Boolean`](#boolean) | Indicates if there is public access to the package. |
| <a id="packagedetailstypepypisetupurl"></a>`pypiSetupUrl` | [`String`](#string) | Url of the PyPi project setup endpoint. |
| <a id="packagedetailstypepypiurl"></a>`pypiUrl` | [`String`](#string) | Url of the PyPi project endpoint. |
| <a id="packagedetailstypestatus"></a>`status` | [`PackageStatus!`](#packagestatus) | Package status. |
......@@ -9,6 +9,7 @@
"version",
"packageType",
"project",
"publicPackage",
"tags",
"pipelines",
"versions",
......@@ -31,13 +32,20 @@
"type": "string"
},
"version": {
"type": ["string", "null"]
"type": [
"string",
"null"
]
},
"canDestroy": {
"type": ["boolean"]
"type": [
"boolean"
]
},
"packageType": {
"type": ["string"],
"type": [
"string"
],
"enum": [
"MAVEN",
"NPM",
......@@ -56,66 +64,126 @@
"type": "object",
"additionalProperties": false,
"properties": {
"count": { "type": "integer" },
"pageInfo": { "type": "object" },
"edges": { "type": "array" },
"nodes": { "type": "array" }
"count": {
"type": "integer"
},
"pageInfo": {
"type": "object"
},
"edges": {
"type": "array"
},
"nodes": {
"type": "array"
}
}
},
"project": {
"type": "object"
},
"publicPackage": {
"type": "boolean"
},
"pipelines": {
"type": "object",
"additionalProperties": false,
"properties": {
"pageInfo": { "type": "object" },
"count": { "type": "integer" },
"edges": { "type": "array" },
"nodes": { "type": "array" }
"pageInfo": {
"type": "object"
},
"count": {
"type": "integer"
},
"edges": {
"type": "array"
},
"nodes": {
"type": "array"
}
}
},
"versions": {
"type": "object",
"additionalProperties": false,
"properties": {
"count": { "type": "integer" },
"pageInfo": { "type": "object" },
"edges": { "type": "array" },
"nodes": { "type": "array" }
"count": {
"type": "integer"
},
"pageInfo": {
"type": "object"
},
"edges": {
"type": "array"
},
"nodes": {
"type": "array"
}
}
},
"metadata": {
"anyOf": [
{ "$ref": "./package_composer_metadata.json" },
{ "$ref": "./package_conan_metadata.json" },
{ "$ref": "./package_maven_metadata.json" },
{ "$ref": "./package_nuget_metadata.json" },
{ "$ref": "./package_pypi_metadata.json" },
{ "type": "null" }
{
"$ref": "./package_composer_metadata.json"
},
{
"$ref": "./package_conan_metadata.json"
},
{
"$ref": "./package_maven_metadata.json"
},
{
"$ref": "./package_nuget_metadata.json"
},
{
"$ref": "./package_pypi_metadata.json"
},
{
"type": "null"
}
]
},
"packageFiles": {
"type": "object",
"additionalProperties": false,
"properties": {
"count": { "type": "integer" },
"pageInfo": { "type": "object" },
"edges": { "type": "array" },
"nodes": { "type": "array" }
"count": {
"type": "integer"
},
"pageInfo": {
"type": "object"
},
"edges": {
"type": "array"
},
"nodes": {
"type": "array"
}
}
},
"status": {
"type": ["string"],
"enum": ["DEFAULT", "HIDDEN", "PROCESSING", "ERROR"]
"type": [
"string"
],
"enum": [
"DEFAULT",
"HIDDEN",
"PROCESSING",
"ERROR"
]
},
"dependencyLinks": {
"type": "object",
"additionalProperties": false,
"properties": {
"pageInfo": { "type": "object" },
"edges": { "type": "array" },
"count": { "type": "integer" },
"pageInfo": {
"type": "object"
},
"edges": {
"type": "array"
},
"count": {
"type": "integer"
},
"nodes": {
"type": "array",
"items": {
......@@ -143,8 +211,12 @@
},
"metadata": {
"anyOf": [
{ "$ref": "./package_nuget_dependency_link_metadata.json" },
{ "type": "null" }
{
"$ref": "./package_nuget_dependency_link_metadata.json"
},
{
"type": "null"
}
]
}
}
......@@ -177,14 +249,20 @@
"type": "string"
},
"lastDownloadedAt": {
"type": ["string", "null"]
"type": [
"string",
"null"
]
},
"_links": {
"type": "object",
"additionalProperties": false,
"properties": {
"webPath": {
"type": ["string", "null"]
"type": [
"string",
"null"
]
}
}
}
......
......@@ -10,7 +10,7 @@
it 'includes all the package fields' do
expected_fields = %w[
id name version created_at updated_at package_type tags project
pipelines versions package_files dependency_links
pipelines versions package_files dependency_links public_package
npm_url maven_url conan_url nuget_url pypi_url pypi_setup_url
composer_url composer_config_repository_url
]
......
......@@ -41,6 +41,7 @@
context 'with unauthorized user' do
before do
project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
project.add_guest(user)
end
it 'returns no packages' do
......@@ -48,6 +49,47 @@
expect(graphql_data_at(:package)).to be_nil
end
context 'with access to package registry for everyone' do
before do
project.project_feature.update!(package_registry_access_level: ProjectFeature::PUBLIC)
subject
end
it_behaves_like 'a working graphql query' do
it 'matches the JSON schema' do
expect(package_details).to match_schema('graphql/packages/package_details')
end
end
it '`public_package` returns true' do
expect(graphql_data_at(:package, :public_package)).to eq(true)
end
end
end
context 'when project is public' do
let_it_be(:public_project) { create(:project, :public, group: group) }
let_it_be(:composer_package) { create(:composer_package, project: public_project) }
let(:package_global_id) { global_id_of(composer_package) }
before do
subject
end
it_behaves_like 'a working graphql query' do
before do
subject
end
it 'matches the JSON schema' do
expect(package_details).to match_schema('graphql/packages/package_details')
end
end
it '`public_package` returns true' do
expect(graphql_data_at(:package, :public_package)).to eq(true)
end
end
context 'with authorized user' do
......@@ -250,6 +292,49 @@ def run_query(args)
end
end
context 'public_package' do
context 'when project is private' do
let_it_be(:private_project) { create(:project, :private, group: group) }
let_it_be(:composer_package) { create(:composer_package, project: private_project) }
let(:package_global_id) { global_id_of(composer_package) }
before do
private_project.add_developer(user)
end
it 'returns false' do
subject
expect(graphql_data_at(:package, :public_package)).to eq(false)
end
context 'with access to package registry for everyone' do
before do
private_project.project_feature.update!(package_registry_access_level: ProjectFeature::PUBLIC)
subject
end
it 'returns true' do
expect(graphql_data_at(:package, :public_package)).to eq(true)
end
end
end
context 'when project is public' do
let_it_be(:public_project) { create(:project, :public, group: group) }
let_it_be(:composer_package) { create(:composer_package, project: public_project) }
let(:package_global_id) { global_id_of(composer_package) }
before do
subject
end
it 'returns true' do
expect(graphql_data_at(:package, :public_package)).to eq(true)
end
end
end
context 'with package that has no default status' do
before do
composer_package.update!(status: :error)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册