Skip to content

Use Current.organization for users created using API

Rutger Wessels requested to merge 443494-api-users-create into master

What does this MR do and why?

As part of cell projects, we are working on introducing Organizations. All Namespaces will have an organization. This means we need to assign an Organization when we create a namespace.

This MR is part the effort of adding Organization to User Namespaces (also known as Personal Namespaces). User namespaces are created using the User.assign_personal_namespace method.

In a previous MR, we added a new optional Organization parameter to that method. And as a follow up, we need to update all code paths that are creating users to specify what Organization should be assigned.

This MR is focussing on user creation logic that is going through API::Users. These users will have the Current.organization for their user namespaces

Related to #443494 (closed)

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.

How to set up and validate locally

  • Enable Feature flag Feature.enable(:current_organization_middleware)
  • Create a new organization Organizations::Organization.create!(name: "My Org", path: 'my-org')
  • Create a user using curl and use the ID of new organization for GITLAB_ORGANIZATION_ID HTTP header:
    curl --request POST --header "GITLAB_ORGANIZATION_ID: 1000" --header "PRIVATE-TOKEN: <token>" --data "email=someuser@example.com&password=2a3b4c2d&username=someuser&name=someuser" "http://localhost:3000/api/v4/users"

The result should be that User.last.namespace.organization is the new organization

Without the Feature flag, the namespace of the newly created user is the Default organization

Edited by Rutger Wessels

Merge request reports