Kantoor.Release (Kantoor v1.0.0)

Tasks to run from a release, where Mix is not available.

bin/migrate                      # runs Kantoor.Release.migrate/0
bin/kantoor eval "Kantoor.Release.rollback(Kantoor.Repo, 20260101000000)"

Ecto's migrator takes a database lock while migrating, so concurrent invocations (for example two containers during a rolling deploy) are safe.

Summary

Functions

Creates an operator API key for the provisioning API and prints it once (the first key, before anyone can open the admin screen)

Deletes the stored chat files of a mail domain (or of one room of it) from the file store, whichever adapter is configured. Nothing calls this when a domain or room is deleted yet: the bytes stay under chat/<domain id>/ until an operator runs it.

Deletes a chat room for good, with its messages, file rows and stored bytes (what an administrator does in the room's menu, for a room of a domain the operator has no mailbox in). The room's name is the confirmation. Recorded in the audit log as the system.

Deletes an organization (a mail domain) that no operator owns, with its chat rooms (messages and stored files), its mailboxes and their mail. The domain's name is the confirmation. A domain an operator owns is refused: its owner deprovisions it through the provisioning API. A person whose account belongs to the domain blocks it; disable or move them in the admin pages first. See Kantoor.Deprovision.

Deletes a person's Kantoor account that no operator owns, found by its e-mail address: app passwords, mailbox grants and identities go with it, and the chat messages they wrote stay as a former member's. An account an operator owns is refused (its operator deletes it through the provisioning API), and so is an administrator. See Kantoor.Deprovision.

Runs all pending migrations for every configured repo.

Rolls repo back to (and including) version.

Ends every session of the person with this e-mail address at once: every browser session that started before now stops working at its next request, and the audit row is written. Run with eval (a new VM, no web server) that is all; run with rpc on the running node it also disconnects open pages at once

Brings every attached domain's Karta routes in step with its mailboxes, aliases and catch-all (Kantoor.Karta.Routes): one exact route per mailbox and alias, and the * route delivering only when the domain has a catch-all.

Functions

create_api_key(attrs)

create_api_key(name, operator, scopes \\ ["provisioning"])

Creates an operator API key for the provisioning API and prints it once (the first key, before anyone can open the admin screen):

bin/kantoor eval 'Kantoor.Release.create_api_key("balie", "balie")'

attrs may also be a map with "name", "operator", "scopes" and "rate_limit_per_minute". Returns what Kantoor.ApiKeys.create_system/1 returns.

delete_chat_files(domain_id, room_id \\ nil)

Deletes the stored chat files of a mail domain (or of one room of it) from the file store, whichever adapter is configured. Nothing calls this when a domain or room is deleted yet: the bytes stay under chat/<domain id>/ until an operator runs it.

bin/kantoor eval 'Kantoor.Release.delete_chat_files("<domain id>")'
bin/kantoor eval 'Kantoor.Release.delete_chat_files("<domain id>", "<room id>")'

delete_chat_room(room_id, name)

Deletes a chat room for good, with its messages, file rows and stored bytes (what an administrator does in the room's menu, for a room of a domain the operator has no mailbox in). The room's name is the confirmation. Recorded in the audit log as the system.

bin/kantoor eval 'Kantoor.Release.delete_chat_room("<room id>", "<room name>")'

delete_domain(name)

Deletes an organization (a mail domain) that no operator owns, with its chat rooms (messages and stored files), its mailboxes and their mail. The domain's name is the confirmation. A domain an operator owns is refused: its owner deprovisions it through the provisioning API. A person whose account belongs to the domain blocks it; disable or move them in the admin pages first. See Kantoor.Deprovision.

bin/kantoor eval 'Kantoor.Release.delete_domain("test.boneiru.online")'
bin/kantoor rpc  'Kantoor.Release.delete_domain("test.boneiru.online")'

delete_user(email)

Deletes a person's Kantoor account that no operator owns, found by its e-mail address: app passwords, mailbox grants and identities go with it, and the chat messages they wrote stay as a former member's. An account an operator owns is refused (its operator deletes it through the provisioning API), and so is an administrator. See Kantoor.Deprovision.

bin/kantoor eval 'Kantoor.Release.delete_user("demi@example.com")'
bin/kantoor rpc  'Kantoor.Release.delete_user("demi@example.com")'

migrate()

Runs all pending migrations for every configured repo.

Behind a transaction pooler (KANTOOR_DATABASE_POOLER) they run through it like everything else: Ecto's migration lock is a table lock inside the migration's own transaction, which transaction mode keeps on one connection. With KANTOOR_DIRECT_DATABASE_URL set they use that direct connection instead (with named prepared statements again): the way for a migration that needs a session.

rollback(repo, version)

Rolls repo back to (and including) version.

sign_out_everywhere(email)

Ends every session of the person with this e-mail address at once: every browser session that started before now stops working at its next request, and the audit row is written. Run with eval (a new VM, no web server) that is all; run with rpc on the running node it also disconnects open pages at once:

bin/kantoor eval 'Kantoor.Release.sign_out_everywhere("qa@example.com")'
bin/kantoor rpc  'Kantoor.Release.sign_out_everywhere("qa@example.com")'

Disabling a user in the admin pages does this itself.

sync_mail_routes()

Brings every attached domain's Karta routes in step with its mailboxes, aliases and catch-all (Kantoor.Karta.Routes): one exact route per mailbox and alias, and the * route delivering only when the domain has a catch-all.

Run once after the release that introduced exact routes (an older domain has the single * route that delivers everything), and after a failed sync:

bin/kantoor eval 'Kantoor.Release.sync_mail_routes()'

Prints a line per domain and answers :ok when every domain synced (or Karta is not configured), :failed otherwise.