Repository navigation
feat: add admin area - #173
Open
NTBBloodbath wants to merge 19 commits into
Open
NTBBloodbath wants to merge 19 commits into
NTBBloodbath wants to merge 19 commits into
Conversation
Admin privilege needs a boundary that cannot be reached through normal user account changes. This adds a separate admins table linked to a user by internal ID, with admin and moderator roles and an active flag. The unique user_id constraint and a database check constraint keep one user from holding multiple admin rows or an unknown role. Granting and revoking go through the Admin context in an Ecto.Multi, and each action writes an audit event in the same transaction. Admin actions also need a durable record that is cheap to store and easy to render. The admin_audit_events table keeps a compact row with the action, actor snapshot, target, and JSON metadata. Audit.record/1 inserts synchronously and broadcasts the event on the admin:audit topic for live admin views. A static permissions module defines what admins and moderators may do without adding an authorization dependency.
Admin access can only be granted from a shell, so the grant and revoke paths need tasks that go through the Admin context instead of direct database edits. The new luxpkgs.admin.grant task accepts an internal user ID and an admin or moderator role, starts the application, and reports the resulting account. luxpkgs.admin.revoke deactivates the admin row without deleting it, which keeps audit references intact. The list task prints active and revoked admins with their user IDs, roles, and usernames so operators can confirm access without opening a database console. Task errors use Mix.raise with the context error, and the tests cover grants, role changes, revocations, listing, and invalid arguments.
Admin access now uses the existing GitHub login and user TOTP instead of a second account system. The admins table remains the only source of privilege, and every admin page requires an active row plus a recent TOTP verification. The first visit lands on /admin/verify, successful codes are stored in the session for 30 minutes, and high-risk actions can use the stricter 10-minute helper. Successful verification writes an audit event. The admin sidebar links to the dashboard and back to the public site, shows the moderator or admin role, and renders the GitHub avatar when one is available. The navbar now shows an Admin link to active admins, and the dashboard itself is intentionally empty until the moderation views land.
Add a status field (active, hidden, removed) with a moderation note and featured timestamp. Public listings, search, profile totals, package lookups, downloads and the direct release endpoint now only see active packages, while owners can still open their hidden or removed package and get a status banner instead of download links. Release downloads are counted atomically, and the seeds include hidden and removed demo packages owned via DEMO_OWNER_EMAIL. Seed runs no longer delete users.
Replace the package-level yanked status with a per-release yanked_at timestamp, keeping package status to active and hidden. Yanked releases are skipped for latest-version resolution and package cards, flagged as yanked in the release and LuaRocks responses, and stay downloadable by exact version so existing builds keep working. Owners can yank and unyank their own releases from the package page. Each change writes an audit event in the same transaction and notifies the package channel. The seeds include a package with a yanked release.
Add an admin package list with status and featured filters, owner search, and quick hide, unhide, feature and unfeature actions. Each action checks the admin capability, writes an audit event in the same transaction, clears the package search cache and notifies the owner. Owners now see their hidden packages, with a status badge, on their own profile while other visitors still see only active packages. LuaRocks uploads to hidden packages return a clear forbidden error instead of a unique-name changeset. Drop the unused package remove and restore permissions now that package moderation only hides or restores visibility.
Add an admin package detail page with the selected release source and package metadata side by side. Releases can be selected from a dropdown or with the previous and next buttons, and the left and right arrow keys navigate between them unless a form control has focus. Source files are read from the rockspec storage directory only, capped at 2 MiB, and labeled as rockspec or lux.toml. Missing or oversized files show an error without hiding the package details or moderation actions
The admin dashboard now shows package, release, download, user and admin counts, with recent audit activity for roles allowed to see it. Navigation is shared between the desktop sidebar and the mobile dock, so destinations and active state stay in sync. The package list gains mobile cards, and the package view puts moderation details before the source on small screens.
Add a package-level removed state for severe moderation cases. Unlike hiding, removal is admin-only and requires TOTP verification within the last 10 minutes, so a stolen admin session cannot remove a package without re-verifying. Restore returns a removed package to active. Removal is soft: the package and its releases stay in the database for audit and restoration, but disappear from public listings, search, profiles, downloads, the API, and LuaRocks. Owners keep a read-only view with a removed banner. Both actions are audited and clear the search cache immediately. --- Removal is a package-level moderation state, not a delete: - packages.status is :active, :hidden, or :removed. - Packages.remove_package/3 sets :removed and writes a package.removed audit event in the same transaction. - Packages.restore_package/2 sets a removed package back to :active and writes package.restored. - Both clear the search cache and broadcast the package update, so lists refresh immediately. - Remove is admin-only and requires TOTP verification within the last 10 minutes. Restore is admin-only but does not require fresh TOTP. - Public reads use Packages.visible/1 or active-only getters. A removed package disappears from listings, search, home, profiles, download totals, the API, LuaRocks, and direct release downloads. - The owner can still open /package/<name>, see the package, see a "This package is removed" banner, and has no download links. - Other users get the normal "Package not found" page. - Files and release rows are retained. Removal does not delete the rockspec or rewrite history.
Add a report form for active packages and an admin queue for review. Reports remain open after hiding or removing a package so moderators can resolve or dismiss them explicitly.
Add an admin-only audit page with a day-grouped timeline, live updates, and filters for search, event type, action, actor, target type, and date range. Quick ranges cover 24h, 7d, 30d, 90d, and all history. Show event metadata as a key-value panel with a raw fallback for nested values. Load events 100 at a time up to 500, and keep the URL filters shareable and restorable. Add a shared action catalog for labels and filter groups, and filter the admin navigation by permission so moderators do not see the audit link. Reuse the catalog for the dashboard recent activity labels.
Record package creation, package updates, and release uploads in the admin audit log. Package updates store only the changed field names, never the values, and no-op updates record nothing. This closes the gap between moderation actions, which were already audited, and the regular package lifecycle.
Render the shared theme toggle in the admin sidebar and mobile header. Make the toggle id and dropdown placement configurable so separate instances close their own dropdown, while the public navbar keeps its existing defaults.
Return only packages with featured_at from list_featured/1, ordered by most recently featured. Keep the previous download ranking as list_popular/1 and use it on the home page when no packages are curated. Cover curated ordering, hidden and removed filtering, popular fallback, and feature/unfeature audit metadata with tests
Suspended accounts lose browser sessions, LiveView access, OAuth login, and API tokens. Suspending a user deletes their sessions in the same transaction, deactivates any admin row, and records an audit event. Admins cannot suspend themselves or the last active admin. Packages owned by suspended users stay active. The API pipeline now returns 401 when a bearer token belongs to a suspended user
Admins can browse, search, and filter accounts at /admin/users and inspect a user's profile, packages, download totals, reports, and audit history. The page is read-only; suspension actions come next. Moderators cannot see the users section. --- feat(admin): add suspend and unsuspend actions Admins can suspend an account from its detail page with a required reason, which also disconnects that user's live sessions. Unsuspending restores access. Suspending requires a fresh second factor, and the context still rejects self-suspension and suspending the last active admin.
Packages left behind by a deleted account can now be transferred to an active user from the admin package page. The page searches active users and requires a fresh second factor before transferring. Transfers reuse the moderation pipeline, so the ownership change, audit event, search cache clear, and package broadcast stay consistent. Only packages owned by the deleted sentinel can be transferred, and suspended users cannot be selected.
NTBBloodbath
marked this pull request as ready for review
November 9, 2026 00:58
Granting admin access to a suspended user created an active admin row, or reactivated a revoked one, so the user regained admin access after being unsuspended. Grant now returns :suspended_user before writing the row, and the CLI explains that the user must be unsuspended first.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #139.
Admin access
Admin access is a separate role managed from the CLI:
mix luxpkgs.admin.grant --user-id 42 --role admingrants admin or moderator access,mix luxpkgs.admin.revoke --user-id 42revokes it, andmix luxpkgs.admin.listshows the current accounts. Revoking keeps the admin row inactive so existing references and audit history stay valid. Admins must pass TOTP before entering the area, and destructive actions ask for a fresh second factor.Moderation
The admin area adds a dashboard with usage stats, a searchable package list, package source review, hide and unhide, remove and restore, and featured package selection. Reports get their own queue with reason and status filters, resolution notes, and resolve, dismiss, or warn actions. Moderators can review packages, hide or unhide them, and handle reports; removing, restoring, featuring, managing users, and viewing the audit log stay admin-only.
The package side also gains cargo-style release yanking semantics, so maintainers can mark a release as yanked without deleting it, along with the release metadata needed to show that state.
Users and audit
Admins can inspect a user's profile, packages, downloads, reports, admin state, suspension state, and audit history. Suspending a user ends their browser sessions and API access, deletes their tokens, and deactivates any admin row, while leaving their packages active. Admins cannot suspend themselves or the last active admin. Packages left behind by deleted accounts can be transferred to an active user from the package page using the search-and-pick flow.
Package moderation, report handling, suspension, featured, and ownership actions write audit events with actor and target details. The audit log is filterable by actor, action, target type, date range, and search term, and forms the history behind each user and package.
Testing
The branch adds context, LiveView, API, permission, and Mix task tests. Run
mix test. Manual checks covered suspension and ownership transfer.Note
The trust and vouches work mentioned in #139 is intentionally left for a follow-up.