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

Screenshots or screen recordings

Not applicable since there is no no visual redesign.

  1. an un-activated organization hides the sidebar entry
  2. and an activated one remains as it is.

How to set up and validate locally

  1. Enable the flag for an organization:

    Feature.enable(:artifact_registry_ui, Organizations::Organization.first)
  2. As an owner of an organization with no ArtifactRegistry::NamespaceMapping row, confirm the Settings sidebar shows no "Artifact registry" entry, and that visiting /o/<organization>/-/settings/artifact_registry answers 404.

  3. Create a mapping row for that organization:

    ArtifactRegistry::NamespaceMapping.create!(
      organization: Organizations::Organization.first,
      ar_namespace_id: SecureRandom.uuid
    )
  4. 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.rb

Queries

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 ms

https://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)

Edited by Keeyan Nejad

Merge request reports

Loading
Loading