pub async fn deactivate(
pool: &PgPool,
actor: &Actor,
user_id: Uuid,
opts: &Offboarding,
) -> AppResult<DeactivationReport>Expand description
Deactivates a user as an offboarding step.
§Invariants
- Permission: administrator (403); an unknown user is “not found”; an administrator cannot offboard themselves (400).
- Locks: the active administrators (
FOR UPDATE, in id order, likeusers::update), then the user’s row, then what the hand-over moves. At least one active administrator remains (409). - Data: with a successor, the hand-over of
ownership::hand_overplus the manager roles; without one, deactivating the only active manager of a group is refused (409) unlessconfirm_no_manager. Withrevoke_tokensthe user’s API tokens are deleted. The account is deactivated and its sessions are deleted. - Audit: those of the hand-over,
project.manager_handoverper group,token.revoke_allwith the count,user.update(inactive) and oneuser.offboardwith the choices; the releases audit each revision (revision.checkout_forced_release). - Notifications / webhooks: those of the releases.
- Atomic: one transaction for everything but the releases, which run afterwards, one transaction per revision (a refused one does not stop the others).