From fbbb5e3dd5b7f9f1b2f391991a323a08ea946cca Mon Sep 17 00:00:00 2001
From: Gerardo Navarro <gerardo@b310.de>
Date: Mon, 13 May 2024 06:44:21 +0000
Subject: [PATCH] Protected packages: Shorten GraphQL field for

- Based on the feedback from @10io,
  we decided to shorten the GraphQL field
  from "packageProtectionRuleExists" to "protectionRuleExists",
  see https://gitlab.com/gitlab-org/gitlab/-/merge_requests/146206#note_1871347682
- Why? Because the GraphQl field is already defined in the context of packages

Changelog: other
---
 app/graphql/types/packages/package_base_type.rb   | 12 ++++++++++--
 doc/api/graphql/reference/index.md                |  9 ++++++---
 .../schemas/graphql/packages/package_details.json |  3 +++
 .../requests/api/graphql/project/packages_spec.rb | 15 +++++++++------
 4 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/app/graphql/types/packages/package_base_type.rb b/app/graphql/types/packages/package_base_type.rb
index 1ab04223f7701..6ee5c31b8353b 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 1bc4bcf821f2a..ae57e43ccef23 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 5ab84cb2b351d..6539f1aa35699 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 16a6beaba46ac..c44cef2e36524 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
-- 
GitLab