Skip to content

Include current organization id with frontend requests

All frontend (AJAX/Websockets) requests should forward through the Current.organization.id if defined.

I propose using headers as there's the precedent with the CSRF token header.

This will allow us to set the Current.organization from the headers. The Organization ID will be cross referenced against the current_user.organizations with User must be able to read Current.organization (#541676).

Implementation guide

Add the following to app/assets/javascripts/lib/utils/axios_utils.js

if (gon.current_organization) {
  axios.defaults.headers.common['X-GitLab-Organization-ID'] = gon.current_organization.id;
}

Add the following to app/assets/javascripts/lib/graphql.js

if (gon.current_organization) {
  httpHeaders['X-GitLab-Organization-ID'] = gon.current_organization.id;
}

There is a corresponding backend issue at Set current Organization by header (#548319 - closed)

There is documentation of this feature at https://handbook.gitlab.com/handbook/engineering/architecture/design-documents/organization/current_organization/#header-field

Edited by 🤖 GitLab Bot 🤖