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.
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.
- Previous MR as an inspriation for this MR: !174033 (comment 2245063847)
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)
-
Changelog entry added, if necessary -
Documentation created/updated via this MR -
Documentation reviewed by technical writer or follow-up review issue created -
Tests added for this feature/bug -
Tested in all supported browsers -
Conforms to the code review guidelines -
Conforms to the merge request performance guidelines -
Conforms to the style guides -
Conforms to the javascript style guides -
Conforms to the database guides -
Wait for !174033 (merged)
Screenshots or screen recordings
| Before | After |
|---|---|
![]() |
![]() |
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
- Create a group with 3 projects
- Publish 2 npm package per project
- For each project, go to "Settings" => "Packages and registries settings" and protect one of the two packages published
- Visit now the package registry overview list of the group
- You should see 6 packages; three of the packages should include the "Protected" badge
Related to #506777 (closed)
Edited by David Fernandez

