Kantoor.Deprovision (Kantoor v1.0.0)

Deleting an organization — a mail domain — that no operator owns: one made by hand in the admin pages, or a test domain left behind.

A domain an operator owns is not deleted here. Its owner deprovisions it through the provisioning API (Kantoor.Provisioning.Domains.delete/2), so that the operator's own records, the Karta route and the audit trail stay in step.

What is deleted, in this order:

  1. every chat room, through Kantoor.Chat.delete_room/3 (messages, edit history, file rows and the stored bytes);
  2. every mailbox, with its folders and mail (the database cascades those);
  3. the domain row, with its aliases, chat files and grants (the database cascades those), and the stored chat files by prefix as a last sweep.

A person whose account belongs to the domain blocks the deletion ({:not_empty, %{users: n}}): deleting accounts is a decision of its own, made in the admin pages first. The domain's name is the confirmation, and the deletion is recorded in the audit log as the system.

Summary

Functions

What delete_domain/2 would remove, without removing it.

Deletes the domain and everything it holds. confirm: must be the domain's own name; without it nothing is deleted ({:error, :confirmation}). An operator-owned domain is refused ({:error, :operator_owned}), and so is a domain a person still belongs to ({:error, {:not_empty, %{users: n}}}).

Deletes a person's account that no operator owns, with its app passwords, mailbox grants and identities; the chat messages they wrote stay, as a former member's. confirm: must be the account's own e-mail address ({:error, :confirmation} otherwise).

Types

summary()

@type summary() :: %{
  name: String.t(),
  mailboxes: non_neg_integer(),
  messages: non_neg_integer(),
  rooms: non_neg_integer()
}

Functions

counts(domain)

@spec counts(Kantoor.Mailboxes.Domain.t()) :: summary()

What delete_domain/2 would remove, without removing it.

delete_domain(domain, opts \\ [])

@spec delete_domain(Kantoor.Mailboxes.Domain.t(), keyword()) ::
  {:ok, summary()}
  | {:error,
     :confirmation | :operator_owned | {:not_empty, %{users: non_neg_integer()}}}

Deletes the domain and everything it holds. confirm: must be the domain's own name; without it nothing is deleted ({:error, :confirmation}). An operator-owned domain is refused ({:error, :operator_owned}), and so is a domain a person still belongs to ({:error, {:not_empty, %{users: n}}}).

Returns {:ok, %{name:, mailboxes:, messages:, rooms:}} with what was removed.

delete_user(user, opts \\ [])

@spec delete_user(Kantoor.Accounts.User.t(), keyword()) ::
  :ok | {:error, :confirmation | :operator_owned | :administrator}

Deletes a person's account that no operator owns, with its app passwords, mailbox grants and identities; the chat messages they wrote stay, as a former member's. confirm: must be the account's own e-mail address ({:error, :confirmation} otherwise).

An account an operator owns is refused ({:error, :operator_owned}): its operator deletes it through the provisioning API. An administrator is refused ({:error, :administrator}): that is a separate decision, made in the admin pages. The deletion is recorded in the audit log as the system.