# Organization

An organization is a workspace several people share. One person has one Adlass
account for every workspace: their personal workspace and each organization in
`account.tenants` (get_context) or `users.me.tenants`.

- Act in an organization by naming it: `tenant_id` on tenant-level operations
  (`organization.*`, `users.*`, `tenants.*`, `api_keys.*`, `spaces.create`,
  `spaces.list`, `integrations.connections.create`). Without `tenant_id` a
  write lands in the personal workspace. Operations on a Space act in the
  Space's workspace automatically.
- `organization.create` makes a new organization on the Team plan; you are
  its admin. Payment happens in the checkout at `checkout_url`; until it is
  paid the organization has no plan and is read-only. The checkout link
  expires; Settings > Billing in the app starts the purchase again at any
  time. An organization whose purchase was abandoned (never had a plan, no
  Spaces, no other members) can be deleted by its admin with
  `organization.delete`; any other one is refused with
  `organization_delete_refused` (`details.reason`). Bring Spaces in with `spaces.move` (you own the space and administer
  the organization) or `spaces.move_requests.create` (an admin approves).
- Members: `organization.invitations.create` (the identity provider sends the
  email), `.list`, `.revoke`; `organization.members.list`, `.update_role`,
  `.remove`; `organization.leave`. `organization.invitations.create` takes
  `spaces` (space ids with a role): the invitee sees those spaces on
  acceptance; `.list` returns them per invitation as
  `spaces: [{space_id, name, role}]`. The last admin cannot be removed, demoted or
  leave (`organization_last_admin`). If the identity provider removes the last
  admin, the earliest seated member becomes admin; with nobody left the
  organization is closed.
- A member who leaves hands their Spaces to an admin. Their connections stay
  in the organization: admins see them in `organization.connections.list`
  (`owner_status: departed`) and can disconnect them, but runs can no longer
  use them.
- Seats: Team bills every member beyond the included seats; Enterprise has a
  fixed number of seats. A member above the seats has no access to the
  organization's spaces until a seat frees. Organizations are limited to 20
  members for now (`organization_member_cap`).
- Admins reach every space of the organization, its connections, its assistant
  conversations and its members' API keys. To see who is in which space of the
  organization, call `organization.spaces.list` (admins only, read-only): per
  space its owner, who enters it with which role and why (`via`), and which
  integration grants it holds (never credentials). Sharing a Space stays inside the organization
  (`organization_closed`); people outside it get read-only access to single
  objects through `shares.*` (see read_docs("shares")).
- `integrations_admin_only` (in `organization.settings.update`, `users.me.tenants`
  and `get_context`): when on, only admins connect, configure and grant
  integrations of the organization; members get
  `integration_management_admin_only` and use the grants an admin shares in
  their Spaces (see read_docs("integrations")). Members still connect in their
  personal workspace. Off by default.
- `identity_provider_unavailable`: nothing changed; retry later.
- While the organization has no plan, is unpaid or has more members than
  seats, its Spaces are read-only: in the app reads, downloads and exports
  work; writes fail with `billing_plan_required` (no plan) or
  `organization_read_only` (`details.reason` is `unpaid` or `over_seats`) and
  automations are skipped. Over MCP the organization is locked completely,
  reads included; `get_context` marks it with `read_only.reason`. Do not
  retry; access resumes by itself once an admin settles it.
- An organization deleted in the identity provider is closed: its Spaces are
  unreachable until Adlass restores it.
- `organization_disabled`: organizations are switched off on this platform.
  `organization_required`: the workspace named is a personal one.

Only people act on these in the Adlass app, never agents: `organization.create`,
`organization.leave`, `organization.delete`, `organization.settings.update`,
`organization.backups.config_update`,
`spaces.move` and `spaces.move_requests.*`, and reading
members' connections and assistant conversations (`organization.connections.*`,
`organization.assistant.sessions.*`). The public REST API routes only the
invitations.

## Backups

- A backup is one ZIP of the organization: per Space its documents (original
  files in their folders), records (schema and rows per type), routines, guides,
  workflows, pages and To-Dos, plus the integration connections without
  secrets, and a `manifest.json` with the size and sha256 of every file.
  `organization.backups.config_get` shows the scope (`all_spaces` /
  `space_ids`, `all_kinds` / `kinds`); admins only, like every
  `organization.backups.*` call (`tenant_id` names the organization).
- `organization.backups.run` starts one now and returns it as `queued`; poll
  `organization.backups.get` until `status` is `completed` or `failed`
  (`error_code`: `archive_failed`, `storage_error`, `timeout`, `stalled`, or
  `enqueue_failed` when the run could not be queued; run it again). A backup
  can stay `queued` for a while: backups of all organizations run one after
  the other. One backup per organization at a time: `backup_in_progress`.
- Schedule (`frequency`): `daily`, `weekly` on Monday, `monthly` on day 1, or
  `off`, each at the organization's own fixed minute between 03:00 and 05:59
  UTC. `next_run_at` is the next scheduled run; it is skipped while another
  backup of the organization is active or the organization is read-only.
- Retention: only the newest `retention_count` (1 to 12, default 3) completed
  archives are stored. Older ones stay in `organization.backups.list` as
  `expired` with `downloadable: false`; `organization.backups.delete` removes
  one for good.
- Download: `organization.backups.download` with `tenant_id` and `backup_id`
  returns `download_url`, valid for `link_hours` (2, 12 or 24; default 2) and
  usable without signing in. Ask for a new link instead of storing one;
  `backup_not_downloadable` means the backup did not complete or its archive
  is gone. When `notify_todo` is on, each completed backup opens an agent
  To-Do in the chosen Space that names the `backup_id`: download the archive
  as above, put it where the note or the Space rules say, then close the To-Do.
- Webhook: `webhook_url` (https, public host) receives a JSON `POST` with
  `event` `backup.completed` or `backup.failed`, the `organization`, the
  `backup` (id, status, size, `sha256`) and, when completed, a `download_url`
  valid for 24 hours. Headers: `X-Adlass-Event`, `X-Adlass-Delivery`,
  `X-Adlass-Timestamp` and, when a secret is set, `X-Adlass-Signature:
  sha256=<hex>`, the HMAC-SHA256 of `<timestamp>.<raw body>` with the secret.
  Three attempts; redirects are not followed. The secret is write-only
  (`webhook_secret_set`).
- Only a person changes the configuration (`organization.backups.config_update`).
