Gate the artifact registry settings route on activation
What does this MR do and why?
This MR gates the organization Artifact Registry settings page on the existence of organization's registry, that require a namespace mapping row.
The gates are added at route level and sidebar menu.
References
- Settings activation gate and real-schema bindin... (#608394 - closed) • Rahul Chanila • 19.4
- All changes are under feature flag: artifact_registry_ui, which is a wip flag and off. No changelog entry, and no user-visible change on this MR.
Screenshots or screen recordings
Not applicable since there is no no visual redesign.
- an un-activated organization hides the sidebar entry
- and an activated one remains as it is.
How to set up and validate locally
-
Enable the flag for an organization:
Feature.enable(:artifact_registry_ui, Organizations::Organization.first) -
As an owner of an organization with no
ArtifactRegistry::NamespaceMappingrow, confirm the Settings sidebar shows no "Artifact registry" entry, and that visiting/o/<organization>/-/settings/artifact_registryanswers 404. -
Create a mapping row for that organization:
ArtifactRegistry::NamespaceMapping.create!( organization: Organizations::Organization.first, ar_namespace_id: SecureRandom.uuid ) -
Reload. The entry appears and the settings page renders.
Specs:
bundle exec rspec \
ee/spec/requests/organizations/settings/artifact_registry_controller_spec.rb \
ee/spec/lib/ee/sidebars/organizations/menus/settings_menu_spec.rb \
ee/spec/features/organizations/settings/artifact_registry_spec.rbQueries
Both gates read the same has_one on Organizations::Organization, so this MR
adds one query, issued from two call sites: the before_action on the settings
route, and show_artifact_registry_menu_item? on the sidebar render path. Each
runs at most once per request, and only after the feature flag and the ability
check have already passed, so a flag-off or unauthorized request issues it not at
all.
Raw SQL:
SELECT "artifact_registry_namespace_mappings".*
FROM "artifact_registry_namespace_mappings"
WHERE "artifact_registry_namespace_mappings"."organization_id" = 1
LIMIT 1;Query plan, for an organization that has a row:
Limit (cost=0.15..2.17 rows=1 width=48) (actual time=0.012..0.012 rows=1 loops=1)
Buffers: shared hit=5
-> Index Scan using index_artifact_registry_namespace_mappings_on_organization_id on artifact_registry_namespace_mappings (cost=0.15..2.17 rows=1 width=48) (actual time=0.012..0.012 rows=1 loops=1)
Index Cond: (organization_id = 1002)
Buffers: shared hit=5
Planning Time: 0.014 ms
Execution Time: 0.016 mshttps://console.postgres.ai/gitlab/projects/gitlab-production-main/sessions/55202/commands/158706
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #608394 (closed)