diff --git a/app/graphql/types/packages/package_base_type.rb b/app/graphql/types/packages/package_base_type.rb index 1ab04223f7701e73f9d6202e001b7020a565b969..6ee5c31b8353b67be122d01ef59d4029b716170b 100644 --- a/app/graphql/types/packages/package_base_type.rb +++ b/app/graphql/types/packages/package_base_type.rb @@ -23,12 +23,18 @@ class PackageBaseType < ::Types::BaseObject field :name, GraphQL::Types::String, null: false, description: 'Name of the package.' field :package_protection_rule_exists, GraphQL::Types::Boolean, null: false, - alpha: { milestone: '16.11' }, + deprecated: { reason: 'Use `protectionRuleExists`', milestone: '17.0' }, description: 'Whether any matching package protection rule exists for this package. ' \ 'Available only when feature flag `packages_protected_packages` is enabled.' field :package_type, Types::Packages::PackageTypeEnum, null: false, description: 'Package type.' field :project, Types::ProjectType, null: false, description: 'Project where the package is stored.' + field :protection_rule_exists, GraphQL::Types::Boolean, + null: false, + alpha: { milestone: '17.0' }, + description: + 'Whether any matching package protection rule exists for this package. ' \ + 'Available only when feature flag `packages_protected_packages` is enabled.' field :status, Types::Packages::PackageStatusEnum, null: false, description: 'Package status.' field :status_message, GraphQL::Types::String, null: true, description: 'Status message.' field :tags, Types::Packages::PackageTagType.connection_type, null: true, description: 'Package tags.' @@ -39,12 +45,14 @@ def project Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, object.project_id).find end - def package_protection_rule_exists + def protection_rule_exists return false if Feature.disabled?(:packages_protected_packages, object.project) object.matching_package_protection_rules.exists? end + alias_method :package_protection_rule_exists, :protection_rule_exists + # NOTE: This method must be kept in sync with the union # type: `Types::Packages::MetadataType`. # diff --git a/doc/api/graphql/reference/index.md b/doc/api/graphql/reference/index.md index 1bc4bcf821f2a98d95d8aef40e3ac4dd1017b846..ae57e43ccef235db8566dccc74d744b515fad4f4 100644 --- a/doc/api/graphql/reference/index.md +++ b/doc/api/graphql/reference/index.md @@ -25904,10 +25904,11 @@ Represents a package with pipelines in the Package Registry. | <a id="packageid"></a>`id` | [`PackagesPackageID!`](#packagespackageid) | ID of the package. | | <a id="packagemetadata"></a>`metadata` | [`PackageMetadata`](#packagemetadata) | Package metadata. | | <a id="packagename"></a>`name` | [`String!`](#string) | Name of the package. | -| <a id="packagepackageprotectionruleexists"></a>`packageProtectionRuleExists` **{warning-solid}** | [`Boolean!`](#boolean) | **Introduced** in GitLab 16.11. **Status**: Experiment. Whether any matching package protection rule exists for this package. Available only when feature flag `packages_protected_packages` is enabled. | +| <a id="packagepackageprotectionruleexists"></a>`packageProtectionRuleExists` **{warning-solid}** | [`Boolean!`](#boolean) | **Deprecated** in GitLab 17.0. Use `protectionRuleExists`. | | <a id="packagepackagetype"></a>`packageType` | [`PackageTypeEnum!`](#packagetypeenum) | Package type. | | <a id="packagepipelines"></a>`pipelines` | [`PipelineConnection`](#pipelineconnection) | Pipelines that built the package. Max page size 20. (see [Connections](#connections)) | | <a id="packageproject"></a>`project` | [`Project!`](#project) | Project where the package is stored. | +| <a id="packageprotectionruleexists"></a>`protectionRuleExists` **{warning-solid}** | [`Boolean!`](#boolean) | **Introduced** in GitLab 17.0. **Status**: Experiment. Whether any matching package protection rule exists for this package. Available only when feature flag `packages_protected_packages` is enabled. | | <a id="packagestatus"></a>`status` | [`PackageStatus!`](#packagestatus) | Package status. | | <a id="packagestatusmessage"></a>`statusMessage` | [`String`](#string) | Status message. | | <a id="packagetags"></a>`tags` | [`PackageTagConnection`](#packagetagconnection) | Package tags. (see [Connections](#connections)) | @@ -25928,9 +25929,10 @@ Represents a package in the Package Registry. | <a id="packagebaseid"></a>`id` | [`PackagesPackageID!`](#packagespackageid) | ID of the package. | | <a id="packagebasemetadata"></a>`metadata` | [`PackageMetadata`](#packagemetadata) | Package metadata. | | <a id="packagebasename"></a>`name` | [`String!`](#string) | Name of the package. | -| <a id="packagebasepackageprotectionruleexists"></a>`packageProtectionRuleExists` **{warning-solid}** | [`Boolean!`](#boolean) | **Introduced** in GitLab 16.11. **Status**: Experiment. Whether any matching package protection rule exists for this package. Available only when feature flag `packages_protected_packages` is enabled. | +| <a id="packagebasepackageprotectionruleexists"></a>`packageProtectionRuleExists` **{warning-solid}** | [`Boolean!`](#boolean) | **Deprecated** in GitLab 17.0. Use `protectionRuleExists`. | | <a id="packagebasepackagetype"></a>`packageType` | [`PackageTypeEnum!`](#packagetypeenum) | Package type. | | <a id="packagebaseproject"></a>`project` | [`Project!`](#project) | Project where the package is stored. | +| <a id="packagebaseprotectionruleexists"></a>`protectionRuleExists` **{warning-solid}** | [`Boolean!`](#boolean) | **Introduced** in GitLab 17.0. **Status**: Experiment. Whether any matching package protection rule exists for this package. Available only when feature flag `packages_protected_packages` is enabled. | | <a id="packagebasestatus"></a>`status` | [`PackageStatus!`](#packagestatus) | Package status. | | <a id="packagebasestatusmessage"></a>`statusMessage` | [`String`](#string) | Status message. | | <a id="packagebasetags"></a>`tags` | [`PackageTagConnection`](#packagetagconnection) | Package tags. (see [Connections](#connections)) | @@ -25998,10 +26000,11 @@ Represents a package details in the Package Registry. | <a id="packagedetailstypenpmurl"></a>`npmUrl` | [`String`](#string) | Url of the NPM project endpoint. | | <a id="packagedetailstypenugeturl"></a>`nugetUrl` | [`String`](#string) | Url of the Nuget project endpoint. | | <a id="packagedetailstypepackagefiles"></a>`packageFiles` | [`PackageFileConnection`](#packagefileconnection) | Package files. (see [Connections](#connections)) | -| <a id="packagedetailstypepackageprotectionruleexists"></a>`packageProtectionRuleExists` **{warning-solid}** | [`Boolean!`](#boolean) | **Introduced** in GitLab 16.11. **Status**: Experiment. Whether any matching package protection rule exists for this package. Available only when feature flag `packages_protected_packages` is enabled. | +| <a id="packagedetailstypepackageprotectionruleexists"></a>`packageProtectionRuleExists` **{warning-solid}** | [`Boolean!`](#boolean) | **Deprecated** in GitLab 17.0. Use `protectionRuleExists`. | | <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="packagedetailstypeprotectionruleexists"></a>`protectionRuleExists` **{warning-solid}** | [`Boolean!`](#boolean) | **Introduced** in GitLab 17.0. **Status**: Experiment. Whether any matching package protection rule exists for this package. Available only when feature flag `packages_protected_packages` is enabled. | | <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. | diff --git a/spec/fixtures/api/schemas/graphql/packages/package_details.json b/spec/fixtures/api/schemas/graphql/packages/package_details.json index 5ab84cb2b351da5ae2896ba9b93c8c9af42c3d52..6539f1aa3569925fc8d90305a80b7196b9b28afc 100644 --- a/spec/fixtures/api/schemas/graphql/packages/package_details.json +++ b/spec/fixtures/api/schemas/graphql/packages/package_details.json @@ -259,6 +259,9 @@ "packageProtectionRuleExists": { "type": "boolean" }, + "protectionRuleExists": { + "type": "boolean" + }, "_links": { "type": "object", "additionalProperties": false, diff --git a/spec/requests/api/graphql/project/packages_spec.rb b/spec/requests/api/graphql/project/packages_spec.rb index 16a6beaba46ac3853b5dcda9db5a76a304611bcc..c44cef2e365240c6b37956a3569e77b0103b4850 100644 --- a/spec/requests/api/graphql/project/packages_spec.rb +++ b/spec/requests/api/graphql/project/packages_spec.rb @@ -14,7 +14,7 @@ it_behaves_like 'group and project packages query' - describe 'packageProtectionRuleExists' do + describe 'protectionRuleExists' do let_it_be(:maven_package) { create(:maven_package, project: project1, name: 'maven-package') } let_it_be(:npm_package) { create(:npm_package, project: project1, name: 'npm-package') } let_it_be(:npm_package_no_match) { create(:npm_package, project: project1, name: 'other-npm-package') } @@ -38,6 +38,7 @@ name packageType packageProtectionRuleExists + protectionRuleExists } QUERY end @@ -45,7 +46,7 @@ context 'when package protection rule for package and user exists' do using RSpec::Parameterized::TableSyntax - where(:current_user_access_level, :expected_package_protection_rule_exists) do + where(:current_user_access_level, :expected_protection_rule_exists) do :reporter | true :developer | true :maintainer | true @@ -66,13 +67,14 @@ hash_including( 'name' => npm_package.name, 'packageType' => npm_package.package_type.upcase, - 'packageProtectionRuleExists' => - expected_package_protection_rule_exists + 'packageProtectionRuleExists' => expected_protection_rule_exists, + 'protectionRuleExists' => expected_protection_rule_exists ), hash_including( 'name' => maven_package.name, 'packageType' => maven_package.package_type.upcase, - 'packageProtectionRuleExists' => false + 'packageProtectionRuleExists' => false, + 'protectionRuleExists' => false ) ) end @@ -90,9 +92,10 @@ post_graphql(query, current_user: current_user) end - it 'returns false for the field packageProtectionRuleExists for each package' do + it 'returns false for the field protectionRuleExists for each package' do graphql_data_at(resource_type, :packages, :nodes).each do |package| expect(package['packageProtectionRuleExists']).to eq false + expect(package['protectionRuleExists']).to eq false end end end