Server admin 13: fluxer-core member moderation: nickname, roles, timeout, kick, ban (#680) #728

Closed
charles wants to merge 0 commits from serveradmin-13-core-member-moderation into serveradmin
Owner

Server administration plan, Task 13: member moderation in fluxer-core (admin::members), spec §3.5 and §6.2 "Member actions".

Stacked on: serveradmin-9b-core-hierarchy-bulk-events (already merged into serveradmin when this branch was cut; the merge was a no-op).

What was built

  • Roles ▸ (AM/items/GuildMemberMenuItems.tsx ManageRolesMenuItem, GuildMemberCommands.addRole/removeRole): MemberAction::ToggleRole sends AddMemberRole / RemoveMemberRole at once. members::roles_menu(app, guild, user) -> Vec<RoleCheck { role, name, color, checked, enabled }>: every role but @everyone, highest first (ordered with perms::is_role_higher, so no position comparison outside perms), enabled with MANAGE_ROLES and perms::can_manage_role. The box shows the change at once (an overlay in app.admin.member_moderation), goes back on a failure, and the overlay is dropped once the store's GUILD_MEMBER_UPDATE agrees; the store's roles change only through the gateway event.
  • Modals (app.admin.moderation, members::modal(app) -> Option<ModerationModalModel { guild_id, user_id, title, body: ModerationModalBody::{Nickname { current, placeholder }, Timeout { description, default_seconds }, Ban}, submitting, error }>):
    • Nickname (BaseChangeNicknameModal.tsx, ChangeNicknameModal.tsx): more than 32 characters refused with "Nickname must not exceed 32 characters"; trimmed, empty clears ({nick: null}); UpdateOwnMember for oneself, UpdateMember otherwise.
    • Timeout (TimeoutMemberModal.tsx, TimeoutMemberOptions.ts): TIMEOUT_DURATIONS 60 s / 5 min / 10 min / 1 h (default) / 1 d / 1 w; communication_disabled_until = the store's clock + duration; trimmed reason (≤ 512) only when not empty.
    • Ban (BanMemberModal.tsx, BanDeleteMessageOptions.ts, GuildCommands.banMemberRequest): BAN_DURATIONS (Permanent … 1 month, Custom…), BAN_HISTORY (seven options), BanForm::default() is now the modal's (permanent, 24 h history, no reason); a temporary duration is clamped to 60–63 072 000 s, history to 7 days, reason cut to 512 and null when empty.
  • Confirms: RemoveTimeout and Kick without confirmed open Confirm::RemoveTimeout / Confirm::KickMember; members::confirm_text gives their original texts, members::confirm_accept the confirmed action. Confirmed, they send UpdateMember {communication_disabled_until: null} / KickMember (no reason), and the confirm stays open until the answer (as ConfirmModal awaits onPrimary); a second press while on its way sends nothing.
  • Answers: each modal or confirm closes on its answer with the original's toast in app.admin.toast ("Nickname updated", "Timed out {tag}", "Removed timeout from {tag}", "Kicked {tag} from the community", "Banned {tag} from the community"). A failure keeps the modal open with members::failure_text: the server's English text for MISSING_PERMISSIONS, UNKNOWN_MEMBER, TIMEOUT_CANNOT_EXCEED_365_DAYS, TWO_FACTOR_REQUIRED (packages/errors/src/i18n/weblate/messages.json), else the action's own "Failed to time out member. Try again." / "Failed to remove timeout. Try again." / "Failed to kick member. Try again." / "Failed to ban member. Try again." (the original's showGenericErrorModal bodies); the nickname shows the server's message as its form does (FormUtils.handleError), the checkboxes the generic form error. Confirm and checkbox failures go to app.admin.error (DismissError clears it). The member leaves the store through GUILD_MEMBER_REMOVE, never through an answer; a member removed while their nickname or timeout modal is open closes it (the ban modal stays: a ban does not need a member). CloseModal closes.
  • Uncached target: OpenNickname / OpenTimeout / OpenBan for a member the store does not know send FetchProfile { user_id, guild_id: Some(guild) } (the profile popout's request) and open the modal once it arrives; members::caps(app, guild, user) -> Option<ModerationCaps> is None until the member is in the store. A profile without guild_member opens only the ban modal; the others show "Member wasn't found in this community."

Deviations / outside the Files list

  • crates/fluxer-core/src/{guilds.rs,app.rs} (same crate, minimal): Guilds::hydrate_member and one call in App::apply put a profile answer's guild_member into the member cache where it has a gap (GuildMembers.hydrateIfMissing). Without it the fetched member never reaches perms::moderation_caps, which reads the store.
  • crates/fluxer-core/src/admin/mod.rs (registration file): one field, Admin::member_moderation.
  • crates/fluxer-core/tests/admin_ports.rs: stubs_emit_nothing skips the Member actions and no longer asserts roles_menu is empty (now filled).
  • The reducer does not re-check permissions before sending (it only sees AdminCtx, and the perms rules take &App); the menus (Task 20) offer only what caps/roles_menu allow, and the server refuses the rest, which reverts and explains.
  • OpenTransfer / Transfer stay Task 19's; ModerationModal::BanDetails Task 14's (modal() answers None for them).
  • No new fixture: the tests use member_update_nick.json, member_update_timeout.json, ban_create.json, user_profile.json from Task 3.

Tests

crates/fluxer-core/tests/admin_members.rs: toggle_role_puts_and_deletes, toggle_role_reverts_on_failure, roles_menu_enabled_by_hierarchy, nickname_self_goes_to_me, empty_nickname_clears, timeout_options_and_iso_time, remove_timeout_sends_null, kick_confirms_and_has_no_reason, ban_body_from_form_defaults, custom_ban_duration_clamped, failure_texts_by_code, modal_closes_on_answer_member_removed_by_event, uncached_target_is_fetched_first. Written first, failed (did not compile), then pass. FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci green locally. No display tests (no UI in this task).

Strings recorded from the original: "Change nickname", "Nickname must not exceed 32 characters", "Time out {tag}", "Prevent {tag} from sending messages, reacting, and joining voice channels for the specified duration.", "Remove timeout", "Removing the timeout will allow {tag} to send messages, react, and join voice channels again.", "Kick member", "Are you sure you want to kick {tag} from the community? They will be able to rejoin with a new invite.", "Kick", "Cancel", "Ban {tag}", "Custom ban duration (seconds)", "Any value from 60 to 63072000 seconds.", and the duration/history labels above.

Closes #680

🤖 Generated with Claude Code

https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K

Server administration plan, Task 13: member moderation in `fluxer-core` (`admin::members`), spec §3.5 and §6.2 "Member actions". Stacked on: serveradmin-9b-core-hierarchy-bulk-events (already merged into serveradmin when this branch was cut; the merge was a no-op). ## What was built - **Roles ▸** (`AM/items/GuildMemberMenuItems.tsx` `ManageRolesMenuItem`, `GuildMemberCommands.addRole/removeRole`): `MemberAction::ToggleRole` sends `AddMemberRole` / `RemoveMemberRole` at once. `members::roles_menu(app, guild, user) -> Vec<RoleCheck { role, name, color, checked, enabled }>`: every role but @everyone, highest first (ordered with `perms::is_role_higher`, so no position comparison outside `perms`), enabled with MANAGE_ROLES and `perms::can_manage_role`. The box shows the change at once (an overlay in `app.admin.member_moderation`), goes back on a failure, and the overlay is dropped once the store's `GUILD_MEMBER_UPDATE` agrees; the store's roles change only through the gateway event. - **Modals** (`app.admin.moderation`, `members::modal(app) -> Option<ModerationModalModel { guild_id, user_id, title, body: ModerationModalBody::{Nickname { current, placeholder }, Timeout { description, default_seconds }, Ban}, submitting, error }>`): - Nickname (`BaseChangeNicknameModal.tsx`, `ChangeNicknameModal.tsx`): more than 32 characters refused with "Nickname must not exceed 32 characters"; trimmed, empty clears (`{nick: null}`); `UpdateOwnMember` for oneself, `UpdateMember` otherwise. - Timeout (`TimeoutMemberModal.tsx`, `TimeoutMemberOptions.ts`): `TIMEOUT_DURATIONS` 60 s / 5 min / 10 min / 1 h (default) / 1 d / 1 w; `communication_disabled_until` = the store's clock + duration; trimmed reason (≤ 512) only when not empty. - Ban (`BanMemberModal.tsx`, `BanDeleteMessageOptions.ts`, `GuildCommands.banMemberRequest`): `BAN_DURATIONS` (Permanent … 1 month, Custom…), `BAN_HISTORY` (seven options), `BanForm::default()` is now the modal's (permanent, 24 h history, no reason); a temporary duration is clamped to 60–63 072 000 s, history to 7 days, reason cut to 512 and `null` when empty. - **Confirms**: `RemoveTimeout` and `Kick` without `confirmed` open `Confirm::RemoveTimeout` / `Confirm::KickMember`; `members::confirm_text` gives their original texts, `members::confirm_accept` the confirmed action. Confirmed, they send `UpdateMember {communication_disabled_until: null}` / `KickMember` (no reason), and the confirm stays open until the answer (as `ConfirmModal` awaits `onPrimary`); a second press while on its way sends nothing. - **Answers**: each modal or confirm closes on its answer with the original's toast in `app.admin.toast` ("Nickname updated", "Timed out {tag}", "Removed timeout from {tag}", "Kicked {tag} from the community", "Banned {tag} from the community"). A failure keeps the modal open with `members::failure_text`: the server's English text for `MISSING_PERMISSIONS`, `UNKNOWN_MEMBER`, `TIMEOUT_CANNOT_EXCEED_365_DAYS`, `TWO_FACTOR_REQUIRED` (`packages/errors/src/i18n/weblate/messages.json`), else the action's own "Failed to time out member. Try again." / "Failed to remove timeout. Try again." / "Failed to kick member. Try again." / "Failed to ban member. Try again." (the original's `showGenericErrorModal` bodies); the nickname shows the server's message as its form does (`FormUtils.handleError`), the checkboxes the generic form error. Confirm and checkbox failures go to `app.admin.error` (`DismissError` clears it). The member leaves the store through `GUILD_MEMBER_REMOVE`, never through an answer; a member removed while their nickname or timeout modal is open closes it (the ban modal stays: a ban does not need a member). `CloseModal` closes. - **Uncached target**: `OpenNickname` / `OpenTimeout` / `OpenBan` for a member the store does not know send `FetchProfile { user_id, guild_id: Some(guild) }` (the profile popout's request) and open the modal once it arrives; `members::caps(app, guild, user) -> Option<ModerationCaps>` is `None` until the member is in the store. A profile without `guild_member` opens only the ban modal; the others show "Member wasn't found in this community." ## Deviations / outside the Files list - `crates/fluxer-core/src/{guilds.rs,app.rs}` (same crate, minimal): `Guilds::hydrate_member` and one call in `App::apply` put a profile answer's `guild_member` into the member cache where it has a gap (`GuildMembers.hydrateIfMissing`). Without it the fetched member never reaches `perms::moderation_caps`, which reads the store. - `crates/fluxer-core/src/admin/mod.rs` (registration file): one field, `Admin::member_moderation`. - `crates/fluxer-core/tests/admin_ports.rs`: `stubs_emit_nothing` skips the `Member` actions and no longer asserts `roles_menu` is empty (now filled). - The reducer does not re-check permissions before sending (it only sees `AdminCtx`, and the `perms` rules take `&App`); the menus (Task 20) offer only what `caps`/`roles_menu` allow, and the server refuses the rest, which reverts and explains. - `OpenTransfer` / `Transfer` stay Task 19's; `ModerationModal::BanDetails` Task 14's (`modal()` answers `None` for them). - No new fixture: the tests use `member_update_nick.json`, `member_update_timeout.json`, `ban_create.json`, `user_profile.json` from Task 3. ## Tests `crates/fluxer-core/tests/admin_members.rs`: `toggle_role_puts_and_deletes`, `toggle_role_reverts_on_failure`, `roles_menu_enabled_by_hierarchy`, `nickname_self_goes_to_me`, `empty_nickname_clears`, `timeout_options_and_iso_time`, `remove_timeout_sends_null`, `kick_confirms_and_has_no_reason`, `ban_body_from_form_defaults`, `custom_ban_duration_clamped`, `failure_texts_by_code`, `modal_closes_on_answer_member_removed_by_event`, `uncached_target_is_fetched_first`. Written first, failed (did not compile), then pass. `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` green locally. No display tests (no UI in this task). Strings recorded from the original: "Change nickname", "Nickname must not exceed 32 characters", "Time out {tag}", "Prevent {tag} from sending messages, reacting, and joining voice channels for the specified duration.", "Remove timeout", "Removing the timeout will allow {tag} to send messages, react, and join voice channels again.", "Kick member", "Are you sure you want to kick {tag} from the community? They will be able to rejoin with a new invite.", "Kick", "Cancel", "Ban {tag}", "Custom ban duration (seconds)", "Any value from 60 to 63072000 seconds.", and the duration/history labels above. Closes #680 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
Roles checkboxes (optimistic, reverted on failure), nickname, timeout,
remove timeout, kick and ban in fluxer-core's admin::members, as the
original's GuildMemberMenuItems.tsx, GuildMemberCommands.ts and the
moderation modals. A member the store does not know is fetched with the
profile request first; the store hydrates the profile's guild_member
(GuildMembers.hydrateIfMissing).

Refs #680

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

Independent review: Server admin 13 (core member moderation), commit 1c678cc6

Scope: git diff 832d40a8..origin/serveradmin-13-core-member-moderation (7 files, all in fluxer-core).

Checks

  1. Plan tests: all 13 named tests exist in crates/fluxer-core/tests/admin_members.rs and assert what the plan asks. The values are the spec's: timeout 60/300/600/3600/86400/604800 with 1 h as the default; ban durations Permanent … 1 month plus Custom, clamped to 60–63 072 000; history 0/1h/6h/12h/24h/3d/7d with 24 h as the default; reasons at most 512; nickname at most 32 characters (counted in chars, not bytes), empty sends {"nick":null}; removing a timeout sends {"communication_disabled_until":null}; kick sends no reason. The bodies are compared with the existing fixtures member_update_timeout.json, member_update_nick.json and ban_create.json. No new fixture was added.
  2. Interfaces: ToggleRole → AddMemberRole/RemoveMemberRole, roles_menu -> Vec<RoleCheck { role, name, color, checked, enabled }>, modal -> Option<ModerationModalModel>, Confirm::{KickMember, RemoveTimeout} and the uncached fetch (FetchProfile, then caps returns None until the member arrives) are present. Field names follow the 9a code (guild_id/user_id/role_id), which is the source of truth.
  3. Invariants: no iced/wgpu/reqwest/tungstenite and no I/O in core; no tracing of reasons; arithmetic is checked (timeout_end, clamps); nothing from the server can panic it. Role order uses perms::is_role_higher only, so no position comparison outside perms. The store changes membership only from gateway events (tested).
  4. Parity, checked against the fork:
    • TimeoutMemberOptions.ts and TimeoutMemberModal.tsx: the reason is trimmed and left out when empty, now + d as ISO, the toast and the failure text match.
    • BanDeleteMessageOptions.ts and BanMemberModal.tsx: the labels and seconds match, the default history is 24 h, reason || undefined, the toast and "Failed to ban member. Try again." match.
    • The Kick and RemoveTimeout confirm bodies and toasts match.
    • BaseChangeNicknameModal.tsx: trim() || null, maxLength 32 with its message, "Nickname updated" match.
    • The 4 error texts match packages/errors/.../messages.json.
  5. Review Focus: item 1, "no role-position comparison outside admin::perms", holds.
  6. CI: I ran FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci three times in the review worktree. The first two runs failed only on fluxer-ui window_input_updates_last_input (last_input() <= Instant::now()). That is the known flake #709: this PR does not touch fluxer-ui, and the test fails 4/50 standalone. A cargo test --workspace --no-fail-fast run passed everything, and the third full run passed all steps, screenshots included. Green. The branch also merges cleanly with the current origin/serveradmin.

Findings

  • [minor] members.rs prune_roles: a role box the server accepted is kept until the store's member agrees. If the GUILD_MEMBER_UPDATE never arrives (a dropped dispatch, or a member update the gateway does not send to this session), the box keeps showing the sent value for the rest of the session. A bounded fallback would fix it, for example dropping the pending entry once it is answered and the next update for that member arrives, or after a timeout.
  • [minor] CloseModal clears moderation, error and awaiting but not member_moderation.request. After a modal is cancelled while its request is in flight, a newly opened modal or confirm silently refuses to submit (submittable, or the request.is_some() guard) until the old answer arrives.
  • [minor] Outside the task's Files list: app.rs (profile → Guilds::hydrate_member) and guilds.rs. Both are in the same crate, no other wave-5 task owns them and the merge is clean. Recorded so Task 20/22 know the store now hydrates members from profile answers (hydrateIfMissing parity).
  • [minor] The reducers send without re-checking moderation_caps. Gating is left to the menus (Task 20) and to the server, which is consistent with spec §7 ("the server remains the authority"). Task 20's table tests must cover it.

No blocking findings.

Verdict: APPROVED (no blocking findings; local CI green, with the known flake #709 seen on 2 of 3 runs).

## Independent review: Server admin 13 (core member moderation), commit 1c678cc6 Scope: `git diff 832d40a8..origin/serveradmin-13-core-member-moderation` (7 files, all in `fluxer-core`). **Checks** 1. **Plan tests:** all 13 named tests exist in `crates/fluxer-core/tests/admin_members.rs` and assert what the plan asks. The values are the spec's: timeout 60/300/600/3600/86400/604800 with 1 h as the default; ban durations Permanent … 1 month plus Custom, clamped to 60–63 072 000; history 0/1h/6h/12h/24h/3d/7d with 24 h as the default; reasons at most 512; nickname at most 32 characters (counted in chars, not bytes), empty sends `{"nick":null}`; removing a timeout sends `{"communication_disabled_until":null}`; kick sends no reason. The bodies are compared with the existing fixtures `member_update_timeout.json`, `member_update_nick.json` and `ban_create.json`. No new fixture was added. 2. **Interfaces:** `ToggleRole` → `AddMemberRole`/`RemoveMemberRole`, `roles_menu -> Vec<RoleCheck { role, name, color, checked, enabled }>`, `modal -> Option<ModerationModalModel>`, `Confirm::{KickMember, RemoveTimeout}` and the uncached fetch (`FetchProfile`, then `caps` returns `None` until the member arrives) are present. Field names follow the 9a code (`guild_id`/`user_id`/`role_id`), which is the source of truth. 3. **Invariants:** no iced/wgpu/reqwest/tungstenite and no I/O in core; no `tracing` of reasons; arithmetic is checked (`timeout_end`, clamps); nothing from the server can panic it. Role order uses `perms::is_role_higher` only, so no position comparison outside `perms`. The store changes membership only from gateway events (tested). 4. **Parity, checked against the fork:** - `TimeoutMemberOptions.ts` and `TimeoutMemberModal.tsx`: the reason is trimmed and left out when empty, `now + d` as ISO, the toast and the failure text match. - `BanDeleteMessageOptions.ts` and `BanMemberModal.tsx`: the labels and seconds match, the default history is 24 h, `reason || undefined`, the toast and "Failed to ban member. Try again." match. - The Kick and RemoveTimeout confirm bodies and toasts match. - `BaseChangeNicknameModal.tsx`: `trim() || null`, maxLength 32 with its message, "Nickname updated" match. - The 4 error texts match `packages/errors/.../messages.json`. 5. **Review Focus:** item 1, "no role-position comparison outside `admin::perms`", holds. 6. **CI:** I ran `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` three times in the review worktree. The first two runs failed only on `fluxer-ui` `window_input_updates_last_input` (`last_input() <= Instant::now()`). That is the known flake #709: this PR does not touch fluxer-ui, and the test fails 4/50 standalone. A `cargo test --workspace --no-fail-fast` run passed everything, and the third full run passed all steps, screenshots included. **Green.** The branch also merges cleanly with the current `origin/serveradmin`. **Findings** - [minor] `members.rs` `prune_roles`: a role box the server accepted is kept until the store's member agrees. If the `GUILD_MEMBER_UPDATE` never arrives (a dropped dispatch, or a member update the gateway does not send to this session), the box keeps showing the sent value for the rest of the session. A bounded fallback would fix it, for example dropping the pending entry once it is answered and the next update for that member arrives, or after a timeout. - [minor] `CloseModal` clears `moderation`, `error` and `awaiting` but not `member_moderation.request`. After a modal is cancelled while its request is in flight, a newly opened modal or confirm silently refuses to submit (`submittable`, or the `request.is_some()` guard) until the old answer arrives. - [minor] Outside the task's Files list: `app.rs` (profile → `Guilds::hydrate_member`) and `guilds.rs`. Both are in the same crate, no other wave-5 task owns them and the merge is clean. Recorded so Task 20/22 know the store now hydrates members from profile answers (`hydrateIfMissing` parity). - [minor] The reducers send without re-checking `moderation_caps`. Gating is left to the menus (Task 20) and to the server, which is consistent with spec §7 ("the server remains the authority"). Task 20's table tests must cover it. No blocking findings. **Verdict: APPROVED** (no blocking findings; local CI green, with the known flake #709 seen on 2 of 3 runs).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 03:02:59 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.