Server admin 19: core-sudo-delete-transfer (#686) #735

Closed
charles wants to merge 0 commits from serveradmin-19-core-sudo-delete-transfer into serveradmin
Owner

Implements Server administration Task 19 in fluxer-core (admin::sudo, admin::guild).

Stacked on: serveradmin-11-core-forms-community (already merged into serveradmin; the merge was a no-op)

What was built

  • Identity check (admin::sudo, spec §3.9, §6.2, §12; RestTransport.ts runWithSudoEscalation, SudoPrompt.tsx, AuthSudo.ts, SudoVerificationModal.tsx): sudo-capable requests (UpdateGuild, DeleteGuild, TransferOwnership) go out through sudo::send, remembered by effect id without any answer. SUDO_MODE_REQUIRED forgets the token and opens SudoPrompt { request, methods, error, attempts } (Totp with 2FA, else Password, none without a user). Submit replays the held request unchanged plus the answer (empty answer: the original's "Enter your password." / "Enter the code from your authenticator app.", nothing sent). Wrong answers (INVALID_PASSWORD, INVALID_MFA_CODE, PASSWORD_NOT_SET) show the field's message ("Verification failed" without one) and re-prompt at most twice, then the action fails. Cancel fails it quietly. CoreEvent::SudoToken is kept (sudo::prompt_expected), closes a prompt whose answer is out, and logout clears it all. sudo::model gives the modal's strings.
  • Delete community (owner only, GuildDeleteModal.tsx): flashes the bar when the open tab is dirty, otherwise Confirm::DeleteGuild. Confirmed, it sends DeleteGuild through the identity check. Success shows the toast "Community deleted", and GUILD_DELETE removes the guild and closes the settings. A refusal goes to admin.error.
  • Transfer ownership (TransferOwnershipModal.tsx): OpenTransfer (owner; another member, not a bot) opens ModerationModal::Transfer, with guild::transfer_model for the modal. Transfer { confirmed: true } sends through the identity check; confirmed: false asks with Confirm::TransferOwnership. Success shows the toast "Transferred ownership to {name}" and closes the modal. A refusal shows "Ownership could not be transferred to {name} at this time." The owner changes through GUILD_UPDATE, and the settings re-gate.
  • The Moderation tab's mfa_level save and pause invites go through the same machine: the save is held (still saving) and replayed; a cancel abandons it quietly; a final refusal shows on the bar.

Tests

  • New crates/fluxer-core/tests/admin_sudo.rs (all 13 tests the plan names), written first and seen failing (compile errors against the base), then passing.
  • crates/fluxer-core/tests/admin_ports.rs: stubs_emit_nothing now skips the actions this task fills (delete, transfer, sudo), as Task 11 did for its own.
  • Locally: the whole fluxer-core suite, clippy -D warnings and fmt are green. The full FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci gate passed fmt, clippy, deny and the parity check, but was stopped during its test step when the agent had to return, so the workspace tests and screenshots still need a run. Core only; no display tests involved.

Deviations / notes for the reviewer

  • Re-prompts: the original re-prompts without limit on a wrong answer and caps only repeated SUDO_MODE_REQUIRED. This follows the plan: at most two re-prompts for either, then the action fails.
  • Methods come from mfa_enabled only. The store does not see the methods object of the 403 body (CoreError carries code and message), so a passkey-only account gets the code field, not the "no methods" text. The "no methods" text shows only without a user.
  • ApiResult::OwnershipTransferred does not write owner_id into the store (that would mean touching guilds.rs, outside the file list). The store takes it from GUILD_UPDATE, per the Global Constraint that the store changes from gateway events.
  • Transfer: the modal's button is the original's only confirmation and should emit Transfer { confirmed: true }. confirmed: false raises Confirm::TransferOwnership for callers without the modal.
  • members.rs is untouched: Transfer and OpenTransfer are handled in guild.rs (Task 13 leaves them as no-ops).

Closes #686

🤖 Generated with Claude Code

https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K

Implements Server administration Task 19 in `fluxer-core` (`admin::sudo`, `admin::guild`). Stacked on: serveradmin-11-core-forms-community (already merged into serveradmin; the merge was a no-op) ## What was built - **Identity check** (`admin::sudo`, spec §3.9, §6.2, §12; `RestTransport.ts` `runWithSudoEscalation`, `SudoPrompt.tsx`, `AuthSudo.ts`, `SudoVerificationModal.tsx`): sudo-capable requests (`UpdateGuild`, `DeleteGuild`, `TransferOwnership`) go out through `sudo::send`, remembered by effect id without any answer. `SUDO_MODE_REQUIRED` forgets the token and opens `SudoPrompt { request, methods, error, attempts }` (`Totp` with 2FA, else `Password`, none without a user). `Submit` replays the held request unchanged plus the answer (empty answer: the original's "Enter your password." / "Enter the code from your authenticator app.", nothing sent). Wrong answers (`INVALID_PASSWORD`, `INVALID_MFA_CODE`, `PASSWORD_NOT_SET`) show the field's message ("Verification failed" without one) and re-prompt at most twice, then the action fails. `Cancel` fails it quietly. `CoreEvent::SudoToken` is kept (`sudo::prompt_expected`), closes a prompt whose answer is out, and logout clears it all. `sudo::model` gives the modal's strings. - **Delete community** (owner only, `GuildDeleteModal.tsx`): flashes the bar when the open tab is dirty, otherwise `Confirm::DeleteGuild`. Confirmed, it sends `DeleteGuild` through the identity check. Success shows the toast "Community deleted", and `GUILD_DELETE` removes the guild and closes the settings. A refusal goes to `admin.error`. - **Transfer ownership** (`TransferOwnershipModal.tsx`): `OpenTransfer` (owner; another member, not a bot) opens `ModerationModal::Transfer`, with `guild::transfer_model` for the modal. `Transfer { confirmed: true }` sends through the identity check; `confirmed: false` asks with `Confirm::TransferOwnership`. Success shows the toast "Transferred ownership to {name}" and closes the modal. A refusal shows "Ownership could not be transferred to {name} at this time." The owner changes through `GUILD_UPDATE`, and the settings re-gate. - The Moderation tab's `mfa_level` save and pause invites go through the same machine: the save is held (still saving) and replayed; a cancel abandons it quietly; a final refusal shows on the bar. ## Tests - New `crates/fluxer-core/tests/admin_sudo.rs` (all 13 tests the plan names), written first and seen failing (compile errors against the base), then passing. - `crates/fluxer-core/tests/admin_ports.rs`: `stubs_emit_nothing` now skips the actions this task fills (delete, transfer, sudo), as Task 11 did for its own. - Locally: the whole `fluxer-core` suite, clippy `-D warnings` and fmt are green. The full `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` gate passed fmt, clippy, deny and the parity check, but was stopped during its test step when the agent had to return, so the workspace tests and screenshots still need a run. Core only; no display tests involved. ## Deviations / notes for the reviewer - Re-prompts: the original re-prompts without limit on a wrong answer and caps only repeated `SUDO_MODE_REQUIRED`. This follows the plan: at most two re-prompts for either, then the action fails. - Methods come from `mfa_enabled` only. The store does not see the `methods` object of the 403 body (CoreError carries code and message), so a passkey-only account gets the code field, not the "no methods" text. The "no methods" text shows only without a user. - `ApiResult::OwnershipTransferred` does not write `owner_id` into the store (that would mean touching `guilds.rs`, outside the file list). The store takes it from `GUILD_UPDATE`, per the Global Constraint that the store changes from gateway events. - Transfer: the modal's button is the original's only confirmation and should emit `Transfer { confirmed: true }`. `confirmed: false` raises `Confirm::TransferOwnership` for callers without the modal. - `members.rs` is untouched: Transfer and OpenTransfer are handled in `guild.rs` (Task 13 leaves them as no-ops). Closes #686 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
The identity check of spec 3.9 / 6.2 over the store's effects: sudo-capable
requests (UpdateGuild, DeleteGuild, TransferOwnership) are remembered without
any answer; SUDO_MODE_REQUIRED opens the prompt holding the request; Submit
replays it unchanged plus the answer; a wrong answer (INVALID_PASSWORD,
INVALID_MFA_CODE, PASSWORD_NOT_SET; fixtures/rest/error_sudo_invalid.json,
api/auth/services/SudoVerificationService.ts) asks again at most twice; Cancel
fails the action quietly. Delete community and transfer ownership confirm,
then go through it; the Moderation tab's mfa_level save too.

Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
Author
Owner

Review of Task 19 (independent reviewer, commit 7698535f, diff 6f5711a4..serveradmin-19-core-sudo-delete-transfer)

Checked: all 13 tests the plan names exist and assert the plan and spec behaviour. The Interfaces block is present: the sudo machine, sudo::model, prompt_expected, Confirm::DeleteGuild/TransferOwnership, OpenTransfer/Transfer, and SudoToken remembered and cleared on logout. fluxer-core gains no I/O and no new dependencies. The secret is stripped before it is kept: Sent and SudoPrompt hold sudo: None.
Parity spot-checks against fluxer-soundboard all match: the strings in TransferOwnershipModal.tsx, GroupOwnershipTransferFailedModal.tsx, GuildDeleteModal.tsx ("I changed my mind", "Community deleted") and SudoVerificationModal.tsx ("Verify it's you", "Verification failed", the self-hosted no-methods text); the method choice (TOTP when a second factor exists, else the password, as deriveMethodsFromCurrentUser); and GuildCommands.transferOwnership, which does not write owner_id from the answer either, so that deviation matches the original.

Findings:

  • [minor] admin/guild.rs on_failure sets guild_writes.held = Some(write) unconditionally. If a second sudo-capable request (B) is refused with SUDO_MODE_REQUIRED while a prompt already holds A, A is overwritten without being released, and sudo::on_failure then releases B, not A. Result: A (a form save) keeps saving: true with no way out, and the replay of B is not tracked by guild_writes (resume_held finds nothing). This is rare: it needs two delete, transfer or mfa_level writes in flight at once. Fix: release the previously held write before holding the new one.
  • [minor] tests/admin_sudo.rs secret_not_in_state_after_submit searches the App debug dump, but SudoAnswer's Debug prints ..., so this check would pass even if an answer were stored. The test does what the plan specifies. A direct assertion that every kept request has sudo: None would make it meaningful.
  • [minor] Documented deviations are acceptable: at most two re-prompts (the spec requires it; the original has no limit); methods come from mfa_enabled only.

CI: the local FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci was started in the review worktree and stopped by the workflow before it finished (still compiling dependencies). There is no gate result from this review; the gate must be run before merge.

Verdict: no blocking code findings; NOT approved, because the local CI gate is unverified.

🤖 Generated with Claude Code

Review of Task 19 (independent reviewer, commit 7698535f, diff 6f5711a4..serveradmin-19-core-sudo-delete-transfer) Checked: all 13 tests the plan names exist and assert the plan and spec behaviour. The Interfaces block is present: the sudo machine, `sudo::model`, `prompt_expected`, `Confirm::DeleteGuild/TransferOwnership`, `OpenTransfer`/`Transfer`, and `SudoToken` remembered and cleared on logout. fluxer-core gains no I/O and no new dependencies. The secret is stripped before it is kept: `Sent` and `SudoPrompt` hold `sudo: None`. Parity spot-checks against fluxer-soundboard all match: the strings in TransferOwnershipModal.tsx, GroupOwnershipTransferFailedModal.tsx, GuildDeleteModal.tsx ("I changed my mind", "Community deleted") and SudoVerificationModal.tsx ("Verify it's you", "Verification failed", the self-hosted no-methods text); the method choice (TOTP when a second factor exists, else the password, as `deriveMethodsFromCurrentUser`); and `GuildCommands.transferOwnership`, which does not write `owner_id` from the answer either, so that deviation matches the original. Findings: - [minor] admin/guild.rs `on_failure` sets `guild_writes.held = Some(write)` unconditionally. If a second sudo-capable request (B) is refused with SUDO_MODE_REQUIRED while a prompt already holds A, A is overwritten without being released, and `sudo::on_failure` then releases B, not A. Result: A (a form save) keeps `saving: true` with no way out, and the replay of B is not tracked by guild_writes (`resume_held` finds nothing). This is rare: it needs two delete, transfer or mfa_level writes in flight at once. Fix: release the previously held write before holding the new one. - [minor] tests/admin_sudo.rs `secret_not_in_state_after_submit` searches the App debug dump, but `SudoAnswer`'s Debug prints `...`, so this check would pass even if an answer were stored. The test does what the plan specifies. A direct assertion that every kept request has `sudo: None` would make it meaningful. - [minor] Documented deviations are acceptable: at most two re-prompts (the spec requires it; the original has no limit); methods come from `mfa_enabled` only. CI: the local `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` was started in the review worktree and stopped by the workflow before it finished (still compiling dependencies). There is no gate result from this review; the gate must be run before merge. Verdict: no blocking code findings; NOT approved, because the local CI gate is unverified. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

Review round 1, minor findings (commit 17bef130):

  1. guild.rs on_failure overwrote the held write — fixed. guild::on_failure now replaces the held write and gives the previous one up quietly (failed(previous, None)), and sudo::on_failure no longer calls release_held when a new refusal replaces an open prompt (it would have released the new write). New test second_refusal_replaces_the_held_request (failed before the fix): a held moderation save stops saving without an error when a transfer is refused, and the prompt then holds and replays the transfer through to its failure.
  2. secret_not_in_state_after_submit could not see a stored answer — fixed. Added Sudo::kept_requests(); the test now also asserts that every kept request and the prompt's request carry sudo: None, after the first answer and after the second.
  3. Documented deviations in sudo.rs — no change needed (the reviewer found them acceptable).

cargo xtask ci (with FLUXER_SCREENSHOT_TESTS=1) green locally.

Review round 1, minor findings (commit 17bef130): 1. **guild.rs `on_failure` overwrote the held write** — fixed. `guild::on_failure` now replaces the held write and gives the previous one up quietly (`failed(previous, None)`), and `sudo::on_failure` no longer calls `release_held` when a new refusal replaces an open prompt (it would have released the new write). New test `second_refusal_replaces_the_held_request` (failed before the fix): a held moderation save stops saving without an error when a transfer is refused, and the prompt then holds and replays the transfer through to its failure. 2. **`secret_not_in_state_after_submit` could not see a stored answer** — fixed. Added `Sudo::kept_requests()`; the test now also asserts that every kept request and the prompt's request carry `sudo: None`, after the first answer and after the second. 3. **Documented deviations in sudo.rs** — no change needed (the reviewer found them acceptable). `cargo xtask ci` (with `FLUXER_SCREENSHOT_TESTS=1`) green locally.
A second sudo-capable write refused with SUDO_MODE_REQUIRED while the
identity check held another one overwrote the held write without failing
it, and sudo then released the new one: the first form stayed "saving"
and the replay of the second was not tracked. guild now gives the
previous held write up quietly before holding the new one, and sudo no
longer releases on a replaced prompt. The secret test now also asserts
that no kept request carries an answer (Sudo::kept_requests), since
SudoAnswer's Debug hides the secret from the dump.

Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
Author
Owner

Independent review: Server admin 19 (head 17bef130, diff 6f5711a4..origin/serveradmin-19-core-sudo-delete-transfer)

Tests (plan Step 1). All 13 named tests exist in crates/fluxer-core/tests/admin_sudo.rs and assert what the plan asks. There is also the regression test second_refusal_replaces_the_held_request. secret_not_in_state_after_submit debug-prints the whole App and the effects. It also checks, through Sudo::kept_requests(), that no kept request and no prompt request carries an answer. The refusals are built from error_sudo_required.json and error_sudo_invalid.json, which are shaped like the server's.

Interfaces. SudoPrompt { request, methods, error, attempts }, SudoAction::{Submit, Cancel}, CoreEvent::SudoToken remembered and cleared on logout, sudo::model(app) -> Option<SudoModel>, Confirm::DeleteGuild, MemberAction::OpenTransfer/Transfer { confirmed } and the three sudo-capable requests all exist as specified. UpdateGuild (the mfa_level save, the Overview save and pause invites), DeleteGuild and TransferOwnership go through sudo::send.

Invariants. No new dependencies and no I/O in fluxer-core. The secret lives only in the one replayed effect. The kept requests and the prompt hold sudo: None. Server errors are matched by code, with no unwraps on server data.

Parity spot-checks (fluxer-soundboard).

  • Strings match:
    • SudoVerificationModal.tsx: "Verify it's you", "For your security, please confirm it's you to continue.", "Enter your password.", "Enter the code from your authenticator app.", "6-digit code", "Verification failed", "No verification methods available" and its self-hosted body.
    • GuildDeleteModal.tsx: the body, "I changed my mind" and "Community deleted".
    • TransferOwnershipModal.tsx and GroupOwnershipTransferFailedModal.tsx: the body, "Transferred ownership to {name}", "Ownership could not be transferred to {name} at this time." and "Failed to transfer ownership".
  • AuthSudo.ts keeps the token for 4.5 min, which matches prompt_expected.
  • deriveMethodsFromCurrentUser: a second factor means TOTP and no password, otherwise the password. This matches.
  • In the original, the transfer answer does not touch the store. Only GUILD_UPDATE changes owner_id, and this branch does the same.
  • An abort (cancel) shows nothing, as isAbortError does in the original.

Review Focus 6. The held request is replayed unchanged plus the answer (mfa_level_save_goes_through_sudo compares the request body). The secret never reaches App. The prompt asks again at most twice (MAX_REPROMPTS = 2), then the action fails with the field's message.

Findings

  1. minor, admin/sudo.rs and admin/guild.rs. This is the same class of bug as the earlier finding 1, in a different order of events. Suppose an answered request (say the save) is out and a second sudo-capable request is refused first, so the new prompt holds that one. If the old answer then comes back wrong, sudo::on_failure counts the attempt and sets the error on the new prompt. guild::on_failure then held.replace(old) gives up the new held write quietly. If the old answer is accepted instead, sudo::on_answer closes the new prompt (sent.answered). This needs a second admin write while the verify button is spinning, so the modal makes it nearly unreachable. One fix: tie Sent to a prompt generation, or refuse new sudo-capable sends while submitting(). It could be a follow-up.
  2. minor, admin/sudo.rs SudoModel.method. Task 9a's interface has SudoModel { method: SudoMethod, .. }; this branch makes it Option<SudoMethod>, which is needed for the no-methods case, and adds fields. No other task consumes it yet, but Task 33's modal must use the new shape. Please note this in the PR body.
  3. minor (parity note). Like the spec, a wrong answer is limited to two re-prompts. In the original, runWithSudoEscalation asks again after every verification failure (reissued) and keeps the two-reissue limit for repeated SUDO_MODE_REQUIRED only. The spec's wording is what was built, so nothing needs to change. It could go in docs/parity as a divergence.

CI. FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci in the review worktree: all steps passed.

Verdict: approve. No blocking findings and CI is green.

## Independent review: Server admin 19 (head 17bef130, diff 6f5711a4..origin/serveradmin-19-core-sudo-delete-transfer) **Tests (plan Step 1).** All 13 named tests exist in `crates/fluxer-core/tests/admin_sudo.rs` and assert what the plan asks. There is also the regression test `second_refusal_replaces_the_held_request`. `secret_not_in_state_after_submit` debug-prints the whole `App` and the effects. It also checks, through `Sudo::kept_requests()`, that no kept request and no prompt request carries an answer. The refusals are built from `error_sudo_required.json` and `error_sudo_invalid.json`, which are shaped like the server's. **Interfaces.** `SudoPrompt { request, methods, error, attempts }`, `SudoAction::{Submit, Cancel}`, `CoreEvent::SudoToken` remembered and cleared on logout, `sudo::model(app) -> Option<SudoModel>`, `Confirm::DeleteGuild`, `MemberAction::OpenTransfer`/`Transfer { confirmed }` and the three sudo-capable requests all exist as specified. `UpdateGuild` (the mfa_level save, the Overview save and pause invites), `DeleteGuild` and `TransferOwnership` go through `sudo::send`. **Invariants.** No new dependencies and no I/O in fluxer-core. The secret lives only in the one replayed effect. The kept requests and the prompt hold `sudo: None`. Server errors are matched by code, with no unwraps on server data. **Parity spot-checks (fluxer-soundboard).** - Strings match: - `SudoVerificationModal.tsx`: "Verify it's you", "For your security, please confirm it's you to continue.", "Enter your password.", "Enter the code from your authenticator app.", "6-digit code", "Verification failed", "No verification methods available" and its self-hosted body. - `GuildDeleteModal.tsx`: the body, "I changed my mind" and "Community deleted". - `TransferOwnershipModal.tsx` and `GroupOwnershipTransferFailedModal.tsx`: the body, "Transferred ownership to {name}", "Ownership could not be transferred to {name} at this time." and "Failed to transfer ownership". - `AuthSudo.ts` keeps the token for 4.5 min, which matches `prompt_expected`. - `deriveMethodsFromCurrentUser`: a second factor means TOTP and no password, otherwise the password. This matches. - In the original, the transfer answer does not touch the store. Only `GUILD_UPDATE` changes `owner_id`, and this branch does the same. - An abort (cancel) shows nothing, as `isAbortError` does in the original. **Review Focus 6.** The held request is replayed unchanged plus the answer (`mfa_level_save_goes_through_sudo` compares the request body). The secret never reaches `App`. The prompt asks again at most twice (`MAX_REPROMPTS = 2`), then the action fails with the field's message. ### Findings 1. **minor**, `admin/sudo.rs` and `admin/guild.rs`. This is the same class of bug as the earlier finding 1, in a different order of events. Suppose an answered request (say the save) is out and a second sudo-capable request is refused first, so the new prompt holds that one. If the old answer then comes back wrong, `sudo::on_failure` counts the attempt and sets the error on the *new* prompt. `guild::on_failure` then `held.replace(old)` gives up the new held write quietly. If the old answer is accepted instead, `sudo::on_answer` closes the new prompt (`sent.answered`). This needs a second admin write while the verify button is spinning, so the modal makes it nearly unreachable. One fix: tie `Sent` to a prompt generation, or refuse new sudo-capable sends while `submitting()`. It could be a follow-up. 2. **minor**, `admin/sudo.rs` `SudoModel.method`. Task 9a's interface has `SudoModel { method: SudoMethod, .. }`; this branch makes it `Option<SudoMethod>`, which is needed for the no-methods case, and adds fields. No other task consumes it yet, but Task 33's modal must use the new shape. Please note this in the PR body. 3. **minor (parity note)**. Like the spec, a wrong answer is limited to two re-prompts. In the original, `runWithSudoEscalation` asks again after every verification failure (`reissued`) and keeps the two-reissue limit for repeated `SUDO_MODE_REQUIRED` only. The spec's wording is what was built, so nothing needs to change. It could go in `docs/parity` as a divergence. **CI.** `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` in the review worktree: all steps passed. **Verdict: approve.** No blocking findings and CI is green.
Author
Owner

Merged into serveradmin by hand (the merge API returns 405); the commits are in the branch.

Merged into `serveradmin` by hand (the merge API returns 405); the commits are in the branch.
charles closed this pull request 2026-11-16 05:49:53 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.