Skip to content

Check if organization_id is set for Namespace objects

Rutger Wessels requested to merge 411832-namespace-org-validation into master

What does this MR do and why?

Add a validation for organization_id to Namespace model. This makes setting an organization on Groups, Personal Namespaces and Project Namespace required. We pass the organization_id now to all code paths that create these Namespaces.

Originally, the plan was to validate on organization and not organization_id. If we would use validates: :organization, presence: true, we would need to instantiate an Organization record for all specs that need a Namespace. That would slow down the specs. We can avoid that by validating the presence of the organization_id.

The organization_id is now defaulting to 1 on the database level. This validation will therefore always be true for new and existing records. Only if organization_id is explicitly set to nil, the Namespace will be invalid.

Loose Ends

  • SAML:
    • For SaaS: how can we derive the group organization?
    • For self-managed: Use Default Organization?
  • GitlabSubscriptions::Trials::CreateService
    • Is now relying on Default Organization, this won't work on SaaS
  • Registrations::StandardNamespaceCreateService
    • Is now relying on Default Organization, this won't work on SaaS

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.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Related to #411832

Edited by Rutger Wessels

Merge request reports