Skip to content

Ensure current org fallback to user org chooses home org

What does this MR do and why?

When we cannot determine the current organization from params or header, we fall back to user. Previously, the from_user method queried for all of a user's organizations, sorted by ID, and took the first entry. For users that belong to one organization but also a member of the default organization (or any organization with a lower ID), the default org/lower ID was always chosen. This is not the desired behavior. Rather, the current organization should be set to the organization the user belongs to instead of just the first with the lowest ID.

References

#558773 (closed)

Screenshots or screen recordings

Before After

How to set up and validate locally

  1. Enable the organizations feature flags

    Feature.enable :allow_organization_creation
    Feature.enable :organization_switching
    Feature.enable :ui_for_organizations
  2. Create a new organization if you don't already have one. Use the plus symbol in the top left > New organization

  3. In the admin area, create a new user. Choose your new organization as the user's organization. Make the user an admin.

  4. Invite the user as a member of a group or project in the default organization. This will add them as a user to another organization.

  5. Sign in as, or impersonate, the new user.

  6. Navigate to the admin area. Observe the organization switcher indicates the non-default organization since that is the one the user belongs to. Previously the default organization would be chosen.

Note: Choosing a different organization from the switcher, such as the default organization, and then navigating to the admin area will not retain the default organization as current. The organization switcher does not persistently switch the organization - each request determines the appropriate current organization based on params, headers, and user.

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.

Edited by Drew Blessing

Merge request reports

Loading