Protected containers: New GraphQL field "protectionRuleExists"
requested to merge gitlab-community/gitlab:441346-gerardo-navarro-protected-containers-show-protection-info-in-container-detail-page-prework-grphql-field-protection-rule-exists into master
-
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
What does this MR do and why?
- This MR is preparation (pre-work) for a feature similar to the Protected badge in the context of "Protected packages":
- When working on a similar feature in the context of "Protected packages", it was necessary to add a new GraphQL field "protectionRuleExists" to determine if a protection rule exists for a given package, see !146206 (merged) and !141134 (merged)
- This MR focusses on adding this a new GraphQL field "protectionRuleExists" to the container repository type that can be consumed in upcoming MRs
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
DB Query
WITH "container_names_and_types_cte" AS MATERIALIZED (
SELECT *
FROM unnest(ARRAY['flightjs/flight/5','flightjs/flight/4','flightjs/flight/3','flightjs/flight/2','flightjs/flight']) AS x(repository_path)
)
SELECT
container_names_and_types_cte."repository_path",
EXISTS(
SELECT 1
FROM "container_registry_protection_rules"
WHERE "container_registry_protection_rules"."project_id" = 7 AND
(container_names_and_types_cte."repository_path" ILIKE REPLACE(REPLACE(REPLACE(repository_path_pattern, '%', '\%'), '_', '\_'), '*', '%'))
) AS protected
FROM container_names_and_types_cte
Screenshots or screen recordings
How to set up and validate locally
- Execute the following GraphQL query
curl --request POST \
--url http://gdk.test:3000/api/graphql \
--header 'Authorization: Bearer ypCa3Dzb23o5nvsixwPA' \
--header 'Content-Type: application/json' \
--data '{"query":"query {\n\tproject(fullPath: \"flightjs/Flight\") {\n\t\tcontainerRepositories{\n\t\t\tnodes {\n\t\t\t\tid\n\t\t\t\tpath\n\t\t\t\tname\n\t\t\t\tprotectionRuleExists\n\t\t\t}\n\t\t}\n\t}\n}\n"}'
- Look at the console output; you should just see one SQL query related to the new field "protectionRuleExists".
Related to #441346 (closed)
Edited by Gerardo Navarro