mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 23:20:18 +01:00
dd34370114
This PR does two things for organizations in Zed Cloud: 1. It adds one yes/no value, `can_manage_organization`, to the organization data that Zed and Delta receive from Cloud. It is true when the signed-in user is an owner or admin of that organization. 2. It fixes Zed so that, when the user loses access to their selected organization, AI features and edit predictions switch to the new organization right away instead of after a restart. ## Why **The new value.** Delta will show a "Manage Organization" link, which opens the organization's page in the dashboard, only to owners and admins of a team organization. Cloud now sends this value ([zed-industries/cloud#4489](https://github.com/zed-industries/cloud/pull/4489)). Delta reads Cloud's account data through `cloud_api_types`, so the crate must describe the new value first. **The fix.** The same Cloud change makes Cloud send a "user updated" message when someone's role changes, when they are removed from an organization, when they accept an invitation, or when they create an organization in the dashboard. Zed already reloads the user's organizations when that message arrives. Before, Cloud never sent it for these changes, so Zed did not notice them until a restart. Now Zed notices, but one step was missing. If the user was removed from their selected organization, the reload selects a different organization. It did not send Zed's "organization changed" signal. That signal is what makes Zed get a new AI token for the selected organization. Without it, AI features and edit predictions kept using the old organization until the token expired or Zed restarted. ## What changed - `cloud_api_types`: `OrganizationUiPermissions` gets `can_manage_organization`, next to the existing `can_install_github_app`. It is true for owners and admins, and false for billing managers and members. It is also true for the owner of a personal organization. Zed does not read it. - `client`: `UserStore::update_authenticated_user` now emits `Event::OrganizationChanged` when a reload replaces the selected organization. The first load after sign-in does not emit it, as before. ## Data impact - The new field defaults to false when the server does not send it, so older servers and older clients keep working. - After a removal, Zed now requests one new AI token for the newly selected organization. Nothing else changes when the selected organization stays the same. ## Limits - When "user updated" arrives, Zed also starts an AI token refresh for the organization that is selected at that moment. If the user was just removed from it, that one request fails and Zed logs an error. The token refresh triggered by the new signal then succeeds. ## Testing - `cargo test -p client --lib`: 23 passed. The new test reloads the account twice: an unchanged reload sends no signal, and a reload after removal sends exactly one and selects the remaining organization. It failed before the fix. - `./script/clippy -p client`: clean. - `cargo test -p cloud_api_types`: 13 passed. Release Notes: - Fixed AI features and edit predictions continuing to use an organization after you were removed from it.