feat/admin-users-mods-chat #1

Merged
nrupard merged 38 commits from feat/admin-users-mods-chat into main 2026-04-10 18:02:37 +02:00
Owner
No description provided.
Comprehensive design covering auth, RBAC, admin panel, moderation,
DMs, and WebSocket real-time updates. FUTURE.md captures deferred
chat enhancements.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
13 tasks covering dependencies, auth DB, models, DB functions with
tests, server functions, login/register pages, AuthLayout, route
protection, and chat integration with authenticated users.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implements DB query functions for auth (create_user, find_user_by_username,
find_user_by_id, count_users, set_user_role, create_session,
get_user_by_session, delete_session, delete_user_sessions), adds integration
tests covering all 8 auth scenarios, and adds lib.rs so integration tests
can access lets_chat::db::auth.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add register/login/logout/get_current_user server functions with argon2
password hashing, session cookies, and first-user auto-admin promotion.
Add LoginPage, RegisterPage components and AuthLayout guard that redirects
unauthenticated users. Update routes to nest authenticated pages under
AuthLayout.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add current user display (avatar initial, username, role) and logout
button to sidebar. Update Message model and chat DB/server functions
to store user_id instead of freeform author, resolving display names
from auth DB at read time. Remove author input from chat composer.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add helpers.rs with require_auth() and require_role() for session
extraction and role-level enforcement. Refactor auth.rs to delegate
get_session_from_cookie() to the canonical helpers implementation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace inline cookie parsing in send_message with require_auth()
from helpers. Also add mute status check using the returned UserRecord.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add placeholder /admin route with AuthLayout+Layout wrapping.
Sidebar conditionally renders an Admin link when user.role == "admin".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Four tests covering default user role, promotion to moderator/admin,
and demotion back to user, using in-memory SQLite.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add migrations/settings/0001_create_tables.sql with 13 default settings
- Add SETTINGS_POOL and get_settings_pool() to db/mod.rs
- Add src/db/settings.rs with get_setting, set_setting, get_all_settings
- Add src/models/settings.rs with SiteSettings struct
- Register settings module in db/mod.rs and models/mod.rs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add list_users and delete_user to db/auth.rs
- Add create_invite_code, list_invite_codes, revoke_invite_code,
  use_invite_code, get_invite_code to db/auth.rs
- Add src/models/invite.rs with InviteCode struct
- Export InviteCode from models/mod.rs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add create_room, delete_room, and update_room to db/chat.rs
to support admin room management operations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add src/server_fns/admin.rs with all admin-only endpoints:
- get_settings / update_settings (reads/writes SiteSettings)
- list_users / change_user_role / delete_user
- create_invite_code / list_invite_codes / revoke_invite_code
- create_room / delete_room / update_room

All functions call require_role("admin") as the first guard.
Register admin module in server_fns/mod.rs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- tests/db_settings.rs: 6 tests covering get/set/list settings
  including default values, overwrite, and missing key behavior
- tests/db_invite.rs: 6 tests covering create, get, list, use,
  revoke, and duplicate invite code scenarios

All 24 tests pass (8 existing + 4 rbac + 6 settings + 6 invite).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the placeholder /admin route with nested admin routes
(Settings, Users, Invite Codes, Rooms) under an AdminLayout
component that renders a tab bar. Update sidebar admin link to
point to AdminSettings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Settings page loads via get_settings(), displays fields grouped
into General, Registration, Limits, and SMTP cards with inline
editing and a single save button calling update_settings().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Users page lists all users in a table with role dropdowns that
call change_user_role() and delete buttons with confirmation
modal that call delete_user().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Invite codes page with a Generate Code button calling
create_invite_code() and a table listing all codes with
status badges and revoke buttons for unused codes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rooms page with a create form (name + topic), a table listing
all rooms with inline edit mode and delete with confirmation
modal. Uses create_room(), update_room(), and delete_room().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add mod_actions table and soft-delete columns to chat.db.
Add ModAction model, ban/mute/suspend DB functions, and
update User struct with ban fields.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds AdminModLog route and page component, updates admin layout to show
role-appropriate tabs (admin sees all, moderator sees Users + Mod Log),
and updates sidebar to show Moderate link for moderators.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds ban/unban and mute/unmute buttons with reason/duration modals to the
admin users page, and allows moderators (not just admins) to view the user list.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds 0003_dms.sql migration (room_type, created_by columns + room_members table),
registers it in init_chat_pool, adds room_type to the Room model, updates all Room
construction sites in db/chat.rs, and adds find_dm_room, create_dm_room, and
list_user_dm_rooms DB functions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements Phase 5 Task 4: creates DmViewPage component, registers it in
components/mod.rs, adds /dm/:user_id route, updates sidebar with a Direct
Messages section, and makes room message author names clickable DM links.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Phases 1-5 complete (Auth, RBAC, Admin, Moderation, DMs).
Phase 6 (WebSockets) is next — requirements documented.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
nrupard deleted branch feat/admin-users-mods-chat 2026-04-10 18:02:41 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/lets-chat!1
No description provided.