From 29403eee7c784aacefd9a4b88fb638d9f48d00df Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Tue, 17 Mar 2026 14:17:32 -0400 Subject: [PATCH] client: Respect the default organization ID from the server (#51777) This PR updates the `UserStore` to use the `default_organization_id` returned from the server to set the default organization rather than always picking the first one. Closes CLO-530. Release Notes: - N/A --- crates/client/src/test.rs | 1 + crates/client/src/user.rs | 10 +++++++++- crates/cloud_api_types/src/cloud_api_types.rs | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/client/src/test.rs b/crates/client/src/test.rs index b506cee822ff9c2e4e31f262886a26ac1acbd134..99fc594e7fd38ea7621e6f62e56ccd74e77b2e9b 100644 --- a/crates/client/src/test.rs +++ b/crates/client/src/test.rs @@ -269,6 +269,7 @@ pub fn make_get_authenticated_user_response( }, feature_flags: vec![], organizations: vec![], + default_organization_id: None, plans_by_organization: BTreeMap::new(), plan: PlanInfo { plan: KnownOrUnknown::Known(Plan::ZedPro), diff --git a/crates/client/src/user.rs b/crates/client/src/user.rs index 71b05dc58f54379f8dfb2ec46d4c280926a56bea..df0c00d86636b6b4a138161a151e20a1c50a688d 100644 --- a/crates/client/src/user.rs +++ b/crates/client/src/user.rs @@ -816,7 +816,15 @@ impl UserStore { } self.organizations = response.organizations.into_iter().map(Arc::new).collect(); - self.current_organization = self.organizations.first().cloned(); + self.current_organization = response + .default_organization_id + .and_then(|default_organization_id| { + self.organizations + .iter() + .find(|organization| organization.id == default_organization_id) + .cloned() + }) + .or_else(|| self.organizations.first().cloned()); self.plans_by_organization = response .plans_by_organization .into_iter() diff --git a/crates/cloud_api_types/src/cloud_api_types.rs b/crates/cloud_api_types/src/cloud_api_types.rs index e2c517edcc78e37bc2eab7055c5ac8d79c9db5b2..286bdbbc1fb08f12ddc41107705975691e6ed1b4 100644 --- a/crates/cloud_api_types/src/cloud_api_types.rs +++ b/crates/cloud_api_types/src/cloud_api_types.rs @@ -23,6 +23,8 @@ pub struct GetAuthenticatedUserResponse { #[serde(default)] pub organizations: Vec, #[serde(default)] + pub default_organization_id: Option, + #[serde(default)] pub plans_by_organization: BTreeMap>, pub plan: PlanInfo, }