feat(32.2-01): in-transaction BackendAccessRevokedEvent at every admin access change

- cabana: BackendAccessRevokedEvent with reasons deleted, deactivated,
  password_changed, password_set, password_reset and permissions, fired
  synchronously inside the save's transaction; a listener error rolls back
- fired on admin delete, deactivate, a password set by another admin, an own
  password change, admin:reset-password, a role/permissions/superuser change
  and a role's permission change (every holder); MCPSubjectChanged unchanged
- role delete fires nothing (refused while the role has holders); no sign
  out everywhere action exists
- smoke test TestBackendAccessRevokedSmoke (Postgres)
This commit is contained in:
Jakub Zych
2026-11-21 00:32:26 +01:00
parent 3f7ce6020d
commit fcc7bbde25
10 changed files with 270 additions and 8 deletions

View File

@@ -96,3 +96,13 @@ Here `acme.pages` listens at a higher priority, so it gets the first chance to c
## Events and transactions
Listeners run where the event is fired, inside any transaction the caller has open. A listener that writes to the database joins that transaction when it uses the transaction handle the event carries. A listener with a side effect outside the database, such as a mail or a broadcast, should defer it with `lagoon.AfterCommit`, so it does not announce a write that rolls back. See [Transactions](../database/transactions.md).
The framework fires these events of its own:
| Event | Fired by | When | Transaction |
|-------|----------|------|-------------|
| `cabana.BackendAccessRevokedEvent` | the admin | an administrator is deleted (`cabana.BackendAccessDeleted`) or deactivated (`cabana.BackendAccessDeactivated`), changes their own password on My account (`cabana.BackendAccessPasswordChanged`), gets a password set by another administrator (`cabana.BackendAccessPasswordSet`) or reset with `admin:reset-password` (`cabana.BackendAccessPasswordReset`), or their role, own permissions or superuser flag change, or the permissions of the role they hold (`cabana.BackendAccessPermissions`) | inside the save's transaction, before the commit, with `cabana.BackendAccessRevokedEvent.Tx` set; a listener's error rolls the save back |
| `pact.MCPSubjectChanged` | the admin, plugins | what a subject may do over MCP changed: permissions, a backend link, a revoked grant or token, a deleted or deactivated user | after the commit; a listener's error is logged and never fails the save |
| `pact.RecordSaved` | the admin | a record was created or updated on an admin screen | after the commit |
Listen for `cabana.BackendAccessRevokedEvent` to revoke what is keyed on an administrator, such as OAuth grants they consented to, atomically with the change: write through `cabana.BackendAccessRevokedEvent.Tx` and do not open a transaction of your own.