Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions src/vaultwarden/models/bitwarden.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down