diff --git a/src/vaultwarden/models/bitwarden.py b/src/vaultwarden/models/bitwarden.py index 8e81b68..a6a5f5e 100644 --- a/src/vaultwarden/models/bitwarden.py +++ b/src/vaultwarden/models/bitwarden.py @@ -842,11 +842,37 @@ def key(self): def get_organization( - bitwarden_client, organisation_id: UUID | str + bitwarden_client, + organisation_id: UUID | str, ) -> Organization: - resp = bitwarden_client.api_request( - "GET", f"api/organizations/{organisation_id}" - ) + """ + Fetch an organization by ID. + + Checks sync data first: if the org is found and the user is not an + Owner (Type != 0), the GET api/organizations/{id} API call is skipped + because that endpoint is Owner-only. The Organization is built directly + from sync data (Id, Name) which is sufficient since collections(), + ciphers(), and key() use less restricted endpoints. + + If the user is an Owner, or the org is not in sync data, the normal + API call proceeds. + """ + sync = bitwarden_client.sync() + for org in sync.Profile.Organizations: + if org.Id == organisation_id and org.Type != 0: + # Non-Owner: skip API call, build from sync data + return Organization( + Id=org.Id, + Name=org.Name, + BillingEmail="", + Object=None, + bitwarden_client=bitwarden_client, + ) + if org.Id == organisation_id: + # Owner: proceed with normal API call + break + + resp = bitwarden_client.api_request("GET", f"api/organizations/{organisation_id}") return Organization.model_validate_json( resp.text, context={"client": bitwarden_client, "parent_id": organisation_id},