Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

/admin shows the moderation actions from the admin log, newest first, with who and when - read-only #254

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

/admin now has a Moderation section above the Log. It lists bans, unbans, mutes, unmutes and "took X out of the line" entries, newest first, each with who did it and when. Names and text are escaped the same way as the Log.

Notes

shipped merged

opened this

/admin now has a Moderation section above the Log. It lists bans, unbans, mutes, unmutes and "took X out of the line" entries, newest first, each with who did it and when. Names and text are escaped the same way as the Log. It shows for the owner and moderators; a plain user still gets no page. I added no routes, forge.json is untouched, and the main page is unchanged.

The new test and lobby.test.ts pass. The type check printed only a bun tempdir write error and no type errors, and I did not run the rest of the suite.

The Moderation section filters existing Admin.log lines by their wording in isModeration in admin-page.ts. Mutes were not being written to the admin log, so I added one admin.record call in the mute case of lobby.ts. It records "muted <name>" or "unmuted <name>" and appears in the Log as well. Deleting a chat line is still not logged. I left that out to keep this small.

The new test in admin-restart.test.ts covers an <img onerror> name rendering escaped, newest-first order, and a plain user not getting /admin. Its first run failed because of my own test: "banned first" also matched inside "unbanned first". I fixed the assertion, not the code.

🤖 Generated with Claude Code

Closes #237

3 earlier comments · 2 events
Changes requested — before the latest push

The page section is sound: filtered from the same log, newest first, escaped, and /admin stays gated. One miss: the only new behaviour in lobby.ts (a mute/unmute now writes a log entry) has no test. The new test calls admin.record directly, so it passes with the lobby.ts line deleted. Fix first: add a test that sends a real mute and unmute over the lobby (as an owner) and asserts that /admin then lists "muted <name>" and "unmuted <name>" in the Moderation section. Also, the mute case should call this.broadcastAdmin() after record, as the words case does, so open admin views show the entry live.

commented

/admin now has a Moderation section above the Log. It lists bans, unbans, mutes, unmutes and "took X out of the line" entries from Admin.log, newest first, with who did it and when. Every name and text is escaped. I added no routes, and forge.json is untouched. The main page's first visit is unchanged, and a plain user still gets no /admin.

Both of juniper's review points are fixed:

  • Broadcast: the mute case in lobby.ts now calls broadcastAdmin() right after it records the entry, as the words case does. Open admin views show a mute or unmute as it happens.
  • Mute test: a new test in lobby.test.ts sends a real mute on and then off as the owner over the lobby. It checks that the admin broadcast carries "muted alice" and then "unmuted alice". It then fetches /admin and checks both appear in the Moderation section, unmute first. I did not delete the lobby.ts line to confirm the test fails without it, but the test only passes if that line runs.

The mute and unmute log entries come from a lobby.ts change in this pull, because mutes were not being logged before. Deleting a chat line is still not logged.

lobby.test.ts and admin-restart.test.ts pass (31 tests). I did not run the full suite or the type check again; the type check was run on the first push and printed only a bun tempdir write error and no type errors.

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed it. The only conflict was in lobby.test.ts, where main and this branch each added a test at the same spot. I kept both tests, and lobby.ts merged without help.

I ran the lobby and admin test files after the merge: 49 pass, 0 fail. I didn't run the type check or the rest of the suite.

The pull still does what it did before:

  • Moderation section: /admin has a Moderation section showing bans, unbans, mutes, unmutes and "took X out of the line" entries from the admin log. They are newest first, with who and when, and every name and text is escaped.
  • Mute logging: mutes and unmutes are now recorded in the admin log and broadcast to open admin views.
  • Tests: they cover an <img onerror> name rendering escaped, newest-first order, a plain user getting no /admin, and a real mute and unmute sent over the lobby.

I added no routes, and forge.json is untouched.

🤖 Generated with Claude Code

Changes requested — before the latest push

The Moderation section misses the one moderator action that already exists. lobby.ts:408 logs a chat-line deletion as deleted chat line ${id}, but isModeration matches removed, which nothing writes, so a moderator deleting a line (#240) never appears in Moderation. The tests do not catch it: they only record banned, muted and unbanned strings by hand. Fix first: match deleted chat line (and drop removed), then add a test that does a real delete over the lobby and finds it in the Moderation section. Two smaller points: the section re-implements the Log list markup, so extract one render function for both; and the log is not reachable from src/tty.ts, so say in the README that the Moderation list is page-only. The mute logging and broadcast addition is reasonable and escaping is correct.

commented

I've fixed all three of juniper's points and pushed. The lobby and admin test files pass (49 tests). The type check printed only a bun tempdir write error and no type errors. I did not run the full suite.

  • Deletions now show up. isModeration in src/admin-page.ts matches deleted chat line and no longer matches removed, which nothing ever wrote.
  • Real-delete test. The existing moderator-delete test in lobby.test.ts now also fetches /admin after bob deletes a line over the lobby. It checks that the Moderation section contains <b>bob</b> deleted chat line N.
  • One list renderer. The Moderation section and the Log now share a single entries() function in admin-page.ts. It does the newest-first ordering and escaping, and takes its own empty-state text.
  • README. Software/so101/README.md now says the Moderation list is page-only, because the admin log isn't reachable from src/tty.ts.

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed it. The lobby, admin and chat test files pass (56 tests). I didn't run the full suite, and the type check printed only a bun tempdir write error and no type errors.

Both conflicts were where main added timed mutes (mute … for: 10m/1h/24h/forever) next to my mute logging.

  • lobby.ts: I kept main's timed-mute and unmute logic and put my admin.record and broadcastAdmin() calls after it. The log line is still muted <name> or unmuted <name>, without the duration.
  • lobby.test.ts: I kept both tests: my mute-logging test and main's timed-mute test.

The pull is otherwise unchanged:

  • /admin has a Moderation section listing bans, unbans, mutes, unmutes, chat-line deletions and removals from the line, newest first, with who and when.
  • It shares one renderer with the Log, escapes every name and text, and is page-only (the README says so).

🤖 Generated with Claude Code

Approved

Approved. /admin gets a Moderation section above the Log, newest first, with who and when. Both lists share one escaped renderer. The tests cover escaping, order, a real mute/unmute and a real delete over the lobby, and a plain user is refused. The README says honestly that the list is page-only. The preview refuses /admin to an anonymous request (404) as it should. I could not look at the owner view, which needs the forge headers. Two things I would do next: (1) put the mute length in the log line (muted alice for 1 h), since a timed mute and a permanent one read the same now. (2) Replace the isModeration regex on free-text log lines with a kind field on the log entry, so a reworded message cannot silently drop out of the list.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs