Protected packages: Fix appearance of protected badge in group package overview

  • Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA. As a benefit of being a GitLab Community Contributor, you can request access to GitLab Duo.

What does this MR do and why?

  • Fixes a bug where protected packages did not display the "protected" badge in the group package registry overview list.

🛠️ with ❤️ at Siemens

References

Please include cross links to any resources that are relevant to this MR This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

MR Checklist (@gerardo-navarro)

Screenshots or screen recordings

Before After
image image

DB queries before MR

Given the steps to reproduce the bug described here, only one SQL query is executed (without the changes in this MR). But as stated before, this was wrong because only the package protection rules of one project have been considered although the protection rules of all three projects should have been considered.

WITH "package_names_and_types_cte" AS MATERIALIZED (SELECT * FROM unnest(ARRAY['@project-57/package-protected','@project-57/package','@project-56/package-protected','@project-56/package','@project-55/package-protected','@project-55/package'], ARRAY[2,2,2,2,2,2]) AS x(package_name, package_type)) SELECT package_names_and_types_cte."package_type", package_names_and_types_cte."package_name", EXISTS(SELECT 1 FROM "packages_protection_rules" WHERE "packages_protection_rules"."project_id" = 57 AND "packages_protection_rules"."package_type" = package_names_and_types_cte."package_type" AND (package_names_and_types_cte."package_name" ILIKE REPLACE(REPLACE(REPLACE(package_name_pattern,
                        '%', '\%'),
                '_', '\_'),
        '*', '%')
)) AS protected FROM package_names_and_types_cte

DB queries after MR

WITH "projects_and_packages_cte" AS MATERIALIZED (
  SELECT * FROM unnest(
    ARRAY[57,57,56,56,55,55]::bigint[],
    ARRAY['@project-57/package-protected','@project-57/package','@project-56/package-protected','@project-56/package','@project-55/package-protected','@project-55/package']::text[],
    ARRAY[2,2,2,2,2,2]::smallint[]
  ) AS x(project_id, package_name, package_type)
)
SELECT projects_and_packages_cte."project_id", projects_and_packages_cte."package_type", projects_and_packages_cte."package_name", EXISTS(SELECT 1 FROM "packages_protection_rules" WHERE (projects_and_packages_cte."project_id" = project_id) AND "packages_protection_rules"."package_type" = projects_and_packages_cte."package_type" AND (projects_and_packages_cte."package_name" ILIKE REPLACE(REPLACE(REPLACE(package_name_pattern,
                        '%', '\%'),
                '_', '\_'),
        '*', '%')
)) AS protected FROM projects_and_packages_cte

💾 Database review

How to set up and validate locally

  1. Create a group with 3 projects
  2. Publish 2 npm package per project
  3. For each project, go to "Settings" => "Packages and registries settings" and protect one of the two packages published
  4. Visit now the package registry overview list of the group
  5. You should see 6 packages; three of the packages should include the "Protected" badge

Related to #506777 (closed)

Edited by David Fernandez

Merge request reports

Loading