client: Respect the default organization ID from the server (#51777)
Marshall Bowers
created 3 weeks ago
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
Change summary
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(-)
Detailed changes
@@ -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),
@@ -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()
@@ -23,6 +23,8 @@ pub struct GetAuthenticatedUserResponse {
#[serde(default)]
pub organizations: Vec<Organization>,
#[serde(default)]
+ pub default_organization_id: Option<OrganizationId>,
+ #[serde(default)]
pub plans_by_organization: BTreeMap<OrganizationId, KnownOrUnknown<Plan, String>>,
pub plan: PlanInfo,
}