Compare commits
43 Commits
0f29f0acb2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e58fd0c6d | |||
| ebb8f870bb | |||
| 27f7fe5d85 | |||
| 10efafbae5 | |||
| 36ee31896b | |||
| 28d0b76f13 | |||
| 673701c91b | |||
| f13b8fe1fe | |||
| 41a1e84b51 | |||
| 7bd93b8bb0 | |||
| d1ae8f943f | |||
| 222bcb02fc | |||
| ebedee146f | |||
| 47a79d841c | |||
| 62eaa7693d | |||
| 0f05098d8f | |||
| 8ec7f399a7 | |||
| 38aef5964e | |||
| 9408fee3c1 | |||
| c18250eb07 | |||
| 61feca50a8 | |||
| 7aafd0dd74 | |||
| 3b9998539f | |||
| 3c1c174337 | |||
| 247323ff05 | |||
| d48d8c473c | |||
| 2a6e307f16 | |||
| c7a24a186c | |||
| c87563bc32 | |||
| 69998ec548 | |||
| cee4ab8aea | |||
| c6f53a1509 | |||
| 4ad746c43e | |||
| b5e0d01a91 | |||
| 8012a457fc | |||
| 6890a74c7c | |||
| 56c6a279dc | |||
| f40dd765c3 | |||
| 9a1654fc54 | |||
| 02897030e5 | |||
| 5e398d8acd | |||
| 6ba2ed90ed | |||
| 8c30cbbddd |
@@ -93,6 +93,22 @@ jobs:
|
|||||||
docker push "${BOT_IMAGE}:latest"
|
docker push "${BOT_IMAGE}:latest"
|
||||||
docker push "${BOT_IMAGE}:${TAG}"
|
docker push "${BOT_IMAGE}:${TAG}"
|
||||||
|
|
||||||
|
- name: Remove this run's images and cap the build cache
|
||||||
|
# The build runs on the HOST daemon, so whatever it leaves stays on the
|
||||||
|
# runner host for good: every run used to leave four tagged images, and
|
||||||
|
# each newer `latest` turned the previous one into a permanent `sha-` image
|
||||||
|
# until the host ran out of disk. Both tags are in the registry by now, so
|
||||||
|
# the local copies are dead weight. BuildKit keeps its layer cache apart
|
||||||
|
# from the images, so the next build stays fast; the cache is pruned to a
|
||||||
|
# cap instead of growing forever (`--reserved-space` is the same flag's
|
||||||
|
# name on newer Docker). Runs even after a failure, and never fails the job.
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
docker image rm "${APP_IMAGE}:latest" "${APP_IMAGE}:${TAG}" \
|
||||||
|
"${BOT_IMAGE}:latest" "${BOT_IMAGE}:${TAG}" 2>/dev/null || true
|
||||||
|
docker builder prune -f --keep-storage 5GB \
|
||||||
|
|| docker builder prune -f --reserved-space 5GB || true
|
||||||
|
|
||||||
- name: Log out (clear cached credentials from the runner)
|
- name: Log out (clear cached credentials from the runner)
|
||||||
if: always()
|
if: always()
|
||||||
run: docker logout "${REGISTRY}" || true
|
run: docker logout "${REGISTRY}" || true
|
||||||
|
|||||||
42
.gitea/workflows/demo-baseline.yml
Normal file
42
.gitea/workflows/demo-baseline.yml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Capture the demo rig's baseline (docs/website/DEMO_MODE.md §7.2). Run by hand,
|
||||||
|
# after setting the demo default set up through the demo site: the permission
|
||||||
|
# groups, a few NPCs, a clan for the demo's Team. It stops the rig (a power stop
|
||||||
|
# runs `quit`, which saves the world, DM22), compresses oxide/data, oxide/config
|
||||||
|
# and server/<identity> into demo-baseline.tar.gz at the server root, and starts
|
||||||
|
# it again. Every wipe from then on restores that archive.
|
||||||
|
#
|
||||||
|
# Run it right after a wipe has finished and the default set is in place, not
|
||||||
|
# while visitors are mid-change: whatever is on the rig is what every later
|
||||||
|
# cycle returns to.
|
||||||
|
|
||||||
|
name: Demo baseline
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch: {}
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: demo-rig
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
env:
|
||||||
|
DEMO_DIR: ${{ vars.DEMO_DIR || '/opt/demo.runicgateway.com' }}
|
||||||
|
PTERODACTYL_URL: ${{ vars.PTERODACTYL_URL || 'http://192.168.0.12' }}
|
||||||
|
PTERODACTYL_SERVER: ${{ vars.PTERODACTYL_SERVER || '6eb9d621' }}
|
||||||
|
NODE_IMAGE: node:22.23.4-alpine
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
baseline:
|
||||||
|
runs-on: demo-site
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
steps:
|
||||||
|
- name: Check out the deploy files
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Capture the baseline
|
||||||
|
env:
|
||||||
|
PTERODACTYL_CLIENT_KEY: ${{ secrets.PTERODACTYL_CLIENT_KEY }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
docker run --rm -v "$PWD/deploy/demo:/demo:ro" \
|
||||||
|
-e PTERODACTYL_URL -e PTERODACTYL_SERVER -e PTERODACTYL_CLIENT_KEY \
|
||||||
|
"$NODE_IMAGE" node /demo/rig.mjs baseline
|
||||||
125
.gitea/workflows/demo-wipe.yml
Normal file
125
.gitea/workflows/demo-wipe.yml
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
# The public demo's wipe (docs/website/DEMO_MODE.md §7). Every 2 hours on the
|
||||||
|
# hour, UTC (DM7), it puts demo.runicgateway.com and its Rust server back to the
|
||||||
|
# demo's starting point:
|
||||||
|
#
|
||||||
|
# 1. versions the latest Rust bundle and the newest Module-Rust release on the
|
||||||
|
# same protocol (§7.5, DM12)
|
||||||
|
# 2. the rig FIRST: kill, write the new bundle if it changed, restore
|
||||||
|
# demo-baseline.tar.gz, start (§7.2). A fresh site imports what is
|
||||||
|
# on the rig, so the rig must be back before the site talks to it (§7.1)
|
||||||
|
# 3. the site down -v, pull, up, seed:demo (§7.3)
|
||||||
|
# 4. smoke the site answers, then the rig reports in (bounded)
|
||||||
|
#
|
||||||
|
# A redeploy is the same path: a push to main that changes deploy/demo/ runs it,
|
||||||
|
# and so does workflow_dispatch (§7.4).
|
||||||
|
#
|
||||||
|
# Runs on the `demo-site` runner, in host mode, on the demo host itself. The host
|
||||||
|
# needs Docker with Compose, and node for actions/checkout; everything else runs
|
||||||
|
# in containers. One-time host setup: deploy/demo/README.md.
|
||||||
|
#
|
||||||
|
# Secret: PTERODACTYL_CLIENT_KEY the demo subuser's client key (file + power)
|
||||||
|
# Variables: PTERODACTYL_URL, PTERODACTYL_SERVER (defaults below), DEMO_DIR
|
||||||
|
|
||||||
|
name: Demo wipe
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 */2 * * *'
|
||||||
|
workflow_dispatch: {}
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
paths:
|
||||||
|
- 'deploy/demo/**'
|
||||||
|
- '.gitea/workflows/demo-wipe.yml'
|
||||||
|
|
||||||
|
# A wipe and a baseline capture must never overlap: both stop the rig.
|
||||||
|
concurrency:
|
||||||
|
group: demo-rig
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
env:
|
||||||
|
DEMO_DIR: ${{ vars.DEMO_DIR || '/opt/demo.runicgateway.com' }}
|
||||||
|
PTERODACTYL_URL: ${{ vars.PTERODACTYL_URL || 'http://192.168.0.12' }}
|
||||||
|
PTERODACTYL_SERVER: ${{ vars.PTERODACTYL_SERVER || '6eb9d621' }}
|
||||||
|
NODE_IMAGE: node:22.23.4-alpine
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
wipe:
|
||||||
|
runs-on: demo-site
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
steps:
|
||||||
|
- name: Check out the deploy files
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install the deploy files
|
||||||
|
# Everything but .env, which only the host holds, and state/, which the
|
||||||
|
# wipe itself writes.
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
test -f "$DEMO_DIR/.env" || { echo "::error::$DEMO_DIR/.env is missing; see deploy/demo/README.md"; exit 1; }
|
||||||
|
mkdir -p "$DEMO_DIR/state" "$DEMO_DIR/logs" "$DEMO_DIR/modules"
|
||||||
|
# The app runs as uid 1000 and unpacks the declared module into ./modules.
|
||||||
|
# The runner is not root, so a host chown fails; a container is root and
|
||||||
|
# the runner may start one. A failure here stops the run: without it the
|
||||||
|
# app comes up healthy with no module and the seed fails much later.
|
||||||
|
docker run --rm -v "$DEMO_DIR:/demo" "$NODE_IMAGE" chown -R 1000:1000 /demo/modules /demo/logs
|
||||||
|
cp deploy/demo/docker-compose.yml deploy/demo/seed.json deploy/demo/rig.mjs "$DEMO_DIR/"
|
||||||
|
|
||||||
|
- name: Decide the versions
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
docker run --rm -v "$DEMO_DIR:/demo" -e STATE_DIR=/demo/state "$NODE_IMAGE" node /demo/rig.mjs plan
|
||||||
|
|
||||||
|
- name: Restore the rig
|
||||||
|
id: rig
|
||||||
|
# The site is wiped even when this fails: a demo left un-wiped is worse
|
||||||
|
# than one whose rig kept a visitor's changes for a cycle. The last step
|
||||||
|
# fails the run so the failure is seen.
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
PTERODACTYL_CLIENT_KEY: ${{ secrets.PTERODACTYL_CLIENT_KEY }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
docker run --rm -v "$DEMO_DIR:/demo" -e STATE_DIR=/demo/state \
|
||||||
|
-e PTERODACTYL_URL -e PTERODACTYL_SERVER -e PTERODACTYL_CLIENT_KEY \
|
||||||
|
"$NODE_IMAGE" node /demo/rig.mjs restore
|
||||||
|
|
||||||
|
- name: Wipe and reseed the site
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
cd "$DEMO_DIR"
|
||||||
|
docker compose pull
|
||||||
|
docker compose down -v --remove-orphans
|
||||||
|
docker compose up -d
|
||||||
|
for attempt in $(seq 1 60); do
|
||||||
|
STATUS="$(docker inspect -f '{{.State.Health.Status}}' rg-demo-app-1 2>/dev/null || echo starting)"
|
||||||
|
[ "$STATUS" = healthy ] && break
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
if [ "$STATUS" != healthy ]; then
|
||||||
|
echo "::error::the app did not become healthy within 300s"
|
||||||
|
docker compose logs --tail 100 app
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
docker compose exec -T app npm run --silent --prefix server seed:demo -- /app/deploy/demo/seed.json
|
||||||
|
docker compose ps
|
||||||
|
|
||||||
|
- name: Smoke check
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
docker run --rm --network rg-demo_default -v "$DEMO_DIR:/demo" \
|
||||||
|
-e SITE_URL=http://app:3000 "$NODE_IMAGE" node /demo/rig.mjs smoke
|
||||||
|
|
||||||
|
- name: Remove the images this wipe replaced
|
||||||
|
# Each pull that finds a newer `latest` leaves the old image untagged on
|
||||||
|
# the demo host, every two hours. Untagged images are never used again, so
|
||||||
|
# drop them. Dangling images only: nothing tagged and nothing a container
|
||||||
|
# is using is touched.
|
||||||
|
if: always()
|
||||||
|
run: docker image prune -f || true
|
||||||
|
|
||||||
|
- name: Report the rig restore
|
||||||
|
if: steps.rig.outcome == 'failure'
|
||||||
|
run: |
|
||||||
|
echo "::error::the rig restore failed (see its step); the site was wiped and reseeded anyway"
|
||||||
|
exit 1
|
||||||
@@ -44,7 +44,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 22.23.4
|
||||||
cache: npm
|
cache: npm
|
||||||
cache-dependency-path: server/package-lock.json
|
cache-dependency-path: server/package-lock.json
|
||||||
- name: Check core names no module identifier
|
- name: Check core names no module identifier
|
||||||
@@ -90,7 +90,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 22.23.4
|
||||||
cache: npm
|
cache: npm
|
||||||
cache-dependency-path: client/package-lock.json
|
cache-dependency-path: client/package-lock.json
|
||||||
- name: Install client deps
|
- name: Install client deps
|
||||||
@@ -113,7 +113,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 22.23.4
|
||||||
cache: npm
|
cache: npm
|
||||||
cache-dependency-path: bot/package-lock.json
|
cache-dependency-path: bot/package-lock.json
|
||||||
- name: Install bot deps
|
- name: Install bot deps
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM node:20-alpine
|
FROM node:22.23.4-alpine
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ flowchart TB
|
|||||||
|
|
||||||
| Layer | Tech |
|
| Layer | Tech |
|
||||||
|---|---|
|
|---|---|
|
||||||
| Backend | Node.js 20+, Express 4, `mariadb` driver (parameterized SQL, no ORM) |
|
| Backend | Node.js 22 (images pin 22.23.4), Express 4, `mariadb` driver (parameterized SQL, no ORM) |
|
||||||
| Auth | Session service over JWT: httpOnly cookie (web) + bearer access/refresh tokens (mobile), bcrypt hashing, optional TOTP 2FA (`speakeasy` + `qrcode`), pluggable OAuth2/OIDC SSO (built-in Google & Discord + generic) |
|
| Auth | Session service over JWT: httpOnly cookie (web) + bearer access/refresh tokens (mobile), bcrypt hashing, optional TOTP 2FA (`speakeasy` + `qrcode`), pluggable OAuth2/OIDC SSO (built-in Google & Discord + generic) |
|
||||||
| Database | MariaDB 11 (own container) |
|
| Database | MariaDB 11 (own container) |
|
||||||
| Frontend | React 18, Vite 5, React Router 6 |
|
| Frontend | React 18, Vite 5, React Router 6 |
|
||||||
@@ -196,7 +196,8 @@ website/
|
|||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
- **Node.js 20+** and npm (Node 22/24 are fine).
|
- **Node.js 22.23.4+** (or 24.22.1+) and npm. Older builds carry the Node2Shell Brotli bug
|
||||||
|
(CVE-2026-111497), and Node 20 is past end of life.
|
||||||
- **Docker Desktop** (for MariaDB, and for the full Compose deploy).
|
- **Docker Desktop** (for MariaDB, and for the full Compose deploy).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM node:20-alpine
|
FROM node:22.23.4-alpine
|
||||||
|
|
||||||
WORKDIR /app/bot
|
WORKDIR /app/bot
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { Routes, Route, Navigate, Outlet } from 'react-router-dom'
|
|||||||
import { AuthProvider } from './contexts/AuthContext.jsx'
|
import { AuthProvider } from './contexts/AuthContext.jsx'
|
||||||
import { SiteProvider } from './contexts/SiteContext.jsx'
|
import { SiteProvider } from './contexts/SiteContext.jsx'
|
||||||
import MaintenanceGate from './components/MaintenanceGate.jsx'
|
import MaintenanceGate from './components/MaintenanceGate.jsx'
|
||||||
|
import DemoBanner from './components/DemoBanner.jsx'
|
||||||
|
import DemoToast from './components/DemoToast.jsx'
|
||||||
import RequireAuth from './components/RequireAuth.jsx'
|
import RequireAuth from './components/RequireAuth.jsx'
|
||||||
import RequirePlayer from './components/RequirePlayer.jsx'
|
import RequirePlayer from './components/RequirePlayer.jsx'
|
||||||
import RoleGate from './components/RoleGate.jsx'
|
import RoleGate from './components/RoleGate.jsx'
|
||||||
@@ -90,6 +92,10 @@ export default function App() {
|
|||||||
the provider hooks are called once for the whole app rather than
|
the provider hooks are called once for the whole app rather than
|
||||||
once per screen. */}
|
once per screen. */}
|
||||||
<ModuleFeaturesProvider>
|
<ModuleFeaturesProvider>
|
||||||
|
{/* The public demo's strip and refusal toast (DEMO_MODE.md §3.1, §6).
|
||||||
|
Both render nothing unless the server says this is the demo. */}
|
||||||
|
<DemoBanner />
|
||||||
|
<DemoToast />
|
||||||
<Routes>
|
<Routes>
|
||||||
{/* Landing hero — always public, even in maintenance mode. The hero is
|
{/* Landing hero — always public, even in maintenance mode. The hero is
|
||||||
itself the pre-launch "coming soon" page, so it sits outside the
|
itself the pre-launch "coming soon" page, so it sits outside the
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
// Thin fetch wrapper. Always sends cookies (httpOnly JWT) and talks to the
|
// Thin fetch wrapper. Always sends cookies (httpOnly JWT) and talks to the
|
||||||
// same-origin API (/api/v1) — proxied to the Express server in dev.
|
// same-origin API (/api/v1) — proxied to the Express server in dev.
|
||||||
|
import { reportIfDemoLocked } from '../lib/demoNotice.js'
|
||||||
|
|
||||||
const BASE = '/api/v1'
|
const BASE = '/api/v1'
|
||||||
|
|
||||||
// Prefix a non-empty query string with "?" (and nothing when it is empty), so
|
// Prefix a non-empty query string with "?" (and nothing when it is empty), so
|
||||||
@@ -28,6 +30,9 @@ async function req(path, { method = 'GET', body, headers, raw } = {}) {
|
|||||||
const text = await res.text()
|
const text = await res.text()
|
||||||
const data = text ? safeParse(text) : null
|
const data = text ? safeParse(text) : null
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
|
// The public demo's lock (DEMO_MODE.md §3.1): shown once, as a toast, for
|
||||||
|
// every caller. The ApiError below still goes to the form as usual.
|
||||||
|
reportIfDemoLocked(data)
|
||||||
const message = (data && data.message) || res.statusText || 'Request failed'
|
const message = (data && data.message) || res.statusText || 'Request failed'
|
||||||
throw new ApiError(res.status, message, data)
|
throw new ApiError(res.status, message, data)
|
||||||
}
|
}
|
||||||
@@ -112,6 +117,10 @@ export const api = {
|
|||||||
// The change endpoints re-issue the session cookie server-side, so the caller
|
// The change endpoints re-issue the session cookie server-side, so the caller
|
||||||
// stays signed in.
|
// stays signed in.
|
||||||
myAccount: () => req('/auth/me/account'),
|
myAccount: () => req('/auth/me/account'),
|
||||||
|
// Delete the signed-in account (ACCOUNT_DELETION.md §4.1). The password always,
|
||||||
|
// and `code` or `recoveryCode` when two-factor is on; refusals carry a `code`.
|
||||||
|
deleteMyAccount: ({ username, password, code, recoveryCode }) =>
|
||||||
|
req('/auth/me/account', { method: 'DELETE', body: { username, password, code, recoveryCode } }),
|
||||||
changeUsername: (username) =>
|
changeUsername: (username) =>
|
||||||
req('/auth/me/account/username', { method: 'PATCH', body: { username } }),
|
req('/auth/me/account/username', { method: 'PATCH', body: { username } }),
|
||||||
changePassword: (newPassword, currentPassword) =>
|
changePassword: (newPassword, currentPassword) =>
|
||||||
@@ -133,14 +142,32 @@ export const api = {
|
|||||||
totpDisable: (code) => req('/auth/me/account/totp/disable', { method: 'POST', body: { code } }),
|
totpDisable: (code) => req('/auth/me/account/totp/disable', { method: 'POST', body: { code } }),
|
||||||
// Linked SSO identities (self-service). Linking starts at /auth/sso/:id/link.
|
// Linked SSO identities (self-service). Linking starts at /auth/sso/:id/link.
|
||||||
myIdentities: () => req('/auth/me/account/identities'),
|
myIdentities: () => req('/auth/me/account/identities'),
|
||||||
unlinkIdentity: (provider) =>
|
// With an identity id, only that one goes (a person may hold several Steam accounts).
|
||||||
req(`/auth/me/account/identities/${encodeURIComponent(provider)}`, { method: 'DELETE' }),
|
unlinkIdentity: (provider, id) =>
|
||||||
|
req(
|
||||||
|
`/auth/me/account/identities/${encodeURIComponent(provider)}${id != null ? `?id=${encodeURIComponent(id)}` : ''}`,
|
||||||
|
{ method: 'DELETE' },
|
||||||
|
),
|
||||||
// Recovery (backup) codes. status → remaining count; generate → a fresh set,
|
// Recovery (backup) codes. status → remaining count; generate → a fresh set,
|
||||||
// returned ONCE (password step-up for accounts that have a password).
|
// returned ONCE (password step-up for accounts that have a password).
|
||||||
recoveryCodesStatus: () => req('/auth/me/account/recovery-codes/status'),
|
recoveryCodesStatus: () => req('/auth/me/account/recovery-codes/status'),
|
||||||
generateRecoveryCodes: (currentPassword) =>
|
generateRecoveryCodes: (currentPassword) =>
|
||||||
req('/auth/me/account/recovery-codes/generate', { method: 'POST', body: { currentPassword } }),
|
req('/auth/me/account/recovery-codes/generate', { method: 'POST', body: { currentPassword } }),
|
||||||
|
|
||||||
|
// Report, block and "Hide for me" (USER_SAFETY.md §4.1). A block and a report
|
||||||
|
// name an ITEM — `{ targetType, targetId }` — never a person: the server reads
|
||||||
|
// who wrote it. Saved on the account, so they apply on every device.
|
||||||
|
reportItem: ({ targetType, targetId, reason, detail }) =>
|
||||||
|
req('/player/reports', { method: 'POST', body: { targetType, targetId, reason, detail } }),
|
||||||
|
myBlocks: () => req('/auth/me/blocks'),
|
||||||
|
blockAuthor: ({ targetType, targetId }) => req('/auth/me/blocks', { method: 'POST', body: { targetType, targetId } }),
|
||||||
|
unblock: (id) => req(`/auth/me/blocks/${encodeURIComponent(id)}`, { method: 'DELETE' }),
|
||||||
|
myHidden: () => req('/auth/me/hidden'),
|
||||||
|
hideItem: ({ targetType, targetId }) => req('/auth/me/hidden', { method: 'POST', body: { targetType, targetId } }),
|
||||||
|
unhideItem: ({ targetType, targetId }) =>
|
||||||
|
req(`/auth/me/hidden/${encodeURIComponent(targetType)}/${encodeURIComponent(targetId)}`, { method: 'DELETE' }),
|
||||||
|
clearHidden: () => req('/auth/me/hidden', { method: 'DELETE' }),
|
||||||
|
|
||||||
// ----- settings (any authenticated account) -----
|
// ----- settings (any authenticated account) -----
|
||||||
// Nav overrides for the layouts the caller's own role renders, and the theme
|
// Nav overrides for the layouts the caller's own role renders, and the theme
|
||||||
// catalog the appearance form is built from. A fifth group, not part of
|
// catalog the appearance form is built from. A fifth group, not part of
|
||||||
@@ -643,6 +670,10 @@ export const api = {
|
|||||||
},
|
},
|
||||||
handleContentReport: (id, body) =>
|
handleContentReport: (id, body) =>
|
||||||
req(`/admin/moderation/reports/${id}/handle`, { method: 'POST', body }),
|
req(`/admin/moderation/reports/${id}/handle`, { method: 'POST', body }),
|
||||||
|
// "Hide for everyone" (USER_SAFETY.md §4.1): hides the item through its own
|
||||||
|
// moderation and actions the report.
|
||||||
|
hideReportedItem: (id, body = {}) =>
|
||||||
|
req(`/admin/moderation/reports/${id}/hide`, { method: 'POST', body }),
|
||||||
modRecent: (params = {}) => {
|
modRecent: (params = {}) => {
|
||||||
const qs = new URLSearchParams()
|
const qs = new URLSearchParams()
|
||||||
if (params.type) qs.set('type', params.type)
|
if (params.type) qs.set('type', params.type)
|
||||||
|
|||||||
47
client/src/components/DemoBanner.jsx
Normal file
47
client/src/components/DemoBanner.jsx
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import { Link } from 'react-router-dom'
|
||||||
|
import { useSite } from '../contexts/SiteContext.jsx'
|
||||||
|
import { formatResetTime } from '../lib/demoNotice.js'
|
||||||
|
|
||||||
|
// The public demo's strip, on every page (docs/website/DEMO_MODE.md §6).
|
||||||
|
// Renders nothing unless GET /public/settings carries a `demo` block, which the
|
||||||
|
// server sends only with DEMO_MODE on — so a real shard never draws it, and the
|
||||||
|
// banner needs no schedule of its own: `resetsAt` is stamped by every wipe.
|
||||||
|
export default function DemoBanner() {
|
||||||
|
const { settings } = useSite()
|
||||||
|
const demo = settings.demo
|
||||||
|
if (!demo) return null
|
||||||
|
|
||||||
|
const at = demo.resetsAt ? formatResetTime(demo.resetsAt) : null
|
||||||
|
const names = (demo.logins || []).map((l) => l.username)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
role="note"
|
||||||
|
className="sans"
|
||||||
|
style={{
|
||||||
|
padding: '7px 16px',
|
||||||
|
textAlign: 'center',
|
||||||
|
fontSize: '0.82rem',
|
||||||
|
lineHeight: 1.45,
|
||||||
|
color: 'var(--head)',
|
||||||
|
background: 'var(--bg-deep)',
|
||||||
|
borderBottom: '1px solid var(--accent)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<strong style={{ color: 'var(--accent)' }}>Demo site</strong>
|
||||||
|
{' — anything you change is wiped '}
|
||||||
|
{at ? `at ${at}` : 'every two hours'}.
|
||||||
|
{names.length > 0 && (
|
||||||
|
<>
|
||||||
|
{' Sign-ins: '}
|
||||||
|
{names.join(' / ')}
|
||||||
|
{' — passwords on the '}
|
||||||
|
<Link to="/account/login" style={{ color: 'var(--accent)' }}>
|
||||||
|
sign-in page
|
||||||
|
</Link>
|
||||||
|
.
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
51
client/src/components/DemoLogins.jsx
Normal file
51
client/src/components/DemoLogins.jsx
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { useSite } from '../contexts/SiteContext.jsx'
|
||||||
|
|
||||||
|
// The published sign-ins, on the sign-in pages of the public demo
|
||||||
|
// (DEMO_MODE.md §4). They are public by design — printed here and on
|
||||||
|
// runicgateway.com/beta — so "Use" fills the form rather than making anyone
|
||||||
|
// copy a password. Renders nothing off the demo.
|
||||||
|
export default function DemoLogins({ onPick }) {
|
||||||
|
const { settings } = useSite()
|
||||||
|
const logins = settings.demo?.logins || []
|
||||||
|
if (logins.length === 0) return null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section
|
||||||
|
aria-label="Demo sign-ins"
|
||||||
|
className="sans"
|
||||||
|
style={{
|
||||||
|
marginTop: 18,
|
||||||
|
padding: '14px 16px',
|
||||||
|
border: '1px solid var(--line)',
|
||||||
|
borderRadius: 10,
|
||||||
|
fontSize: '0.84rem',
|
||||||
|
// Opaque: the admin sign-in page draws it over the hero image.
|
||||||
|
background: 'var(--bg-deep)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<p style={{ margin: '0 0 10px', color: 'var(--head)' }}>
|
||||||
|
<strong>Demo sign-ins</strong> <span style={{ color: 'var(--dim)' }}>— shared by everyone, reset every wipe</span>
|
||||||
|
</p>
|
||||||
|
<table style={{ width: '100%', borderCollapse: 'collapse' }}>
|
||||||
|
<tbody>
|
||||||
|
{logins.map((l) => (
|
||||||
|
<tr key={l.username}>
|
||||||
|
<td style={{ padding: '5px 0', verticalAlign: 'middle' }}>
|
||||||
|
<div style={{ color: 'var(--head)', whiteSpace: 'nowrap' }}>{l.username}</div>
|
||||||
|
<div style={{ color: 'var(--dim)', fontFamily: 'monospace', fontSize: '0.78rem', wordBreak: 'break-all' }}>
|
||||||
|
{l.password}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td style={{ padding: '5px 8px', color: 'var(--dim)', verticalAlign: 'middle' }}>{l.role}</td>
|
||||||
|
<td style={{ padding: '5px 0', textAlign: 'right', verticalAlign: 'middle' }}>
|
||||||
|
<button type="button" className="btn btn-ghost" style={{ padding: '3px 10px', fontSize: '0.8rem' }} onClick={() => onPick(l.username, l.password)}>
|
||||||
|
Use
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
51
client/src/components/DemoToast.jsx
Normal file
51
client/src/components/DemoToast.jsx
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { onDemoLocked } from '../lib/demoNotice.js'
|
||||||
|
import { onNotice } from '../lib/notice.js'
|
||||||
|
|
||||||
|
// The one toast for a write the public demo refused (DEMO_MODE.md §3.1). Fed
|
||||||
|
// by api/client.js through lib/demoNotice.js, so every screen — and every
|
||||||
|
// installed module's screens — gets it without handling the code itself. On a
|
||||||
|
// real shard nothing is ever refused that way, so it never appears.
|
||||||
|
const SHOW_MS = 5000
|
||||||
|
|
||||||
|
export default function DemoToast() {
|
||||||
|
const [message, setMessage] = useState(null)
|
||||||
|
|
||||||
|
useEffect(() => onDemoLocked((text) => setMessage(text)), [])
|
||||||
|
// Also the site's one passing notice (lib/notice.js), on any deployment: the
|
||||||
|
// account page's "Your account has been deleted." after it has navigated home.
|
||||||
|
useEffect(() => onNotice((text) => setMessage(text)), [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!message) return undefined
|
||||||
|
const t = setTimeout(() => setMessage(null), SHOW_MS)
|
||||||
|
return () => clearTimeout(t)
|
||||||
|
}, [message])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
role="status"
|
||||||
|
aria-live="polite"
|
||||||
|
style={{ position: 'fixed', left: 16, right: 16, bottom: 20, zIndex: 1000, display: 'flex', justifyContent: 'center', pointerEvents: 'none' }}
|
||||||
|
>
|
||||||
|
{message && (
|
||||||
|
<div
|
||||||
|
className="sans"
|
||||||
|
style={{
|
||||||
|
maxWidth: 480,
|
||||||
|
padding: '11px 16px',
|
||||||
|
borderRadius: 10,
|
||||||
|
fontSize: '0.88rem',
|
||||||
|
color: 'var(--head)',
|
||||||
|
background: 'var(--bg-deep)',
|
||||||
|
border: '1px solid var(--accent)',
|
||||||
|
boxShadow: '0 12px 32px rgba(0,0,0,0.45)',
|
||||||
|
pointerEvents: 'auto',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{message}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// Inline SVG brand icons for SSO providers. No binary assets — these scale
|
// Inline SVG brand icons for SSO providers. No binary assets — these scale
|
||||||
// crisply at any size and keep their own brand colors. `icon` matches the
|
// crisply at any size and keep their own brand colors. `icon` matches the
|
||||||
// provider `kind` from the discovery endpoint ('google' | 'discord' | oidc/oauth2).
|
// provider `kind` from the discovery endpoint ('google' | 'discord' | 'steam' | oidc/oauth2).
|
||||||
// Anything unknown falls back to a neutral key glyph in the current text color.
|
// Anything unknown falls back to a neutral key glyph in the current text color.
|
||||||
|
|
||||||
function GoogleMark({ size }) {
|
function GoogleMark({ size }) {
|
||||||
@@ -22,6 +22,16 @@ function DiscordMark({ size }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Steam's mark in the current text color: its brand ink is near-black, which
|
||||||
|
// would vanish on the dark theme.
|
||||||
|
function SteamMark({ size }) {
|
||||||
|
return (
|
||||||
|
<svg width={size} height={size} viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" focusable="false">
|
||||||
|
<path d="M11.979 0C5.678 0 .511 4.86.022 11.037l6.432 2.658c.545-.371 1.203-.59 1.912-.59.063 0 .125.004.188.006l2.861-4.142V8.91c0-2.495 2.028-4.524 4.524-4.524 2.494 0 4.524 2.031 4.524 4.527s-2.03 4.525-4.524 4.525h-.105l-4.076 2.911c0 .052.004.105.004.159 0 1.875-1.515 3.396-3.39 3.396-1.635 0-3.016-1.173-3.331-2.727L.436 15.27C1.862 20.307 6.486 24 11.979 24c6.627 0 11.999-5.373 11.999-12S18.605 0 11.979 0zM7.54 18.21l-1.473-.61c.262.543.714.999 1.314 1.25 1.297.539 2.793-.076 3.332-1.375.263-.63.264-1.319.005-1.949s-.75-1.121-1.377-1.383c-.624-.26-1.29-.249-1.878-.03l1.523.63c.956.4 1.409 1.5 1.009 2.455-.397.957-1.497 1.41-2.454 1.012H7.54zm11.415-9.303c0-1.662-1.353-3.015-3.015-3.015-1.665 0-3.015 1.353-3.015 3.015 0 1.665 1.35 3.015 3.015 3.015 1.663 0 3.015-1.35 3.015-3.015zm-5.273-.005c0-1.252 1.013-2.266 2.265-2.266 1.249 0 2.266 1.014 2.266 2.266 0 1.251-1.017 2.265-2.266 2.265-1.253 0-2.265-1.014-2.265-2.265z" />
|
||||||
|
</svg>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function GenericMark({ size }) {
|
function GenericMark({ size }) {
|
||||||
return (
|
return (
|
||||||
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false">
|
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false">
|
||||||
@@ -33,5 +43,6 @@ function GenericMark({ size }) {
|
|||||||
export default function ProviderIcon({ icon, size = 18 }) {
|
export default function ProviderIcon({ icon, size = 18 }) {
|
||||||
if (icon === 'google') return <GoogleMark size={size} />
|
if (icon === 'google') return <GoogleMark size={size} />
|
||||||
if (icon === 'discord') return <DiscordMark size={size} />
|
if (icon === 'discord') return <DiscordMark size={size} />
|
||||||
|
if (icon === 'steam') return <SteamMark size={size} />
|
||||||
return <GenericMark size={size} />
|
return <GenericMark size={size} />
|
||||||
}
|
}
|
||||||
|
|||||||
119
client/src/components/security/BlockedPanel.jsx
Normal file
119
client/src/components/security/BlockedPanel.jsx
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
|
import { api } from '../../api/client.js'
|
||||||
|
import { blockSubtitle } from '../../lib/userSafety.js'
|
||||||
|
|
||||||
|
// Account → Blocked (docs/website/USER_SAFETY.md §1, §4.1). The members and
|
||||||
|
// players this account has blocked, each with Unblock, and the items it hid for
|
||||||
|
// itself, with one "Show them again".
|
||||||
|
//
|
||||||
|
// Blocks and hides are saved on the account, so this list is the same one the
|
||||||
|
// app shows, and undoing one here undoes it everywhere. The role-agnostic
|
||||||
|
// /auth/me surface, so the same panel serves players and staff.
|
||||||
|
//
|
||||||
|
// Two kinds of block, and the panel names which: an account (a forum author, or
|
||||||
|
// a chat speaker whose game account is linked — S12) or a game identity nobody
|
||||||
|
// has linked yet (a Steam id). A block whose target has since become staff no
|
||||||
|
// longer applies (S8), and the row says so rather than the block vanishing.
|
||||||
|
|
||||||
|
export default function BlockedPanel() {
|
||||||
|
const [blocks, setBlocks] = useState(null)
|
||||||
|
const [hiddenCount, setHiddenCount] = useState(0)
|
||||||
|
const [error, setError] = useState('')
|
||||||
|
const [msg, setMsg] = useState('')
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const [b, h] = await Promise.all([api.myBlocks(), api.myHidden()])
|
||||||
|
setBlocks(b.blocks || [])
|
||||||
|
setHiddenCount((h.hidden || []).length)
|
||||||
|
} catch {
|
||||||
|
setError('Could not load your blocks.')
|
||||||
|
setBlocks([])
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
useEffect(() => {
|
||||||
|
load()
|
||||||
|
}, [load])
|
||||||
|
|
||||||
|
async function unblock(block) {
|
||||||
|
setBusy(true)
|
||||||
|
setMsg('')
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
await api.unblock(block.id)
|
||||||
|
setMsg(block.name ? `${block.name} is unblocked.` : 'Unblocked.')
|
||||||
|
await load()
|
||||||
|
} catch {
|
||||||
|
setError('Could not unblock that.')
|
||||||
|
} finally {
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function showHidden() {
|
||||||
|
setBusy(true)
|
||||||
|
setMsg('')
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
await api.clearHidden()
|
||||||
|
setMsg('Everything you hid is shown again.')
|
||||||
|
await load()
|
||||||
|
} catch {
|
||||||
|
setError('Could not show those again.')
|
||||||
|
} finally {
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!blocks) return null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ marginTop: 40, borderTop: '1px solid var(--line-soft)', paddingTop: 28 }}>
|
||||||
|
<h2 className="display" style={{ marginTop: 0, fontSize: '1.2rem', color: 'var(--head)' }}>
|
||||||
|
Blocked
|
||||||
|
</h2>
|
||||||
|
<p className="sans" style={{ color: 'var(--muted)', fontSize: '0.9rem', lineHeight: 1.6 }}>
|
||||||
|
You don’t see anything a blocked member or player writes — forum posts and in-game chat — on this
|
||||||
|
site or in the app. They aren’t told. Staff can’t be blocked.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{blocks.length > 0 ? (
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 10, margin: '14px 0' }}>
|
||||||
|
{blocks.map((b) => (
|
||||||
|
<div key={b.id} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '10px 14px', border: '1px solid var(--line)', borderRadius: 8 }}>
|
||||||
|
<div style={{ flex: 1, minWidth: 0 }}>
|
||||||
|
<div className="sans" style={{ color: 'var(--head)', fontSize: '0.9rem' }}>{b.name || 'Unknown player'}</div>
|
||||||
|
<div className="sans dim" style={{ fontSize: '0.76rem', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||||
|
{blockSubtitle(b)}
|
||||||
|
</div>
|
||||||
|
{!b.applies && b.reason === 'staff' && (
|
||||||
|
<div className="sans" style={{ fontSize: '0.76rem', color: '#d9b884', marginTop: 2 }}>
|
||||||
|
Not applied: this account is now a staff member, and staff can’t be blocked.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<button onClick={() => unblock(b)} disabled={busy} className="pill">
|
||||||
|
Unblock
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="sans dim" style={{ fontSize: '0.86rem', margin: '14px 0' }}>You haven’t blocked anyone.</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{hiddenCount > 0 && (
|
||||||
|
<div style={{ display: 'flex', gap: 10, alignItems: 'center', flexWrap: 'wrap' }}>
|
||||||
|
<span className="sans dim" style={{ fontSize: '0.86rem' }}>
|
||||||
|
You’ve hidden {hiddenCount} {hiddenCount === 1 ? 'item' : 'items'} for yourself.
|
||||||
|
</span>
|
||||||
|
<button onClick={showHidden} disabled={busy} className="pill">Show them again</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{msg && <p className="sans" style={{ marginTop: 14, color: '#7fd0a4', fontSize: '0.86rem' }}>{msg}</p>}
|
||||||
|
{error && <p className="sans" style={{ marginTop: 14, color: '#d98b84', fontSize: '0.86rem' }}>{error}</p>}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
178
client/src/components/security/DeleteAccountPanel.jsx
Normal file
178
client/src/components/security/DeleteAccountPanel.jsx
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { useAuth } from '../../contexts/AuthContext.jsx'
|
||||||
|
import { useSite } from '../../contexts/SiteContext.jsx'
|
||||||
|
import { api } from '../../api/client.js'
|
||||||
|
import { showNotice } from '../../lib/notice.js'
|
||||||
|
import {
|
||||||
|
WHAT_GOES, WHAT_STAYS, STAFF_NAME_NOTE, isStaffRole, usernameMatches, isSharedDemoLogin, refusalMessage,
|
||||||
|
} from '../../lib/accountDeletion.js'
|
||||||
|
|
||||||
|
// "Delete my account" (docs/website/ACCOUNT_DELETION.md §4.2). Last on the
|
||||||
|
// Account page and set apart from the sections above it.
|
||||||
|
//
|
||||||
|
// The account goes at once — there is no grace period (AD4) — so the safeguard
|
||||||
|
// is the confirm step: the typed username, the password, and a two-factor code
|
||||||
|
// when two-factor is on. Delete stays off until the username matches.
|
||||||
|
//
|
||||||
|
// On success the server has already dropped every session. This screen sends
|
||||||
|
// the browser home, re-reads the session (which is now gone) and says so.
|
||||||
|
|
||||||
|
const DANGER = '#d98b84'
|
||||||
|
|
||||||
|
export default function DeleteAccountPanel({ account }) {
|
||||||
|
const { refresh } = useAuth()
|
||||||
|
const { settings } = useSite()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
const [typed, setTyped] = useState('')
|
||||||
|
const [password, setPassword] = useState('')
|
||||||
|
const [code, setCode] = useState('')
|
||||||
|
const [useRecovery, setUseRecovery] = useState(false)
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
|
const demoLocked = isSharedDemoLogin(settings, account.username)
|
||||||
|
const noPassword = account.has_password === false
|
||||||
|
const needsCode = Boolean(account.totp_enabled)
|
||||||
|
const ready = usernameMatches(typed, account.username) && password.length > 0 && (!needsCode || code.trim().length > 0)
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
setOpen(false)
|
||||||
|
setTyped('')
|
||||||
|
setPassword('')
|
||||||
|
setCode('')
|
||||||
|
setUseRecovery(false)
|
||||||
|
setError('')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function confirm(e) {
|
||||||
|
e.preventDefault()
|
||||||
|
if (!ready || busy) return
|
||||||
|
setBusy(true)
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
await api.deleteMyAccount({
|
||||||
|
username: typed.trim(),
|
||||||
|
password,
|
||||||
|
...(needsCode ? (useRecovery ? { recoveryCode: code.trim() } : { code: code.trim() }) : {}),
|
||||||
|
})
|
||||||
|
navigate('/', { replace: true })
|
||||||
|
showNotice('Your account has been deleted.')
|
||||||
|
await refresh()
|
||||||
|
} catch (err) {
|
||||||
|
setError(refusalMessage(err))
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section
|
||||||
|
aria-labelledby="delete-account-heading"
|
||||||
|
style={{ borderTop: `1px solid ${DANGER}`, paddingTop: 26, marginTop: 40 }}
|
||||||
|
>
|
||||||
|
<h2 id="delete-account-heading" className="display" style={{ marginTop: 0, fontSize: '1.15rem', color: DANGER }}>
|
||||||
|
Delete my account
|
||||||
|
</h2>
|
||||||
|
<div className="sans" style={{ color: 'var(--muted)', fontSize: '0.88rem', lineHeight: 1.6, maxWidth: 640 }}>
|
||||||
|
<p style={{ marginTop: 0 }}>
|
||||||
|
Your account is deleted straight away and cannot be restored. These go with it:
|
||||||
|
</p>
|
||||||
|
<ul style={{ margin: '0 0 12px', paddingLeft: 20 }}>
|
||||||
|
{WHAT_GOES.map((line) => <li key={line}>{line}</li>)}
|
||||||
|
</ul>
|
||||||
|
<p style={{ margin: '0 0 6px' }}>What stays:</p>
|
||||||
|
<ul style={{ margin: '0 0 12px', paddingLeft: 20 }}>
|
||||||
|
{WHAT_STAYS.map((line) => <li key={line}>{line}</li>)}
|
||||||
|
</ul>
|
||||||
|
{isStaffRole(account.role) && <p style={{ margin: '0 0 12px' }}>{STAFF_NAME_NOTE}</p>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{noPassword && (
|
||||||
|
<p className="sans" style={{ color: DANGER, fontSize: '0.86rem' }}>
|
||||||
|
This account has no password yet. Set one in the Password section above first; the password is how you
|
||||||
|
confirm a deletion.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!open && (
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setOpen(true)}
|
||||||
|
disabled={demoLocked || noPassword}
|
||||||
|
className="btn btn-sq"
|
||||||
|
style={{ borderColor: DANGER, color: DANGER }}
|
||||||
|
>
|
||||||
|
Delete my account…
|
||||||
|
</button>
|
||||||
|
{demoLocked && (
|
||||||
|
<p className="sans dim" style={{ fontSize: '0.82rem', margin: '8px 0 0' }}>
|
||||||
|
This is turned off on the demo site.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{open && (
|
||||||
|
<form
|
||||||
|
onSubmit={confirm}
|
||||||
|
style={{ display: 'flex', flexDirection: 'column', gap: 12, maxWidth: 360, padding: 16, border: `1px solid ${DANGER}`, borderRadius: 10 }}
|
||||||
|
>
|
||||||
|
<label>
|
||||||
|
<span className="field-label">
|
||||||
|
Type <strong style={{ color: 'var(--head)' }}>{account.username}</strong> to confirm
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={typed}
|
||||||
|
onChange={(e) => setTyped(e.target.value)}
|
||||||
|
className="input"
|
||||||
|
autoComplete="off"
|
||||||
|
autoCapitalize="none"
|
||||||
|
spellCheck={false}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span className="field-label">Password</span>
|
||||||
|
<input type="password" value={password} onChange={(e) => setPassword(e.target.value)} className="input" autoComplete="current-password" />
|
||||||
|
</label>
|
||||||
|
{needsCode && (
|
||||||
|
<label>
|
||||||
|
<span className="field-label">{useRecovery ? 'Recovery code' : 'Authenticator code'}</span>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
inputMode={useRecovery ? 'text' : 'numeric'}
|
||||||
|
autoComplete="one-time-code"
|
||||||
|
value={code}
|
||||||
|
onChange={(e) => setCode(e.target.value)}
|
||||||
|
className="input"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="pill"
|
||||||
|
style={{ marginTop: 8 }}
|
||||||
|
onClick={() => { setUseRecovery((v) => !v); setCode('') }}
|
||||||
|
>
|
||||||
|
{useRecovery ? 'Use an authenticator code instead' : 'Use a recovery code instead'}
|
||||||
|
</button>
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
|
<div style={{ display: 'flex', gap: 10, alignItems: 'center', flexWrap: 'wrap' }}>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={!ready || busy}
|
||||||
|
className="btn btn-sq"
|
||||||
|
style={{ background: ready ? DANGER : undefined, borderColor: DANGER, color: ready ? '#1a1a1a' : DANGER }}
|
||||||
|
>
|
||||||
|
{busy ? 'Deleting…' : 'Delete my account'}
|
||||||
|
</button>
|
||||||
|
<button type="button" onClick={close} disabled={busy} className="pill">Cancel</button>
|
||||||
|
</div>
|
||||||
|
{error && <p role="alert" className="sans" style={{ margin: 0, color: DANGER, fontSize: '0.85rem' }}>{error}</p>}
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
66
client/src/components/security/linkedIdentities.jsx
Normal file
66
client/src/components/security/linkedIdentities.jsx
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import ProviderIcon from '../ProviderIcon.jsx'
|
||||||
|
|
||||||
|
// What the player's and the staff account pages share about a linked sign-in
|
||||||
|
// identity. Steam is the one provider that differs (STEAM_SIGNIN.md): a person may
|
||||||
|
// link several Steam accounts, each shows its persona name, avatar and SteamID64,
|
||||||
|
// and unlinking one removes only the sign-in — a game link made from it stays
|
||||||
|
// (D393).
|
||||||
|
|
||||||
|
// Providers a person may link more than one account of.
|
||||||
|
const MULTI_LINK = new Set(['steam'])
|
||||||
|
|
||||||
|
export function canLinkAgain(providerId) {
|
||||||
|
return MULTI_LINK.has(providerId)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function identityIcon(provider) {
|
||||||
|
return provider === 'google' || provider === 'discord' || provider === 'steam' ? provider : 'oidc'
|
||||||
|
}
|
||||||
|
|
||||||
|
// The outcome of a link round trip, from the query string it returns with.
|
||||||
|
export function linkBanner(search) {
|
||||||
|
const q = new URLSearchParams(search)
|
||||||
|
if (q.get('linked')) return { ok: true, text: 'Account linked.' }
|
||||||
|
if (q.get('link_error') === 'in_use') return { ok: false, text: 'That external account is already linked to another user on this site.' }
|
||||||
|
if (q.get('link_error') === 'refused') return { ok: false, text: 'That account cannot be linked right now. Please try again later.' }
|
||||||
|
if (q.get('link_error')) return { ok: false, text: 'Could not link that account. Please try again.' }
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Providers to offer a Link button for: every enabled one not yet linked, and a
|
||||||
|
// multi-link one (Steam) always.
|
||||||
|
export function linkableProviders(available, linked) {
|
||||||
|
const linkedIds = new Set(linked.map((i) => i.provider))
|
||||||
|
return available.filter((p) => !linkedIds.has(p.id) || canLinkAgain(p.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function unlinkPrompt(identity, providerName) {
|
||||||
|
if (identity.provider === 'steam') {
|
||||||
|
const who = identity.display_name ? `${identity.display_name} (${identity.subject})` : identity.subject
|
||||||
|
return `Unlink the Steam account ${who}? You will no longer be able to sign in with it. A game link made with it stays until you remove it on that game's page.`
|
||||||
|
}
|
||||||
|
return `Unlink ${providerName} from your account?`
|
||||||
|
}
|
||||||
|
|
||||||
|
// The icon (or Steam avatar), the provider name, and what identifies the account.
|
||||||
|
export function IdentitySummary({ identity, providerName }) {
|
||||||
|
const isSteam = identity.provider === 'steam'
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<span style={{ display: 'inline-flex', width: 20, height: 20, color: 'var(--head)', flex: '0 0 auto' }}>
|
||||||
|
{isSteam && identity.avatar_url ? (
|
||||||
|
<img src={identity.avatar_url} alt="" width={20} height={20} style={{ borderRadius: 4 }} referrerPolicy="no-referrer" />
|
||||||
|
) : (
|
||||||
|
<ProviderIcon icon={identityIcon(identity.provider)} size={20} />
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
<div style={{ flex: 1, minWidth: 0 }}>
|
||||||
|
<div className="sans" style={{ color: 'var(--head)', fontSize: '0.9rem', overflowWrap: 'anywhere' }}>
|
||||||
|
{isSteam && identity.display_name ? `${providerName}: ${identity.display_name}` : providerName}
|
||||||
|
</div>
|
||||||
|
{isSteam && identity.subject && <div className="sans dim" style={{ fontSize: '0.78rem' }}>{identity.subject}</div>}
|
||||||
|
{!isSteam && identity.email && <div className="sans dim" style={{ fontSize: '0.78rem' }}>{identity.email}</div>}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
69
client/src/lib/accountDeletion.js
Normal file
69
client/src/lib/accountDeletion.js
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
// What the Account page's "Delete my account" section says and decides
|
||||||
|
// (docs/website/ACCOUNT_DELETION.md §4.1, §4.2). Plain JS with tests, so the
|
||||||
|
// words and the confirm rule can be checked without a browser.
|
||||||
|
//
|
||||||
|
// The server is the guard: it checks the username, the password and the code
|
||||||
|
// again whatever this file decides. What is here only keeps a mis-tap from
|
||||||
|
// reaching it and turns its refusal codes into sentences.
|
||||||
|
|
||||||
|
/** What goes with the account. The same list as BACKEND_DESIGN.md's. */
|
||||||
|
export const WHAT_GOES = [
|
||||||
|
'your sign-in, password, email address, two-factor settings and recovery codes',
|
||||||
|
'every signed-in device, trusted device and push registration',
|
||||||
|
'your linked sign-ins, such as Google, Discord or Steam',
|
||||||
|
'your game-account links, and anything this site granted in the game through them',
|
||||||
|
'your notification settings and inbox',
|
||||||
|
]
|
||||||
|
|
||||||
|
/** What stays, and who sees what of it. */
|
||||||
|
export const WHAT_STAYS = [
|
||||||
|
'What you wrote where others read it, such as forum posts, stays. Other members see it as written by “[deleted player]”.',
|
||||||
|
'Reports you filed and appeals you made stay as moderation records. Staff can still see who it was, and the activity log keeps its IP addresses.',
|
||||||
|
'Event results stay with the score and the in-game name, with no site account behind them.',
|
||||||
|
'A game account stays on the game server. Only its link to this site goes.',
|
||||||
|
]
|
||||||
|
|
||||||
|
/** Said only to staff: their name is never free again (AD9). */
|
||||||
|
export const STAFF_NAME_NOTE =
|
||||||
|
'You are staff, so your username can never be used again, by anyone, once this account is deleted.'
|
||||||
|
|
||||||
|
/** True for every role but player. */
|
||||||
|
export const isStaffRole = (role) => Boolean(role) && role !== 'player'
|
||||||
|
|
||||||
|
/** The confirm button is live once the typed name matches, ignoring case. */
|
||||||
|
export function usernameMatches(typed, username) {
|
||||||
|
return typeof typed === 'string'
|
||||||
|
&& typeof username === 'string'
|
||||||
|
&& typed.trim().length > 0
|
||||||
|
&& typed.trim().toLowerCase() === username.toLowerCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True when the signed-in account is one of the demo's shared logins, which the
|
||||||
|
* server refuses to delete. The section still shows (Play's reviewer must find
|
||||||
|
* it); only its button is off.
|
||||||
|
*/
|
||||||
|
export function isSharedDemoLogin(settings, username) {
|
||||||
|
const logins = settings?.demo?.logins
|
||||||
|
if (!Array.isArray(logins) || typeof username !== 'string') return false
|
||||||
|
const name = username.toLowerCase()
|
||||||
|
return logins.some((l) => typeof l?.username === 'string' && l.username.toLowerCase() === name)
|
||||||
|
}
|
||||||
|
|
||||||
|
const BY_CODE = {
|
||||||
|
username_mismatch: 'Type your username exactly as it is shown.',
|
||||||
|
wrong_password: 'Your password is incorrect.',
|
||||||
|
code_required: 'Enter a code from your authenticator app, or a recovery code.',
|
||||||
|
wrong_code: 'That code is not valid. Try again.',
|
||||||
|
password_required: 'This account has no password yet. Set one in the Password section above, then delete the account.',
|
||||||
|
last_admin: 'You are the only admin. Make someone else an admin before you delete your account.',
|
||||||
|
DEMO_LOCKED: 'This is turned off on the demo site.',
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A refusal from DELETE /auth/me/account, as one sentence. */
|
||||||
|
export function refusalMessage(err) {
|
||||||
|
const code = err?.body?.code
|
||||||
|
if (code && BY_CODE[code]) return BY_CODE[code]
|
||||||
|
if (err?.status === 429) return 'Too many attempts. Wait a few minutes and try again.'
|
||||||
|
return err?.message || 'Could not delete your account. Try again.'
|
||||||
|
}
|
||||||
25
client/src/lib/deletedAccount.js
Normal file
25
client/src/lib/deletedAccount.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// How a deleted account's name is shown (ACCOUNT_DELETION.md AD5, AD6).
|
||||||
|
//
|
||||||
|
// The server decides WHAT name a viewer gets (server/src/utils/displayAuthor.js):
|
||||||
|
// a member is sent "[deleted player]", staff are sent the stored name and a
|
||||||
|
// `…Deleted` flag. All this file does is mark the staff case, so a moderator
|
||||||
|
// reading "Ravenna" knows that account no longer exists.
|
||||||
|
|
||||||
|
export const DELETED_PLAYER = '[deleted player]'
|
||||||
|
|
||||||
|
/** "Ravenna (deleted account)" for staff; the placeholder is left as it is. */
|
||||||
|
export function markDeleted(name, deleted) {
|
||||||
|
if (!name) return name
|
||||||
|
return deleted && name !== DELETED_PLAYER ? `${name} (deleted account)` : name
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The same for an admin view that is handed raw ledger rows (`actor_user_id`,
|
||||||
|
* `actor_username`): an id that is NULL beside a snapshot that is not is a
|
||||||
|
* deleted account, and nothing else clears those ids. Only an explicit null
|
||||||
|
* counts — a row that does not carry the id column at all says nothing.
|
||||||
|
*/
|
||||||
|
export function rowName(userId, username, fallback = '—') {
|
||||||
|
if (!username) return fallback
|
||||||
|
return markDeleted(username, userId === null)
|
||||||
|
}
|
||||||
57
client/src/lib/demoNotice.js
Normal file
57
client/src/lib/demoNotice.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
// The public demo's refusal (docs/website/DEMO_MODE.md §3.1).
|
||||||
|
//
|
||||||
|
// With DEMO_MODE on, the server answers a locked write `403 { code:
|
||||||
|
// 'DEMO_LOCKED', message }`. Every request goes through api/client.js's req(),
|
||||||
|
// installed modules' included, so req() reports the refusal here and the one
|
||||||
|
// toast (components/DemoToast.jsx) shows it — wherever the action was, without
|
||||||
|
// each form learning the code. The form still gets its ApiError as usual.
|
||||||
|
//
|
||||||
|
// The lock is the server's (DM10). Nothing here decides what is allowed; it
|
||||||
|
// only explains what was refused.
|
||||||
|
|
||||||
|
export const DEMO_LOCKED = 'DEMO_LOCKED'
|
||||||
|
|
||||||
|
const listeners = new Set()
|
||||||
|
|
||||||
|
/** Subscribe to refusals. Returns the unsubscribe function. */
|
||||||
|
export function onDemoLocked(fn) {
|
||||||
|
listeners.add(fn)
|
||||||
|
return () => listeners.delete(fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Report a refusal, if this response body is one. Returns whether it was. */
|
||||||
|
export function reportIfDemoLocked(body) {
|
||||||
|
if (!body || typeof body !== 'object' || body.code !== DEMO_LOCKED) return false
|
||||||
|
const message = typeof body.message === 'string' && body.message ? body.message : 'This is turned off on the demo site.'
|
||||||
|
for (const fn of listeners) {
|
||||||
|
try {
|
||||||
|
fn(message)
|
||||||
|
} catch {
|
||||||
|
// A broken listener must not turn a refusal into a different error.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Was this ApiError the demo's refusal? For the few screens that turn a 403
|
||||||
|
* into a sentence of their own ("only an administrator can…"), which would
|
||||||
|
* otherwise blame the role of somebody who is signed in as an admin.
|
||||||
|
*/
|
||||||
|
export function isDemoLocked(err) {
|
||||||
|
return Boolean(err && err.body && err.body.code === DEMO_LOCKED)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "14:00 UTC" for the banner. The wipe runs on the hour in UTC (DM7), so the
|
||||||
|
* banner says UTC rather than converting — a converted time in a reviewer's
|
||||||
|
* zone reads as a different schedule from the one published on /beta.
|
||||||
|
*/
|
||||||
|
export function formatResetTime(iso) {
|
||||||
|
const ms = Date.parse(iso)
|
||||||
|
if (Number.isNaN(ms)) return null
|
||||||
|
const d = new Date(ms)
|
||||||
|
const hh = String(d.getUTCHours()).padStart(2, '0')
|
||||||
|
const mm = String(d.getUTCMinutes()).padStart(2, '0')
|
||||||
|
return `${hh}:${mm} UTC`
|
||||||
|
}
|
||||||
27
client/src/lib/notice.js
Normal file
27
client/src/lib/notice.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
// A one-line notice for the site-wide toast (components/DemoToast.jsx), for the
|
||||||
|
// rare moment a screen has to say something after it has navigated away — the
|
||||||
|
// account page cannot show "Your account has been deleted." on itself, because
|
||||||
|
// the account it would be shown on no longer exists.
|
||||||
|
//
|
||||||
|
// The same shape as lib/demoNotice.js and drawn by the same toast, so the site
|
||||||
|
// has one place a passing message appears.
|
||||||
|
|
||||||
|
const listeners = new Set()
|
||||||
|
|
||||||
|
/** Subscribe to notices. Returns the unsubscribe function. */
|
||||||
|
export function onNotice(fn) {
|
||||||
|
listeners.add(fn)
|
||||||
|
return () => listeners.delete(fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Show one notice. */
|
||||||
|
export function showNotice(message) {
|
||||||
|
if (typeof message !== 'string' || !message) return
|
||||||
|
for (const fn of listeners) {
|
||||||
|
try {
|
||||||
|
fn(message)
|
||||||
|
} catch {
|
||||||
|
// A broken listener must not stop the caller.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,7 +41,7 @@ export function relativeTime(when, now = Date.now()) {
|
|||||||
* Distinct from `teamAdmin.freshnessOf`, which is worded for an operator
|
* Distinct from `teamAdmin.freshnessOf`, which is worded for an operator
|
||||||
* debugging a sync. A visitor needs one sentence about whether what they are
|
* debugging a sync. A visitor needs one sentence about whether what they are
|
||||||
* looking at is current, and specifically must never be shown an unconfirmed
|
* looking at is current, and specifically must never be shown an unconfirmed
|
||||||
* empty projection as though it were a confirmed empty shard.
|
* empty projection as though it were a confirmed empty one.
|
||||||
*/
|
*/
|
||||||
export function freshnessNote(sync = {}, now = Date.now()) {
|
export function freshnessNote(sync = {}, now = Date.now()) {
|
||||||
// Nothing supplies Teams here, so there is nothing to be stale ABOUT. A
|
// Nothing supplies Teams here, so there is nothing to be stale ABOUT. A
|
||||||
@@ -57,7 +57,7 @@ export function freshnessNote(sync = {}, now = Date.now()) {
|
|||||||
* Group feed items into days, newest first, preserving order within a day (§4.3).
|
* Group feed items into days, newest first, preserving order within a day (§4.3).
|
||||||
*
|
*
|
||||||
* Keyed by local calendar date rather than by a UTC slice: "yesterday" is a
|
* Keyed by local calendar date rather than by a UTC slice: "yesterday" is a
|
||||||
* property of where the reader is sitting, and a shard's evening raid landing at
|
* property of where the reader is sitting, and a game server's evening raid landing at
|
||||||
* 00:30 UTC belongs on the day the players experienced it.
|
* 00:30 UTC belongs on the day the players experienced it.
|
||||||
*/
|
*/
|
||||||
export function groupByDay(items = [], locale = undefined) {
|
export function groupByDay(items = [], locale = undefined) {
|
||||||
|
|||||||
@@ -3,10 +3,12 @@
|
|||||||
//
|
//
|
||||||
// Plain JS with tests, following lib/moduleAdmin.js. The reason it is worth
|
// Plain JS with tests, following lib/moduleAdmin.js. The reason it is worth
|
||||||
// splitting here specifically: this screen's job is to tell an operator the
|
// splitting here specifically: this screen's job is to tell an operator the
|
||||||
// difference between "the shard has no Teams" and "core has not been able to ask
|
// difference between "the game server has no Teams" and "core has not been able to ask
|
||||||
// for two hours", and those two produce almost the same page. Getting that
|
// for two hours", and those two produce almost the same page. Getting that
|
||||||
// wording right is logic, not markup.
|
// wording right is logic, not markup.
|
||||||
|
|
||||||
|
import { markDeleted, rowName } from './deletedAccount.js'
|
||||||
|
|
||||||
/** Tones the screen uses. Names, not colours — the view maps them. */
|
/** Tones the screen uses. Names, not colours — the view maps them. */
|
||||||
export const TONE = { ok: 'ok', warn: 'warn', bad: 'bad', idle: 'idle' }
|
export const TONE = { ok: 'ok', warn: 'warn', bad: 'bad', idle: 'idle' }
|
||||||
|
|
||||||
@@ -31,7 +33,7 @@ export function freshnessOf(sync = {}) {
|
|||||||
return {
|
return {
|
||||||
tone: TONE.bad,
|
tone: TONE.bad,
|
||||||
label: 'Never synced',
|
label: 'Never synced',
|
||||||
detail: 'Core has never had an answer it could trust. What is shown below is not a confirmed empty shard.',
|
detail: 'Core has never had an answer it could trust. What is shown below does not confirm that the game server has no Teams.',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sync.stale) {
|
if (sync.stale) {
|
||||||
@@ -91,7 +93,7 @@ export const GATED_NOTE =
|
|||||||
/** A one-line description of a queued request, for the approval queue. */
|
/** A one-line description of a queued request, for the approval queue. */
|
||||||
export function describeRequest(request = {}) {
|
export function describeRequest(request = {}) {
|
||||||
const payload = parsePayload(request.payload)
|
const payload = parsePayload(request.payload)
|
||||||
const who = request.requested_username || 'a deleted user'
|
const who = rowName(request.requested_by, request.requested_username, 'a deleted user')
|
||||||
switch (request.action) {
|
switch (request.action) {
|
||||||
case 'unhide':
|
case 'unhide':
|
||||||
return `${who} asks to publish “${request.team_name}”`
|
return `${who} asks to publish “${request.team_name}”`
|
||||||
@@ -133,7 +135,7 @@ export function leadershipOf(member = {}) {
|
|||||||
return {
|
return {
|
||||||
isLeader: granted,
|
isLeader: granted,
|
||||||
overridden: true,
|
overridden: true,
|
||||||
note: `${granted ? 'Granted' : 'Denied'} by ${member.leaderOverride.by || 'a deleted user'}`
|
note: `${granted ? 'Granted' : 'Denied'} by ${markDeleted(member.leaderOverride.by, member.leaderOverride.byDeleted) || 'a deleted user'}`
|
||||||
+ `${member.leaderOverride.reason ? ` — ${member.leaderOverride.reason}` : ''}`
|
+ `${member.leaderOverride.reason ? ` — ${member.leaderOverride.reason}` : ''}`
|
||||||
+ ` (the game says ${member.isLeaderSynced ? 'leader' : 'not a leader'})`,
|
+ ` (the game says ${member.isLeaderSynced ? 'leader' : 'not a leader'})`,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
// `created_at` when the write arrives. A client that granted one would be
|
// `created_at` when the write arrives. A client that granted one would be
|
||||||
// deciding a time-bounded permission against the clock of the party it bounds.
|
// deciding a time-bounded permission against the clock of the party it bounds.
|
||||||
|
|
||||||
|
import { markDeleted } from './deletedAccount.js'
|
||||||
|
|
||||||
export const REPORT_REASONS = [
|
export const REPORT_REASONS = [
|
||||||
['abuse', 'Abusive or harassing'],
|
['abuse', 'Abusive or harassing'],
|
||||||
['spam', 'Spam'],
|
['spam', 'Spam'],
|
||||||
@@ -75,7 +77,7 @@ export function stripToText(html) {
|
|||||||
export function threadSummary(thread) {
|
export function threadSummary(thread) {
|
||||||
const parts = []
|
const parts = []
|
||||||
if (thread.type === 'announcement') parts.push('Announcement')
|
if (thread.type === 'announcement') parts.push('Announcement')
|
||||||
parts.push(thread.author)
|
parts.push(markDeleted(thread.author, thread.authorDeleted))
|
||||||
if (thread.type === 'discussion' && thread.postCount > 1) {
|
if (thread.type === 'discussion' && thread.postCount > 1) {
|
||||||
const replies = thread.postCount - 1
|
const replies = thread.postCount - 1
|
||||||
parts.push(`${replies} ${replies === 1 ? 'reply' : 'replies'}`)
|
parts.push(`${replies} ${replies === 1 ? 'reply' : 'replies'}`)
|
||||||
|
|||||||
35
client/src/lib/userSafety.js
Normal file
35
client/src/lib/userSafety.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
// Report, block and hide — the parts of the screens that are rules rather than
|
||||||
|
// markup (docs/website/USER_SAFETY.md §1, §4.1). Plain JS so the client's
|
||||||
|
// node --test suite can hold them.
|
||||||
|
|
||||||
|
function fmtDate(s) {
|
||||||
|
if (!s) return ''
|
||||||
|
const d = new Date(s)
|
||||||
|
return Number.isNaN(d.getTime()) ? '' : d.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The second line of a row on Account → Blocked: what was blocked, and when.
|
||||||
|
* An account block is the normal one (S12); a game block names the identity
|
||||||
|
* and says it is not linked to an account yet, since that is why it is a Steam
|
||||||
|
* id and not a username.
|
||||||
|
*/
|
||||||
|
export function blockSubtitle(block) {
|
||||||
|
const parts = []
|
||||||
|
if (block.kind === 'game' && block.identity) {
|
||||||
|
parts.push(`${block.identity.label} ${block.identity.id}, not linked to an account`)
|
||||||
|
} else {
|
||||||
|
parts.push('Account')
|
||||||
|
}
|
||||||
|
const when = fmtDate(block.createdAt)
|
||||||
|
if (when) parts.push(`blocked ${when}`)
|
||||||
|
return parts.join(' · ')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* May the Reports queue offer "Hide for everyone" on this report? Not on an
|
||||||
|
* upload — it is shown inside a post, and hiding that post is the act — and not
|
||||||
|
* once this report has already hidden its item.
|
||||||
|
*/
|
||||||
|
export const canHideForEveryone = (report) =>
|
||||||
|
report.targetType !== 'team_forum_upload' && report.actionedWith !== 'hide'
|
||||||
@@ -5,6 +5,8 @@ import { api } from '../api/client.js'
|
|||||||
import { useAuth } from '../contexts/AuthContext.jsx'
|
import { useAuth } from '../contexts/AuthContext.jsx'
|
||||||
import { useSite } from '../contexts/SiteContext.jsx'
|
import { useSite } from '../contexts/SiteContext.jsx'
|
||||||
import { REPORT_REASONS, editOfferOpen, stripToText, threadSummary } from '../lib/teamForum.js'
|
import { REPORT_REASONS, editOfferOpen, stripToText, threadSummary } from '../lib/teamForum.js'
|
||||||
|
// A member is sent "[deleted player]"; staff the stored name, which this marks.
|
||||||
|
import { markDeleted } from '../lib/deletedAccount.js'
|
||||||
|
|
||||||
// Core's Team forum, rendered into a second slot a MODULE declares
|
// Core's Team forum, rendered into a second slot a MODULE declares
|
||||||
// (TEAMS.md Part 5, and the phase 3 amendment to §3.4).
|
// (TEAMS.md Part 5, and the phase 3 amendment to §3.4).
|
||||||
@@ -124,6 +126,10 @@ export default function TeamForumPanel({ externalId, moduleId }) {
|
|||||||
imageMode={imageMode}
|
imageMode={imageMode}
|
||||||
onBack={() => openThread(null)}
|
onBack={() => openThread(null)}
|
||||||
onChanged={() => loadThread(team.slug, thread.id)}
|
onChanged={() => loadThread(team.slug, thread.id)}
|
||||||
|
onGone={async () => {
|
||||||
|
await loadThreads(team.slug)
|
||||||
|
openThread(null)
|
||||||
|
}}
|
||||||
onModerate={async (action) => {
|
onModerate={async (action) => {
|
||||||
await api.teamForumModerate(team.slug, thread.id, { action })
|
await api.teamForumModerate(team.slug, thread.id, { action })
|
||||||
await loadThreads(team.slug)
|
await loadThreads(team.slug)
|
||||||
@@ -309,7 +315,7 @@ function GuestManager({ slug }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function ThreadView({ slug, thread, canModerate, imageMode, onBack, onChanged, onModerate }) {
|
function ThreadView({ slug, thread, canModerate, imageMode, onBack, onChanged, onGone, onModerate }) {
|
||||||
// A clock that ticks, so an edit control whose deadline passed while the page
|
// A clock that ticks, so an edit control whose deadline passed while the page
|
||||||
// sat open goes away instead of becoming a button that fails. It only ever
|
// sat open goes away instead of becoming a button that fails. It only ever
|
||||||
// REMOVES an offer — the server decides whether an edit happens, and re-derives
|
// REMOVES an offer — the server decides whether an edit happens, and re-derives
|
||||||
@@ -332,8 +338,7 @@ function ThreadView({ slug, thread, canModerate, imageMode, onBack, onChanged, o
|
|||||||
</h2>
|
</h2>
|
||||||
<p className="sans dim" style={{ fontSize: '0.8rem', margin: '0 0 14px' }}>
|
<p className="sans dim" style={{ fontSize: '0.8rem', margin: '0 0 14px' }}>
|
||||||
{thread.type === 'announcement' ? 'Announcement · ' : ''}
|
{thread.type === 'announcement' ? 'Announcement · ' : ''}
|
||||||
{thread.author}
|
{markDeleted(thread.author, thread.authorDeleted)}
|
||||||
{thread.authorDeleted && ' (account removed)'}
|
|
||||||
{thread.locked && ' · locked'}
|
{thread.locked && ' · locked'}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -385,6 +390,15 @@ function ThreadView({ slug, thread, canModerate, imageMode, onBack, onChanged, o
|
|||||||
targetId={thread.id}
|
targetId={thread.id}
|
||||||
label="Report this thread"
|
label="Report this thread"
|
||||||
/>
|
/>
|
||||||
|
{/* A thread this reader hides, or whose author they block, is gone
|
||||||
|
from their view, so the panel goes back to the list. */}
|
||||||
|
<SafetyControls
|
||||||
|
targetType="team_forum_thread"
|
||||||
|
targetId={thread.id}
|
||||||
|
author={thread.author}
|
||||||
|
canBlock={thread.canBlock}
|
||||||
|
onDone={onGone}
|
||||||
|
/>
|
||||||
{canModerate && (
|
{canModerate && (
|
||||||
<>
|
<>
|
||||||
<button type="button" className="pill" onClick={() => onModerate(thread.pinned ? 'unpin' : 'pin')}>
|
<button type="button" className="pill" onClick={() => onModerate(thread.pinned ? 'unpin' : 'pin')}>
|
||||||
@@ -448,8 +462,7 @@ function PostView({ slug, post, canModerate, now, onChanged }) {
|
|||||||
return (
|
return (
|
||||||
<article style={{ marginBottom: 16 }}>
|
<article style={{ marginBottom: 16 }}>
|
||||||
<p className="sans dim" style={{ fontSize: '0.78rem', margin: '0 0 2px' }}>
|
<p className="sans dim" style={{ fontSize: '0.78rem', margin: '0 0 2px' }}>
|
||||||
{post.author}
|
{markDeleted(post.author, post.authorDeleted)}
|
||||||
{post.authorDeleted && ' (account removed)'}
|
|
||||||
{post.editedAt && ' · edited'}
|
{post.editedAt && ' · edited'}
|
||||||
{post.status === 'hidden' && ' · hidden'}
|
{post.status === 'hidden' && ' · hidden'}
|
||||||
</p>
|
</p>
|
||||||
@@ -515,6 +528,15 @@ function PostView({ slug, post, canModerate, now, onChanged }) {
|
|||||||
label="Report"
|
label="Report"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{!post.mine && (
|
||||||
|
<SafetyControls
|
||||||
|
targetType="team_forum_post"
|
||||||
|
targetId={post.id}
|
||||||
|
author={post.author}
|
||||||
|
canBlock={post.canBlock}
|
||||||
|
onDone={onChanged}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{canModerate && (
|
{canModerate && (
|
||||||
<>
|
<>
|
||||||
<button type="button" className="pill" onClick={() => moderate(post.status === 'hidden' ? 'unhide' : 'hide')}>
|
<button type="button" className="pill" onClick={() => moderate(post.status === 'hidden' ? 'unhide' : 'hide')}>
|
||||||
@@ -529,6 +551,76 @@ function PostView({ slug, post, canModerate, now, onChanged }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Hide for me" and "Block author" (USER_SAFETY.md §1).
|
||||||
|
*
|
||||||
|
* Both are the reader's own tools and both are saved on their account, so they
|
||||||
|
* hold on every device and in the app. Neither files a report or changes the
|
||||||
|
* item for anyone else, and the blocked person is not told (S9) — the
|
||||||
|
* confirmation says so, because a member deciding whether to block someone is
|
||||||
|
* usually deciding whether it will start something.
|
||||||
|
*
|
||||||
|
* `canBlock` is the server's answer (S8: never yourself, a deleted account or
|
||||||
|
* staff); this offers Block only when it is true. "Hide for me" works on any
|
||||||
|
* single item, a staff member's included.
|
||||||
|
*/
|
||||||
|
function SafetyControls({ targetType, targetId, author, canBlock, onDone }) {
|
||||||
|
const [confirming, setConfirming] = useState(false)
|
||||||
|
const [error, setError] = useState(null)
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
|
||||||
|
const run = async (call) => {
|
||||||
|
setBusy(true)
|
||||||
|
setError(null)
|
||||||
|
try {
|
||||||
|
await call({ targetType, targetId })
|
||||||
|
setConfirming(false)
|
||||||
|
await onDone()
|
||||||
|
} catch (err) {
|
||||||
|
setError(err.message || 'Could not do that')
|
||||||
|
} finally {
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (confirming) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'grid', gap: 8, marginTop: 8, padding: 12, width: '100%',
|
||||||
|
border: '1px solid var(--rule, #ccc)', borderRadius: 6,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<p className="sans" style={{ fontSize: '0.85rem', margin: 0 }}>
|
||||||
|
Block <strong>{author}</strong>? You won’t see anything they write, here or in the app.
|
||||||
|
They aren’t told. You can undo it from <em>Account → Blocked</em>.
|
||||||
|
</p>
|
||||||
|
{error && <p className="sans" style={{ color: 'var(--danger, crimson)', fontSize: '0.85rem', margin: 0 }}>{error}</p>}
|
||||||
|
<div style={{ display: 'flex', gap: 8 }}>
|
||||||
|
<button type="button" className="btn btn-primary btn-sq" disabled={busy} onClick={() => run(api.blockAuthor)}>
|
||||||
|
Block
|
||||||
|
</button>
|
||||||
|
<button type="button" className="pill" onClick={() => setConfirming(false)}>Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<button type="button" className="pill" disabled={busy} onClick={() => run(api.hideItem)}>
|
||||||
|
Hide for me
|
||||||
|
</button>
|
||||||
|
{canBlock && (
|
||||||
|
<button type="button" className="pill" onClick={() => setConfirming(true)}>
|
||||||
|
Block author
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
{error && <span className="sans" style={{ color: 'var(--danger, crimson)', fontSize: '0.8rem' }}>{error}</span>}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The report control — the first user-facing report flow this site has ever had.
|
* The report control — the first user-facing report flow this site has ever had.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -11,6 +11,29 @@
|
|||||||
// that the two files can drift, so a test asserts they agree
|
// that the two files can drift, so a test asserts they agree
|
||||||
// (client/test/moduleRegistry.test.js) rather than trusting a bump to remember
|
// (client/test/moduleRegistry.test.js) rather than trusting a bump to remember
|
||||||
// both.
|
// both.
|
||||||
|
// 1.21.0 — report, block and hide reach a module's content (USER_SAFETY.md
|
||||||
|
// §4.1): `api.registerReportTargets`, `api.registerGameIdentities`,
|
||||||
|
// `ctx.safety`. Server-side: a module filters its own feeds per reader on the
|
||||||
|
// server (S11), and its client half calls core's ordinary `/player/reports` and
|
||||||
|
// `/auth/me/blocks` routes through the shared request primitive. This file bumps
|
||||||
|
// for the reason at the top.
|
||||||
|
// 1.20.0 — `api.onUserDeleting` (ACCOUNT_DELETION.md §4.1, AD10): a module
|
||||||
|
// unlinks a person's game links before their account is deleted. Server-side
|
||||||
|
// only. This file bumps for the reason at the top.
|
||||||
|
// 1.19.0 — an event action may declare `demoRefuses(params)` (DEMO_MODE.md §3.4,
|
||||||
|
// DM18): the demo refuses a step at save. Server-side only; the refusal reaches
|
||||||
|
// the browser as an ordinary DEMO_LOCKED answer. This file bumps for the reason at the top.
|
||||||
|
// 1.18.0 — the public demo (DEMO_MODE.md §3.2): `demoLocks` in module.json,
|
||||||
|
// `ctx.demoMode`, `api.onDemoSeed`. Server-side; the client half is core's own
|
||||||
|
// banner and refusal toast, which an installed module's requests reach through
|
||||||
|
// the shared request primitive. This file bumps for the reason at the top.
|
||||||
|
// 1.17.0 — a module may take part in linking a sign-in identity (STEAM_SIGNIN.md
|
||||||
|
// §4): `ctx.identities.list`, `api.onIdentityLinking`, `api.onIdentityLinked`.
|
||||||
|
// Server-side; the client half is core's own account pages showing Steam. This
|
||||||
|
// file bumps for the reason at the top.
|
||||||
|
// 1.16.0 — a dry run's `detail.warnings` (Rust PLAN_REDESIGNS §11.4, D391): a
|
||||||
|
// module's advice, shown by core's own event editor as warning findings.
|
||||||
|
// Server-side; this file bumps for the reason at the top.
|
||||||
// 1.15.0 — a failed step's `retryAfterMs` (Rust PLAN_REDESIGNS §14.3.13): when
|
// 1.15.0 — a failed step's `retryAfterMs` (Rust PLAN_REDESIGNS §14.3.13): when
|
||||||
// to try again. Server-side; the run console's retry line now says when. This
|
// to try again. Server-side; the run console's retry line now says when. This
|
||||||
// file bumps for the reason at the top.
|
// file bumps for the reason at the top.
|
||||||
@@ -91,4 +114,4 @@
|
|||||||
// but the two halves state ONE version: a module declares a single coreApi range
|
// but the two halves state ONE version: a module declares a single coreApi range
|
||||||
// and is served one chunk, so a client that claimed 1.0.0 while the server
|
// and is served one chunk, so a client that claimed 1.0.0 while the server
|
||||||
// answered 1.1.0 would be two answers to one question.
|
// answered 1.1.0 would be two answers to one question.
|
||||||
export const MODULE_API_VERSION = '1.15.0'
|
export const MODULE_API_VERSION = '1.21.0'
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import MoonDot from '../../components/MoonDot.jsx'
|
|||||||
import BrandLogo from '../../components/BrandLogo.jsx'
|
import BrandLogo from '../../components/BrandLogo.jsx'
|
||||||
import ProviderIcon from '../../components/ProviderIcon.jsx'
|
import ProviderIcon from '../../components/ProviderIcon.jsx'
|
||||||
import TrustLimitModal from '../../components/security/TrustLimitModal.jsx'
|
import TrustLimitModal from '../../components/security/TrustLimitModal.jsx'
|
||||||
|
import DemoLogins from '../../components/DemoLogins.jsx'
|
||||||
import { useAuth } from '../../contexts/AuthContext.jsx'
|
import { useAuth } from '../../contexts/AuthContext.jsx'
|
||||||
import { useSite } from '../../contexts/SiteContext.jsx'
|
import { useSite } from '../../contexts/SiteContext.jsx'
|
||||||
import { api } from '../../api/client.js'
|
import { api } from '../../api/client.js'
|
||||||
@@ -342,6 +343,14 @@ export default function AdminLogin() {
|
|||||||
Protected area — not indexed. Sessions expire after 1 day.
|
Protected area — not indexed. Sessions expire after 1 day.
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
|
{stage === 'creds' && (
|
||||||
|
<DemoLogins
|
||||||
|
onPick={(u, p) => {
|
||||||
|
setUsername(u)
|
||||||
|
setPassword(p)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<p style={{ textAlign: 'center', margin: '20px 0 0' }}>
|
<p style={{ textAlign: 'center', margin: '20px 0 0' }}>
|
||||||
<Link to="/" className="sans" style={{ color: 'var(--accent)', fontSize: '0.84rem', textDecoration: 'none' }}>
|
<Link to="/" className="sans" style={{ color: 'var(--accent)', fontSize: '0.84rem', textDecoration: 'none' }}>
|
||||||
← Back to site
|
← Back to site
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import RecoveryCodesDisplay from '../../../components/security/RecoveryCodesDisp
|
|||||||
import TrustedDevicesPanel from '../../../components/security/TrustedDevicesPanel.jsx'
|
import TrustedDevicesPanel from '../../../components/security/TrustedDevicesPanel.jsx'
|
||||||
import RecoveryCodesPanel from '../../../components/security/RecoveryCodesPanel.jsx'
|
import RecoveryCodesPanel from '../../../components/security/RecoveryCodesPanel.jsx'
|
||||||
import EmailAddressPanel from '../../../components/security/EmailAddressPanel.jsx'
|
import EmailAddressPanel from '../../../components/security/EmailAddressPanel.jsx'
|
||||||
|
import DeleteAccountPanel from '../../../components/security/DeleteAccountPanel.jsx'
|
||||||
|
import BlockedPanel from '../../../components/security/BlockedPanel.jsx'
|
||||||
|
import { IdentitySummary, linkBanner, linkableProviders, unlinkPrompt } from '../../../components/security/linkedIdentities.jsx'
|
||||||
import { api } from '../../../api/client.js'
|
import { api } from '../../../api/client.js'
|
||||||
|
|
||||||
// Link/unlink external SSO identities to this account. Linking redirects through
|
// Link/unlink external SSO identities to this account. Linking redirects through
|
||||||
@@ -15,13 +18,7 @@ function LinkedAccounts() {
|
|||||||
const [available, setAvailable] = useState([])
|
const [available, setAvailable] = useState([])
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
const banner = (() => {
|
const banner = linkBanner(window.location.search)
|
||||||
const q = new URLSearchParams(window.location.search)
|
|
||||||
if (q.get('linked')) return { ok: true, text: 'Account linked.' }
|
|
||||||
if (q.get('link_error') === 'in_use') return { ok: false, text: 'That external account is already linked to another user.' }
|
|
||||||
if (q.get('link_error')) return { ok: false, text: 'Could not link that account. Please try again.' }
|
|
||||||
return null
|
|
||||||
})()
|
|
||||||
|
|
||||||
const load = useCallback(async () => {
|
const load = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -40,12 +37,11 @@ function LinkedAccounts() {
|
|||||||
}, [load])
|
}, [load])
|
||||||
|
|
||||||
const nameFor = (id) => available.find((p) => p.id === id)?.name || id.charAt(0).toUpperCase() + id.slice(1)
|
const nameFor = (id) => available.find((p) => p.id === id)?.name || id.charAt(0).toUpperCase() + id.slice(1)
|
||||||
const iconFor = (id) => (id === 'google' || id === 'discord' ? id : 'oidc')
|
|
||||||
|
|
||||||
async function unlink(provider) {
|
async function unlink(identity) {
|
||||||
if (!window.confirm(`Unlink ${nameFor(provider)} from your account?`)) return
|
if (!window.confirm(unlinkPrompt(identity, nameFor(identity.provider)))) return
|
||||||
try {
|
try {
|
||||||
await api.unlinkIdentity(provider)
|
await api.unlinkIdentity(identity.provider, identity.id)
|
||||||
await load()
|
await load()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err.message || 'Could not unlink.')
|
setError(err.message || 'Could not unlink.')
|
||||||
@@ -55,8 +51,7 @@ function LinkedAccounts() {
|
|||||||
if (error) return <ErrorState message={error} />
|
if (error) return <ErrorState message={error} />
|
||||||
if (!linked) return null
|
if (!linked) return null
|
||||||
|
|
||||||
const linkedIds = new Set(linked.map((i) => i.provider))
|
const linkable = linkableProviders(available, linked)
|
||||||
const linkable = available.filter((p) => !linkedIds.has(p.id))
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ marginTop: 40, borderTop: '1px solid var(--line-soft)', paddingTop: 28 }}>
|
<div style={{ marginTop: 40, borderTop: '1px solid var(--line-soft)', paddingTop: 28 }}>
|
||||||
@@ -64,7 +59,7 @@ function LinkedAccounts() {
|
|||||||
Linked accounts
|
Linked accounts
|
||||||
</h2>
|
</h2>
|
||||||
<p className="sans" style={{ color: 'var(--muted)', fontSize: '0.9rem', lineHeight: 1.6 }}>
|
<p className="sans" style={{ color: 'var(--muted)', fontSize: '0.9rem', lineHeight: 1.6 }}>
|
||||||
Link a Google, Discord, or other SSO account so you can sign in with it. SSO can only sign in
|
Link a Google, Discord, Steam, or other SSO account so you can sign in with it. SSO can only sign in
|
||||||
to an account it is linked to — linking here is what grants that access.
|
to an account it is linked to — linking here is what grants that access.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -77,15 +72,9 @@ function LinkedAccounts() {
|
|||||||
{linked.length > 0 && (
|
{linked.length > 0 && (
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 10, margin: '14px 0' }}>
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 10, margin: '14px 0' }}>
|
||||||
{linked.map((i) => (
|
{linked.map((i) => (
|
||||||
<div key={i.provider} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '10px 14px', border: '1px solid var(--line)', borderRadius: 8 }}>
|
<div key={i.id ?? i.provider} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '10px 14px', border: '1px solid var(--line)', borderRadius: 8 }}>
|
||||||
<span style={{ display: 'inline-flex', width: 20, height: 20 }}>
|
<IdentitySummary identity={i} providerName={nameFor(i.provider)} />
|
||||||
<ProviderIcon icon={iconFor(i.provider)} size={20} />
|
<button onClick={() => unlink(i)} className="pill" style={{ color: '#d98b84', borderColor: '#d98b84' }}>
|
||||||
</span>
|
|
||||||
<div style={{ flex: 1, minWidth: 0 }}>
|
|
||||||
<div className="sans" style={{ color: 'var(--head)', fontSize: '0.9rem' }}>{nameFor(i.provider)}</div>
|
|
||||||
{i.email && <div className="sans dim" style={{ fontSize: '0.78rem' }}>{i.email}</div>}
|
|
||||||
</div>
|
|
||||||
<button onClick={() => unlink(i.provider)} className="pill" style={{ color: '#d98b84', borderColor: '#d98b84' }}>
|
|
||||||
Unlink
|
Unlink
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -328,6 +317,14 @@ export default function AccountAdmin() {
|
|||||||
{account && <EmailAddressPanel account={account} reload={load} />}
|
{account && <EmailAddressPanel account={account} reload={load} />}
|
||||||
|
|
||||||
<LinkedAccounts />
|
<LinkedAccounts />
|
||||||
|
|
||||||
|
{/* Blocks and hides are the member's own (USER_SAFETY.md §1); staff are
|
||||||
|
members too, and the list is the one the app shows. */}
|
||||||
|
<BlockedPanel />
|
||||||
|
|
||||||
|
{/* The same section the player portal shows: every member can delete
|
||||||
|
themself, staff included (ACCOUNT_DELETION.md §1). */}
|
||||||
|
{account && <DeleteAccountPanel account={account} />}
|
||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,14 @@ import { api } from '../../../api/client.js'
|
|||||||
|
|
||||||
// Admin config for authentication providers. Local password + TOTP is always on
|
// Admin config for authentication providers. Local password + TOTP is always on
|
||||||
// (informational tab). Google/Discord are built-ins with a fixed config surface
|
// (informational tab). Google/Discord are built-ins with a fixed config surface
|
||||||
// (Enabled + Client ID + Client Secret). Custom providers use the full OIDC editor.
|
// (Enabled + Client ID + Client Secret); Steam is a built-in with Enabled + a
|
||||||
|
// Steam Web API key. Custom providers use the full OIDC editor.
|
||||||
|
|
||||||
const TABS = [
|
const TABS = [
|
||||||
{ id: 'local', label: 'Local Accounts' },
|
{ id: 'local', label: 'Local Accounts' },
|
||||||
{ id: 'google', label: 'Google' },
|
{ id: 'google', label: 'Google' },
|
||||||
{ id: 'discord', label: 'Discord' },
|
{ id: 'discord', label: 'Discord' },
|
||||||
|
{ id: 'steam', label: 'Steam' },
|
||||||
{ id: 'custom', label: 'Custom Providers' },
|
{ id: 'custom', label: 'Custom Providers' },
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -141,6 +143,87 @@ function BuiltinForm({ provider, onSaved }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Steam (OpenID 2.0) ─────────────────────────────────────────────────────
|
||||||
|
// No client id and no redirect URL to register: Steam's sign-in takes neither.
|
||||||
|
// What it needs is a Steam Web API key, without which it cannot be enabled
|
||||||
|
// (STEAM_SIGNIN.md D394) — the key is how a linked account shows its persona
|
||||||
|
// name and avatar. Steam never creates an account (D395): a player links Steam
|
||||||
|
// to the account they already have.
|
||||||
|
function SteamForm({ provider, onSaved }) {
|
||||||
|
const [enabled, setEnabled] = useState(provider.enabled)
|
||||||
|
const [apiKey, setApiKey] = useState('')
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
const [msg, setMsg] = useState('')
|
||||||
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
setBusy(true)
|
||||||
|
setMsg('')
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
const body = { enabled }
|
||||||
|
if (apiKey) body.secret = apiKey // only send a new key when entered
|
||||||
|
await api.admin.updateAuthProvider(provider.id, body)
|
||||||
|
setApiKey('')
|
||||||
|
setMsg('Saved.')
|
||||||
|
await onSaved()
|
||||||
|
} catch (err) {
|
||||||
|
setError(err.message || 'Could not save.')
|
||||||
|
} finally {
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ maxWidth: 560, display: 'flex', flexDirection: 'column', gap: 16 }}>
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
|
||||||
|
<span style={{ display: 'inline-flex', width: 26, height: 26, color: 'var(--head)' }}>
|
||||||
|
<ProviderIcon icon="steam" size={26} />
|
||||||
|
</span>
|
||||||
|
<h2 className="display" style={{ margin: 0, fontSize: '1.2rem', color: 'var(--head)' }}>
|
||||||
|
{provider.name}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p className="sans" style={{ margin: 0, color: 'var(--muted)', fontSize: '0.88rem', lineHeight: 1.6 }}>
|
||||||
|
Players link their Steam account from their account page and can then sign in with it. Steam never
|
||||||
|
creates an account: an unlinked Steam account signs nobody in, whatever the registration setting.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<Toggle checked={enabled} onChange={setEnabled} label="Enable this sign-in method" />
|
||||||
|
<HealthWarning provider={provider} />
|
||||||
|
|
||||||
|
<label style={{ display: 'block' }}>
|
||||||
|
<span className="field-label">Steam Web API key (required)</span>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
value={apiKey}
|
||||||
|
onChange={(e) => setApiKey(e.target.value)}
|
||||||
|
className="input"
|
||||||
|
autoComplete="new-password"
|
||||||
|
placeholder={provider.hasSecret ? '•••••••• configured — leave blank to keep' : 'Steam Web API key'}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<p className="sans dim" style={{ margin: '-8px 0 0', fontSize: '0.82rem', lineHeight: 1.5 }}>
|
||||||
|
Get one at{' '}
|
||||||
|
<a href="https://steamcommunity.com/dev/apikey" target="_blank" rel="noreferrer" className="link-accent">
|
||||||
|
steamcommunity.com/dev/apikey
|
||||||
|
</a>{' '}
|
||||||
|
with this site's domain. It is used only to show a linked account's Steam name and avatar, and is
|
||||||
|
never sent to a browser. No redirect URL needs registering with Steam.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div style={{ display: 'flex', gap: 10, alignItems: 'center', marginTop: 4 }}>
|
||||||
|
<button onClick={save} disabled={busy} className="btn btn-primary btn-sq">
|
||||||
|
{busy ? 'Saving…' : 'Save changes'}
|
||||||
|
</button>
|
||||||
|
{msg && <span className="sans" style={{ color: '#7fd0a4', fontSize: '0.85rem' }}>{msg}</span>}
|
||||||
|
{error && <span className="sans" style={{ color: '#d98b84', fontSize: '0.85rem' }}>{error}</span>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// ── Local accounts (informational) ─────────────────────────────────────────
|
// ── Local accounts (informational) ─────────────────────────────────────────
|
||||||
function LocalInfo() {
|
function LocalInfo() {
|
||||||
return (
|
return (
|
||||||
@@ -376,6 +459,7 @@ export default function AuthProvidersAdmin() {
|
|||||||
{tab === 'local' && <LocalInfo />}
|
{tab === 'local' && <LocalInfo />}
|
||||||
{tab === 'google' && <BuiltinForm provider={byId('google')} onSaved={load} />}
|
{tab === 'google' && <BuiltinForm provider={byId('google')} onSaved={load} />}
|
||||||
{tab === 'discord' && <BuiltinForm provider={byId('discord')} onSaved={load} />}
|
{tab === 'discord' && <BuiltinForm provider={byId('discord')} onSaved={load} />}
|
||||||
|
{tab === 'steam' && byId('steam') && <SteamForm key="steam" provider={byId('steam')} onSaved={load} />}
|
||||||
{tab === 'custom' && <CustomProviders items={customs} onChanged={load} />}
|
{tab === 'custom' && <CustomProviders items={customs} onChanged={load} />}
|
||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { Loading, ErrorState } from '../../../components/PageState.jsx'
|
|||||||
import { useAsync } from '../../../lib/useAsync.js'
|
import { useAsync } from '../../../lib/useAsync.js'
|
||||||
import { ago, dateTime } from '../../../lib/format.js'
|
import { ago, dateTime } from '../../../lib/format.js'
|
||||||
import { api } from '../../../api/client.js'
|
import { api } from '../../../api/client.js'
|
||||||
|
import { markDeleted } from '../../../lib/deletedAccount.js'
|
||||||
|
import { canHideForEveryone } from '../../../lib/userSafety.js'
|
||||||
|
|
||||||
// The member-raised content-report queue (TEAMS.md §5.6).
|
// The member-raised content-report queue (TEAMS.md §5.6).
|
||||||
//
|
//
|
||||||
@@ -20,10 +22,20 @@ import { api } from '../../../api/client.js'
|
|||||||
// row here rather than as a new screen.
|
// row here rather than as a new screen.
|
||||||
//
|
//
|
||||||
// **Handling a report is bookkeeping about the REPORT, not moderation of the
|
// **Handling a report is bookkeeping about the REPORT, not moderation of the
|
||||||
// content.** Acting on the content itself is the ordinary forum moderation
|
// content.** Keeping those separate is what stops "report" from becoming a way
|
||||||
// control, or a site-wide sanction against the account. Keeping those separate is
|
// for any member to hide anything.
|
||||||
// what stops "report" from becoming a way for any member to hide anything, so
|
//
|
||||||
// this screen deliberately offers no hide/delete button of its own.
|
// **The one exception is "Hide for everyone"** (USER_SAFETY.md §4.1, S3), and it
|
||||||
|
// is a separate button with its own words, not a status. It hides the item
|
||||||
|
// through the item's OWN moderation — the forum's hide, or a game module's for a
|
||||||
|
// chat line — so it is a staff moderation recorded where that content's
|
||||||
|
// moderation is recorded, and the report is actioned with that named. Undoing it
|
||||||
|
// happens where the item lives, where staff still see it marked (S10). Delete
|
||||||
|
// stays the forum's.
|
||||||
|
//
|
||||||
|
// Since 1.21.0 a report can be about a game module's item (a Rust chat line),
|
||||||
|
// and every new report carries a snapshot of what the item said, which is what
|
||||||
|
// this screen shows once the item itself is gone.
|
||||||
|
|
||||||
const STATUS_TABS = [
|
const STATUS_TABS = [
|
||||||
{ key: 'open_work', label: 'Open work', param: undefined },
|
{ key: 'open_work', label: 'Open work', param: undefined },
|
||||||
@@ -70,12 +82,44 @@ const bytes = (n) => {
|
|||||||
* was gone" is a fact worth seeing, and dropping it would hide the pattern of a
|
* was gone" is a fact worth seeing, and dropping it would hide the pattern of a
|
||||||
* member deleting their own content the moment it is reported.
|
* member deleting their own content the moment it is reported.
|
||||||
*/
|
*/
|
||||||
|
function SnapshotLine({ snapshot }) {
|
||||||
|
// An unlinked chat speaker is named by their in-game name and Steam id; the
|
||||||
|
// queue is staff-only, and the id is what a staffer acts on in game.
|
||||||
|
const who = markDeleted(snapshot.author, snapshot.authorDeleted) || 'unknown'
|
||||||
|
const idNote = snapshot.authorIdentity ? ` (${snapshot.authorIdentity.kind} ${snapshot.authorIdentity.id})` : ''
|
||||||
|
return (
|
||||||
|
<span className="dim" style={{ display: 'block', fontSize: '0.78rem' }}>
|
||||||
|
{snapshot.label ? `${snapshot.label} · ` : ''}{who}{idNote}
|
||||||
|
{snapshot.where?.server ? ` on ${snapshot.where.server}` : ''}
|
||||||
|
{snapshot.at ? ` · ${dateTime(snapshot.at)}` : ''}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function TargetCell({ report }) {
|
function TargetCell({ report }) {
|
||||||
const t = report.target
|
const t = report.target
|
||||||
|
const snap = report.snapshot
|
||||||
if (!t) {
|
if (!t) {
|
||||||
return (
|
return (
|
||||||
<span style={{ color: 'var(--muted)' }}>
|
<span style={{ color: 'var(--muted)' }}>
|
||||||
{report.targetType.replace('team_forum_', '')} #{report.targetId} — no longer exists
|
{report.targetType.replace('team_forum_', '')} #{report.targetId} — no longer exists
|
||||||
|
{/* What it said when it was reported, kept on the report (1.21.0). */}
|
||||||
|
{snap && (
|
||||||
|
<>
|
||||||
|
<span style={{ display: 'block', color: 'var(--text)' }}>{snap.text || <em>(no text)</em>}</span>
|
||||||
|
<SnapshotLine snapshot={snap} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (t.kind === 'module') {
|
||||||
|
return (
|
||||||
|
<span>
|
||||||
|
{t.text || <em className="dim">(no text)</em>}
|
||||||
|
{snap ? <SnapshotLine snapshot={snap} /> : (
|
||||||
|
<span className="dim" style={{ display: 'block', fontSize: '0.78rem' }}>{t.label}</span>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -84,7 +128,7 @@ function TargetCell({ report }) {
|
|||||||
<span>
|
<span>
|
||||||
<a href={t.url} target="_blank" rel="noopener noreferrer" className="link-accent">{t.filename}</a>
|
<a href={t.url} target="_blank" rel="noopener noreferrer" className="link-accent">{t.filename}</a>
|
||||||
<span className="dim" style={{ display: 'block', fontSize: '0.78rem' }}>
|
<span className="dim" style={{ display: 'block', fontSize: '0.78rem' }}>
|
||||||
{t.uploader || 'unknown'} · {t.mimetype} · {bytes(t.byteSize)}
|
{markDeleted(t.uploader, t.uploaderDeleted) || 'unknown'} · {t.mimetype} · {bytes(t.byteSize)}
|
||||||
{t.deleted && ' · removed'}
|
{t.deleted && ' · removed'}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
@@ -95,7 +139,7 @@ function TargetCell({ report }) {
|
|||||||
<span>
|
<span>
|
||||||
<strong>{t.title}</strong>
|
<strong>{t.title}</strong>
|
||||||
<span className="dim" style={{ display: 'block', fontSize: '0.78rem' }}>
|
<span className="dim" style={{ display: 'block', fontSize: '0.78rem' }}>
|
||||||
{t.type} by {t.author || 'unknown'}
|
{t.type} by {markDeleted(t.author, t.authorDeleted) || 'unknown'}
|
||||||
{t.status !== 'visible' && ` · ${t.status}`}
|
{t.status !== 'visible' && ` · ${t.status}`}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
@@ -105,7 +149,7 @@ function TargetCell({ report }) {
|
|||||||
<span>
|
<span>
|
||||||
{t.excerpt || <em className="dim">(no text)</em>}
|
{t.excerpt || <em className="dim">(no text)</em>}
|
||||||
<span className="dim" style={{ display: 'block', fontSize: '0.78rem' }}>
|
<span className="dim" style={{ display: 'block', fontSize: '0.78rem' }}>
|
||||||
{t.author || 'unknown'} in “{t.threadTitle}”
|
{markDeleted(t.author, t.authorDeleted) || 'unknown'} in “{t.threadTitle}”
|
||||||
{t.status !== 'visible' && ` · ${t.status}`}
|
{t.status !== 'visible' && ` · ${t.status}`}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
@@ -133,10 +177,11 @@ export default function ContentReports() {
|
|||||||
return (
|
return (
|
||||||
<section>
|
<section>
|
||||||
<p className="sans dim" style={{ margin: '0 0 14px', fontSize: '0.85rem', maxWidth: 720 }}>
|
<p className="sans dim" style={{ margin: '0 0 14px', fontSize: '0.85rem', maxWidth: 720 }}>
|
||||||
Reports raised by members about Team forum content. They come to site staff and are not visible
|
Reports raised by members about Team forum content and in-game chat. They come to site staff and
|
||||||
to a Team’s own leaders — a leader moderates their own forum, so a report about a leader
|
are not visible to a Team’s own leaders — a leader moderates their own forum, so a report
|
||||||
has to reach someone above them. Handling a report records a decision about the report; hiding
|
about a leader has to reach someone above them. Handling a report records a decision about the
|
||||||
or removing the content itself is done from the forum, or as a sanction against the account.
|
report. <em>Hide for everyone</em> also hides the item, for everyone but staff; removing it is
|
||||||
|
done from the forum, or as a sanction against the account.
|
||||||
{typeof data?.openCount === 'number' && ` ${data.openCount} open.`}
|
{typeof data?.openCount === 'number' && ` ${data.openCount} open.`}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -192,13 +237,16 @@ export default function ContentReports() {
|
|||||||
<span className="badge">{REASON_LABEL[r.reason] || r.reason}</span>
|
<span className="badge">{REASON_LABEL[r.reason] || r.reason}</span>
|
||||||
</td>
|
</td>
|
||||||
<td className="adm-td dim" style={{ maxWidth: 260 }}>{r.detail || '—'}</td>
|
<td className="adm-td dim" style={{ maxWidth: 260 }}>{r.detail || '—'}</td>
|
||||||
<td className="adm-td dim">{r.reporter}</td>
|
<td className="adm-td dim">{markDeleted(r.reporter, r.reporterDeleted)}</td>
|
||||||
<td className="adm-td dim" title={dateTime(r.createdAt)}>{ago(r.createdAt)}</td>
|
<td className="adm-td dim" title={dateTime(r.createdAt)}>{ago(r.createdAt)}</td>
|
||||||
<td className="adm-td">
|
<td className="adm-td">
|
||||||
<span className="badge" style={STATUS_STYLE[r.status]}>{STATUS_LABEL[r.status] || r.status}</span>
|
<span className="badge" style={STATUS_STYLE[r.status]}>{STATUS_LABEL[r.status] || r.status}</span>
|
||||||
|
{r.actionedWith === 'hide' && (
|
||||||
|
<span className="dim" style={{ display: 'block', fontSize: '0.75rem' }}>Hidden for everyone</span>
|
||||||
|
)}
|
||||||
{r.handledBy && (
|
{r.handledBy && (
|
||||||
<span className="dim" style={{ display: 'block', fontSize: '0.75rem' }}>
|
<span className="dim" style={{ display: 'block', fontSize: '0.75rem' }}>
|
||||||
{r.handledBy}
|
{markDeleted(r.handledBy, r.handledByDeleted)}
|
||||||
{r.handledNote ? ` — ${r.handledNote}` : ''}
|
{r.handledNote ? ` — ${r.handledNote}` : ''}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
@@ -222,9 +270,9 @@ export default function ContentReports() {
|
|||||||
<HandleModal
|
<HandleModal
|
||||||
report={handling}
|
report={handling}
|
||||||
onCancel={() => setHandling(null)}
|
onCancel={() => setHandling(null)}
|
||||||
onDone={() => {
|
onDone={(text = 'Report updated.') => {
|
||||||
setHandling(null)
|
setHandling(null)
|
||||||
setNotice({ text: 'Report updated.', tone: 'ok' })
|
setNotice({ text, tone: 'ok' })
|
||||||
reload()
|
reload()
|
||||||
}}
|
}}
|
||||||
onError={(message) => setNotice({ text: message, tone: 'error' })}
|
onError={(message) => setNotice({ text: message, tone: 'error' })}
|
||||||
@@ -257,6 +305,17 @@ function HandleModal({ report, onCancel, onDone, onError }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hideForEveryone = async () => {
|
||||||
|
setBusy(true)
|
||||||
|
try {
|
||||||
|
await api.admin.hideReportedItem(report.id, { note: note || undefined })
|
||||||
|
onDone('Hidden for everyone, and the report is actioned.')
|
||||||
|
} catch (err) {
|
||||||
|
onError(err.message || 'Could not hide that.')
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title={`Report #${report.id}`}
|
title={`Report #${report.id}`}
|
||||||
@@ -264,6 +323,11 @@ function HandleModal({ report, onCancel, onDone, onError }) {
|
|||||||
footer={(
|
footer={(
|
||||||
<>
|
<>
|
||||||
<button className="pill" onClick={onCancel}>Cancel</button>
|
<button className="pill" onClick={onCancel}>Cancel</button>
|
||||||
|
{canHideForEveryone(report) && (
|
||||||
|
<button className="pill" onClick={hideForEveryone} disabled={busy} style={{ color: '#d98b84', borderColor: '#d98b84' }}>
|
||||||
|
Hide for everyone
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<button className="btn btn-primary btn-sq" onClick={submit} disabled={busy}>
|
<button className="btn btn-primary btn-sq" onClick={submit} disabled={busy}>
|
||||||
{busy ? 'Saving…' : 'Save'}
|
{busy ? 'Saving…' : 'Save'}
|
||||||
</button>
|
</button>
|
||||||
@@ -272,8 +336,12 @@ function HandleModal({ report, onCancel, onDone, onError }) {
|
|||||||
>
|
>
|
||||||
<div style={{ display: 'grid', gap: 12 }}>
|
<div style={{ display: 'grid', gap: 12 }}>
|
||||||
<p className="sans dim" style={{ margin: 0, fontSize: '0.82rem' }}>
|
<p className="sans dim" style={{ margin: 0, fontSize: '0.82rem' }}>
|
||||||
This records a decision about the report. It does not hide, delete or restore the content —
|
<strong>Save</strong> records a decision about the report and changes nothing about the content.
|
||||||
do that from the forum itself, or against the account.
|
{' '}
|
||||||
|
{canHideForEveryone(report)
|
||||||
|
? <><strong>Hide for everyone</strong> hides the item for everyone but staff, who still see it marked
|
||||||
|
where it is and can unhide it there, and actions this report.</>
|
||||||
|
: 'Deleting or restoring the content is done from the forum itself, or against the account.'}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
|
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Loading, ErrorState } from '../../../components/PageState.jsx'
|
|||||||
import { useAsync } from '../../../lib/useAsync.js'
|
import { useAsync } from '../../../lib/useAsync.js'
|
||||||
import { ago, dateTime } from '../../../lib/format.js'
|
import { ago, dateTime } from '../../../lib/format.js'
|
||||||
import { api } from '../../../api/client.js'
|
import { api } from '../../../api/client.js'
|
||||||
|
import { isDemoLocked } from '../../../lib/demoNotice.js'
|
||||||
import { useSite } from '../../../contexts/SiteContext.jsx'
|
import { useSite } from '../../../contexts/SiteContext.jsx'
|
||||||
import { useAuth } from '../../../contexts/AuthContext.jsx'
|
import { useAuth } from '../../../contexts/AuthContext.jsx'
|
||||||
|
|
||||||
@@ -49,11 +50,10 @@ export default function Dashboard() {
|
|||||||
await refreshSite()
|
await refreshSite()
|
||||||
reload()
|
reload()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setModeError(
|
let message = 'Could not change the site mode. Try again.'
|
||||||
err.status === 403
|
if (isDemoLocked(err)) message = err.message
|
||||||
? 'Only an administrator can change the site mode.'
|
else if (err.status === 403) message = 'Only an administrator can change the site mode.'
|
||||||
: 'Could not change the site mode. Try again.',
|
setModeError(message)
|
||||||
)
|
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false)
|
setBusy(false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1497,11 +1497,16 @@ export default function EventEditor() {
|
|||||||
setEvent(result.event)
|
setEvent(result.event)
|
||||||
setVersions(await api.admin.listEventVersions(id).then((r) => r.versions || []))
|
setVersions(await api.admin.listEventVersions(id).then((r) => r.versions || []))
|
||||||
// The re-pin count is said out loud, because an editor who does not know
|
// The re-pin count is said out loud, because an editor who does not know
|
||||||
// their fix reached next Friday finds out on Friday.
|
// their fix reached next Friday finds out on Friday. So is a dry run that
|
||||||
|
// carried over from the draft (W5): it is why no second one is asked for.
|
||||||
setNotice(
|
setNotice(
|
||||||
result.repinned
|
[
|
||||||
? `Published as v${result.version}. ${result.repinned} scheduled occurrence${result.repinned === 1 ? '' : 's'} moved to it.`
|
`Published as v${result.version}.`,
|
||||||
: `Published as v${result.version}.`,
|
result.verified ? 'The dry run that passed on this draft counts for it.' : '',
|
||||||
|
result.repinned
|
||||||
|
? `${result.repinned} scheduled occurrence${result.repinned === 1 ? '' : 's'} moved to it.`
|
||||||
|
: '',
|
||||||
|
].filter(Boolean).join(' '),
|
||||||
)
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setProblems(err.body?.errors || [err.message])
|
setProblems(err.body?.errors || [err.message])
|
||||||
@@ -1674,6 +1679,7 @@ export default function EventEditor() {
|
|||||||
report that did not say would be read as the other one. */}
|
report that did not say would be read as the other one. */}
|
||||||
{report.target === 'version' ? `published v${report.version}` : 'the working draft'}
|
{report.target === 'version' ? `published v${report.version}` : 'the working draft'}
|
||||||
{report.recorded && ' · recorded, so scheduled occurrences may now start'}
|
{report.recorded && ' · recorded, so scheduled occurrences may now start'}
|
||||||
|
{report.draftRecorded && ' · kept, so publishing this draft unchanged makes a verified version'}
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -2019,7 +2025,7 @@ export default function EventEditor() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p className="sans dim" style={{ fontSize: '0.76rem', margin: '8px 0 0' }}>
|
<p className="sans dim" style={{ fontSize: '0.76rem', margin: '8px 0 0' }}>
|
||||||
The key is what the run console groups by and what “phase 3 has not started” names, so it
|
The key is what the run console groups by and what “Phase p3: steps done, waiting to advance” names, so it
|
||||||
cannot change once runs exist.
|
cannot change once runs exist.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,9 @@ function GateRow({ gate, current }) {
|
|||||||
<div style={{ padding: '8px 0', borderTop: '1px solid var(--rule)' }}>
|
<div style={{ padding: '8px 0', borderTop: '1px solid var(--rule)' }}>
|
||||||
<div className="sans" style={{ fontSize: '0.86rem', color: colour }}>
|
<div className="sans" style={{ fontSize: '0.86rem', color: colour }}>
|
||||||
Phase <strong>{gate.phase}</strong>
|
Phase <strong>{gate.phase}</strong>
|
||||||
{current && !gate.satisfied ? ' has not started' : ''}
|
{/* W2: the phase is running and its steps are done; it is the advance
|
||||||
|
that waits, so "has not started" was the wrong sentence. */}
|
||||||
|
{current && !gate.satisfied ? ': steps done, waiting to advance' : ''}
|
||||||
{gate.satisfied && ` — released ${gate.satisfiedBy === 'forced' ? 'by hand' : `on its ${gate.satisfiedBy === 'elapsed' ? 'deadline' : 'condition'}`}`}
|
{gate.satisfied && ` — released ${gate.satisfiedBy === 'forced' ? 'by hand' : `on its ${gate.satisfiedBy === 'elapsed' ? 'deadline' : 'condition'}`}`}
|
||||||
{gate.stalled && ' — STALLED'}
|
{gate.stalled && ' — STALLED'}
|
||||||
</div>
|
</div>
|
||||||
@@ -389,7 +391,7 @@ export default function EventRun() {
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* ── Why this phase has not started (Phase 5) ──
|
{/* ── Why this phase has not advanced (Phase 5) ──
|
||||||
Above the step list for the same reason the parked cue is: a phase
|
Above the step list for the same reason the parked cue is: a phase
|
||||||
waiting on a condition is `running` and looks completely healthy, and
|
waiting on a condition is `running` and looks completely healthy, and
|
||||||
the one screen an operator opens to find out why nothing is happening
|
the one screen an operator opens to find out why nothing is happening
|
||||||
@@ -400,7 +402,7 @@ export default function EventRun() {
|
|||||||
style={{ padding: 14, marginBottom: 14, borderLeft: `3px solid ${waiting ? (waiting.stalled ? '#d98b84' : '#d9c184') : 'var(--rule)'}` }}
|
style={{ padding: 14, marginBottom: 14, borderLeft: `3px solid ${waiting ? (waiting.stalled ? '#d98b84' : '#d9c184') : 'var(--rule)'}` }}
|
||||||
>
|
>
|
||||||
<h3 className="sans" style={{ margin: '0 0 4px', fontSize: '0.92rem' }}>
|
<h3 className="sans" style={{ margin: '0 0 4px', fontSize: '0.92rem' }}>
|
||||||
{waiting ? 'Why this phase has not started' : 'Phase advance conditions'}
|
{waiting ? 'Why this phase has not advanced' : 'Phase advance conditions'}
|
||||||
</h3>
|
</h3>
|
||||||
<p className="sans dim" style={{ margin: '0 0 4px', fontSize: '0.8rem' }}>
|
<p className="sans dim" style={{ margin: '0 0 4px', fontSize: '0.8rem' }}>
|
||||||
{waiting ? (
|
{waiting ? (
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react'
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
import { Loading, ErrorState } from '../../../components/PageState.jsx'
|
import { Loading, ErrorState } from '../../../components/PageState.jsx'
|
||||||
import { dateTime } from '../../../lib/format.js'
|
import { dateTime } from '../../../lib/format.js'
|
||||||
|
import { rowName } from '../../../lib/deletedAccount.js'
|
||||||
import {
|
import {
|
||||||
freshnessOf, statusOf, gateLabelFor, describeRequest, leadershipOf, GATED_NOTE,
|
freshnessOf, statusOf, gateLabelFor, describeRequest, leadershipOf, GATED_NOTE,
|
||||||
} from '../../../lib/teamAdmin.js'
|
} from '../../../lib/teamAdmin.js'
|
||||||
@@ -14,7 +15,7 @@ import TeamVoice from './TeamVoice.jsx'
|
|||||||
// Three panels, in the order an operator needs them:
|
// Three panels, in the order an operator needs them:
|
||||||
//
|
//
|
||||||
// 1. **Sync state**, verbatim, including the last error. The screen's first job
|
// 1. **Sync state**, verbatim, including the last error. The screen's first job
|
||||||
// is to make "the shard has no Teams" and "core has not been able to ask for
|
// is to make "the game server has no Teams" and "core has not been able to ask for
|
||||||
// two hours" impossible to confuse — they render almost identically
|
// two hours" impossible to confuse — they render almost identically
|
||||||
// otherwise, and one is fine while the other is an outage.
|
// otherwise, and one is fine while the other is an outage.
|
||||||
// 2. **The review queue** — Teams auto-hidden because their name matched the
|
// 2. **The review queue** — Teams auto-hidden because their name matched the
|
||||||
@@ -331,7 +332,7 @@ function ForumLedger({ team, onClose }) {
|
|||||||
<td className="adm-td dim">{dateTime(r.created_at)}</td>
|
<td className="adm-td dim">{dateTime(r.created_at)}</td>
|
||||||
<td className="adm-td" style={{ color: 'var(--head)' }}>{r.action}</td>
|
<td className="adm-td" style={{ color: 'var(--head)' }}>{r.action}</td>
|
||||||
<td className="adm-td dim">{r.target_type} #{r.target_id}</td>
|
<td className="adm-td dim">{r.target_type} #{r.target_id}</td>
|
||||||
<td className="adm-td">{r.actor_username || '—'}</td>
|
<td className="adm-td">{rowName(r.actor_user_id, r.actor_username)}</td>
|
||||||
<td className="adm-td">
|
<td className="adm-td">
|
||||||
{/* The distinction the whole ledger exists to preserve. */}
|
{/* The distinction the whole ledger exists to preserve. */}
|
||||||
<Pill tone={r.actor_role === 'staff' ? 'warn' : 'ok'}>{r.actor_role}</Pill>
|
<Pill tone={r.actor_role === 'staff' ? 'warn' : 'ok'}>{r.actor_role}</Pill>
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import RecoveryCodesDisplay from '../../components/security/RecoveryCodesDisplay
|
|||||||
import TrustedDevicesPanel from '../../components/security/TrustedDevicesPanel.jsx'
|
import TrustedDevicesPanel from '../../components/security/TrustedDevicesPanel.jsx'
|
||||||
import RecoveryCodesPanel from '../../components/security/RecoveryCodesPanel.jsx'
|
import RecoveryCodesPanel from '../../components/security/RecoveryCodesPanel.jsx'
|
||||||
import EmailAddressPanel from '../../components/security/EmailAddressPanel.jsx'
|
import EmailAddressPanel from '../../components/security/EmailAddressPanel.jsx'
|
||||||
|
import DeleteAccountPanel from '../../components/security/DeleteAccountPanel.jsx'
|
||||||
|
import BlockedPanel from '../../components/security/BlockedPanel.jsx'
|
||||||
|
import { IdentitySummary, linkBanner, linkableProviders, unlinkPrompt } from '../../components/security/linkedIdentities.jsx'
|
||||||
import { useAuth } from '../../contexts/AuthContext.jsx'
|
import { useAuth } from '../../contexts/AuthContext.jsx'
|
||||||
import { api } from '../../api/client.js'
|
import { api } from '../../api/client.js'
|
||||||
|
|
||||||
@@ -224,13 +227,7 @@ function LinkedAccounts() {
|
|||||||
const [available, setAvailable] = useState([])
|
const [available, setAvailable] = useState([])
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
const banner = (() => {
|
const banner = linkBanner(window.location.search)
|
||||||
const q = new URLSearchParams(window.location.search)
|
|
||||||
if (q.get('linked')) return { ok: true, text: 'Account linked.' }
|
|
||||||
if (q.get('link_error') === 'in_use') return { ok: false, text: 'That external account is already linked to another user.' }
|
|
||||||
if (q.get('link_error')) return { ok: false, text: 'Could not link that account. Please try again.' }
|
|
||||||
return null
|
|
||||||
})()
|
|
||||||
|
|
||||||
const load = useCallback(async () => {
|
const load = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -247,12 +244,11 @@ function LinkedAccounts() {
|
|||||||
useEffect(() => { load() }, [load])
|
useEffect(() => { load() }, [load])
|
||||||
|
|
||||||
const nameFor = (id) => available.find((p) => p.id === id)?.name || id.charAt(0).toUpperCase() + id.slice(1)
|
const nameFor = (id) => available.find((p) => p.id === id)?.name || id.charAt(0).toUpperCase() + id.slice(1)
|
||||||
const iconFor = (id) => (id === 'google' || id === 'discord' ? id : 'oidc')
|
|
||||||
|
|
||||||
async function unlink(provider) {
|
async function unlink(identity) {
|
||||||
if (!window.confirm(`Unlink ${nameFor(provider)} from your account?`)) return
|
if (!window.confirm(unlinkPrompt(identity, nameFor(identity.provider)))) return
|
||||||
try {
|
try {
|
||||||
await api.unlinkIdentity(provider)
|
await api.unlinkIdentity(identity.provider, identity.id)
|
||||||
await load()
|
await load()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err.message || 'Could not unlink.')
|
setError(err.message || 'Could not unlink.')
|
||||||
@@ -262,13 +258,12 @@ function LinkedAccounts() {
|
|||||||
if (error) return <ErrorState message={error} />
|
if (error) return <ErrorState message={error} />
|
||||||
if (!linked) return null
|
if (!linked) return null
|
||||||
|
|
||||||
const linkedIds = new Set(linked.map((i) => i.provider))
|
const linkable = linkableProviders(available, linked)
|
||||||
const linkable = available.filter((p) => !linkedIds.has(p.id))
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Section title="Linked accounts">
|
<Section title="Linked accounts">
|
||||||
<p className="sans" style={{ marginTop: 0, color: 'var(--muted)', fontSize: '0.88rem', lineHeight: 1.6 }}>
|
<p className="sans" style={{ marginTop: 0, color: 'var(--muted)', fontSize: '0.88rem', lineHeight: 1.6 }}>
|
||||||
Link a Google, Discord, or other provider so you can sign in with it.
|
Link a Google, Discord, Steam, or other provider so you can sign in with it.
|
||||||
</p>
|
</p>
|
||||||
{banner && (
|
{banner && (
|
||||||
<p className="sans" style={{ color: banner.ok ? '#7fd0a4' : '#d98b84', fontSize: '0.86rem' }}>{banner.text}</p>
|
<p className="sans" style={{ color: banner.ok ? '#7fd0a4' : '#d98b84', fontSize: '0.86rem' }}>{banner.text}</p>
|
||||||
@@ -276,15 +271,9 @@ function LinkedAccounts() {
|
|||||||
{linked.length > 0 && (
|
{linked.length > 0 && (
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 10, margin: '14px 0' }}>
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 10, margin: '14px 0' }}>
|
||||||
{linked.map((i) => (
|
{linked.map((i) => (
|
||||||
<div key={i.provider} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '10px 14px', border: '1px solid var(--line)', borderRadius: 8 }}>
|
<div key={i.id ?? i.provider} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '10px 14px', border: '1px solid var(--line)', borderRadius: 8 }}>
|
||||||
<span style={{ display: 'inline-flex', width: 20, height: 20 }}>
|
<IdentitySummary identity={i} providerName={nameFor(i.provider)} />
|
||||||
<ProviderIcon icon={iconFor(i.provider)} size={20} />
|
<button onClick={() => unlink(i)} className="pill" style={{ color: '#d98b84', borderColor: '#d98b84' }}>Unlink</button>
|
||||||
</span>
|
|
||||||
<div style={{ flex: 1, minWidth: 0 }}>
|
|
||||||
<div className="sans" style={{ color: 'var(--head)', fontSize: '0.9rem' }}>{nameFor(i.provider)}</div>
|
|
||||||
{i.email && <div className="sans dim" style={{ fontSize: '0.78rem' }}>{i.email}</div>}
|
|
||||||
</div>
|
|
||||||
<button onClick={() => unlink(i.provider)} className="pill" style={{ color: '#d98b84', borderColor: '#d98b84' }}>Unlink</button>
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -435,6 +424,8 @@ export default function PlayerAccount() {
|
|||||||
)}
|
)}
|
||||||
<LinkedAccounts />
|
<LinkedAccounts />
|
||||||
<ActiveDevices />
|
<ActiveDevices />
|
||||||
|
<BlockedPanel />
|
||||||
|
<DeleteAccountPanel account={account} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react'
|
|||||||
import { Link, useNavigate, useLocation } from 'react-router-dom'
|
import { Link, useNavigate, useLocation } from 'react-router-dom'
|
||||||
import ProviderIcon from '../../components/ProviderIcon.jsx'
|
import ProviderIcon from '../../components/ProviderIcon.jsx'
|
||||||
import TrustLimitModal from '../../components/security/TrustLimitModal.jsx'
|
import TrustLimitModal from '../../components/security/TrustLimitModal.jsx'
|
||||||
|
import DemoLogins from '../../components/DemoLogins.jsx'
|
||||||
import { useAuth } from '../../contexts/AuthContext.jsx'
|
import { useAuth } from '../../contexts/AuthContext.jsx'
|
||||||
import { api } from '../../api/client.js'
|
import { api } from '../../api/client.js'
|
||||||
import PlayerShell, { honeypotStyle } from './PlayerShell.jsx'
|
import PlayerShell, { honeypotStyle } from './PlayerShell.jsx'
|
||||||
@@ -272,6 +273,15 @@ export default function PlayerLogin() {
|
|||||||
)}
|
)}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
{stage === 'creds' && (
|
||||||
|
<DemoLogins
|
||||||
|
onPick={(u, p) => {
|
||||||
|
setUsername(u)
|
||||||
|
setPassword(p)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{trustLimit && (
|
{trustLimit && (
|
||||||
<TrustLimitModal
|
<TrustLimitModal
|
||||||
devices={trustLimit.devices}
|
devices={trustLimit.devices}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Link, useNavigate } from 'react-router-dom'
|
|||||||
import ProviderIcon from '../../components/ProviderIcon.jsx'
|
import ProviderIcon from '../../components/ProviderIcon.jsx'
|
||||||
import { useAuth } from '../../contexts/AuthContext.jsx'
|
import { useAuth } from '../../contexts/AuthContext.jsx'
|
||||||
import { api } from '../../api/client.js'
|
import { api } from '../../api/client.js'
|
||||||
|
import { isDemoLocked } from '../../lib/demoNotice.js'
|
||||||
import PlayerShell, { honeypotStyle } from './PlayerShell.jsx'
|
import PlayerShell, { honeypotStyle } from './PlayerShell.jsx'
|
||||||
|
|
||||||
export default function PlayerRegister() {
|
export default function PlayerRegister() {
|
||||||
@@ -54,6 +55,7 @@ export default function PlayerRegister() {
|
|||||||
navigate('/player', { replace: true })
|
navigate('/player', { replace: true })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.status === 409) setError('That username is already taken.')
|
if (err.status === 409) setError('That username is already taken.')
|
||||||
|
else if (isDemoLocked(err)) setError(err.message)
|
||||||
else if (err.status === 403) setError('Registration is not open right now.')
|
else if (err.status === 403) setError('Registration is not open right now.')
|
||||||
else if (err.status === 400) setError(err.message || 'Please check your details and try again.')
|
else if (err.status === 400) setError(err.message || 'Please check your details and try again.')
|
||||||
else setError('Could not create your account right now.')
|
else setError('Could not create your account right now.')
|
||||||
|
|||||||
80
client/test/accountDeletion.test.js
Normal file
80
client/test/accountDeletion.test.js
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
// The Account page's "Delete my account" section (client/src/lib/accountDeletion.js)
|
||||||
|
// and how a deleted account's name is marked for staff (lib/deletedAccount.js).
|
||||||
|
// docs/website/ACCOUNT_DELETION.md §4.1, §4.2, AD5, AD6.
|
||||||
|
import { test } from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
|
||||||
|
import {
|
||||||
|
usernameMatches, isSharedDemoLogin, refusalMessage, isStaffRole, WHAT_GOES, WHAT_STAYS,
|
||||||
|
} from '../src/lib/accountDeletion.js'
|
||||||
|
import { DELETED_PLAYER, markDeleted, rowName } from '../src/lib/deletedAccount.js'
|
||||||
|
import { describeRequest, leadershipOf } from '../src/lib/teamAdmin.js'
|
||||||
|
import { threadSummary } from '../src/lib/teamForum.js'
|
||||||
|
|
||||||
|
// ── the confirm step ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
test('Delete is live only once the typed username matches, ignoring case and spaces', () => {
|
||||||
|
assert.equal(usernameMatches('Thorne', 'Thorne'), true)
|
||||||
|
assert.equal(usernameMatches(' thorne ', 'Thorne'), true)
|
||||||
|
assert.equal(usernameMatches('Thorn', 'Thorne'), false)
|
||||||
|
assert.equal(usernameMatches('', 'Thorne'), false)
|
||||||
|
assert.equal(usernameMatches(' ', 'Thorne'), false)
|
||||||
|
assert.equal(usernameMatches(undefined, 'Thorne'), false)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('the demo’s shared logins are recognised from the published list, and nothing else is', () => {
|
||||||
|
const settings = { demo: { logins: [{ username: 'demo-player' }, { username: 'play-review' }] } }
|
||||||
|
assert.equal(isSharedDemoLogin(settings, 'Demo-Player'), true)
|
||||||
|
assert.equal(isSharedDemoLogin(settings, 'alice'), false)
|
||||||
|
// Off the demo there is no `demo` block, so nobody is a shared login.
|
||||||
|
assert.equal(isSharedDemoLogin({}, 'demo-player'), false)
|
||||||
|
assert.equal(isSharedDemoLogin(undefined, 'demo-player'), false)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('every refusal code the route answers has its own sentence', () => {
|
||||||
|
for (const code of ['username_mismatch', 'wrong_password', 'code_required', 'wrong_code', 'password_required', 'last_admin', 'DEMO_LOCKED']) {
|
||||||
|
const msg = refusalMessage({ status: 400, body: { code }, message: 'server words' })
|
||||||
|
assert.notEqual(msg, 'server words', code)
|
||||||
|
assert.ok(msg.length > 10, code)
|
||||||
|
}
|
||||||
|
assert.match(refusalMessage({ status: 429, body: null }), /Too many attempts/)
|
||||||
|
assert.equal(refusalMessage({ status: 500, message: 'Internal Server Error' }), 'Internal Server Error')
|
||||||
|
assert.match(refusalMessage(null), /Could not delete/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('the screen says what goes and what stays, and that staff names are kept forever', () => {
|
||||||
|
assert.ok(WHAT_GOES.some((l) => /game-account links/.test(l)))
|
||||||
|
assert.ok(WHAT_STAYS.some((l) => l.includes('[deleted player]')))
|
||||||
|
assert.equal(isStaffRole('moderator'), true)
|
||||||
|
assert.equal(isStaffRole('player'), false)
|
||||||
|
})
|
||||||
|
|
||||||
|
// ── staff see a deleted account's name, marked ─────────────────────────────
|
||||||
|
|
||||||
|
test('a deleted account’s stored name is marked; the placeholder is left alone', () => {
|
||||||
|
assert.equal(markDeleted('Ravenna', true), 'Ravenna (deleted account)')
|
||||||
|
assert.equal(markDeleted('Ravenna', false), 'Ravenna')
|
||||||
|
assert.equal(markDeleted(DELETED_PLAYER, true), DELETED_PLAYER)
|
||||||
|
assert.equal(markDeleted(null, true), null)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('a raw ledger row is a deleted account only when its id is an explicit null', () => {
|
||||||
|
assert.equal(rowName(null, 'OldMod'), 'OldMod (deleted account)')
|
||||||
|
assert.equal(rowName(4, 'OldMod'), 'OldMod')
|
||||||
|
assert.equal(rowName(undefined, 'OldMod'), 'OldMod')
|
||||||
|
assert.equal(rowName(null, null), '—')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('Admin → Teams marks a deleted requester and a deleted override author', () => {
|
||||||
|
assert.match(
|
||||||
|
describeRequest({ action: 'unhide', requested_by: null, requested_username: 'mod1', team_name: 'X' }),
|
||||||
|
/^mod1 \(deleted account\) asks/,
|
||||||
|
)
|
||||||
|
const l = leadershipOf({ isLeaderSynced: true, leaderOverride: { effect: 'deny', by: 'mod1', byDeleted: true } })
|
||||||
|
assert.match(l.note, /Denied by mod1 \(deleted account\)/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('a forum thread by a deleted account is marked in the list for staff', () => {
|
||||||
|
assert.match(threadSummary({ type: 'discussion', author: 'Ravenna', authorDeleted: true, postCount: 1 }), /^Ravenna \(deleted account\)/)
|
||||||
|
assert.equal(threadSummary({ type: 'discussion', author: DELETED_PLAYER, authorDeleted: true, postCount: 1 }), DELETED_PLAYER)
|
||||||
|
})
|
||||||
@@ -247,6 +247,32 @@ test('the report queue defaults to the open work rather than to everything', asy
|
|||||||
assert.equal(calls[0].url, '/api/v1/admin/moderation/reports')
|
assert.equal(calls[0].url, '/api/v1/admin/moderation/reports')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// USER_SAFETY.md §4.1: a report, a block and a hide name an ITEM, never a
|
||||||
|
// person, and the server reads who wrote it.
|
||||||
|
test('report, block and hide name an item, on the one route for every target', async () => {
|
||||||
|
willReply({ body: { ok: true } })
|
||||||
|
await api.reportItem({ targetType: 'rust.chat', targetId: 4410, reason: 'abuse' })
|
||||||
|
assert.equal(calls[0].url, '/api/v1/player/reports')
|
||||||
|
assert.deepEqual(JSON.parse(calls[0].opts.body), { targetType: 'rust.chat', targetId: 4410, reason: 'abuse' })
|
||||||
|
|
||||||
|
calls = []
|
||||||
|
willReply({ body: { block: {} } })
|
||||||
|
await api.blockAuthor({ targetType: 'team_forum_post', targetId: 80 })
|
||||||
|
assert.equal(calls[0].url, '/api/v1/auth/me/blocks')
|
||||||
|
assert.deepEqual(JSON.parse(calls[0].opts.body), { targetType: 'team_forum_post', targetId: 80 })
|
||||||
|
|
||||||
|
calls = []
|
||||||
|
willReply({ body: { ok: true } })
|
||||||
|
await api.unhideItem({ targetType: 'rust.chat', targetId: 4410 })
|
||||||
|
assert.equal(calls[0].url, '/api/v1/auth/me/hidden/rust.chat/4410')
|
||||||
|
assert.equal(calls[0].opts.method, 'DELETE')
|
||||||
|
|
||||||
|
calls = []
|
||||||
|
willReply({ body: {} })
|
||||||
|
await api.admin.hideReportedItem(41, { note: 'x' })
|
||||||
|
assert.equal(calls[0].url, '/api/v1/admin/moderation/reports/41/hide')
|
||||||
|
})
|
||||||
|
|
||||||
test('a Team slug is URL-encoded on every forum path', async () => {
|
test('a Team slug is URL-encoded on every forum path', async () => {
|
||||||
willReply({ body: { ok: true } })
|
willReply({ body: { ok: true } })
|
||||||
await api.teamForumReport('a b/c', { targetType: 'team_forum_thread', targetId: 1, reason: 'spam' })
|
await api.teamForumReport('a b/c', { targetType: 'team_forum_thread', targetId: 1, reason: 'spam' })
|
||||||
|
|||||||
71
client/test/demoNotice.test.js
Normal file
71
client/test/demoNotice.test.js
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { test, afterEach } from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { api } from '../src/api/client.js'
|
||||||
|
import { onDemoLocked, reportIfDemoLocked, formatResetTime, isDemoLocked } from '../src/lib/demoNotice.js'
|
||||||
|
|
||||||
|
// The public demo's refusal reaches the one toast from req() itself, so every
|
||||||
|
// screen and every installed module gets it without handling the code — and
|
||||||
|
// the caller still gets its ApiError, so a form's own error line is unchanged.
|
||||||
|
|
||||||
|
const realFetch = global.fetch
|
||||||
|
afterEach(() => {
|
||||||
|
global.fetch = realFetch
|
||||||
|
})
|
||||||
|
|
||||||
|
function replyOnce(status, body) {
|
||||||
|
global.fetch = async () => ({
|
||||||
|
ok: status >= 200 && status < 300,
|
||||||
|
status,
|
||||||
|
statusText: 'Forbidden',
|
||||||
|
text: async () => JSON.stringify(body),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
test('a DEMO_LOCKED answer is reported once and still thrown to the caller', async () => {
|
||||||
|
const heard = []
|
||||||
|
const off = onDemoLocked((m) => heard.push(m))
|
||||||
|
replyOnce(403, { code: 'DEMO_LOCKED', message: 'This is turned off on the demo site.' })
|
||||||
|
await assert.rejects(() => api.publicSettings(), (err) => err.status === 403 && err.message === 'This is turned off on the demo site.')
|
||||||
|
off()
|
||||||
|
assert.deepEqual(heard, ['This is turned off on the demo site.'])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('any other refusal is not a demo refusal', async () => {
|
||||||
|
const heard = []
|
||||||
|
const off = onDemoLocked((m) => heard.push(m))
|
||||||
|
replyOnce(403, { message: 'Admin role required' })
|
||||||
|
await assert.rejects(() => api.publicSettings())
|
||||||
|
off()
|
||||||
|
assert.deepEqual(heard, [])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('reportIfDemoLocked recognises the code alone and survives a broken listener', () => {
|
||||||
|
const off1 = onDemoLocked(() => {
|
||||||
|
throw new Error('boom')
|
||||||
|
})
|
||||||
|
const heard = []
|
||||||
|
const off2 = onDemoLocked((m) => heard.push(m))
|
||||||
|
assert.equal(reportIfDemoLocked({ code: 'DEMO_LOCKED' }), true)
|
||||||
|
assert.equal(reportIfDemoLocked({ code: 'OTHER' }), false)
|
||||||
|
assert.equal(reportIfDemoLocked('text'), false)
|
||||||
|
assert.equal(reportIfDemoLocked(null), false)
|
||||||
|
off1()
|
||||||
|
off2()
|
||||||
|
assert.deepEqual(heard, ['This is turned off on the demo site.'])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('isDemoLocked tells the demo refusal from a role 403', async () => {
|
||||||
|
replyOnce(403, { code: 'DEMO_LOCKED', message: 'This is turned off on the demo site.' })
|
||||||
|
const locked = await api.publicSettings().catch((e) => e)
|
||||||
|
replyOnce(403, { message: 'Admin role required' })
|
||||||
|
const role = await api.publicSettings().catch((e) => e)
|
||||||
|
assert.equal(isDemoLocked(locked), true)
|
||||||
|
assert.equal(isDemoLocked(role), false)
|
||||||
|
assert.equal(isDemoLocked(null), false)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('the reset time is said in UTC, as the wipe runs', () => {
|
||||||
|
assert.equal(formatResetTime('2026-10-24T14:00:00.000Z'), '14:00 UTC')
|
||||||
|
assert.equal(formatResetTime('2026-10-24T09:05:00+02:00'), '07:05 UTC')
|
||||||
|
assert.equal(formatResetTime('nope'), null)
|
||||||
|
})
|
||||||
@@ -19,7 +19,7 @@ test('a deployment with no provider is not stale, it is uninvolved', () => {
|
|||||||
assert.equal(freshnessNote({ configured: false }, NOW), null)
|
assert.equal(freshnessNote({ configured: false }, NOW), null)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('never synced is a warning, and never reads as a confirmed empty shard', () => {
|
test('never synced is a warning, and never reads as a confirmed empty roster', () => {
|
||||||
const note = freshnessNote({ configured: true, lastSyncAt: null }, NOW)
|
const note = freshnessNote({ configured: true, lastSyncAt: null }, NOW)
|
||||||
assert.equal(note.tone, 'warn')
|
assert.equal(note.tone, 'warn')
|
||||||
assert.match(note.text, /Not yet confirmed/)
|
assert.match(note.text, /Not yet confirmed/)
|
||||||
|
|||||||
@@ -21,13 +21,13 @@ test('no provider is idle, not a fault', () => {
|
|||||||
assert.match(f.label, /No Team provider/)
|
assert.match(f.label, /No Team provider/)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('never synced is reported as never synced, not as an empty shard', () => {
|
test('never synced is reported as never synced, not as a game server with no Teams', () => {
|
||||||
// The failure this prevents: an empty projection core has never confirmed,
|
// The failure this prevents: an empty projection core has never confirmed,
|
||||||
// rendered as though the game genuinely has no Teams.
|
// rendered as though the game genuinely has no Teams.
|
||||||
const f = freshnessOf({ configured: true, lastSyncAt: null })
|
const f = freshnessOf({ configured: true, lastSyncAt: null })
|
||||||
assert.equal(f.tone, TONE.bad)
|
assert.equal(f.tone, TONE.bad)
|
||||||
assert.equal(f.label, 'Never synced')
|
assert.equal(f.label, 'Never synced')
|
||||||
assert.match(f.detail, /not a confirmed empty shard/)
|
assert.match(f.detail, /does not confirm that the game server has no Teams/)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('stale says how old it is', () => {
|
test('stale says how old it is', () => {
|
||||||
|
|||||||
24
client/test/userSafety.test.js
Normal file
24
client/test/userSafety.test.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// Account → Blocked and the Reports queue's "Hide for everyone"
|
||||||
|
// (client/src/lib/userSafety.js; docs/website/USER_SAFETY.md §1, §4.1).
|
||||||
|
import { test } from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
|
||||||
|
import { blockSubtitle, canHideForEveryone } from '../src/lib/userSafety.js'
|
||||||
|
|
||||||
|
test('a game block says it is a Steam id with no account yet; an account block says Account', () => {
|
||||||
|
const game = blockSubtitle({
|
||||||
|
kind: 'game',
|
||||||
|
identity: { module: 'rust', kind: 'steam', label: 'Steam account', id: '76561198000000123' },
|
||||||
|
})
|
||||||
|
assert.equal(game, 'Steam account 76561198000000123, not linked to an account')
|
||||||
|
assert.equal(blockSubtitle({ kind: 'account', identity: null }), 'Account')
|
||||||
|
assert.match(blockSubtitle({ kind: 'account', createdAt: '2026-10-30T10:00:00Z' }), /^Account · blocked /)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('hide for everyone is offered on a post, a thread and a chat line, never on an upload or twice', () => {
|
||||||
|
assert.equal(canHideForEveryone({ targetType: 'team_forum_post', actionedWith: null }), true)
|
||||||
|
assert.equal(canHideForEveryone({ targetType: 'team_forum_thread', actionedWith: null }), true)
|
||||||
|
assert.equal(canHideForEveryone({ targetType: 'rust.chat', actionedWith: null }), true)
|
||||||
|
assert.equal(canHideForEveryone({ targetType: 'team_forum_upload', actionedWith: null }), false)
|
||||||
|
assert.equal(canHideForEveryone({ targetType: 'rust.chat', actionedWith: 'hide' }), false)
|
||||||
|
})
|
||||||
61
deploy/demo/.env.example
Normal file
61
deploy/demo/.env.example
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
# ─── The demo site's environment (docs/website/DEMO_MODE.md) ───
|
||||||
|
# Copy to /opt/demo.runicgateway.com/.env on the `demo-site` host and fill in.
|
||||||
|
# NEVER commit the real file. The wipe workflow never writes it; it only reads it.
|
||||||
|
|
||||||
|
IMAGE_TAG=latest
|
||||||
|
NODE_ENV=production
|
||||||
|
PORT=3000
|
||||||
|
# The host port the external reverse proxy forwards demo.runicgateway.com to.
|
||||||
|
DEMO_HOST_PORT=3000
|
||||||
|
# How often the wipe runs, for the banner's "wiped at" time. Must match the cron
|
||||||
|
# in .gitea/workflows/demo-wipe.yml (every 2 hours on the hour, UTC, DM7).
|
||||||
|
DEMO_RESET_EVERY_HOURS=2
|
||||||
|
|
||||||
|
# Branding
|
||||||
|
BRAND_NAME=Runic Gateway Demo
|
||||||
|
BRAND_SHORT_NAME=RG Demo
|
||||||
|
BRAND_URL=https://demo.runicgateway.com
|
||||||
|
CLIENT_ORIGIN=https://demo.runicgateway.com
|
||||||
|
|
||||||
|
# Database. Recreated empty at every wipe; the passwords only need to be stable.
|
||||||
|
DB_HOST=db
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_NAME=runic_gateway
|
||||||
|
DB_USER=runic
|
||||||
|
DB_PASSWORD=
|
||||||
|
DB_ROOT_PASSWORD=
|
||||||
|
|
||||||
|
# Long random strings, e.g. `openssl rand -hex 32`. SECRET_ENC_KEY is required in
|
||||||
|
# production. Every stored secret is re-seeded at each wipe, so rotating either
|
||||||
|
# one only signs people out.
|
||||||
|
JWT_SECRET=
|
||||||
|
SECRET_ENC_KEY=
|
||||||
|
COOKIE_SECURE=auto
|
||||||
|
# The guard on the app's unpublished internal port. The demo runs no bot, but the
|
||||||
|
# app refuses to start in production without it. Another long random string.
|
||||||
|
BOT_INTERNAL_KEY=
|
||||||
|
# One proxy hop: the external reverse proxy.
|
||||||
|
TRUST_PROXY=1
|
||||||
|
|
||||||
|
# Leave ADMIN_USERNAME unset: the boot seed must not create a fifth admin. The four
|
||||||
|
# demo accounts come from seed.json (§4).
|
||||||
|
ADMIN_USERNAME=
|
||||||
|
|
||||||
|
# Where modules may be installed from. A fresh database seeds the allowlist from
|
||||||
|
# this, and the declared module (state/modules.env) installs under it.
|
||||||
|
MODULE_SOURCE_HOSTS=gitea.whitlocktech.com
|
||||||
|
|
||||||
|
# ── seed.json reads these through "$env:NAME" ──
|
||||||
|
# The published logins (§4) are not secrets, but they live here so the repo does
|
||||||
|
# not pin them. play-review's is NOT published; it goes in the Play Console only.
|
||||||
|
DEMO_ADMIN_PASSWORD=
|
||||||
|
DEMO_MODERATOR_PASSWORD=
|
||||||
|
DEMO_PLAYER_PASSWORD=
|
||||||
|
PLAY_REVIEW_PASSWORD=
|
||||||
|
# A stand-in Steam id that has played on the rig, so demo-player's Rust screens
|
||||||
|
# have data (DM6).
|
||||||
|
DEMO_PLAYER_STEAM_ID=
|
||||||
|
# The rig's sidecar web API (rust-oxide's last allocation) and its web token: the
|
||||||
|
# RUSTLINK_WEB_TOKEN in the rig's startup command, or rust-link/sidecar.toml.
|
||||||
|
DEMO_RIG_SIDECAR_URL=http://192.168.0.12:21004
|
||||||
|
DEMO_RIG_SIDECAR_TOKEN=
|
||||||
53
deploy/demo/README.md
Normal file
53
deploy/demo/README.md
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# deploy/demo — demo.runicgateway.com
|
||||||
|
|
||||||
|
The public demo site: the normal image with `DEMO_MODE=true`, wiped every two hours together
|
||||||
|
with its Rust server. Design of record: `docs/website/DEMO_MODE.md`.
|
||||||
|
|
||||||
|
| File | What it is |
|
||||||
|
| --- | --- |
|
||||||
|
| `docker-compose.yml` | The app and its database. No bot and no ntfy: the demo sends nothing outward (§5) |
|
||||||
|
| `.env.example` | Every variable the host's `.env` needs, with what each one is for |
|
||||||
|
| `seed.json` | The fixture `seed:demo` writes after every wipe: the four logins, settings, content, and the Rust module's server link and Steam link (§7.3). Passwords and credentials are `"$env:NAME"` references to `.env` |
|
||||||
|
| `rig.mjs` | Versions (`plan`), the rig restore (`restore`), the baseline capture (`baseline`) and the smoke check (`smoke`), against the Pterodactyl client API (§7.2, §7.5) |
|
||||||
|
|
||||||
|
Two workflows drive it, both on the `demo-site` runner:
|
||||||
|
|
||||||
|
- **`demo-wipe.yml`**: every 2 hours on the hour (UTC), on a push to `main` that changes this
|
||||||
|
directory, and by hand. Versions, then the rig, then the site, then a smoke check.
|
||||||
|
- **`demo-baseline.yml`**: by hand only. It captures the rig's current state as
|
||||||
|
`demo-baseline.tar.gz`, which every wipe restores.
|
||||||
|
|
||||||
|
## One-time host setup
|
||||||
|
|
||||||
|
1. The `demo-site` runner in **host mode** on the demo host, with Docker and Compose, and `node`
|
||||||
|
on the `PATH` (for `actions/checkout`). The host must reach `gitea.whitlocktech.com`, the
|
||||||
|
Pterodactyl panel and the rig's sidecar port.
|
||||||
|
2. `sudo mkdir -p /opt/demo.runicgateway.com`, owned by the runner's user (or the runner runs as
|
||||||
|
root). To use another path, set the `DEMO_DIR` Actions variable.
|
||||||
|
3. Copy `.env.example` to `/opt/demo.runicgateway.com/.env` and fill every blank. Generate
|
||||||
|
secrets on the host, e.g. `openssl rand -hex 32`. The file never leaves the host.
|
||||||
|
4. Log the host in to the registry if the images are not public: `docker login gitea.whitlocktech.com`.
|
||||||
|
5. Point the external reverse proxy at `<host>:DEMO_HOST_PORT` (default 3000).
|
||||||
|
6. Run **Demo wipe** by hand. The first run finds no baseline, so it leaves the rig as it is and
|
||||||
|
starts it.
|
||||||
|
|
||||||
|
Then set the demo default set up through the site: the permission groups, a few NPCs, a clan. Run
|
||||||
|
**Demo baseline** while nobody else is changing anything. Every later wipe returns the rig to that.
|
||||||
|
|
||||||
|
The panel URL and the rig's server identifier default to `http://192.168.0.12` and `6eb9d621`
|
||||||
|
(`rust-oxide`). Override them with the `PTERODACTYL_URL` and `PTERODACTYL_SERVER` Actions
|
||||||
|
variables. `PTERODACTYL_CLIENT_KEY` is the demo subuser's key, an Actions secret.
|
||||||
|
|
||||||
|
## What the wipe keeps on the host
|
||||||
|
|
||||||
|
`state/` in the deploy directory:
|
||||||
|
|
||||||
|
- `bundle.json`: the Rust bundle last written onto the rig. A new bundle is written only when
|
||||||
|
this differs.
|
||||||
|
- `modules.env`: `MODULES=rust@<version>=<manifest>`, the newest Module-Rust release on the bundle's
|
||||||
|
protocol. When no release matches a new bundle yet, the wipe keeps this file and the rig's
|
||||||
|
bundle as they were and warns (§7.5).
|
||||||
|
- `plan.json`: this cycle's decision, from `plan` to `restore`.
|
||||||
|
|
||||||
|
`modules/` keeps the unpacked module between wipes. `down -v` drops the database and the uploads,
|
||||||
|
never this directory.
|
||||||
70
deploy/demo/docker-compose.yml
Normal file
70
deploy/demo/docker-compose.yml
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
# The public demo, demo.runicgateway.com (docs/website/DEMO_MODE.md).
|
||||||
|
#
|
||||||
|
# The same image as every other deployment, switched by DEMO_MODE=true (§2). Only
|
||||||
|
# the app and its database: no bot and no ntfy, because the demo sends nothing
|
||||||
|
# outward (§5). The wipe workflow (.gitea/workflows/demo-wipe.yml) copies this
|
||||||
|
# file into the deploy directory on the `demo-site` host and runs it from there;
|
||||||
|
# the host's own `.env` beside it holds every secret.
|
||||||
|
#
|
||||||
|
# The project name is fixed so the network is `rg-demo_default` whatever the
|
||||||
|
# directory is called: the workflow's smoke check joins it to reach the app.
|
||||||
|
name: rg-demo
|
||||||
|
|
||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: mariadb:11
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
MARIADB_DATABASE: ${DB_NAME}
|
||||||
|
MARIADB_USER: ${DB_USER}
|
||||||
|
MARIADB_PASSWORD: ${DB_PASSWORD}
|
||||||
|
MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
|
||||||
|
volumes:
|
||||||
|
# Dropped at every wipe (`down -v`) with the uploads volume: that is the wipe.
|
||||||
|
- dbdata:/var/lib/mysql
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
app:
|
||||||
|
image: gitea.whitlocktech.com/runicgateway/website-app:${IMAGE_TAG:-latest}
|
||||||
|
restart: unless-stopped
|
||||||
|
# modules.env is written by the wipe (rig.mjs plan): MODULES=rust@<version>=…,
|
||||||
|
# the newest Module-Rust release on the bundle's protocol (§7.5). Kept out of
|
||||||
|
# .env so the workflow never edits the file holding the secrets.
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
- state/modules.env
|
||||||
|
environment:
|
||||||
|
DEMO_MODE: "true"
|
||||||
|
DB_HOST: db
|
||||||
|
UPLOAD_DIR: /app/uploads
|
||||||
|
LOG_DIR: /app/logs
|
||||||
|
MODULES_DIR: /app/modules
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
volumes:
|
||||||
|
- uploads:/app/uploads
|
||||||
|
- ./logs:/app/logs
|
||||||
|
# A bind mount, not a volume, so `down -v` keeps the unpacked module and a
|
||||||
|
# wipe does not download it again. Must be writable by uid 1000.
|
||||||
|
- ./modules:/app/modules
|
||||||
|
# The seed fixture (§7.3), read by `seed:demo` after every wipe.
|
||||||
|
- ./seed.json:/app/deploy/demo/seed.json:ro
|
||||||
|
# Busybox wget is in the Alpine image; `/status` answers once the server listens.
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:3000/api/v1/public/status"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
start_period: 30s
|
||||||
|
retries: 30
|
||||||
|
# The external reverse proxy (DNS + HTTPS) forwards here.
|
||||||
|
ports:
|
||||||
|
- "${DEMO_HOST_PORT:-3000}:3000"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
dbdata:
|
||||||
|
uploads:
|
||||||
372
deploy/demo/rig.mjs
Normal file
372
deploy/demo/rig.mjs
Normal file
@@ -0,0 +1,372 @@
|
|||||||
|
// ── The demo's rig and versions (docs/website/DEMO_MODE.md §7.2, §7.5) ──────
|
||||||
|
//
|
||||||
|
// One script, four commands, run by the demo workflows on the `demo-site` host
|
||||||
|
// inside a stock Node container (so the host needs Docker and nothing else):
|
||||||
|
//
|
||||||
|
// node rig.mjs plan decide the versions for this cycle (§7.5)
|
||||||
|
// node rig.mjs restore put the rig back to the baseline, updating its plugins
|
||||||
|
// and sidecar first when the bundle changed (§7.2)
|
||||||
|
// node rig.mjs baseline capture the rig's current state as the baseline (§7.2)
|
||||||
|
// node rig.mjs smoke wait for the site, then for the rig to report in (§7.3.6)
|
||||||
|
//
|
||||||
|
// State lives in $STATE_DIR (the deploy directory's `state/`):
|
||||||
|
// bundle.json the bundle last written onto the rig
|
||||||
|
// modules.env MODULES=rust@<version>=<manifest>, read by docker-compose.yml
|
||||||
|
// plan.json this cycle's decision, written by `plan`, read by `restore`
|
||||||
|
//
|
||||||
|
// Environment:
|
||||||
|
// PTERODACTYL_URL the panel, e.g. http://192.168.0.12
|
||||||
|
// PTERODACTYL_SERVER the rig's short identifier, e.g. e6758c06
|
||||||
|
// PTERODACTYL_CLIENT_KEY the demo subuser's client key (file + power only)
|
||||||
|
// PTERODACTYL_IDENTITY optional: the folder under /server holding the save;
|
||||||
|
// found by listing /server when unset
|
||||||
|
// GITEA_URL default https://gitea.whitlocktech.com
|
||||||
|
// SITE_URL for `smoke`, e.g. http://app:3000
|
||||||
|
// SMOKE_TIMEOUT_SECONDS for `smoke`, default 900 (a Rust boot is ~9 minutes)
|
||||||
|
//
|
||||||
|
// Dependency-free on purpose: Node's own fetch and crypto, and the image's tar.
|
||||||
|
|
||||||
|
import { createHash } from 'node:crypto'
|
||||||
|
import { execFileSync } from 'node:child_process'
|
||||||
|
import fs from 'node:fs'
|
||||||
|
import os from 'node:os'
|
||||||
|
import path from 'node:path'
|
||||||
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||||
|
|
||||||
|
const GITEA = (process.env.GITEA_URL || 'https://gitea.whitlocktech.com').replace(/\/+$/, '')
|
||||||
|
const STATE_DIR = process.env.STATE_DIR || path.join(path.dirname(fileURLToPath(import.meta.url)), 'state')
|
||||||
|
const BASELINE = 'demo-baseline.tar.gz'
|
||||||
|
const MODULE_REPO = 'RunicGateway/Module-Rust'
|
||||||
|
const BUNDLE_PATH = 'RunicGateway/installer/contents/v2/rust/current.json?ref=bundles'
|
||||||
|
|
||||||
|
const log = (...a) => console.log(...a)
|
||||||
|
const warn = (msg) => console.log(`::warning::${msg}`)
|
||||||
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
|
||||||
|
|
||||||
|
function need(name) {
|
||||||
|
const v = process.env[name]
|
||||||
|
if (!v) throw new Error(`${name} is not set`)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
const statePath = (f) => path.join(STATE_DIR, f)
|
||||||
|
function readJson(file, fallback = null) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(fs.readFileSync(file, 'utf8'))
|
||||||
|
} catch {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function writeFile(file, text) {
|
||||||
|
fs.mkdirSync(path.dirname(file), { recursive: true })
|
||||||
|
fs.writeFileSync(file, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Gitea ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
// The JSON API, never /raw/: /raw/ is CDN-cached for hours on this instance, and
|
||||||
|
// a stale current.json would pin the demo to an old bundle without a word.
|
||||||
|
async function gitea(apiPath) {
|
||||||
|
const res = await fetch(`${GITEA}/api/v1/repos/${apiPath}`, { headers: { Accept: 'application/json' } })
|
||||||
|
if (!res.ok) throw new Error(`GET ${apiPath}: HTTP ${res.status}`)
|
||||||
|
return res.json()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function currentBundle() {
|
||||||
|
const file = await gitea(BUNDLE_PATH)
|
||||||
|
return JSON.parse(Buffer.from(file.content, 'base64').toString('utf8'))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function download(url, sha256) {
|
||||||
|
const res = await fetch(url)
|
||||||
|
if (!res.ok) throw new Error(`GET ${url}: HTTP ${res.status}`)
|
||||||
|
const buf = Buffer.from(await res.arrayBuffer())
|
||||||
|
if (sha256) {
|
||||||
|
const got = createHash('sha256').update(buf).digest('hex')
|
||||||
|
if (got !== sha256) throw new Error(`${url}: sha256 ${got} does not match the bundle's ${sha256}`)
|
||||||
|
}
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
|
const semver = (v) => String(v).replace(/^v/, '').split('.').map((n) => Number.parseInt(n, 10) || 0)
|
||||||
|
function newerFirst(a, b) {
|
||||||
|
const x = semver(a)
|
||||||
|
const y = semver(b)
|
||||||
|
for (let i = 0; i < 3; i += 1) if (x[i] !== y[i]) return y[i] - x[i]
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The newest Module-Rust release whose install manifest says `protocol` (DM12). */
|
||||||
|
async function moduleFor(protocol) {
|
||||||
|
const releases = (await gitea(`${MODULE_REPO}/releases?limit=50`))
|
||||||
|
.filter((r) => !r.draft && !r.prerelease)
|
||||||
|
.sort((a, b) => newerFirst(a.tag_name, b.tag_name))
|
||||||
|
for (const r of releases) {
|
||||||
|
const asset = (r.assets || []).find((a) => /^module-rust-.+\.json$/.test(a.name))
|
||||||
|
if (!asset) continue
|
||||||
|
const res = await fetch(asset.browser_download_url)
|
||||||
|
if (!res.ok) continue
|
||||||
|
const manifest = await res.json()
|
||||||
|
// Releases from before §7.5 carry no `protocol`; they never match.
|
||||||
|
if (manifest.protocol === protocol) {
|
||||||
|
return { version: manifest.version, manifestUrl: asset.browser_download_url }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Pterodactyl (client API: files + power only) ─────────────────────────
|
||||||
|
|
||||||
|
function ptero() {
|
||||||
|
const base = `${need('PTERODACTYL_URL').replace(/\/+$/, '')}/api/client/servers/${need('PTERODACTYL_SERVER')}`
|
||||||
|
const key = need('PTERODACTYL_CLIENT_KEY')
|
||||||
|
|
||||||
|
async function call(method, sub, { json, body, type, raw = false } = {}) {
|
||||||
|
const headers = { Authorization: `Bearer ${key}`, Accept: 'application/json' }
|
||||||
|
let payload
|
||||||
|
if (json !== undefined) {
|
||||||
|
headers['Content-Type'] = 'application/json'
|
||||||
|
payload = JSON.stringify(json)
|
||||||
|
} else if (body !== undefined) {
|
||||||
|
headers['Content-Type'] = type || 'application/octet-stream'
|
||||||
|
payload = body
|
||||||
|
}
|
||||||
|
const res = await fetch(`${base}${sub}`, { method, headers, body: payload })
|
||||||
|
const text = await res.text()
|
||||||
|
if (!res.ok) throw new Error(`${method} ${sub}: HTTP ${res.status} ${text.slice(0, 300)}`)
|
||||||
|
if (raw) return text
|
||||||
|
return text ? JSON.parse(text) : null
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
state: async () => (await call('GET', '/resources')).attributes.current_state,
|
||||||
|
power: (signal) => call('POST', '/power', { json: { signal } }),
|
||||||
|
list: async (dir) =>
|
||||||
|
(await call('GET', `/files/list?directory=${encodeURIComponent(dir)}`)).data.map((f) => f.attributes),
|
||||||
|
remove: (files) => call('POST', '/files/delete', { json: { root: '/', files } }),
|
||||||
|
decompress: (file) => call('POST', '/files/decompress', { json: { root: '/', file } }),
|
||||||
|
compress: async (files) => (await call('POST', '/files/compress', { json: { root: '/', files } })).attributes,
|
||||||
|
rename: (from, to) => call('PUT', '/files/rename', { json: { root: '/', files: [{ from, to }] } }),
|
||||||
|
read: (file) => call('GET', `/files/contents?file=${encodeURIComponent(file)}`, { raw: true }),
|
||||||
|
write: (file, body, type) => call('POST', `/files/write?file=${encodeURIComponent(file)}`, { body, type }),
|
||||||
|
// One file per call: a chmod naming two applies only the first, silently.
|
||||||
|
chmod: (dir, file, mode) => call('POST', '/files/chmod', { json: { root: dir, files: [{ file, mode }] } }),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function waitFor(p, wanted, seconds) {
|
||||||
|
const until = Date.now() + seconds * 1000
|
||||||
|
for (;;) {
|
||||||
|
const s = await p.state()
|
||||||
|
if (s === wanted) return
|
||||||
|
if (Date.now() > until) throw new Error(`the rig is "${s}" after ${seconds}s, expected "${wanted}"`)
|
||||||
|
await sleep(5000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The folder under /server holding the world save and cfg/. */
|
||||||
|
async function identity(p) {
|
||||||
|
if (process.env.PTERODACTYL_IDENTITY) return process.env.PTERODACTYL_IDENTITY
|
||||||
|
const dirs = (await p.list('/server')).filter((f) => !f.is_file).map((f) => f.name)
|
||||||
|
if (dirs.length !== 1) {
|
||||||
|
throw new Error(`cannot tell the server identity: /server holds ${JSON.stringify(dirs)}; set PTERODACTYL_IDENTITY`)
|
||||||
|
}
|
||||||
|
return dirs[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
const baselineDirs = (id) => ['oxide/data', 'oxide/config', `server/${id}`]
|
||||||
|
|
||||||
|
// ── plan ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
async function plan() {
|
||||||
|
const bundle = await currentBundle()
|
||||||
|
const applied = readJson(statePath('bundle.json'))
|
||||||
|
const previousModules = fs.existsSync(statePath('modules.env'))
|
||||||
|
log(`bundle ${bundle.bundle} (protocol ${bundle.protocol}); on the rig: ${applied ? applied.bundle : 'none recorded'}`)
|
||||||
|
|
||||||
|
const module = await moduleFor(bundle.protocol)
|
||||||
|
if (!module) {
|
||||||
|
// §7.5: a half-released protocol bump never takes the demo down.
|
||||||
|
if (!previousModules) {
|
||||||
|
throw new Error(`no Module-Rust release speaks protocol ${bundle.protocol}, and there is no previous set to keep`)
|
||||||
|
}
|
||||||
|
warn(`no Module-Rust release speaks protocol ${bundle.protocol} yet; keeping the previous bundle and module`)
|
||||||
|
writeFile(statePath('plan.json'), JSON.stringify({ bundle: null }, null, 2))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log(`module rust ${module.version} (protocol ${bundle.protocol})`)
|
||||||
|
writeFile(statePath('modules.env'), `MODULES=rust@${module.version}=${module.manifestUrl}\n`)
|
||||||
|
const changed = !applied || applied.bundle !== bundle.bundle
|
||||||
|
writeFile(statePath('plan.json'), JSON.stringify({ bundle: changed ? bundle : null }, null, 2))
|
||||||
|
log(changed ? 'the rig gets the new bundle at this wipe' : 'the rig is already on this bundle')
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── restore ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
async function writeBundle(p, bundle) {
|
||||||
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bundle-'))
|
||||||
|
try {
|
||||||
|
const plugins = []
|
||||||
|
for (const part of [bundle.payload, bundle.npc].filter(Boolean)) {
|
||||||
|
const tarball = path.join(tmp, part.asset.name)
|
||||||
|
fs.writeFileSync(tarball, await download(part.asset.url, part.asset.sha256))
|
||||||
|
const out = path.join(tmp, `${part.asset.name}.d`)
|
||||||
|
fs.mkdirSync(out)
|
||||||
|
execFileSync('tar', ['-xzf', tarball, '-C', out])
|
||||||
|
for (const dir of fs.readdirSync(out)) {
|
||||||
|
for (const f of fs.readdirSync(path.join(out, dir))) {
|
||||||
|
if (f.endsWith('.cs')) plugins.push({ name: f, text: fs.readFileSync(path.join(out, dir, f)) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!plugins.length) throw new Error(`bundle ${bundle.bundle} carries no plugin files`)
|
||||||
|
|
||||||
|
const sidecar = bundle.sidecar.assets['linux-x86_64']
|
||||||
|
const binary = await download(sidecar.url, sidecar.sha256)
|
||||||
|
const launcher = await download(bundle.sidecar.launcher.url, bundle.sidecar.launcher.sha256)
|
||||||
|
|
||||||
|
for (const f of plugins) {
|
||||||
|
await p.write(`/oxide/plugins/${f.name}`, f.text, 'text/plain')
|
||||||
|
log(` wrote oxide/plugins/${f.name}`)
|
||||||
|
}
|
||||||
|
await p.write('/rust-link/rust-link-sidecar', binary)
|
||||||
|
await p.write('/rust-link/with-sidecar.sh', launcher, 'text/plain')
|
||||||
|
await p.chmod('/rust-link', 'rust-link-sidecar', '755')
|
||||||
|
await p.chmod('/rust-link', 'with-sidecar.sh', '755')
|
||||||
|
log(` wrote the sidecar ${bundle.sidecar.version} and its launcher`)
|
||||||
|
|
||||||
|
// The rig's own record of what it runs, in the shape the rig push writes, so
|
||||||
|
// anyone reading the rig sees the bundle the wipe put there.
|
||||||
|
const prior = JSON.parse((await p.read('/rust-link/bundle.json').catch(() => null)) || '{}')
|
||||||
|
const record = {
|
||||||
|
bundle: bundle.bundle,
|
||||||
|
protocol: bundle.protocol,
|
||||||
|
framework: prior.framework || 'oxide',
|
||||||
|
installed: new Date().toISOString().replace(/\.\d+Z$/, 'Z'),
|
||||||
|
sidecar: { tag: bundle.sidecar.tag },
|
||||||
|
plugin: { tag: bundle.payload.tag, commit: bundle.payload.commit },
|
||||||
|
...(bundle.npc ? { runicnpc: { tag: bundle.npc.tag, api: bundle.npc.api } } : {}),
|
||||||
|
}
|
||||||
|
await p.write('/rust-link/bundle.json', `${JSON.stringify(record, null, 2)}\n`, 'text/plain')
|
||||||
|
} finally {
|
||||||
|
fs.rmSync(tmp, { recursive: true, force: true })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function restore() {
|
||||||
|
const p = ptero()
|
||||||
|
const decided = readJson(statePath('plan.json'))
|
||||||
|
if (!decided) throw new Error('no plan.json; run `plan` first')
|
||||||
|
|
||||||
|
// 1. Kill: no save, the world is about to be replaced.
|
||||||
|
if ((await p.state()) !== 'offline') {
|
||||||
|
await p.power('kill')
|
||||||
|
await waitFor(p, 'offline', 120)
|
||||||
|
}
|
||||||
|
log('the rig is stopped')
|
||||||
|
|
||||||
|
// §7.5: the bundle goes on while the server is stopped.
|
||||||
|
if (decided.bundle) {
|
||||||
|
log(`writing bundle ${decided.bundle.bundle} onto the rig`)
|
||||||
|
await writeBundle(p, decided.bundle)
|
||||||
|
writeFile(
|
||||||
|
statePath('bundle.json'),
|
||||||
|
JSON.stringify({ bundle: decided.bundle.bundle, protocol: decided.bundle.protocol, applied: new Date().toISOString() }, null, 2),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2-3. Delete the three directories and unpack the baseline over them.
|
||||||
|
const root = (await p.list('/')).map((f) => f.name)
|
||||||
|
if (root.includes(BASELINE)) {
|
||||||
|
const id = await identity(p)
|
||||||
|
// Only what exists: a visitor cannot delete these, but a half-finished
|
||||||
|
// earlier run can have.
|
||||||
|
const oxide = new Set((await p.list('/oxide')).map((f) => `oxide/${f.name}`))
|
||||||
|
const dirs = baselineDirs(id).filter((d) => oxide.has(d) || d === `server/${id}`)
|
||||||
|
await p.remove(dirs)
|
||||||
|
log(` deleted ${dirs.join(', ')}`)
|
||||||
|
await p.decompress(BASELINE)
|
||||||
|
log(` unpacked ${BASELINE}`)
|
||||||
|
} else {
|
||||||
|
warn(`there is no ${BASELINE} on the rig yet; it starts as it is. Capture one with the "Demo baseline" workflow.`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Start. Rust takes minutes to boot; the site does not wait for it.
|
||||||
|
await p.power('start')
|
||||||
|
log('the rig is starting')
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── baseline ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
async function baseline() {
|
||||||
|
const p = ptero()
|
||||||
|
// A power stop runs the egg's stop command, `quit`, which writes the save, so
|
||||||
|
// the subuser needs no console permission (DM22).
|
||||||
|
if ((await p.state()) !== 'offline') {
|
||||||
|
await p.power('stop')
|
||||||
|
await waitFor(p, 'offline', 300)
|
||||||
|
}
|
||||||
|
log('the rig is stopped and saved')
|
||||||
|
|
||||||
|
const id = await identity(p)
|
||||||
|
const made = await p.compress(baselineDirs(id))
|
||||||
|
log(` compressed ${baselineDirs(id).join(', ')} into ${made.name}`)
|
||||||
|
if ((await p.list('/')).some((f) => f.name === BASELINE)) await p.remove([BASELINE])
|
||||||
|
await p.rename(made.name, BASELINE)
|
||||||
|
log(` saved as ${BASELINE} (${made.size} bytes)`)
|
||||||
|
|
||||||
|
await p.power('start')
|
||||||
|
log('the rig is starting')
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── smoke ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
async function smoke() {
|
||||||
|
const site = need('SITE_URL').replace(/\/+$/, '')
|
||||||
|
const until = Date.now() + (Number(process.env.SMOKE_TIMEOUT_SECONDS) || 900) * 1000
|
||||||
|
const get = async (p) => {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${site}${p}`)
|
||||||
|
return res.ok ? await res.json() : null
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!(await get('/api/v1/public/status'))) {
|
||||||
|
if (Date.now() > until) throw new Error('the site never answered /api/v1/public/status')
|
||||||
|
await sleep(5000)
|
||||||
|
}
|
||||||
|
log('the site answers')
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
const list = (await get('/api/v1/public/rust/servers'))?.servers || []
|
||||||
|
if (list.length && list.every((s) => s.online)) {
|
||||||
|
log(`the rig reports in: ${list.map((s) => s.name || s.id).join(', ')}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (Date.now() > until) {
|
||||||
|
throw new Error(`the rig has not reported in (${JSON.stringify(list.map((s) => ({ id: s.id, online: s.online })))}); the site serves with it shown offline`)
|
||||||
|
}
|
||||||
|
await sleep(15000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── main ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export { ptero, identity, baselineDirs, writeBundle, moduleFor, newerFirst, currentBundle, BASELINE }
|
||||||
|
|
||||||
|
// Run only when invoked, so a test can import the pieces without running one.
|
||||||
|
if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {
|
||||||
|
const commands = { plan, restore, baseline, smoke }
|
||||||
|
const command = commands[process.argv[2]]
|
||||||
|
if (!command) {
|
||||||
|
console.error(`usage: node rig.mjs ${Object.keys(commands).join('|')}`)
|
||||||
|
process.exit(2)
|
||||||
|
}
|
||||||
|
command().catch((err) => {
|
||||||
|
console.log(`::error::${err.message}`)
|
||||||
|
process.exit(1)
|
||||||
|
})
|
||||||
|
}
|
||||||
158
deploy/demo/seed.json
Normal file
158
deploy/demo/seed.json
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
{
|
||||||
|
"accounts": {
|
||||||
|
"demo-admin": { "role": "admin", "password": "$env:DEMO_ADMIN_PASSWORD" },
|
||||||
|
"demo-moderator": { "role": "moderator", "password": "$env:DEMO_MODERATOR_PASSWORD" },
|
||||||
|
"demo-player": { "role": "player", "password": "$env:DEMO_PLAYER_PASSWORD" },
|
||||||
|
"play-review": { "role": "admin", "password": "$env:PLAY_REVIEW_PASSWORD", "published": false }
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"site_title": "Runic Gateway Demo",
|
||||||
|
"status_message": "A public demo. Look around, change things — every change is wiped every two hours."
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"posts": [
|
||||||
|
{
|
||||||
|
"category": "news",
|
||||||
|
"title": "Welcome to the Runic Gateway demo",
|
||||||
|
"slug": "welcome-to-the-demo",
|
||||||
|
"body": "<p>This is a live Runic Gateway site, linked to a real Rust server. Sign in with one of the logins on the sign-in page and look around: the admin panel, the moderation queue, a player's own pages.</p><p>You can change most things. A few would break the demo for the next visitor — uploads, the server link, deleting accounts — and those answer <em>This is turned off on the demo site</em>. Everything is put back every two hours.</p>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"category": "news",
|
||||||
|
"title": "What the Rust module adds",
|
||||||
|
"slug": "what-the-rust-module-adds",
|
||||||
|
"body": "<p>The server list, the kill feed and the leaderboard come from the game as it happens. Signed in as an admin you can manage permission groups, place NPCs, edit plugin configs and build events that run on the server.</p>"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"wiki": [
|
||||||
|
{
|
||||||
|
"slug": "about-this-demo",
|
||||||
|
"title": "About this demo",
|
||||||
|
"category": "guides",
|
||||||
|
"published": true,
|
||||||
|
"body": "<h2>The logins</h2><p>The sign-in page lists them, with a button that fills the form: an admin, a moderator and a player.</p><h2>The wipe</h2><p>The site and its Rust server go back to this starting point every two hours, on the hour, UTC. The banner says when the next one is. Anyone signed in is signed out by it.</p><h2>What is turned off</h2><p>Anything that would break the demo for the next visitor: uploads, the contact form, changing the shared logins, the site mode, the server link, and console commands that would stop the server.</p>"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"events": [
|
||||||
|
{
|
||||||
|
"title": "Server greeting",
|
||||||
|
"summary": "Says hello in the game chat. Run it from Admin → Events.",
|
||||||
|
"timezone": "UTC",
|
||||||
|
"spec": {
|
||||||
|
"schedule": { "kind": "manual" },
|
||||||
|
"phases": [
|
||||||
|
{
|
||||||
|
"key": "main",
|
||||||
|
"label": "Greet",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"actionId": "rust.command.run",
|
||||||
|
"params": {
|
||||||
|
"server": "demo",
|
||||||
|
"commands": ["say Hello from the Runic Gateway demo site!"],
|
||||||
|
"confirm": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"publish": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Treasure drop",
|
||||||
|
"summary": "Starts a Dangerous Treasures event: a guarded, burning chest somewhere on the map. Run it from Admin → Events.",
|
||||||
|
"timezone": "UTC",
|
||||||
|
"spec": {
|
||||||
|
"schedule": { "kind": "manual" },
|
||||||
|
"phases": [
|
||||||
|
{
|
||||||
|
"key": "main",
|
||||||
|
"label": "Drop the treasure",
|
||||||
|
"steps": [
|
||||||
|
{ "actionId": "rust.dt.start", "params": { "server": "demo", "level": 0 } }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"publish": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Payday",
|
||||||
|
"summary": "Pays every linked player 500 coins through Economics. Run it from Admin → Events.",
|
||||||
|
"timezone": "UTC",
|
||||||
|
"spec": {
|
||||||
|
"schedule": { "kind": "manual" },
|
||||||
|
"phases": [
|
||||||
|
{
|
||||||
|
"key": "main",
|
||||||
|
"label": "Pay",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"actionId": "rust.coins.pay",
|
||||||
|
"params": {
|
||||||
|
"server": "demo",
|
||||||
|
"amount": 500,
|
||||||
|
"recipients": "linked",
|
||||||
|
"message": "Payday! You received {amount} coins.",
|
||||||
|
"delivery": "chat"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"publish": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"modules": {
|
||||||
|
"rust": {
|
||||||
|
"servers": [
|
||||||
|
{
|
||||||
|
"id": "demo",
|
||||||
|
"name": "Demo server",
|
||||||
|
"sidecarBaseUrl": "$env:DEMO_RIG_SIDECAR_URL",
|
||||||
|
"sidecarToken": "$env:DEMO_RIG_SIDECAR_TOKEN"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"links": [
|
||||||
|
{ "username": "demo-player", "steamId": "$env:DEMO_PLAYER_STEAM_ID", "serverId": "demo" }
|
||||||
|
],
|
||||||
|
"npcs": {
|
||||||
|
"factions": [{ "a": "bandits", "b": "guards", "relation": "allied" }],
|
||||||
|
"profiles": [
|
||||||
|
{
|
||||||
|
"name": "bandit",
|
||||||
|
"servers": ["demo"],
|
||||||
|
"body": {
|
||||||
|
"kits": ["rnpc_raider"],
|
||||||
|
"names": ["Bandit", "Bandit Scout"],
|
||||||
|
"role": "roamer",
|
||||||
|
"movement": { "mode": "wander", "radius": 20 },
|
||||||
|
"health": 150,
|
||||||
|
"faction": "bandits"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "guard",
|
||||||
|
"servers": ["demo"],
|
||||||
|
"body": {
|
||||||
|
"kits": ["rnpc_campguard"],
|
||||||
|
"names": ["Camp Guard"],
|
||||||
|
"prefab": "scientistnpc_heavy",
|
||||||
|
"role": "sentry",
|
||||||
|
"health": 300,
|
||||||
|
"faction": "guards",
|
||||||
|
"kitUse": { "heal": true, "grenades": false, "melee": false, "rockets": false, "flamethrower": false }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"chat": [
|
||||||
|
{ "serverId": "demo", "group": "vip", "style": { "Title": "[VIP]", "TitleColor": "#ffaa00", "UsernameColor": "#ffaa00", "Priority": "10" } },
|
||||||
|
{ "serverId": "demo", "group": "moderator", "style": { "Title": "[MOD]", "TitleColor": "#55ff55", "UsernameColor": "#55ff55", "Priority": "50" } }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,6 +65,22 @@ CREATE TABLE IF NOT EXISTS users (
|
|||||||
UNIQUE KEY uq_users_email_norm (email_norm)
|
UNIQUE KEY uq_users_email_norm (email_norm)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
-- Usernames that can never be taken again (ACCOUNT_DELETION.md AD9). A deleted
|
||||||
|
-- STAFF account's name lands here in the same transaction that deletes the row,
|
||||||
|
-- so nobody can register "Ravenna" the day after the moderator Ravenna left and
|
||||||
|
-- speak with her name. A player's name is never added and is free at once.
|
||||||
|
--
|
||||||
|
-- There is no release path, by decision ("completely unavailable"). The column
|
||||||
|
-- carries the users.username collation so "reserved" means exactly what "taken"
|
||||||
|
-- means: the same case folding the UNIQUE index above applies. Registration, an
|
||||||
|
-- invite's acceptance, an admin creating or renaming an account and a username
|
||||||
|
-- change all refuse a reserved name with the answer they give a taken one.
|
||||||
|
CREATE TABLE IF NOT EXISTS reserved_usernames (
|
||||||
|
username_norm VARCHAR(32) NOT NULL COLLATE utf8mb4_general_ci PRIMARY KEY,
|
||||||
|
reason ENUM('deleted_staff') NOT NULL,
|
||||||
|
reserved_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS posts (
|
CREATE TABLE IF NOT EXISTS posts (
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
category ENUM('news','five_on_friday','newsletter','screenshot') NOT NULL,
|
category ENUM('news','five_on_friday','newsletter','screenshot') NOT NULL,
|
||||||
@@ -179,7 +195,7 @@ CREATE TABLE IF NOT EXISTS activity_log (
|
|||||||
-- custom (oidc/oauth2) providers.
|
-- custom (oidc/oauth2) providers.
|
||||||
CREATE TABLE IF NOT EXISTS auth_providers (
|
CREATE TABLE IF NOT EXISTS auth_providers (
|
||||||
id VARCHAR(64) PRIMARY KEY, -- 'google' | 'discord' | custom slug
|
id VARCHAR(64) PRIMARY KEY, -- 'google' | 'discord' | custom slug
|
||||||
kind ENUM('google','discord','oidc','oauth2') NOT NULL,
|
kind ENUM('google','discord','oidc','oauth2','steam') NOT NULL,
|
||||||
name VARCHAR(80) NOT NULL,
|
name VARCHAR(80) NOT NULL,
|
||||||
enabled TINYINT(1) NOT NULL DEFAULT 0,
|
enabled TINYINT(1) NOT NULL DEFAULT 0,
|
||||||
client_id VARCHAR(255) NULL,
|
client_id VARCHAR(255) NULL,
|
||||||
@@ -203,6 +219,8 @@ CREATE TABLE IF NOT EXISTS user_identities (
|
|||||||
provider VARCHAR(64) NOT NULL, -- matches auth_providers.id
|
provider VARCHAR(64) NOT NULL, -- matches auth_providers.id
|
||||||
subject VARCHAR(191) NOT NULL, -- external stable user id (sub / discord id)
|
subject VARCHAR(191) NOT NULL, -- external stable user id (sub / discord id)
|
||||||
email VARCHAR(255) NULL,
|
email VARCHAR(255) NULL,
|
||||||
|
display_name VARCHAR(191) NULL, -- Steam persona name (D394); null for other providers
|
||||||
|
avatar_url VARCHAR(500) NULL, -- Steam avatar, a Steam CDN https URL; null for others
|
||||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
CONSTRAINT fk_identity_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
CONSTRAINT fk_identity_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||||
UNIQUE KEY uq_identity_provider_subject (provider, subject),
|
UNIQUE KEY uq_identity_provider_subject (provider, subject),
|
||||||
@@ -1151,7 +1169,7 @@ CREATE TABLE IF NOT EXISTS team_forum_posts (
|
|||||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
thread_id INT NOT NULL,
|
thread_id INT NOT NULL,
|
||||||
author_user_id INT NULL,
|
author_user_id INT NULL,
|
||||||
author_username VARCHAR(32) NULL, -- snapshot; renders as "[deleted account]" when both are gone
|
author_username VARCHAR(32) NULL, -- snapshot; with the id NULL it is a deleted account: "[deleted player]" to members, the name to staff (utils/displayAuthor.js)
|
||||||
body_html MEDIUMTEXT NOT NULL, -- sanitised on write via utils/forumHtml.js
|
body_html MEDIUMTEXT NOT NULL, -- sanitised on write via utils/forumHtml.js
|
||||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
edited_at DATETIME NULL,
|
edited_at DATETIME NULL,
|
||||||
@@ -1283,6 +1301,72 @@ CREATE TABLE IF NOT EXISTS content_reports (
|
|||||||
INDEX idx_cr_team (team_id, created_at)
|
INDEX idx_cr_team (team_id, created_at)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
-- What the reported item said when it was reported (USER_SAFETY.md §4.1). A chat
|
||||||
|
-- line is pruned with the rest of a module's event log, and a queue row must still
|
||||||
|
-- show what was said after that; a forum author editing a post after the report
|
||||||
|
-- must not change what staff read. NULL on reports filed before 1.21.0.
|
||||||
|
--
|
||||||
|
-- `actioned_with` names what the queue DID when a staffer actioned a report
|
||||||
|
-- through it ('hide' — hide for everyone). NULL for an "actioned" that only
|
||||||
|
-- records a decision, which is every report before 1.21.0.
|
||||||
|
ALTER TABLE content_reports ADD COLUMN IF NOT EXISTS snapshot JSON NULL;
|
||||||
|
ALTER TABLE content_reports ADD COLUMN IF NOT EXISTS actioned_with VARCHAR(16) NULL;
|
||||||
|
|
||||||
|
-- A member's blocks (USER_SAFETY.md §4.1, S2, S12, S14). Saved on the account,
|
||||||
|
-- so a block applies on the website and in the app, on every device.
|
||||||
|
--
|
||||||
|
-- Two kinds of row, never both at once:
|
||||||
|
-- • an ACCOUNT block names `blocked_user_id`. This is the normal block (S12):
|
||||||
|
-- a forum author, and a chat speaker whose game identity is linked to an
|
||||||
|
-- account, are blocked as the account.
|
||||||
|
-- • a GAME block names (`module_id`, `identity_kind`, `external_id`) — a
|
||||||
|
-- Steam id in a chat feed that no account has linked. When that identity is
|
||||||
|
-- later linked, the row is rewritten as an account block the next time it is
|
||||||
|
-- read (S14).
|
||||||
|
--
|
||||||
|
-- Staff cannot be blocked (S8). The refusal happens when the block is made; a
|
||||||
|
-- row whose target LATER became staff is kept and simply stops applying, so the
|
||||||
|
-- Blocked page can say why rather than the block vanishing.
|
||||||
|
--
|
||||||
|
-- Each kind has its own unique key, and MySQL's NULL-distinct rule keeps them
|
||||||
|
-- out of each other's way: an account row's game columns are NULL, and a game
|
||||||
|
-- row's `blocked_user_id` is.
|
||||||
|
--
|
||||||
|
-- `display_name` is a snapshot of what the member saw when they blocked: the
|
||||||
|
-- username, or the in-game name of an unlinked speaker.
|
||||||
|
CREATE TABLE IF NOT EXISTS user_blocks (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
blocker_user_id INT NOT NULL,
|
||||||
|
blocked_user_id INT NULL,
|
||||||
|
module_id VARCHAR(32) NULL,
|
||||||
|
identity_kind VARCHAR(32) NULL,
|
||||||
|
external_id VARCHAR(64) NULL,
|
||||||
|
display_name VARCHAR(64) NULL,
|
||||||
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_ub_blocker FOREIGN KEY (blocker_user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_ub_blocked FOREIGN KEY (blocked_user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
UNIQUE KEY uq_ub_account (blocker_user_id, blocked_user_id),
|
||||||
|
UNIQUE KEY uq_ub_game (blocker_user_id, module_id, identity_kind, external_id),
|
||||||
|
INDEX idx_ub_external (module_id, identity_kind, external_id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
-- A member's "Hide for me" (USER_SAFETY.md §1, S3): one item gone from their own
|
||||||
|
-- view on every device. No report is filed and nothing about the item changes.
|
||||||
|
--
|
||||||
|
-- `target_type` is a report target type (`team_forum_thread`, `team_forum_post`,
|
||||||
|
-- or a module's, e.g. `rust.chat`) and `target_id` its id. Nothing checks the
|
||||||
|
-- item exists: answering "no such item" would tell a member whether a thread id
|
||||||
|
-- exists in a forum they cannot see, and a row for an item that is not there
|
||||||
|
-- hides nothing.
|
||||||
|
CREATE TABLE IF NOT EXISTS user_hidden_items (
|
||||||
|
user_id INT NOT NULL,
|
||||||
|
target_type VARCHAR(32) NOT NULL,
|
||||||
|
target_id BIGINT NOT NULL,
|
||||||
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (user_id, target_type, target_id),
|
||||||
|
CONSTRAINT fk_uhi_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
-- The §2.9 approval queue. A MODERATOR performing one of the three actions that
|
-- The §2.9 approval queue. A MODERATOR performing one of the three actions that
|
||||||
-- publish untrusted game-sourced strings creates a pending row here; an ADMIN
|
-- publish untrusted game-sourced strings creates a pending row here; an ADMIN
|
||||||
-- performing one applies it immediately. Rows are kept after a decision — "a
|
-- performing one applies it immediately. Rows are kept after a decision — "a
|
||||||
@@ -2606,6 +2690,18 @@ ALTER TABLE event_run_resources MODIFY COLUMN status
|
|||||||
ALTER TABLE event_versions ADD COLUMN IF NOT EXISTS verified_at DATETIME NULL;
|
ALTER TABLE event_versions ADD COLUMN IF NOT EXISTS verified_at DATETIME NULL;
|
||||||
ALTER TABLE event_versions ADD COLUMN IF NOT EXISTS verified_by INT NULL;
|
ALTER TABLE event_versions ADD COLUMN IF NOT EXISTS verified_by INT NULL;
|
||||||
|
|
||||||
|
-- A dry run that passed on the DRAFT, and the fingerprint of the spec it passed
|
||||||
|
-- on (W5, Rust PLAN_LAST_FIXES). A draft changes under the author's hands, so a
|
||||||
|
-- pass on it is not a property of any version -- but publish compares this
|
||||||
|
-- fingerprint with the spec it is about to freeze, and when they are equal the
|
||||||
|
-- new version is stamped verified with this pass's reviewer and time. Without it
|
||||||
|
-- an author who dry-ran and then published found v1 "not dry run", and its
|
||||||
|
-- scheduled and trigger starts held, until they ran the same check again. An
|
||||||
|
-- edit after the dry run changes the fingerprint, so nothing stale carries.
|
||||||
|
ALTER TABLE event_definitions ADD COLUMN IF NOT EXISTS draft_verified_at DATETIME NULL;
|
||||||
|
ALTER TABLE event_definitions ADD COLUMN IF NOT EXISTS draft_verified_by INT NULL;
|
||||||
|
ALTER TABLE event_definitions ADD COLUMN IF NOT EXISTS draft_verified_hash CHAR(64) NULL;
|
||||||
|
|
||||||
-- Whether this definition appears on the PUBLIC calendar (Phase 14a).
|
-- Whether this definition appears on the PUBLIC calendar (Phase 14a).
|
||||||
--
|
--
|
||||||
-- **Not a second answer to the question `state` answers**, which is the trap the
|
-- **Not a second answer to the question `state` answers**, which is the trap the
|
||||||
@@ -2744,3 +2840,12 @@ CREATE TABLE IF NOT EXISTS event_trigger_starts (
|
|||||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
CONSTRAINT fk_evtrig_def FOREIGN KEY (definition_id) REFERENCES event_definitions(id) ON DELETE CASCADE
|
CONSTRAINT fk_evtrig_def FOREIGN KEY (definition_id) REFERENCES event_definitions(id) ON DELETE CASCADE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
-- Sign in with Steam (STEAM_SIGNIN.md §4). Steam is a built-in provider beside
|
||||||
|
-- Google and Discord, so its row needs the kind; and a linked Steam account
|
||||||
|
-- shows its persona name and avatar (D394), kept on the identity and refreshed
|
||||||
|
-- at each Steam sign-in. Both additive. MODIFY has no IF NOT EXISTS form, but
|
||||||
|
-- re-declaring the same ENUM is an idempotent no-op.
|
||||||
|
ALTER TABLE auth_providers MODIFY COLUMN kind ENUM('google','discord','oidc','oauth2','steam') NOT NULL;
|
||||||
|
ALTER TABLE user_identities ADD COLUMN IF NOT EXISTS display_name VARCHAR(191) NULL;
|
||||||
|
ALTER TABLE user_identities ADD COLUMN IF NOT EXISTS avatar_url VARCHAR(500) NULL;
|
||||||
|
|||||||
284
server/db/seedDemo.js
Normal file
284
server/db/seedDemo.js
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
// ── `npm run seed:demo` — the public demo's base (DEMO_MODE.md §7.3) ────────
|
||||||
|
//
|
||||||
|
// Run by the wipe workflow inside the app container, after `compose down -v` and
|
||||||
|
// a fresh `up` have left an empty database with the schema in place:
|
||||||
|
//
|
||||||
|
// docker compose exec app npm run seed:demo -- /app/deploy/demo/seed.json
|
||||||
|
//
|
||||||
|
// It writes, from one fixture file:
|
||||||
|
// 1. the four static logins (§4) — upserted, so a password a visitor somehow
|
||||||
|
// changed is back within one cycle and a re-run is harmless;
|
||||||
|
// 2. the site settings the demo starts from (live, registration disabled, and
|
||||||
|
// whatever the fixture adds);
|
||||||
|
// 3. the seeded content — posts, wiki pages, pages, events — on the first run
|
||||||
|
// against a database only, so a re-run never duplicates it;
|
||||||
|
// 4. each installed module's own rows, through the module's `onDemoSeed` hook
|
||||||
|
// (API 1.18.0, DM15): core never writes a module's tables;
|
||||||
|
// 5. `demo_state` — when the next wipe is due and the published logins, for
|
||||||
|
// the banner and the sign-in page (§6).
|
||||||
|
//
|
||||||
|
// With the events it also switches on, in the events switchboard, every action
|
||||||
|
// those events' steps use — otherwise a seeded event cannot run (§7.3).
|
||||||
|
//
|
||||||
|
// A string `"$env:NAME"` anywhere in the fixture is replaced with that variable,
|
||||||
|
// so the rig's sidecar token lives in the host's .env and never in the repo. An
|
||||||
|
// unset variable fails the run rather than seeding an empty credential.
|
||||||
|
//
|
||||||
|
// Refuses to run without DEMO_MODE=true: pointed at a real shard by mistake, it
|
||||||
|
// would reset four accounts' passwords and flip the site live.
|
||||||
|
|
||||||
|
require('dotenv').config()
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
const { isDemo, DEMO_ACCOUNTS } = require('../src/demo/mode')
|
||||||
|
|
||||||
|
const ROLES = ['admin', 'editor', 'moderator', 'player']
|
||||||
|
|
||||||
|
const log = require('../src/utils/logger')('seed-demo')
|
||||||
|
|
||||||
|
// ── Pure helpers (tested in test/seedDemo.test.js) ─────────────────────────
|
||||||
|
|
||||||
|
/** Replace every `"$env:NAME"` string, at any depth. Throws on an unset one. */
|
||||||
|
function resolveEnv(value, env = process.env, where = 'fixture') {
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
const m = /^\$env:([A-Z_][A-Z0-9_]*)$/.exec(value)
|
||||||
|
if (!m) return value
|
||||||
|
const got = env[m[1]]
|
||||||
|
if (got === undefined || got === '') throw new Error(`${where}: environment variable ${m[1]} is not set`)
|
||||||
|
return got
|
||||||
|
}
|
||||||
|
if (Array.isArray(value)) return value.map((v, i) => resolveEnv(v, env, `${where}[${i}]`))
|
||||||
|
if (value && typeof value === 'object') {
|
||||||
|
const out = {}
|
||||||
|
for (const [k, v] of Object.entries(value)) out[k] = resolveEnv(v, env, `${where}.${k}`)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When the next wipe is due: the next whole multiple of `everyHours` past
|
||||||
|
* midnight UTC, strictly after `now` — the schedule the wipe workflow's cron
|
||||||
|
* runs on (DM7: every 2 hours on the hour). The seed runs a minute or two after
|
||||||
|
* a wipe starts, so "strictly after" lands on the following slot.
|
||||||
|
*/
|
||||||
|
function nextResetAt(now = new Date(), everyHours = 2) {
|
||||||
|
const step = everyHours * 60 * 60 * 1000
|
||||||
|
const midnight = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())
|
||||||
|
const slots = Math.floor((now.getTime() - midnight) / step) + 1
|
||||||
|
return new Date(midnight + slots * step)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Check the fixture's shape before anything is written. Returns a list of problems. */
|
||||||
|
function checkFixture(fixture) {
|
||||||
|
const problems = []
|
||||||
|
if (!fixture || typeof fixture !== 'object' || Array.isArray(fixture)) return ['the fixture must be a JSON object']
|
||||||
|
const accounts = fixture.accounts || {}
|
||||||
|
for (const name of DEMO_ACCOUNTS) {
|
||||||
|
const a = accounts[name]
|
||||||
|
if (!a) {
|
||||||
|
problems.push(`accounts.${name} is missing`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (typeof a.password !== 'string' || a.password.length < 8) {
|
||||||
|
problems.push(`accounts.${name}.password must be a string of at least 8 characters`)
|
||||||
|
}
|
||||||
|
if (!ROLES.includes(a.role)) problems.push(`accounts.${name}.role must be one of ${ROLES.join(', ')}`)
|
||||||
|
}
|
||||||
|
for (const name of Object.keys(accounts)) {
|
||||||
|
if (!DEMO_ACCOUNTS.includes(name)) {
|
||||||
|
problems.push(`accounts.${name} is not a demo account (the lock only knows ${DEMO_ACCOUNTS.join(', ')})`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fixture.settings !== undefined) {
|
||||||
|
if (!fixture.settings || typeof fixture.settings !== 'object' || Array.isArray(fixture.settings)) {
|
||||||
|
problems.push('settings must be an object')
|
||||||
|
} else if ('demo_state' in fixture.settings) {
|
||||||
|
problems.push('settings.demo_state is written by the seed itself')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const key of ['posts', 'wiki', 'pages', 'events']) {
|
||||||
|
const list = fixture.content?.[key]
|
||||||
|
if (list !== undefined && !Array.isArray(list)) problems.push(`content.${key} must be an array`)
|
||||||
|
}
|
||||||
|
if (fixture.modules !== undefined && (typeof fixture.modules !== 'object' || Array.isArray(fixture.modules))) {
|
||||||
|
problems.push('modules must be an object keyed by module id')
|
||||||
|
}
|
||||||
|
return problems
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every action a seeded event's steps use, once each, in first-use order.
|
||||||
|
*
|
||||||
|
* A fresh database has no switchboard rows, so every `change` and `irreversible`
|
||||||
|
* action starts disabled (EVENTS.md §K) — and a seeded event that answers "not
|
||||||
|
* enabled on this deployment" when a visitor runs it is a showcase that does not
|
||||||
|
* show (step-5 walk, W1). The seed switches on exactly these and nothing else.
|
||||||
|
*/
|
||||||
|
function eventActionIds(events = []) {
|
||||||
|
const ids = []
|
||||||
|
for (const e of events) {
|
||||||
|
for (const phase of e?.spec?.phases || []) {
|
||||||
|
for (const step of phase?.steps || []) {
|
||||||
|
if (step?.actionId && !ids.includes(step.actionId)) ids.push(step.actionId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── The run ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/* eslint-disable global-require */
|
||||||
|
async function upsertAccounts(fixture) {
|
||||||
|
const users = require('../src/model/users/users.model')
|
||||||
|
const ids = {}
|
||||||
|
for (const username of DEMO_ACCOUNTS) {
|
||||||
|
const { password, role } = fixture.accounts[username]
|
||||||
|
const existing = await users.getRawByUsername(username)
|
||||||
|
let id
|
||||||
|
if (existing) {
|
||||||
|
id = existing.id
|
||||||
|
// A password change bumps the session cutoff, which signs every visitor out
|
||||||
|
// of this account — the right outcome at a wipe, and on a fresh database
|
||||||
|
// (the normal case) there is nobody to sign out.
|
||||||
|
await users.update(id, { password, role, status: 'active', emailVerified: true })
|
||||||
|
await users.disableTotp(id)
|
||||||
|
} else {
|
||||||
|
const created = await users.createUser({ username, password, role, status: 'active', emailVerified: true })
|
||||||
|
id = created.id
|
||||||
|
}
|
||||||
|
ids[username] = id
|
||||||
|
log.info(`account ${username} (${role}) ready`, { id })
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
async function writeSettings(fixture) {
|
||||||
|
const settings = require('../src/model/settings/settings.model')
|
||||||
|
await settings.setMany({
|
||||||
|
site_mode: 'live',
|
||||||
|
site_mode_changed_at: new Date().toISOString(),
|
||||||
|
site_mode_changed_by: 'seed:demo',
|
||||||
|
// §4: registration is closed, and the route is locked too (DM16).
|
||||||
|
[settings.REGISTRATION_KEY]: 'disabled',
|
||||||
|
...(fixture.settings || {}),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function writeContent(fixture, authorId) {
|
||||||
|
const content = fixture.content || {}
|
||||||
|
const posts = require('../src/model/posts/posts.model')
|
||||||
|
const wiki = require('../src/model/wiki/wiki.model')
|
||||||
|
const pages = require('../src/model/pages/pages.model')
|
||||||
|
const events = require('../src/model/events/eventDefinitions.model')
|
||||||
|
|
||||||
|
for (const p of content.posts || []) {
|
||||||
|
const category = posts.toDbCategory(p.category || 'news')
|
||||||
|
if (!category) throw new Error(`post "${p.title}": unknown category "${p.category}"`)
|
||||||
|
await posts.create({ ...p, category, published: p.published !== false, author_id: authorId })
|
||||||
|
}
|
||||||
|
for (const w of content.wiki || []) {
|
||||||
|
const category = w.category ? await wiki.getCategoryBySlug(w.category) : null
|
||||||
|
if (w.category && !category) throw new Error(`wiki "${w.slug}": unknown category "${w.category}"`)
|
||||||
|
await wiki.create({ ...w, categoryId: category ? category.id : null, updatedBy: authorId })
|
||||||
|
}
|
||||||
|
for (const pg of content.pages || []) {
|
||||||
|
await pages.create(pg, authorId)
|
||||||
|
}
|
||||||
|
for (const e of content.events || []) {
|
||||||
|
const { publish, ...input } = e
|
||||||
|
const made = await events.create(input, authorId, { role: 'admin' })
|
||||||
|
if (!made.ok) throw new Error(`event "${input.name || input.title}": ${(made.errors || []).join('; ')}`)
|
||||||
|
if (publish) {
|
||||||
|
const pub = await events.publish(made.id, authorId)
|
||||||
|
if (!pub.ok) throw new Error(`event "${input.name || input.title}" did not publish: ${(pub.errors || []).join('; ')}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Uncapped, like a switch an admin flips without filling the cap boxes: the
|
||||||
|
// deny list (DM11) is what keeps a visitor's own command step harmless, and the
|
||||||
|
// wipe takes the row away with the rest of the database.
|
||||||
|
const actionSettings = require('../src/model/events/eventActionSettings.db')
|
||||||
|
const enabled = eventActionIds(content.events)
|
||||||
|
for (const actionId of enabled) await actionSettings.put(actionId, { enabled: true, caps: {} }, authorId)
|
||||||
|
log.info('content written', {
|
||||||
|
posts: (content.posts || []).length,
|
||||||
|
wiki: (content.wiki || []).length,
|
||||||
|
pages: (content.pages || []).length,
|
||||||
|
events: (content.events || []).length,
|
||||||
|
actionsEnabled: enabled,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function seedModules(fixture, accounts) {
|
||||||
|
const modules = require('../src/modules/loader')
|
||||||
|
const hooks = modules.demoSeedHooks()
|
||||||
|
const wanted = fixture.modules || {}
|
||||||
|
for (const id of Object.keys(wanted)) {
|
||||||
|
if (!hooks.some((h) => h.id === id)) {
|
||||||
|
throw new Error(`modules.${id}: no installed module "${id}" takes a demo seed (onDemoSeed)`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const { id, hook } of hooks) {
|
||||||
|
if (wanted[id] === undefined) continue
|
||||||
|
// The module gets its part of the fixture and the demo accounts' ids, so it
|
||||||
|
// can link one of them to a game identity without reading core's users table.
|
||||||
|
await hook(wanted[id], { accounts: { ...accounts } })
|
||||||
|
log.info(`module ${id} seeded`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function writeState(fixture, now = new Date()) {
|
||||||
|
const settings = require('../src/model/settings/settings.model')
|
||||||
|
const everyHours = Number(process.env.DEMO_RESET_EVERY_HOURS) || 2
|
||||||
|
const logins = DEMO_ACCOUNTS
|
||||||
|
.filter((name) => fixture.accounts[name].published !== false)
|
||||||
|
.map((name) => ({ username: name, password: fixture.accounts[name].password, role: fixture.accounts[name].role }))
|
||||||
|
const state = { resetsAt: nextResetAt(now, everyHours).toISOString(), logins }
|
||||||
|
await settings.set(settings.DEMO_STATE_KEY, JSON.stringify(state))
|
||||||
|
log.info('demo state stamped', { resetsAt: state.resetsAt, logins: logins.length })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function run(file) {
|
||||||
|
if (!isDemo()) throw new Error('seed:demo runs only with DEMO_MODE=true')
|
||||||
|
if (!file) throw new Error('usage: npm run seed:demo -- <fixture.json> (or set DEMO_SEED_FILE)')
|
||||||
|
|
||||||
|
const fixture = resolveEnv(JSON.parse(fs.readFileSync(path.resolve(file), 'utf8')))
|
||||||
|
const problems = checkFixture(fixture)
|
||||||
|
if (problems.length) throw new Error(`the fixture has problems:\n - ${problems.join('\n - ')}`)
|
||||||
|
|
||||||
|
// The app itself, without listening: this is what loads the installed modules
|
||||||
|
// (and core's registries, which an event definition is validated against)
|
||||||
|
// exactly as the server does. Nothing here calls onBoot, so no module starts
|
||||||
|
// its workers in this process.
|
||||||
|
require('../src/app')
|
||||||
|
const settings = require('../src/model/settings/settings.model')
|
||||||
|
|
||||||
|
const firstRun = !(await settings.get(settings.DEMO_STATE_KEY))
|
||||||
|
const accounts = await upsertAccounts(fixture)
|
||||||
|
await writeSettings(fixture)
|
||||||
|
if (firstRun) await writeContent(fixture, accounts['demo-admin'])
|
||||||
|
else log.info('content already seeded on this database; left as is')
|
||||||
|
await seedModules(fixture, accounts)
|
||||||
|
await writeState(fixture)
|
||||||
|
}
|
||||||
|
/* eslint-enable global-require */
|
||||||
|
|
||||||
|
if (require.main === module) {
|
||||||
|
;(async () => {
|
||||||
|
const { close } = require('../src/utils/db') // eslint-disable-line global-require
|
||||||
|
try {
|
||||||
|
await run(process.argv[2] || process.env.DEMO_SEED_FILE)
|
||||||
|
log.info('demo seeded')
|
||||||
|
} catch (err) {
|
||||||
|
log.error(`seed:demo failed: ${err.message}`)
|
||||||
|
process.exitCode = 1
|
||||||
|
} finally {
|
||||||
|
await close()
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { resolveEnv, nextResetAt, checkFixture, eventActionIds, run }
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"_comment": "Generated event-trigger inventory - the authoritative freeze of CORE's engagement contract (docs/website/ENGAGEMENT.md 4.3). Regenerate with `npm run engagement:manifest` in website/server. A renamed variable, a changed type or a widened ceiling breaks stored templates and rules, so the diff here is the review signal. A module ships its own copy in its bundle; this file never contains one.",
|
"_comment": "Generated event-trigger inventory - the authoritative freeze of CORE's engagement contract (docs/website/ENGAGEMENT.md 4.3). Regenerate with `npm run engagement:manifest` in website/server. A renamed variable, a changed type or a widened ceiling breaks stored templates and rules, so the diff here is the review signal. A module ships its own copy in its bundle; this file never contains one.",
|
||||||
"moduleApiVersion": "1.15.0",
|
"moduleApiVersion": "1.21.0",
|
||||||
"triggers": [
|
"triggers": [
|
||||||
{
|
{
|
||||||
"id": "event.phase.changed",
|
"id": "event.phase.changed",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
"start": "node src/server.js",
|
"start": "node src/server.js",
|
||||||
"dev": "nodemon src/server.js",
|
"dev": "nodemon src/server.js",
|
||||||
"seed": "node db/seed.js",
|
"seed": "node db/seed.js",
|
||||||
|
"seed:demo": "node db/seedDemo.js",
|
||||||
"swagger": "node swagger/swagger.js",
|
"swagger": "node swagger/swagger.js",
|
||||||
"routes:manifest": "node scripts/routeManifest.js",
|
"routes:manifest": "node scripts/routeManifest.js",
|
||||||
"engagement:manifest": "node scripts/engagementManifest.js",
|
"engagement:manifest": "node scripts/engagementManifest.js",
|
||||||
|
|||||||
@@ -818,6 +818,17 @@
|
|||||||
"validate"
|
"validate"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "POST",
|
||||||
|
"path": "/api/v1/admin/moderation/reports/:id/hide",
|
||||||
|
"handlers": 4,
|
||||||
|
"gates": [
|
||||||
|
"noindex",
|
||||||
|
"requireAuth",
|
||||||
|
"middleware",
|
||||||
|
"validate"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/api/v1/admin/moderation/search",
|
"path": "/api/v1/admin/moderation/search",
|
||||||
@@ -1784,6 +1795,18 @@
|
|||||||
"requireAuth"
|
"requireAuth"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "DELETE",
|
||||||
|
"path": "/api/v1/auth/me/account",
|
||||||
|
"handlers": 9,
|
||||||
|
"gates": [
|
||||||
|
"noindex",
|
||||||
|
"requireAuth",
|
||||||
|
"backoffGuard",
|
||||||
|
"middleware",
|
||||||
|
"validate"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/api/v1/auth/me/account",
|
"path": "/api/v1/auth/me/account",
|
||||||
@@ -1834,7 +1857,7 @@
|
|||||||
{
|
{
|
||||||
"method": "DELETE",
|
"method": "DELETE",
|
||||||
"path": "/api/v1/auth/me/account/identities/:provider",
|
"path": "/api/v1/auth/me/account/identities/:provider",
|
||||||
"handlers": 3,
|
"handlers": 4,
|
||||||
"gates": [
|
"gates": [
|
||||||
"noindex",
|
"noindex",
|
||||||
"requireAuth",
|
"requireAuth",
|
||||||
@@ -1916,6 +1939,37 @@
|
|||||||
"validate"
|
"validate"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "GET",
|
||||||
|
"path": "/api/v1/auth/me/blocks",
|
||||||
|
"handlers": 1,
|
||||||
|
"gates": [
|
||||||
|
"noindex",
|
||||||
|
"requireAuth"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "POST",
|
||||||
|
"path": "/api/v1/auth/me/blocks",
|
||||||
|
"handlers": 5,
|
||||||
|
"gates": [
|
||||||
|
"noindex",
|
||||||
|
"requireAuth",
|
||||||
|
"middleware",
|
||||||
|
"validate"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "DELETE",
|
||||||
|
"path": "/api/v1/auth/me/blocks/:id",
|
||||||
|
"handlers": 4,
|
||||||
|
"gates": [
|
||||||
|
"noindex",
|
||||||
|
"requireAuth",
|
||||||
|
"middleware",
|
||||||
|
"validate"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/api/v1/auth/me/devices",
|
"path": "/api/v1/auth/me/devices",
|
||||||
@@ -1947,6 +2001,46 @@
|
|||||||
"validate"
|
"validate"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "DELETE",
|
||||||
|
"path": "/api/v1/auth/me/hidden",
|
||||||
|
"handlers": 2,
|
||||||
|
"gates": [
|
||||||
|
"noindex",
|
||||||
|
"requireAuth"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "GET",
|
||||||
|
"path": "/api/v1/auth/me/hidden",
|
||||||
|
"handlers": 1,
|
||||||
|
"gates": [
|
||||||
|
"noindex",
|
||||||
|
"requireAuth"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "POST",
|
||||||
|
"path": "/api/v1/auth/me/hidden",
|
||||||
|
"handlers": 5,
|
||||||
|
"gates": [
|
||||||
|
"noindex",
|
||||||
|
"requireAuth",
|
||||||
|
"middleware",
|
||||||
|
"validate"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "DELETE",
|
||||||
|
"path": "/api/v1/auth/me/hidden/:targetType/:targetId",
|
||||||
|
"handlers": 5,
|
||||||
|
"gates": [
|
||||||
|
"noindex",
|
||||||
|
"requireAuth",
|
||||||
|
"middleware",
|
||||||
|
"validate"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/api/v1/auth/me/notifications",
|
"path": "/api/v1/auth/me/notifications",
|
||||||
@@ -2285,6 +2379,17 @@
|
|||||||
"requireAuth"
|
"requireAuth"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "POST",
|
||||||
|
"path": "/api/v1/player/reports",
|
||||||
|
"handlers": 7,
|
||||||
|
"gates": [
|
||||||
|
"noindex",
|
||||||
|
"requireAuth",
|
||||||
|
"middleware",
|
||||||
|
"validate"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/api/v1/player/teams",
|
"path": "/api/v1/player/teams",
|
||||||
|
|||||||
@@ -357,6 +357,10 @@
|
|||||||
"method": "POST",
|
"method": "POST",
|
||||||
"path": "/api/v1/admin/moderation/reports/:id/handle"
|
"path": "/api/v1/admin/moderation/reports/:id/handle"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "POST",
|
||||||
|
"path": "/api/v1/admin/moderation/reports/:id/hide"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/api/v1/admin/moderation/search"
|
"path": "/api/v1/admin/moderation/search"
|
||||||
@@ -733,6 +737,10 @@
|
|||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/api/v1/auth/me"
|
"path": "/api/v1/auth/me"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "DELETE",
|
||||||
|
"path": "/api/v1/auth/me/account"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/api/v1/auth/me/account"
|
"path": "/api/v1/auth/me/account"
|
||||||
@@ -785,6 +793,18 @@
|
|||||||
"method": "PATCH",
|
"method": "PATCH",
|
||||||
"path": "/api/v1/auth/me/account/username"
|
"path": "/api/v1/auth/me/account/username"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "GET",
|
||||||
|
"path": "/api/v1/auth/me/blocks"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "POST",
|
||||||
|
"path": "/api/v1/auth/me/blocks"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "DELETE",
|
||||||
|
"path": "/api/v1/auth/me/blocks/:id"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/api/v1/auth/me/devices"
|
"path": "/api/v1/auth/me/devices"
|
||||||
@@ -797,6 +817,22 @@
|
|||||||
"method": "DELETE",
|
"method": "DELETE",
|
||||||
"path": "/api/v1/auth/me/devices/:id"
|
"path": "/api/v1/auth/me/devices/:id"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "DELETE",
|
||||||
|
"path": "/api/v1/auth/me/hidden"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "GET",
|
||||||
|
"path": "/api/v1/auth/me/hidden"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "POST",
|
||||||
|
"path": "/api/v1/auth/me/hidden"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "DELETE",
|
||||||
|
"path": "/api/v1/auth/me/hidden/:targetType/:targetId"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/api/v1/auth/me/notifications"
|
"path": "/api/v1/auth/me/notifications"
|
||||||
@@ -941,6 +977,10 @@
|
|||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/api/v1/player/events/history"
|
"path": "/api/v1/player/events/history"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "POST",
|
||||||
|
"path": "/api/v1/player/reports"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/api/v1/player/teams"
|
"path": "/api/v1/player/teams"
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ const createLogger = require('./utils/logger')
|
|||||||
const htmlShell = require('./utils/htmlShell')
|
const htmlShell = require('./utils/htmlShell')
|
||||||
const { applyTrustProxy, trustProxyDebug } = require('./utils/trustProxy')
|
const { applyTrustProxy, trustProxyDebug } = require('./utils/trustProxy')
|
||||||
const botScore = require('./middleware/botScore')
|
const botScore = require('./middleware/botScore')
|
||||||
|
const { isDemo } = require('./demo/mode')
|
||||||
|
const demoLock = require('./demo/locks')
|
||||||
|
|
||||||
const httpLog = createLogger('http')
|
const httpLog = createLogger('http')
|
||||||
const errLog = createLogger('error')
|
const errLog = createLogger('error')
|
||||||
@@ -84,6 +86,24 @@ app.use(morgan(accessFormat, { stream: { write: (line) => httpLog.info(line.trim
|
|||||||
app.use(express.json({ limit: '2mb' }))
|
app.use(express.json({ limit: '2mb' }))
|
||||||
app.use(cookieParser())
|
app.use(cookieParser())
|
||||||
|
|
||||||
|
// ── The public demo ───────────────────────────────────────────────────
|
||||||
|
// DEMO_MODE=true turns this deployment into demo.runicgateway.com
|
||||||
|
// (docs/website/DEMO_MODE.md). Unset, nothing here is mounted, so a real shard
|
||||||
|
// runs none of it. After the body parser, because one lock reads the body of
|
||||||
|
// PUT /admin/settings; after cookieParser, because the shared-login locks read
|
||||||
|
// the session; ahead of `/api` and of the SPA's static files (robots.txt).
|
||||||
|
// The module locks are asked per request: the loader runs further down.
|
||||||
|
if (isDemo()) {
|
||||||
|
app.use(demoLock.noindex)
|
||||||
|
app.get('/robots.txt', (req, res) => {
|
||||||
|
// #swagger.ignore = true
|
||||||
|
demoLock.robots(req, res)
|
||||||
|
})
|
||||||
|
app.use(demoLock.refuseMultipart)
|
||||||
|
app.use(demoLock.refuseDataUri)
|
||||||
|
app.use('/api/v1', demoLock.createLock(() => modules.demoLocks()))
|
||||||
|
}
|
||||||
|
|
||||||
// ── Paths ─────────────────────────────────────────────────────────────
|
// ── Paths ─────────────────────────────────────────────────────────────
|
||||||
const SERVER_ROOT = path.join(__dirname, '..')
|
const SERVER_ROOT = path.join(__dirname, '..')
|
||||||
const REPO_ROOT = path.join(SERVER_ROOT, '..')
|
const REPO_ROOT = path.join(SERVER_ROOT, '..')
|
||||||
|
|||||||
174
server/src/auth/accountDeletion.js
Normal file
174
server/src/auth/accountDeletion.js
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
// ── Deleting an account (docs/website/ACCOUNT_DELETION.md §4.1) ────────────
|
||||||
|
//
|
||||||
|
// One procedure for both ways an account goes: a member deleting their own
|
||||||
|
// (`DELETE /auth/me/account`, by: 'self') and staff deleting it from the admin
|
||||||
|
// panel (`DELETE /admin/users/:id`, by: 'staff'). The two routes check different
|
||||||
|
// things before they get here — the member proves who they are, the admin is not
|
||||||
|
// allowed to delete themself — and from here on they do the same thing.
|
||||||
|
//
|
||||||
|
// In order:
|
||||||
|
//
|
||||||
|
// 1. **Before the delete.** Read what is needed afterwards (the address for the
|
||||||
|
// notice, the username, the role), then ask every started module's
|
||||||
|
// `onUserDeleting` hook in turn (MODULE_API 1.20.0). That is where game links
|
||||||
|
// are unlinked through each module's own unlink (AD10): a cascade is not an
|
||||||
|
// unlink, and for UO the link lives on the shard.
|
||||||
|
// 2. **One transaction.** A staff name is added to `reserved_usernames` (AD9)
|
||||||
|
// and the users row is deleted. The foreign keys do the rest: credentials,
|
||||||
|
// sessions and settings cascade, authored content is detached. Snapshot
|
||||||
|
// columns, the content and the activity log are NOT touched (AD5, AD6) —
|
||||||
|
// who sees which name is utils/displayAuthor's rule, applied when read.
|
||||||
|
// 3. **After commit**, fire-and-forget, each step on its own: a Teams
|
||||||
|
// reconcile, the activity-log entry, and the notice to the old address.
|
||||||
|
//
|
||||||
|
// **Nothing stops a deletion once it starts** (AD11). A hook that throws, or runs
|
||||||
|
// past HOOK_TIMEOUT_MS, is logged and the deletion goes ahead: Play requires the
|
||||||
|
// request to be honoured, and a game server that is down must not hold a
|
||||||
|
// member's request open. Whatever a module could not finish is its own pending
|
||||||
|
// work. The refusals below all come BEFORE step 1.
|
||||||
|
|
||||||
|
const users = require('../model/users/users.model')
|
||||||
|
const activity = require('../model/activity/activity.model')
|
||||||
|
const teamSync = require('../model/teams/teamSync.model')
|
||||||
|
const loader = require('../modules/loader')
|
||||||
|
const mailer = require('../utils/mailer')
|
||||||
|
const { isDemo, isDemoUsername } = require('../demo/mode')
|
||||||
|
const log = require('../utils/logger')('account-deletion')
|
||||||
|
|
||||||
|
const HOOK_TIMEOUT_MS = 10_000
|
||||||
|
const BY = ['self', 'staff']
|
||||||
|
|
||||||
|
function withTimeout(fn, ms) {
|
||||||
|
let timer
|
||||||
|
const deadline = new Promise((_, reject) => {
|
||||||
|
timer = setTimeout(() => reject(new Error(`no answer within ${ms} ms`)), ms)
|
||||||
|
})
|
||||||
|
return Promise.race([Promise.resolve().then(fn), deadline]).finally(() => clearTimeout(timer))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ask every started module's `onUserDeleting`, one at a time.
|
||||||
|
*
|
||||||
|
* In turn rather than at once so a module's log lines read in the order they ran,
|
||||||
|
* and because a site runs one module: there is nothing to parallelise. Never
|
||||||
|
* throws; returns what each module did, for the log.
|
||||||
|
*
|
||||||
|
* @returns {Promise<{module: string, ok: boolean, error?: string}[]>}
|
||||||
|
*/
|
||||||
|
async function runHooks(payload, timeoutMs) {
|
||||||
|
const frozen = Object.freeze({ userId: payload.userId, deletedBy: payload.deletedBy })
|
||||||
|
const outcomes = []
|
||||||
|
for (const { id, hook } of loader.userDeletingHooks()) {
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await withTimeout(() => hook(frozen), timeoutMs)
|
||||||
|
outcomes.push({ module: id, ok: true })
|
||||||
|
} catch (err) {
|
||||||
|
log.error('a module could not finish before an account was deleted; deleting anyway', {
|
||||||
|
module: id,
|
||||||
|
userId: frozen.userId,
|
||||||
|
message: err.message,
|
||||||
|
})
|
||||||
|
outcomes.push({ module: id, ok: false, error: err.message })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return outcomes
|
||||||
|
}
|
||||||
|
|
||||||
|
// "29 October 2026", in UTC so the date in the mail does not depend on the
|
||||||
|
// host's zone.
|
||||||
|
function formatDate(when) {
|
||||||
|
return when.toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Step 3. Each step in its own try, and the whole thing never rejects, so the
|
||||||
|
* caller may leave it un-awaited. Returned anyway, so a test has a moment at
|
||||||
|
* which the after-commit work has happened.
|
||||||
|
*/
|
||||||
|
async function afterCommit({ userId, by, req, email, username, reserved, when }) {
|
||||||
|
try {
|
||||||
|
teamSync.request({ reason: 'account deleted' })
|
||||||
|
} catch (err) {
|
||||||
|
log.warn('teams reconcile request failed after a deletion', { message: err.message })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Never the username: the entry outlives the account, and the activity log is
|
||||||
|
// a record of what was done, not a second place the name is kept. A member
|
||||||
|
// deleting themself is no longer a user the row could name, so the entry
|
||||||
|
// carries no user id, only the IP the request came from (AD6).
|
||||||
|
try {
|
||||||
|
const action = by === 'self' ? 'user.self_delete' : 'user.delete'
|
||||||
|
const detail = { id: userId, ...(reserved ? { usernameReserved: true } : {}) }
|
||||||
|
if (by === 'self') {
|
||||||
|
await activity.log({ req: { ip: req ? req.ip : null }, action, detail })
|
||||||
|
} else {
|
||||||
|
await activity.log({ req, action, detail })
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
log.warn('activity entry failed after a deletion', { message: err.message })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (email) {
|
||||||
|
try {
|
||||||
|
const sent = await mailer.sendAccountDeleted({ to: email, username, deletedOn: formatDate(when), by })
|
||||||
|
if (!sent.sent) log.info('deletion notice not sent (mail not configured)', { userId })
|
||||||
|
} catch (err) {
|
||||||
|
log.warn('deletion notice failed', { userId, message: err.message })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete one account.
|
||||||
|
*
|
||||||
|
* @param {number} userId
|
||||||
|
* @param {{by: 'self'|'staff', req?: object, hookTimeoutMs?: number}} opts
|
||||||
|
* @returns {Promise<
|
||||||
|
* | {ok: true, id: number, reserved: boolean, modules: object[], settled: Promise<void>}
|
||||||
|
* | {ok: false, reason: 'not_found' | 'demo' | 'last_admin'}
|
||||||
|
* >}
|
||||||
|
*/
|
||||||
|
async function deleteAccount(userId, { by, req = null, hookTimeoutMs = HOOK_TIMEOUT_MS } = {}) {
|
||||||
|
if (!BY.includes(by)) throw new Error(`deleteAccount: by must be one of ${BY.join(', ')}`)
|
||||||
|
|
||||||
|
const target = await users.getById(userId)
|
||||||
|
if (!target) return { ok: false, reason: 'not_found' }
|
||||||
|
// The demo's shared logins. The demo lock refuses both routes before they get
|
||||||
|
// here (demo/locks.js); this is the line behind it, so no future caller of the
|
||||||
|
// service can delete the account every visitor signs in as.
|
||||||
|
if (isDemo() && isDemoUsername(target.username)) return { ok: false, reason: 'demo' }
|
||||||
|
// A deployment with no admin left has nobody who can run it.
|
||||||
|
if (target.role === 'admin' && (await users.countAdmins()) <= 1) return { ok: false, reason: 'last_admin' }
|
||||||
|
|
||||||
|
// 1. Before the delete.
|
||||||
|
const modules = await runHooks({ userId, deletedBy: by }, hookTimeoutMs)
|
||||||
|
|
||||||
|
// 2. One transaction: reserve a staff name, delete the row.
|
||||||
|
const reserveName = target.role !== 'player' ? target.username : null
|
||||||
|
const removed = await users.removeReserving(userId, reserveName)
|
||||||
|
// Gone between the read above and now: somebody else's deletion won. Nothing
|
||||||
|
// of ours happened, so nothing after commit runs either.
|
||||||
|
if (!removed) return { ok: false, reason: 'not_found' }
|
||||||
|
|
||||||
|
log.info('account deleted', {
|
||||||
|
userId,
|
||||||
|
by,
|
||||||
|
reserved: Boolean(reserveName),
|
||||||
|
modules: modules.map((m) => `${m.module}:${m.ok ? 'ok' : 'failed'}`),
|
||||||
|
})
|
||||||
|
|
||||||
|
// 3. After commit.
|
||||||
|
const settled = afterCommit({
|
||||||
|
userId,
|
||||||
|
by,
|
||||||
|
req,
|
||||||
|
email: target.email || null,
|
||||||
|
username: target.username,
|
||||||
|
reserved: Boolean(reserveName),
|
||||||
|
when: new Date(),
|
||||||
|
})
|
||||||
|
return { ok: true, id: userId, reserved: Boolean(reserveName), modules, settled }
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { deleteAccount, HOOK_TIMEOUT_MS }
|
||||||
97
server/src/auth/identityHooks.js
Normal file
97
server/src/auth/identityHooks.js
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
// ── Modules and identity links (MODULE_API 1.17.0) ─────────────────────────
|
||||||
|
//
|
||||||
|
// Core owns linking an external sign-in identity to an account. Modules take part
|
||||||
|
// in exactly two places (STEAM_SIGNIN.md §4):
|
||||||
|
//
|
||||||
|
// checkLink() before the identity is written. Each module that registered
|
||||||
|
// `onIdentityLinking` may refuse. Rust uses it for D396: a Steam
|
||||||
|
// id that is already another website account's Rust link.
|
||||||
|
// notifyLinked() after it is written. Rust uses it for D392: the Steam account
|
||||||
|
// becomes a linked Rust player.
|
||||||
|
//
|
||||||
|
// A refusal can only stop a link. It runs inside the link flow of a user who is
|
||||||
|
// already signed in, so nothing here can mint a session or let through a link
|
||||||
|
// core would refuse.
|
||||||
|
//
|
||||||
|
// What a module says is never shown to the player: `reason: 'in_use'` reads as
|
||||||
|
// the same "already linked to another user" core says itself, and anything else
|
||||||
|
// as a plain refusal. A module's own words go to the log. Putting module text in
|
||||||
|
// a redirect URL would let anybody craft a link that prints a sentence of their
|
||||||
|
// choosing on our account page.
|
||||||
|
|
||||||
|
const loader = require('../modules/loader')
|
||||||
|
const log = require('../utils/logger')('sso')
|
||||||
|
|
||||||
|
const HOOK_TIMEOUT_MS = 5_000
|
||||||
|
|
||||||
|
function withTimeout(fn, ms) {
|
||||||
|
let timer
|
||||||
|
const deadline = new Promise((_, reject) => {
|
||||||
|
timer = setTimeout(() => reject(new Error(`no answer within ${ms} ms`)), ms)
|
||||||
|
})
|
||||||
|
return Promise.race([Promise.resolve().then(fn), deadline]).finally(() => clearTimeout(timer))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ask every started module whether this link may be made.
|
||||||
|
*
|
||||||
|
* **Fails closed.** A module that throws or does not answer in time refuses the
|
||||||
|
* link: the hook exists to stop a link that must not happen, and a module that
|
||||||
|
* could not look is a module that could not say it was safe. The player is told
|
||||||
|
* to try again; a link is never the urgent half of anything.
|
||||||
|
*
|
||||||
|
* @param {{userId: number, provider: string, subject: string}} link
|
||||||
|
* @returns {Promise<{ok: true} | {ok: false, reason: 'in_use' | 'refused', module: string}>}
|
||||||
|
*/
|
||||||
|
async function checkLink(link) {
|
||||||
|
const frozen = Object.freeze({ userId: link.userId, provider: link.provider, subject: link.subject })
|
||||||
|
for (const { id, hook } of loader.identityHooks('onIdentityLinking')) {
|
||||||
|
let answer
|
||||||
|
try {
|
||||||
|
answer = await withTimeout(() => hook(frozen), HOOK_TIMEOUT_MS)
|
||||||
|
} catch (err) {
|
||||||
|
log.error('identity link check failed; refusing the link', { module: id, provider: frozen.provider, message: err.message })
|
||||||
|
return { ok: false, reason: 'refused', module: id }
|
||||||
|
}
|
||||||
|
if (answer && answer.ok === false) {
|
||||||
|
const reason = answer.reason === 'in_use' ? 'in_use' : 'refused'
|
||||||
|
log.info('identity link refused by a module', {
|
||||||
|
module: id,
|
||||||
|
provider: frozen.provider,
|
||||||
|
userId: frozen.userId,
|
||||||
|
reason,
|
||||||
|
message: typeof answer.message === 'string' ? answer.message.slice(0, 200) : undefined,
|
||||||
|
})
|
||||||
|
return { ok: false, reason, module: id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { ok: true }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell every started module a link was written.
|
||||||
|
*
|
||||||
|
* Awaited (bounded) so the page the player lands on already shows what a module
|
||||||
|
* made of it — the Rust page listing the Steam account they just linked — but a
|
||||||
|
* failure never reaches the link: the identity is written, and that is core's
|
||||||
|
* answer. A module that missed it is logged.
|
||||||
|
*
|
||||||
|
* @param {{userId: number, provider: string, subject: string, displayName?: string|null}} link
|
||||||
|
*/
|
||||||
|
async function notifyLinked(link) {
|
||||||
|
const frozen = Object.freeze({
|
||||||
|
userId: link.userId,
|
||||||
|
provider: link.provider,
|
||||||
|
subject: link.subject,
|
||||||
|
displayName: link.displayName || null,
|
||||||
|
})
|
||||||
|
await Promise.all(
|
||||||
|
loader.identityHooks('onIdentityLinked').map(({ id, hook }) =>
|
||||||
|
withTimeout(() => hook(frozen), HOOK_TIMEOUT_MS).catch((err) => {
|
||||||
|
log.error('identity linked hook failed', { module: id, provider: frozen.provider, message: err.message })
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { checkLink, notifyLinked, HOOK_TIMEOUT_MS }
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
const GoogleProvider = require('./google.provider')
|
const GoogleProvider = require('./google.provider')
|
||||||
const DiscordProvider = require('./discord.provider')
|
const DiscordProvider = require('./discord.provider')
|
||||||
const GenericOidcProvider = require('./genericOidc.provider')
|
const GenericOidcProvider = require('./genericOidc.provider')
|
||||||
|
const SteamProvider = require('./steam.provider')
|
||||||
const authProviders = require('../../model/authProviders/authProviders.model')
|
const authProviders = require('../../model/authProviders/authProviders.model')
|
||||||
|
|
||||||
// kind → provider class.
|
// kind → provider class.
|
||||||
@@ -20,6 +21,7 @@ const KINDS = {
|
|||||||
discord: DiscordProvider,
|
discord: DiscordProvider,
|
||||||
oidc: GenericOidcProvider,
|
oidc: GenericOidcProvider,
|
||||||
oauth2: GenericOidcProvider,
|
oauth2: GenericOidcProvider,
|
||||||
|
steam: SteamProvider,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Built-in providers and their fixed display metadata. Endpoints are in the
|
// Built-in providers and their fixed display metadata. Endpoints are in the
|
||||||
@@ -27,6 +29,9 @@ const KINDS = {
|
|||||||
const BUILTINS = [
|
const BUILTINS = [
|
||||||
{ id: 'google', kind: 'google', name: 'Google', priority: 1 },
|
{ id: 'google', kind: 'google', name: 'Google', priority: 1 },
|
||||||
{ id: 'discord', kind: 'discord', name: 'Discord', priority: 2 },
|
{ id: 'discord', kind: 'discord', name: 'Discord', priority: 2 },
|
||||||
|
// OpenID 2.0, not OAuth2 (STEAM_SIGNIN.md §3): no client id, and the "secret"
|
||||||
|
// is the Steam Web API key it cannot be enabled without (D394).
|
||||||
|
{ id: 'steam', kind: 'steam', name: 'Steam', priority: 3 },
|
||||||
]
|
]
|
||||||
|
|
||||||
const BUILTIN_IDS = new Set(BUILTINS.map((b) => b.id))
|
const BUILTIN_IDS = new Set(BUILTINS.map((b) => b.id))
|
||||||
@@ -35,6 +40,18 @@ function isBuiltin(id) {
|
|||||||
return BUILTIN_IDS.has(id)
|
return BUILTIN_IDS.has(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Providers whose callback is OpenID 2.0 (`openid.*` fields) rather than an OAuth2
|
||||||
|
// `code`. Steam is the only one, and only as the built-in: a custom provider can
|
||||||
|
// only be oidc/oauth2, so the kind is known from the id before any row is read.
|
||||||
|
function isOpenId(id) {
|
||||||
|
return id === 'steam'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Providers that never sign anybody up, whatever player_registration says (D395).
|
||||||
|
function neverProvisions(kind) {
|
||||||
|
return kind === 'steam'
|
||||||
|
}
|
||||||
|
|
||||||
// Instantiate a provider from a config row (secret already decrypted by the
|
// Instantiate a provider from a config row (secret already decrypted by the
|
||||||
// model as `client_secret`). Returns null for an unknown kind.
|
// model as `client_secret`). Returns null for an unknown kind.
|
||||||
function instantiate(row) {
|
function instantiate(row) {
|
||||||
@@ -66,6 +83,11 @@ async function load(id) {
|
|||||||
// custom (oidc/oauth2) also need the three endpoint URLs. Returns { valid, missing }.
|
// custom (oidc/oauth2) also need the three endpoint URLs. Returns { valid, missing }.
|
||||||
function validateConfig(row) {
|
function validateConfig(row) {
|
||||||
const missing = []
|
const missing = []
|
||||||
|
if (row.kind === 'steam') {
|
||||||
|
// No client id; the Web API key is the one thing it needs (D394).
|
||||||
|
if (!row.client_secret_enc && !row.client_secret) missing.push('api_key')
|
||||||
|
return { valid: missing.length === 0, missing }
|
||||||
|
}
|
||||||
if (!row.client_id) missing.push('client_id')
|
if (!row.client_id) missing.push('client_id')
|
||||||
// A stored secret shows up as client_secret_enc on plain rows, or client_secret
|
// A stored secret shows up as client_secret_enc on plain rows, or client_secret
|
||||||
// on decrypted rows — accept either as "has a secret".
|
// on decrypted rows — accept either as "has a secret".
|
||||||
@@ -110,7 +132,7 @@ async function listEnabledValid() {
|
|||||||
.map((p) => ({
|
.map((p) => ({
|
||||||
id: p.id,
|
id: p.id,
|
||||||
name: p.name,
|
name: p.name,
|
||||||
icon: p.kind, // 'google' | 'discord' | 'oidc' | 'oauth2'
|
icon: p.kind, // 'google' | 'discord' | 'steam' | 'oidc' | 'oauth2'
|
||||||
loginUrl: `/api/v1/auth/sso/${p.id}/start`,
|
loginUrl: `/api/v1/auth/sso/${p.id}/start`,
|
||||||
priority: p.priority ?? 100,
|
priority: p.priority ?? 100,
|
||||||
}))
|
}))
|
||||||
@@ -120,6 +142,8 @@ module.exports = {
|
|||||||
KINDS,
|
KINDS,
|
||||||
BUILTINS,
|
BUILTINS,
|
||||||
isBuiltin,
|
isBuiltin,
|
||||||
|
isOpenId,
|
||||||
|
neverProvisions,
|
||||||
instantiate,
|
instantiate,
|
||||||
load,
|
load,
|
||||||
validateConfig,
|
validateConfig,
|
||||||
|
|||||||
172
server/src/auth/providers/steam.provider.js
Normal file
172
server/src/auth/providers/steam.provider.js
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
// Built-in Steam provider (OpenID 2.0, STEAM_SIGNIN.md §3).
|
||||||
|
//
|
||||||
|
// Steam is not OAuth2: there is no client id, no token endpoint and no `state`
|
||||||
|
// parameter. The browser goes to steamcommunity.com with an OpenID 2.0
|
||||||
|
// `checkid_setup` request and comes back carrying `openid.*` fields, and the ONLY
|
||||||
|
// proof those fields are genuine is asking Steam itself — a server-to-server
|
||||||
|
// `check_authentication` POST of the same fields, which must answer
|
||||||
|
// `is_valid:true`. Our CSRF `state` rides inside `return_to`, where the existing
|
||||||
|
// single-use tx cookie verifies it exactly as it does for the OAuth providers.
|
||||||
|
//
|
||||||
|
// The admin-configured "secret" is a Steam Web API key (D394), used for one thing:
|
||||||
|
// the persona name and avatar shown beside a linked Steam account. That lookup
|
||||||
|
// decorates an identity and never decides a sign-in — if it fails, the sign-in
|
||||||
|
// goes ahead with the bare id.
|
||||||
|
|
||||||
|
const BaseProvider = require('./base.provider')
|
||||||
|
const log = require('../../utils/logger')('sso')
|
||||||
|
|
||||||
|
const OP_ENDPOINT = 'https://steamcommunity.com/openid/login'
|
||||||
|
const OPENID_NS = 'http://specs.openid.net/auth/2.0'
|
||||||
|
const IDENTIFIER_SELECT = 'http://specs.openid.net/auth/2.0/identifier_select'
|
||||||
|
const CLAIMED_ID_RE = /^https:\/\/steamcommunity\.com\/openid\/id\/(\d{17})$/
|
||||||
|
const SUMMARIES_URL = 'https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/'
|
||||||
|
// Steam serves avatars from its own CDNs. Anything else in that field is not
|
||||||
|
// something we render.
|
||||||
|
const AVATAR_RE = /^https:\/\/([a-z0-9-]+\.)*(steamstatic\.com|akamaihd\.net)\/[^\s"'<>]{1,400}$/i
|
||||||
|
|
||||||
|
const VERIFY_TIMEOUT_MS = 10_000
|
||||||
|
const SUMMARY_TIMEOUT_MS = 5_000
|
||||||
|
|
||||||
|
// A failure the controller turns into a sentence rather than a 500.
|
||||||
|
class SteamAssertionError extends Error {
|
||||||
|
constructor(reason) {
|
||||||
|
super(`steam assertion refused: ${reason}`)
|
||||||
|
this.reason = reason
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The 17-digit SteamID64 at the end of a claimed id, or null.
|
||||||
|
function parseClaimedId(claimedId) {
|
||||||
|
const m = typeof claimedId === 'string' ? CLAIMED_ID_RE.exec(claimedId) : null
|
||||||
|
return m ? m[1] : null
|
||||||
|
}
|
||||||
|
|
||||||
|
// The `return_to` we send, and must get back byte for byte: the callback URL with
|
||||||
|
// our tx nonce as `state`.
|
||||||
|
function returnToFor(redirectUri, state) {
|
||||||
|
const sep = redirectUri.includes('?') ? '&' : '?'
|
||||||
|
return `${redirectUri}${sep}state=${encodeURIComponent(state)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
// The realm is the origin the return_to lives under — what Steam shows the user
|
||||||
|
// as "you are signing in to".
|
||||||
|
function realmFor(redirectUri) {
|
||||||
|
return new URL(redirectUri).origin
|
||||||
|
}
|
||||||
|
|
||||||
|
// Every `openid.*` field from a parsed query, as strings. Anything else is ours
|
||||||
|
// (`state`) and does not go back to Steam.
|
||||||
|
function openidFields(query = {}) {
|
||||||
|
const out = {}
|
||||||
|
for (const [k, v] of Object.entries(query)) {
|
||||||
|
if (k.startsWith('openid.') && typeof v === 'string') out[k] = v
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
class SteamProvider extends BaseProvider {
|
||||||
|
constructor(config = {}) {
|
||||||
|
super({ kind: 'steam', name: 'Steam', ...config, id: config.id || 'steam' })
|
||||||
|
// Stored in client_secret_enc like any secret; it is a Web API key here.
|
||||||
|
this.apiKey = config.clientSecret ?? config.client_secret ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
getAuthorizationUrl(state, { redirectUri } = {}) {
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
'openid.ns': OPENID_NS,
|
||||||
|
'openid.mode': 'checkid_setup',
|
||||||
|
'openid.return_to': returnToFor(redirectUri, state),
|
||||||
|
'openid.realm': realmFor(redirectUri),
|
||||||
|
'openid.identity': IDENTIFIER_SELECT,
|
||||||
|
'openid.claimed_id': IDENTIFIER_SELECT,
|
||||||
|
})
|
||||||
|
return `${OP_ENDPOINT}?${params.toString()}`
|
||||||
|
}
|
||||||
|
|
||||||
|
// `query` is the callback's parsed query string; `redirectUri` and `state` are
|
||||||
|
// what we sent, so `return_to` can be matched exactly. Resolves to the usual
|
||||||
|
// { subject, email, emailVerified, name } plus displayName/avatarUrl, or throws
|
||||||
|
// SteamAssertionError.
|
||||||
|
async handleCallback({ query, redirectUri, state } = {}) {
|
||||||
|
const fields = openidFields(query)
|
||||||
|
if (fields['openid.mode'] !== 'id_res') throw new SteamAssertionError('mode')
|
||||||
|
if (fields['openid.ns'] !== OPENID_NS) throw new SteamAssertionError('ns')
|
||||||
|
if (fields['openid.op_endpoint'] !== OP_ENDPOINT) throw new SteamAssertionError('op_endpoint')
|
||||||
|
if (fields['openid.return_to'] !== returnToFor(redirectUri, state)) throw new SteamAssertionError('return_to')
|
||||||
|
const subject = parseClaimedId(fields['openid.claimed_id'])
|
||||||
|
if (!subject) throw new SteamAssertionError('claimed_id')
|
||||||
|
if (fields['openid.identity'] !== fields['openid.claimed_id']) throw new SteamAssertionError('identity')
|
||||||
|
|
||||||
|
if (!(await this.verifyAssertion(fields))) throw new SteamAssertionError('not_valid')
|
||||||
|
|
||||||
|
const summary = await this.playerSummary(subject)
|
||||||
|
return {
|
||||||
|
subject,
|
||||||
|
email: null, // Steam never sends one
|
||||||
|
emailVerified: false,
|
||||||
|
name: summary.displayName,
|
||||||
|
displayName: summary.displayName,
|
||||||
|
avatarUrl: summary.avatarUrl,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The one proof (§5): send the same fields back with mode check_authentication.
|
||||||
|
// Never skipped; any transport failure is a refusal, not a pass.
|
||||||
|
async verifyAssertion(fields) {
|
||||||
|
const body = new URLSearchParams({ ...fields, 'openid.mode': 'check_authentication' })
|
||||||
|
let text
|
||||||
|
try {
|
||||||
|
const res = await fetch(OP_ENDPOINT, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
|
body,
|
||||||
|
signal: AbortSignal.timeout(VERIFY_TIMEOUT_MS),
|
||||||
|
})
|
||||||
|
if (!res.ok) {
|
||||||
|
log.warn('steam check_authentication failed', { status: res.status })
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
text = await res.text()
|
||||||
|
} catch (err) {
|
||||||
|
log.warn('steam check_authentication unreachable', { message: err.message })
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return /^is_valid:true$/m.test(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Persona name + avatar through the Web API key. Decoration only: every failure
|
||||||
|
// answers nulls and the sign-in carries on (D394). The key rides in the URL, so
|
||||||
|
// the URL is never logged.
|
||||||
|
async playerSummary(steamId) {
|
||||||
|
const none = { displayName: null, avatarUrl: null }
|
||||||
|
if (!this.apiKey) return none
|
||||||
|
try {
|
||||||
|
const url = `${SUMMARIES_URL}?key=${encodeURIComponent(this.apiKey)}&steamids=${steamId}`
|
||||||
|
const res = await fetch(url, { headers: { Accept: 'application/json' }, signal: AbortSignal.timeout(SUMMARY_TIMEOUT_MS) })
|
||||||
|
if (!res.ok) {
|
||||||
|
log.warn('steam player summary failed; signing in with the bare id', { status: res.status })
|
||||||
|
return none
|
||||||
|
}
|
||||||
|
const data = await res.json()
|
||||||
|
const player = data && data.response && Array.isArray(data.response.players) ? data.response.players[0] : null
|
||||||
|
if (!player || player.steamid !== steamId) return none
|
||||||
|
const name = typeof player.personaname === 'string' ? player.personaname.trim().slice(0, 191) : ''
|
||||||
|
const avatar = player.avatarfull || player.avatarmedium || player.avatar
|
||||||
|
return {
|
||||||
|
displayName: name || null,
|
||||||
|
avatarUrl: typeof avatar === 'string' && AVATAR_RE.test(avatar) ? avatar : null,
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
log.warn('steam player summary unreachable; signing in with the bare id', { message: err.message })
|
||||||
|
return none
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SteamProvider.SteamAssertionError = SteamAssertionError
|
||||||
|
SteamProvider.parseClaimedId = parseClaimedId
|
||||||
|
SteamProvider.returnToFor = returnToFor
|
||||||
|
SteamProvider.OP_ENDPOINT = OP_ENDPOINT
|
||||||
|
|
||||||
|
module.exports = SteamProvider
|
||||||
@@ -442,8 +442,12 @@ const ACTIONS = [
|
|||||||
|
|
||||||
const baseline = await lease.read({ target })
|
const baseline = await lease.read({ target })
|
||||||
if (!baseline || baseline.ok !== true) {
|
if (!baseline || baseline.ok !== true) {
|
||||||
|
// A module that says `retry: false` has said a retry cannot help, so that
|
||||||
|
// verdict is passed through; anything else stays undefined so the
|
||||||
|
// dispatcher's own default (retry) still applies.
|
||||||
return {
|
return {
|
||||||
ok: false,
|
ok: false,
|
||||||
|
retry: baseline && baseline.retry === false ? false : undefined,
|
||||||
error: baseline && baseline.error
|
error: baseline && baseline.error
|
||||||
? String(baseline.error)
|
? String(baseline.error)
|
||||||
: `could not read the current value of ${lease.label}`,
|
: `could not read the current value of ${lease.label}`,
|
||||||
@@ -494,7 +498,11 @@ const ACTIONS = [
|
|||||||
}
|
}
|
||||||
if (!applied || applied.ok !== true) {
|
if (!applied || applied.ok !== true) {
|
||||||
await resourcesDb.markReverted(reserved.id)
|
await resourcesDb.markReverted(reserved.id)
|
||||||
return { ok: false, error: applied && applied.error ? String(applied.error) : `${lease.label} refused the new value` }
|
return {
|
||||||
|
ok: false,
|
||||||
|
retry: applied && applied.retry === false ? false : undefined,
|
||||||
|
error: applied && applied.error ? String(applied.error) : `${lease.label} refused the new value`,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await resourcesDb.confirm(reserved.id)
|
await resourcesDb.confirm(reserved.id)
|
||||||
|
|||||||
250
server/src/demo/locks.js
Normal file
250
server/src/demo/locks.js
Normal file
@@ -0,0 +1,250 @@
|
|||||||
|
// ── The demo lock (docs/website/DEMO_MODE.md §3) ───────────────────────────
|
||||||
|
//
|
||||||
|
// With DEMO_MODE on, app.js mounts four middlewares from this file, and with it
|
||||||
|
// off none of them is mounted at all, so a real shard runs none of this code.
|
||||||
|
//
|
||||||
|
// • `refuseMultipart` — any request with a multipart body, anywhere, before a
|
||||||
|
// router sees it (§3.3 "Uploads — locked hard"). An upload route added later
|
||||||
|
// is locked without anyone remembering to list it, and a module cannot open one.
|
||||||
|
// • `lock` — each write request against core's list below plus every module's
|
||||||
|
// declared `demoLocks`, at `/api/v1`, ahead of every router.
|
||||||
|
// • `refuseDataUri` — any write whose JSON body carries a data: URI in any
|
||||||
|
// string (DM25): a pasted image is an upload that did not use multipart.
|
||||||
|
// • `noindex` + `robots` — nothing a visitor writes reaches a search engine.
|
||||||
|
//
|
||||||
|
// **The server is the lock (DM10).** Everything here is decided from the request
|
||||||
|
// alone, so `curl`, an old app build and a hand-edited page are refused exactly
|
||||||
|
// like a click. The client explains a refusal; it never enforces one.
|
||||||
|
//
|
||||||
|
// A refusal is always the same answer, so the web client and the app can each
|
||||||
|
// recognise it by `code` and show one sentence for it.
|
||||||
|
|
||||||
|
const { compile, match } = require('./paths')
|
||||||
|
const { isDemoUsername } = require('./mode')
|
||||||
|
|
||||||
|
const log = require('../utils/logger')('demo')
|
||||||
|
|
||||||
|
const CODE = 'DEMO_LOCKED'
|
||||||
|
const MESSAGE = 'This is turned off on the demo site.'
|
||||||
|
const WRITES = ['POST', 'PUT', 'PATCH', 'DELETE']
|
||||||
|
|
||||||
|
function refuse(res, extra = {}) {
|
||||||
|
return res.status(403).json({ message: MESSAGE, code: CODE, ...extra })
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Conditions ─────────────────────────────────────────────────────────────
|
||||||
|
// A few rows lock a route only for some requests. Each condition is asked only
|
||||||
|
// after the method and path have matched, so the DB is touched on a handful of
|
||||||
|
// rare admin and self-service writes and on nothing else.
|
||||||
|
|
||||||
|
// Required lazily: this file is required by app.js, and the users model would
|
||||||
|
// otherwise make the DB pool a startup dependency of the lock.
|
||||||
|
/* eslint-disable global-require */
|
||||||
|
const users = () => require('../model/users/users.model')
|
||||||
|
const sessions = () => require('../auth/session.service')
|
||||||
|
/* eslint-enable global-require */
|
||||||
|
|
||||||
|
async function isDemoUserId(id) {
|
||||||
|
const n = Number(id)
|
||||||
|
if (!Number.isInteger(n) || n < 1) return false
|
||||||
|
const user = await users().getById(n)
|
||||||
|
return Boolean(user && isDemoUsername(user.username))
|
||||||
|
}
|
||||||
|
|
||||||
|
// `PUT /admin/users/:id` and its kin: an admin acting on one of the shared logins.
|
||||||
|
const targetIsDemo = (req, params) => isDemoUserId(params.id)
|
||||||
|
|
||||||
|
// `/auth/me/*`: the caller signed in as one of the shared logins. The identity is
|
||||||
|
// read the way requireAuth reads it, and the account row decides — not the
|
||||||
|
// username claim in the token. No session is not a refusal: the route's own
|
||||||
|
// requireAuth answers that with its usual 401.
|
||||||
|
async function callerIsDemo(req) {
|
||||||
|
const session = sessions().validateSession(req)
|
||||||
|
return Boolean(session && (await isDemoUserId(session.userId)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// `PUT /admin/settings` stays open (DM2), but that one route writes arbitrary
|
||||||
|
// keys, and a few keys are another door into something Tier A locks: `site_mode`
|
||||||
|
// is what `PUT /admin/site-mode` writes, `module_source_hosts` what the Modules
|
||||||
|
// screen's sources do, `teams_voice_*` the voice settings. `demo_*` is the
|
||||||
|
// banner and the published logins, which the seed owns. `hero_layout` is the
|
||||||
|
// live homepage hero (DM21): the editor's draft (`hero_layout_draft`) and its
|
||||||
|
// Preview stay open, its Publish is refused.
|
||||||
|
const PROTECTED_SETTINGS = [/^site_mode/, /^module_source_hosts$/, /^teams_voice_/, /^demo_/, /^hero_layout$/]
|
||||||
|
|
||||||
|
function protectedKeys(body) {
|
||||||
|
if (!body || typeof body !== 'object' || Array.isArray(body)) return []
|
||||||
|
return Object.keys(body).filter((key) => PROTECTED_SETTINGS.some((re) => re.test(key)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Core's list (§3.3) ─────────────────────────────────────────────────────
|
||||||
|
// Paths are relative to /api/v1 and written as the routers declare them;
|
||||||
|
// test/demoLocks.test.js holds every row against routes.manifest.json, so a
|
||||||
|
// row that stops naming a real route fails the build rather than reading as a lock.
|
||||||
|
|
||||||
|
const CORE_LOCKS = [
|
||||||
|
// Tier A — site configuration.
|
||||||
|
{ methods: ['PUT'], path: '/admin/site-mode' },
|
||||||
|
{ methods: WRITES, path: '/admin/modules/*' },
|
||||||
|
{ methods: WRITES, path: '/admin/auth/providers/*' },
|
||||||
|
{ methods: ['PUT'], path: '/admin/email/config' },
|
||||||
|
{ methods: ['POST'], path: '/admin/email/test' },
|
||||||
|
{ methods: ['POST'], path: '/admin/email/disconnect' },
|
||||||
|
{ methods: ['PUT'], path: '/admin/discord-bot/config' },
|
||||||
|
{ methods: WRITES, path: '/admin/teams/voice/*' },
|
||||||
|
{ methods: ['PUT'], path: '/admin/settings', when: (req) => protectedKeys(req.body).length > 0 },
|
||||||
|
|
||||||
|
// Tier A — the shared logins, by an admin.
|
||||||
|
{ methods: ['PUT', 'DELETE'], path: '/admin/users/:id', when: targetIsDemo },
|
||||||
|
{ methods: ['DELETE'], path: '/admin/users/:id/trusted-devices', when: targetIsDemo },
|
||||||
|
{ methods: ['DELETE'], path: '/admin/users/:id/trusted-devices/:deviceId', when: targetIsDemo },
|
||||||
|
{ methods: ['POST'], path: '/admin/users/:id/mfa/reset', when: targetIsDemo },
|
||||||
|
|
||||||
|
// Tier A — the shared logins, by whoever is signed in as one.
|
||||||
|
{ methods: ['PATCH'], path: '/auth/me/account/username', when: callerIsDemo },
|
||||||
|
{ methods: ['PATCH'], path: '/auth/me/account/password', when: callerIsDemo },
|
||||||
|
{ methods: ['PATCH'], path: '/auth/me/account/email', when: callerIsDemo },
|
||||||
|
{ methods: ['POST'], path: '/auth/me/account/totp/setup', when: callerIsDemo },
|
||||||
|
{ methods: ['POST'], path: '/auth/me/account/totp/enable', when: callerIsDemo },
|
||||||
|
{ methods: ['POST'], path: '/auth/me/account/totp/disable', when: callerIsDemo },
|
||||||
|
{ methods: ['POST'], path: '/auth/me/account/recovery-codes/generate', when: callerIsDemo },
|
||||||
|
{ methods: ['DELETE'], path: '/auth/me/account/identities/:provider', when: callerIsDemo },
|
||||||
|
// ACCOUNT_DELETION.md §4.3: the screen stays visible on the demo, because
|
||||||
|
// Play's reviewer must be able to find it, and the shared logins cannot be
|
||||||
|
// deleted. An account an admin created on the demo can be.
|
||||||
|
{ methods: ['DELETE'], path: '/auth/me/account', when: callerIsDemo },
|
||||||
|
// DM17: the whole route, because a mobile access token carries no refresh-row
|
||||||
|
// id and "a session that is not the caller's" cannot be decided. Signing out
|
||||||
|
// (POST /auth/mobile/logout) revokes the caller's own row and stays open.
|
||||||
|
{ methods: ['DELETE'], path: '/auth/me/sessions/:id', when: callerIsDemo },
|
||||||
|
|
||||||
|
// Tier A — credentials for everyone.
|
||||||
|
{ methods: ['POST'], path: '/auth/password/forgot' },
|
||||||
|
{ methods: ['POST'], path: '/auth/password/reset/:token' },
|
||||||
|
// DM16: settings are open, so `player_registration` can be switched on; the
|
||||||
|
// route is what keeps registration closed (§4).
|
||||||
|
{ methods: ['POST'], path: '/auth/register' },
|
||||||
|
|
||||||
|
// Tier C's one exception: the contact form mails a person.
|
||||||
|
{ methods: ['POST'], path: '/public/contact' },
|
||||||
|
|
||||||
|
// Uploads. `refuseMultipart` already stops every one of these; they are
|
||||||
|
// listed too so the table in §3.3 and this file say the same thing, and so a
|
||||||
|
// non-multipart body sent to an upload route is refused the same way.
|
||||||
|
{ methods: ['POST'], path: '/admin/uploads' },
|
||||||
|
{ methods: ['POST'], path: '/admin/posts/upload' },
|
||||||
|
{ methods: ['POST'], path: '/admin/settings/brand-asset/:slot' },
|
||||||
|
{ methods: ['POST'], path: '/player/teams/:slug/forum/uploads' },
|
||||||
|
].map((rule) => ({ ...rule, source: 'core', compiled: compile(rule.path) }))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the lock middleware.
|
||||||
|
*
|
||||||
|
* @param {() => object[]} moduleLocks returns the installed modules' compiled
|
||||||
|
* locks — asked per request, because the loader runs after app.js mounts this.
|
||||||
|
*/
|
||||||
|
function createLock(moduleLocks = () => []) {
|
||||||
|
return async function lock(req, res, next) {
|
||||||
|
if (!WRITES.includes(req.method)) return next()
|
||||||
|
const rules = CORE_LOCKS.concat(moduleLocks())
|
||||||
|
for (const rule of rules) {
|
||||||
|
if (!rule.methods.includes(req.method)) continue
|
||||||
|
const params = match(rule.compiled, req.path)
|
||||||
|
if (!params) continue
|
||||||
|
if (rule.when) {
|
||||||
|
let applies
|
||||||
|
try {
|
||||||
|
applies = await rule.when(req, params)
|
||||||
|
} catch (err) {
|
||||||
|
// Fail closed: a lock that cannot decide is a lock.
|
||||||
|
log.warn('lock condition failed; refusing', { path: rule.path, message: err.message })
|
||||||
|
applies = true
|
||||||
|
}
|
||||||
|
if (!applies) continue
|
||||||
|
}
|
||||||
|
log.info('refused', { method: req.method, path: req.originalUrl, rule: rule.path, source: rule.source })
|
||||||
|
const keys = rule.path === '/admin/settings' ? { keys: protectedKeys(req.body) } : {}
|
||||||
|
return refuse(res, keys)
|
||||||
|
}
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Any multipart content type, not only form-data: nothing on the demo takes one,
|
||||||
|
// and a narrower test is one more spelling to get wrong. The header alone
|
||||||
|
// decides, so a multipart request with no body is refused too.
|
||||||
|
function refuseMultipart(req, res, next) {
|
||||||
|
const type = String(req.headers['content-type'] || '').trim().toLowerCase()
|
||||||
|
if (!type.startsWith('multipart/')) return next()
|
||||||
|
log.info('refused upload', { method: req.method, path: req.originalUrl })
|
||||||
|
return refuse(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DM25: an image pasted into rich text travels inside the JSON body as a data:
|
||||||
|
// URI, which is an upload by another name. Any string anywhere in a write's
|
||||||
|
// body is checked, so a field added later, a setting or a module's route is
|
||||||
|
// covered without being listed, as with multipart.
|
||||||
|
//
|
||||||
|
// A data: URI is `data:` (not the tail of a word like "metadata:") followed by
|
||||||
|
// a comma, a `;`, or a type/subtype and then a comma. Prose such as
|
||||||
|
// "Data: none, yet" does not match. Before testing, HTML character references
|
||||||
|
// are decoded and tabs and newlines removed, because a browser does both when
|
||||||
|
// it reads an attribute: `data:` and `da<newline>ta:` are still data: URIs.
|
||||||
|
const DATA_URI = /(?<![a-z0-9+.-])data:\s*(?:[,;]|[a-z]+\/[a-z0-9.+-]+[^,<>"']{0,256},)/i
|
||||||
|
|
||||||
|
function browserReading(s) {
|
||||||
|
return s
|
||||||
|
.replace(/&#x([0-9a-f]+);?/gi, (m, hex) => safeChar(parseInt(hex, 16), m))
|
||||||
|
.replace(/&#(\d+);?/g, (m, dec) => safeChar(parseInt(dec, 10), m))
|
||||||
|
.replace(/:/gi, ':')
|
||||||
|
.replace(/&(?:tab|newline);/gi, '')
|
||||||
|
.replace(/[\t\n\r]/g, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
function safeChar(code, original) {
|
||||||
|
return code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : original
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasDataUri(body) {
|
||||||
|
const stack = [body]
|
||||||
|
while (stack.length) {
|
||||||
|
const value = stack.pop()
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
if (value.length > 5 && DATA_URI.test(browserReading(value))) return true
|
||||||
|
} else if (value && typeof value === 'object') {
|
||||||
|
for (const v of Object.values(value)) stack.push(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
function refuseDataUri(req, res, next) {
|
||||||
|
if (!WRITES.includes(req.method) || !hasDataUri(req.body)) return next()
|
||||||
|
log.info('refused data: URI', { method: req.method, path: req.originalUrl })
|
||||||
|
return refuse(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
function noindex(req, res, next) {
|
||||||
|
res.set('X-Robots-Tag', 'noindex, nofollow')
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
function robots(req, res) {
|
||||||
|
res.type('text/plain').send('User-agent: *\nDisallow: /\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
CODE,
|
||||||
|
MESSAGE,
|
||||||
|
WRITES,
|
||||||
|
CORE_LOCKS,
|
||||||
|
PROTECTED_SETTINGS,
|
||||||
|
createLock,
|
||||||
|
refuseMultipart,
|
||||||
|
refuseDataUri,
|
||||||
|
hasDataUri,
|
||||||
|
noindex,
|
||||||
|
robots,
|
||||||
|
refuse,
|
||||||
|
protectedKeys,
|
||||||
|
}
|
||||||
26
server/src/demo/mode.js
Normal file
26
server/src/demo/mode.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// ── Demo mode: the flag and the four shared accounts ───────────────────────
|
||||||
|
//
|
||||||
|
// `DEMO_MODE=true` on a deployment turns it into the public demo
|
||||||
|
// (docs/website/DEMO_MODE.md). Read per call rather than once at require time,
|
||||||
|
// so a test can flip it without re-requiring every file that asks — and so
|
||||||
|
// there is exactly one spelling of "is this the demo" in the codebase.
|
||||||
|
//
|
||||||
|
// Only the literal string `true` turns it on. A stray `DEMO_MODE=1` or `yes` on
|
||||||
|
// a real shard must not lock its admin panel, and the opposite mistake — a demo
|
||||||
|
// that forgot the flag — is caught by `seed:demo`, which refuses to run without it.
|
||||||
|
|
||||||
|
function isDemo() {
|
||||||
|
return process.env.DEMO_MODE === 'true'
|
||||||
|
}
|
||||||
|
|
||||||
|
// The static logins (DEMO_MODE.md §4). Fixed here, in core, rather than read
|
||||||
|
// from the seed fixture: the lock has to recognise them on every request, and a
|
||||||
|
// fixture that dropped one would quietly unlock the account everybody shares.
|
||||||
|
// The seed creates exactly these; their passwords come from the fixture.
|
||||||
|
const DEMO_ACCOUNTS = Object.freeze(['demo-admin', 'demo-moderator', 'demo-player', 'play-review'])
|
||||||
|
|
||||||
|
function isDemoUsername(username) {
|
||||||
|
return typeof username === 'string' && DEMO_ACCOUNTS.includes(username.toLowerCase())
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { isDemo, DEMO_ACCOUNTS, isDemoUsername }
|
||||||
70
server/src/demo/paths.js
Normal file
70
server/src/demo/paths.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
// ── Lock patterns: `:param` segments and a trailing `*` ────────────────────
|
||||||
|
//
|
||||||
|
// The demo's lock list names routes the way the routers declare them —
|
||||||
|
// `/admin/users/:id` — so a reviewer can hold the list against the route
|
||||||
|
// manifest line by line. A trailing `/*` means "this path and everything under
|
||||||
|
// it", for the areas DEMO_MODE.md §3.3 locks as a whole ("every write under
|
||||||
|
// /admin/modules").
|
||||||
|
//
|
||||||
|
// The matcher reproduces the two express 4 routing defaults that decide whether
|
||||||
|
// a request reaches a handler at all: matching is case-insensitive, and a
|
||||||
|
// trailing slash is optional. A lock that was stricter than the router about
|
||||||
|
// either would let `PUT /Admin/Site-Mode/` through to a handler that answers it.
|
||||||
|
|
||||||
|
const SEGMENT = /^(?::[A-Za-z][A-Za-z0-9]*|[A-Za-z0-9._-]+)$/
|
||||||
|
|
||||||
|
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compile a lock pattern.
|
||||||
|
*
|
||||||
|
* @param {string} pattern e.g. `/admin/users/:id` or `/admin/modules/*`
|
||||||
|
* @returns {{pattern: string, names: string[], re: RegExp}}
|
||||||
|
* @throws on a pattern that is not absolute, has an empty segment, or puts `*`
|
||||||
|
* anywhere but last — a lock that silently compiled to something else would
|
||||||
|
* be worse than no lock, because it would read as one.
|
||||||
|
*/
|
||||||
|
function compile(pattern) {
|
||||||
|
if (typeof pattern !== 'string' || !pattern.startsWith('/')) {
|
||||||
|
throw new Error(`lock path "${pattern}" must start with /`)
|
||||||
|
}
|
||||||
|
const segs = pattern.slice(1).split('/')
|
||||||
|
const names = []
|
||||||
|
let source = ''
|
||||||
|
segs.forEach((seg, i) => {
|
||||||
|
if (seg === '*') {
|
||||||
|
if (i !== segs.length - 1) throw new Error(`lock path "${pattern}": * must be the last segment`)
|
||||||
|
source += '(?:/.*)?'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!SEGMENT.test(seg)) throw new Error(`lock path "${pattern}": bad segment "${seg}"`)
|
||||||
|
if (seg.startsWith(':')) {
|
||||||
|
names.push(seg.slice(1))
|
||||||
|
source += '/([^/]+)'
|
||||||
|
} else {
|
||||||
|
source += `/${escape(seg)}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return { pattern, names, re: new RegExp(`^${source}/?$`, 'i') }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Match a request path against a compiled pattern.
|
||||||
|
*
|
||||||
|
* @returns {Record<string,string>|null} the decoded params, or null
|
||||||
|
*/
|
||||||
|
function match(compiled, path) {
|
||||||
|
const m = compiled.re.exec(path)
|
||||||
|
if (!m) return null
|
||||||
|
const params = {}
|
||||||
|
compiled.names.forEach((name, i) => {
|
||||||
|
try {
|
||||||
|
params[name] = decodeURIComponent(m[i + 1])
|
||||||
|
} catch {
|
||||||
|
params[name] = m[i + 1]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { compile, match }
|
||||||
@@ -157,6 +157,36 @@ const SEEDS = [
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// ACCOUNT_DELETION.md §4.1 step 3: the one notice a person gets if somebody
|
||||||
|
// else used their unlocked phone. It goes to the address the account HAD,
|
||||||
|
// read before the row went, and there is no link in it because there is no
|
||||||
|
// account left for a link to reach.
|
||||||
|
key: 'auth.account-deleted',
|
||||||
|
name: 'Account deleted',
|
||||||
|
channel: 'email',
|
||||||
|
protected: true,
|
||||||
|
seedVersion: 1,
|
||||||
|
subject: 'Your {{siteName}} account was deleted',
|
||||||
|
variables: [
|
||||||
|
{ name: 'username', type: 'string', required: true, example: 'Darrow' },
|
||||||
|
{ name: 'deletedOn', type: 'string', required: true, example: '29 October 2026' },
|
||||||
|
{ name: 'byWhom', type: 'string', required: false, example: ' at your request' },
|
||||||
|
],
|
||||||
|
blocks: [
|
||||||
|
text('p1', 'The {{siteName}} account “{{username}}” was deleted on {{deletedOn}}{{byWhom}}.'),
|
||||||
|
text(
|
||||||
|
'p2',
|
||||||
|
'Its sign-in, email address, two-factor settings, linked sign-ins and game links are gone. ' +
|
||||||
|
'What it wrote where others read it stays, and other members see it as written by “[deleted player]”.',
|
||||||
|
),
|
||||||
|
text(
|
||||||
|
'p3',
|
||||||
|
'If you did not ask for this, contact the {{siteName}} staff at {{siteUrl}}. ' +
|
||||||
|
'A deleted account cannot be restored, but they can find out what happened.',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'admin.contact-message',
|
key: 'admin.contact-message',
|
||||||
name: 'Contact form message',
|
name: 'Contact form message',
|
||||||
|
|||||||
@@ -357,13 +357,16 @@ async function sweep() {
|
|||||||
* Reverting it would be core recording that it put something back when what
|
* Reverting it would be core recording that it put something back when what
|
||||||
* actually happened is that the thing vanished while nobody was looking, and the
|
* actually happened is that the thing vanished while nobody was looking, and the
|
||||||
* two are different sentences to the operator reading the console afterwards.
|
* two are different sentences to the operator reading the console afterwards.
|
||||||
|
* One gone after its `until` is neither: the game ended it on time, so it is
|
||||||
|
* `expired`, the line `expired()` would have written (W1).
|
||||||
*
|
*
|
||||||
* A module with no `reconcile()` on the action is not broken: core keeps
|
* A module with no `reconcile()` on the action is not broken: core keeps
|
||||||
* believing its own ledger, which is precisely the behaviour before this phase.
|
* believing its own ledger, which is precisely the behaviour before this phase.
|
||||||
*/
|
*/
|
||||||
async function reconcileModule(owner) {
|
async function reconcileModule(owner, now = new Date()) {
|
||||||
const rows = await resourcesDb.liveForModule(owner)
|
const rows = await resourcesDb.liveForModule(owner)
|
||||||
const summary = { asked: 0, inForce: 0, orphaned: 0, unanswered: 0 }
|
const summary = { asked: 0, inForce: 0, orphaned: 0, expired: 0, unanswered: 0 }
|
||||||
|
const settled = new Set()
|
||||||
if (!rows.length) return summary
|
if (!rows.length) return summary
|
||||||
|
|
||||||
const byStep = new Map()
|
const byStep = new Map()
|
||||||
@@ -411,6 +414,19 @@ async function reconcileModule(owner) {
|
|||||||
summary.inForce += 1
|
summary.inForce += 1
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// **Gone after its deadline is the deadline working** (W1, Rust
|
||||||
|
// PLAN_LAST_FIXES). A resource that carries `until` is one the game ends
|
||||||
|
// by itself, and on a reconnect the module's reconcile can run before the
|
||||||
|
// game's backlog says so: the run log read `resource.orphaned` five seconds
|
||||||
|
// before `resource.expired`. Past its `until`, gone is expired. Before it,
|
||||||
|
// gone is still nobody-was-looking, which is what orphaned means.
|
||||||
|
if (row.lease_until && new Date(row.lease_until).getTime() <= now.getTime()) {
|
||||||
|
if (await settleExpired(owner, row)) {
|
||||||
|
summary.expired += 1
|
||||||
|
settled.add(row.run_id)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
await resourcesDb.markOrphaned(row.id, 'the module reports this is no longer in force')
|
await resourcesDb.markOrphaned(row.id, 'the module reports this is no longer in force')
|
||||||
summary.orphaned += 1
|
summary.orphaned += 1
|
||||||
await logDb.write({
|
await logDb.write({
|
||||||
@@ -420,9 +436,42 @@ async function reconcileModule(owner) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
await closeSettledRuns(settled)
|
||||||
return summary
|
return summary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One row the game ended at its deadline: `expired`, and its log line. The same
|
||||||
|
* line whichever way core learned it, from the module's `expired()` or from a
|
||||||
|
* reconcile that found it gone past its `until`, so the console reads one way.
|
||||||
|
*/
|
||||||
|
async function settleExpired(owner, row) {
|
||||||
|
if (!(await resourcesDb.markExpired(row.id, 'the game ended it at its deadline'))) return false
|
||||||
|
await logDb.write({
|
||||||
|
runId: row.run_id,
|
||||||
|
kind: 'resource.expired',
|
||||||
|
detail: { module: owner, resource: `${row.kind}:${row.ref}` },
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A finished run whose last unresolved row just expired has nothing left to
|
||||||
|
* clean up. The sweep would settle a `pending` one by itself, but not an
|
||||||
|
* `incomplete` one — that status takes a run out of the sweep's scan, and it
|
||||||
|
* would go on saying "not finished" about a ledger that is. A run still in
|
||||||
|
* flight is left alone: its own terminal path computes the status.
|
||||||
|
*/
|
||||||
|
async function closeSettledRuns(runIds) {
|
||||||
|
for (const runId of runIds) {
|
||||||
|
const run = await runsDb.getById(runId)
|
||||||
|
if (!run || !runsDb.TERMINAL.includes(run.status)) continue
|
||||||
|
if ((await resourcesDb.unresolvedCount(runId)) === 0) {
|
||||||
|
await runsDb.setCleanupStatus(runId, 'complete', ['pending', 'incomplete'])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Ask every module that owns a live row. Core's own boot-time sweep. */
|
/** Ask every module that owns a live row. Core's own boot-time sweep. */
|
||||||
async function reconcileAll() {
|
async function reconcileAll() {
|
||||||
const owners = await resourcesDb.modulesWithLiveRows()
|
const owners = await resourcesDb.modulesWithLiveRows()
|
||||||
@@ -469,28 +518,11 @@ async function expireResource(owner, { kind, ref } = {}) {
|
|||||||
let expired = 0
|
let expired = 0
|
||||||
|
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
if (!(await resourcesDb.markExpired(row.id, 'the game ended it at its deadline'))) continue
|
if (!(await settleExpired(owner, row))) continue
|
||||||
expired += 1
|
expired += 1
|
||||||
runs.add(row.run_id)
|
runs.add(row.run_id)
|
||||||
await logDb.write({
|
|
||||||
runId: row.run_id,
|
|
||||||
kind: 'resource.expired',
|
|
||||||
detail: { module: owner, resource: `${row.kind}:${row.ref}` },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// A finished run whose last unresolved row this was has nothing left to clean
|
|
||||||
// up. The sweep would settle a `pending` one by itself, but not an
|
|
||||||
// `incomplete` one — that status takes a run out of the sweep's scan, and it
|
|
||||||
// would go on saying "not finished" about a ledger that is. A run still in
|
|
||||||
// flight is left alone: its own terminal path computes the status.
|
|
||||||
for (const runId of runs) {
|
|
||||||
const run = await runsDb.getById(runId)
|
|
||||||
if (!run || !runsDb.TERMINAL.includes(run.status)) continue
|
|
||||||
if ((await resourcesDb.unresolvedCount(runId)) === 0) {
|
|
||||||
await runsDb.setCleanupStatus(runId, 'complete', ['pending', 'incomplete'])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
await closeSettledRuns(runs)
|
||||||
|
|
||||||
return { expired }
|
return { expired }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
// DST gap shifts it, it is never rejected), so a schedule that validates here
|
// DST gap shifts it, it is never rejected), so a schedule that validates here
|
||||||
// computes there.
|
// computes there.
|
||||||
|
|
||||||
|
const crypto = require('crypto')
|
||||||
|
|
||||||
const registries = require('../modules/registries')
|
const registries = require('../modules/registries')
|
||||||
// For `priceOf` and `undeclaredDimensions` only — the save-time half of §F's
|
// For `priceOf` and `undeclaredDimensions` only — the save-time half of §F's
|
||||||
// fail-closed budget rule (Phase 7). Nothing here reaches the database:
|
// fail-closed budget rule (Phase 7). Nothing here reaches the database:
|
||||||
@@ -730,6 +732,31 @@ function publishable(spec) {
|
|||||||
return dormant.length ? { ok: false, dormant: [...new Set(dormant)] } : { ok: true, dormant: [] }
|
return dormant.length ? { ok: false, dormant: [...new Set(dormant)] } : { ok: true, dormant: [] }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** JSON with every object's keys sorted, so equal specs serialise equally. */
|
||||||
|
function canonical(value) {
|
||||||
|
if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`
|
||||||
|
if (value && typeof value === 'object') {
|
||||||
|
const keys = Object.keys(value).filter((k) => value[k] !== undefined).sort()
|
||||||
|
return `{${keys.map((k) => `${JSON.stringify(k)}:${canonical(value[k])}`).join(',')}}`
|
||||||
|
}
|
||||||
|
return JSON.stringify(value) ?? 'null'
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A spec's fingerprint: the sha256 of its canonical JSON (W5, Rust
|
||||||
|
* PLAN_LAST_FIXES).
|
||||||
|
*
|
||||||
|
* What lets a dry run that passed on a draft count for the version published
|
||||||
|
* from it. The draft is fingerprinted when the dry run passes and the version
|
||||||
|
* when it is published, both from `validate`'s output, so an edit in between is
|
||||||
|
* a different fingerprint and nothing carries over. Key order is not part of it:
|
||||||
|
* a spec that round-trips through the database with its keys reordered is the
|
||||||
|
* same plan.
|
||||||
|
*/
|
||||||
|
function fingerprint(spec) {
|
||||||
|
return crypto.createHash('sha256').update(canonical(spec)).digest('hex')
|
||||||
|
}
|
||||||
|
|
||||||
/** An empty, valid spec — what a newly created draft carries. */
|
/** An empty, valid spec — what a newly created draft carries. */
|
||||||
const emptySpec = () => ({
|
const emptySpec = () => ({
|
||||||
schedule: { kind: 'manual' },
|
schedule: { kind: 'manual' },
|
||||||
@@ -742,6 +769,7 @@ module.exports = {
|
|||||||
// 1.13.0): eventDefinitions.model `buildFromTemplate`.
|
// 1.13.0): eventDefinitions.model `buildFromTemplate`.
|
||||||
checkParams,
|
checkParams,
|
||||||
publishable,
|
publishable,
|
||||||
|
fingerprint,
|
||||||
actionIdsIn,
|
actionIdsIn,
|
||||||
emptySpec,
|
emptySpec,
|
||||||
defaultOnFailure,
|
defaultOnFailure,
|
||||||
|
|||||||
@@ -36,6 +36,26 @@ const authorize = require('./authorize')
|
|||||||
const settingsDb = require('../model/events/eventActionSettings.db')
|
const settingsDb = require('../model/events/eventActionSettings.db')
|
||||||
const registries = require('../modules/registries')
|
const registries = require('../modules/registries')
|
||||||
|
|
||||||
|
/** The most advice lines one step's dry run carries, and the longest one. */
|
||||||
|
const ADVICE_MAX = 10
|
||||||
|
const ADVICE_CHARS = 500
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A dry run's `detail.warnings`, as the lines a dry run shows: strings only,
|
||||||
|
* trimmed, the empty dropped, at most ten, each cut at 500 characters. Anything
|
||||||
|
* else a module put there is ignored rather than refused — advice that cannot be
|
||||||
|
* read is not a reason to fail a plan that would run.
|
||||||
|
*/
|
||||||
|
function adviceOf(detail) {
|
||||||
|
if (!detail || typeof detail !== 'object' || !Array.isArray(detail.warnings)) return []
|
||||||
|
return detail.warnings
|
||||||
|
.filter((w) => typeof w === 'string')
|
||||||
|
.map((w) => w.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
.slice(0, ADVICE_MAX)
|
||||||
|
.map((w) => (w.length > ADVICE_CHARS ? `${w.slice(0, ADVICE_CHARS - 1)}…` : w))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dry-run a spec.
|
* Dry-run a spec.
|
||||||
*
|
*
|
||||||
@@ -108,13 +128,21 @@ async function verifySpec(spec, { user = null, scope = '' } = {}) {
|
|||||||
)
|
)
|
||||||
if (result.outcome === 'retry' || result.outcome === 'terminal') {
|
if (result.outcome === 'retry' || result.outcome === 'terminal') {
|
||||||
findings.push({ ...where, level: 'error', code: 'refused', message: result.error })
|
findings.push({ ...where, level: 'error', code: 'refused', message: result.error })
|
||||||
} else if (result.actionVersionDrift) {
|
} else {
|
||||||
findings.push({
|
if (result.actionVersionDrift) {
|
||||||
...where,
|
findings.push({
|
||||||
level: 'warning',
|
...where,
|
||||||
code: 'version-drift',
|
level: 'warning',
|
||||||
message: `authored against version ${result.actionVersionDrift.authored}; ${step.actionId} is now version ${result.actionVersionDrift.registered}`,
|
code: 'version-drift',
|
||||||
})
|
message: `authored against version ${result.actionVersionDrift.authored}; ${step.actionId} is now version ${result.actionVersionDrift.registered}`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// MODULE_API 1.16.0: a module's ADVICE on a step that would run — the
|
||||||
|
// world as it stands now, which may change before the run does (Rust
|
||||||
|
// PLAN_REDESIGNS §11.4, D391). A warning, so it never fails the dry run.
|
||||||
|
for (const message of adviceOf(result.detail)) {
|
||||||
|
findings.push({ ...where, level: 'warning', code: 'advice', message })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,4 +178,4 @@ async function verifySpec(spec, { user = null, scope = '' } = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { verifySpec }
|
module.exports = { verifySpec, adviceOf }
|
||||||
|
|||||||
@@ -126,6 +126,18 @@ const markReady = (id, versionId, userId) =>
|
|||||||
[versionId, userId, id],
|
[versionId, userId, id],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Record a dry run that passed on the draft, with the fingerprint of the spec it
|
||||||
|
* passed on (W5). Publish reads it back through `getById`'s `d.*`.
|
||||||
|
*/
|
||||||
|
const markDraftVerified = (id, { at = new Date(), userId = null, hash }) =>
|
||||||
|
query(
|
||||||
|
`UPDATE event_definitions
|
||||||
|
SET draft_verified_at = ?, draft_verified_by = ?, draft_verified_hash = ?
|
||||||
|
WHERE id = ?`,
|
||||||
|
[at, userId, hash, id],
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Every definition the runner should expand a recurrence for (Phase 4).
|
* Every definition the runner should expand a recurrence for (Phase 4).
|
||||||
*
|
*
|
||||||
@@ -234,5 +246,6 @@ module.exports = {
|
|||||||
insert,
|
insert,
|
||||||
update,
|
update,
|
||||||
markReady,
|
markReady,
|
||||||
|
markDraftVerified,
|
||||||
archive,
|
archive,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ const spec = require('../../events/spec')
|
|||||||
const authorize = require('../../events/authorize')
|
const authorize = require('../../events/authorize')
|
||||||
const verifier = require('../../events/verify')
|
const verifier = require('../../events/verify')
|
||||||
const registries = require('../../modules/registries')
|
const registries = require('../../modules/registries')
|
||||||
|
const { isDemo } = require('../../demo/mode')
|
||||||
|
const { CODE: DEMO_LOCKED } = require('../../demo/locks')
|
||||||
const { slugify, uniqueSlug } = require('../teams/teamSlug')
|
const { slugify, uniqueSlug } = require('../teams/teamSlug')
|
||||||
const { cleanBody } = require('../../utils/sanitizeHtml')
|
const { cleanBody } = require('../../utils/sanitizeHtml')
|
||||||
const log = require('../../utils/logger')('events')
|
const log = require('../../utils/logger')('events')
|
||||||
@@ -181,6 +183,8 @@ async function create(input, userId, { role = null } = {}) {
|
|||||||
if (!result.ok) return result
|
if (!result.ok) return result
|
||||||
const floor = checkRoleFloor(result.definition.spec, role)
|
const floor = checkRoleFloor(result.definition.spec, role)
|
||||||
if (floor) return floor
|
if (floor) return floor
|
||||||
|
const refused = await checkDemoRefusals(result.definition.spec)
|
||||||
|
if (refused) return refused
|
||||||
const id = await db.insert({ ...result.definition, created_by: userId })
|
const id = await db.insert({ ...result.definition, created_by: userId })
|
||||||
return { ok: true, id, definition: await db.getById(id) }
|
return { ok: true, id, definition: await db.getById(id) }
|
||||||
}
|
}
|
||||||
@@ -203,6 +207,8 @@ async function save(id, input, userId, { role = null } = {}) {
|
|||||||
if (!result.ok) return result
|
if (!result.ok) return result
|
||||||
const floor = checkRoleFloor(result.definition.spec, role)
|
const floor = checkRoleFloor(result.definition.spec, role)
|
||||||
if (floor) return floor
|
if (floor) return floor
|
||||||
|
const refused = await checkDemoRefusals(result.definition.spec)
|
||||||
|
if (refused) return refused
|
||||||
await db.update(id, { ...result.definition, updated_by: userId })
|
await db.update(id, { ...result.definition, updated_by: userId })
|
||||||
return { ok: true, id, definition: await db.getById(id) }
|
return { ok: true, id, definition: await db.getById(id) }
|
||||||
}
|
}
|
||||||
@@ -228,6 +234,11 @@ async function publish(id, userId) {
|
|||||||
})
|
})
|
||||||
if (!checked.ok) return { ok: false, status: 400, errors: checked.errors }
|
if (!checked.ok) return { ok: false, status: 400, errors: checked.errors }
|
||||||
|
|
||||||
|
// Asked again here, as the registries are: a draft saved before the module's
|
||||||
|
// list grew must not become a version that runs (DM18).
|
||||||
|
const refused = await checkDemoRefusals(checked.spec)
|
||||||
|
if (refused) return refused
|
||||||
|
|
||||||
const publishable = spec.publishable(checked.spec)
|
const publishable = spec.publishable(checked.spec)
|
||||||
if (!publishable.ok) {
|
if (!publishable.ok) {
|
||||||
return {
|
return {
|
||||||
@@ -249,6 +260,16 @@ async function publish(id, userId) {
|
|||||||
const versionId = await versionsDb.insert(id, version, checked.spec, userId)
|
const versionId = await versionsDb.insert(id, version, checked.spec, userId)
|
||||||
await db.markReady(id, versionId, userId)
|
await db.markReady(id, versionId, userId)
|
||||||
|
|
||||||
|
// A dry run that passed on this exact draft counts for the version made from
|
||||||
|
// it (W5), stamped with that pass's reviewer and time rather than the
|
||||||
|
// publisher's and now: "who last looked at this before it ran unattended" is
|
||||||
|
// the person who ran the check. Any edit since is a different fingerprint.
|
||||||
|
const verified = Boolean(
|
||||||
|
existing.draft_verified_hash &&
|
||||||
|
existing.draft_verified_hash === spec.fingerprint(checked.spec) &&
|
||||||
|
(await versionsDb.markVerified(versionId, existing.draft_verified_by || null, existing.draft_verified_at || new Date())),
|
||||||
|
)
|
||||||
|
|
||||||
// Occurrences already materialised ahead of their instant move to the new
|
// Occurrences already materialised ahead of their instant move to the new
|
||||||
// version; ones that have begun do not (org lead, 2026-09-02). Logged per run
|
// version; ones that have begun do not (org lead, 2026-09-02). Logged per run
|
||||||
// rather than only counted, because "which version did this run actually use"
|
// rather than only counted, because "which version did this run actually use"
|
||||||
@@ -270,9 +291,18 @@ async function publish(id, userId) {
|
|||||||
by: userId,
|
by: userId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
// The held occurrence is now going to start, and the line saying why
|
||||||
|
// belongs on it, as it does when the version is dry-run by hand.
|
||||||
|
if (verified) {
|
||||||
|
await logDb.write({
|
||||||
|
runId: run.id,
|
||||||
|
kind: 'version.verified',
|
||||||
|
detail: { versionId, version, by: existing.draft_verified_by || null, fromDraft: true },
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ok: true, versionId, version, repinned, definition: await db.getById(id) }
|
return { ok: true, versionId, version, repinned, verified, definition: await db.getById(id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -346,6 +376,37 @@ function checkRoleFloor(specValue, role) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The public demo's save-time refusal (MODULE_API 1.19.0, DEMO_MODE.md §3.4,
|
||||||
|
* DM18): each step whose action declares `demoRefuses(params)` is asked, and
|
||||||
|
* the first sentence back refuses the whole save `403 DEMO_LOCKED`. Null off
|
||||||
|
* the demo, where nothing is asked.
|
||||||
|
*
|
||||||
|
* A hook that throws refuses too, with core's sentence: this is a lock, and a
|
||||||
|
* lock that cannot decide fails closed, as the route lock does (§3.3).
|
||||||
|
*/
|
||||||
|
async function checkDemoRefusals(specValue) {
|
||||||
|
if (!isDemo()) return null
|
||||||
|
for (const phase of specValue?.phases || []) {
|
||||||
|
for (const step of phase.steps || []) {
|
||||||
|
const action = registries.eventAction(step.actionId)
|
||||||
|
if (!action || !action.demoRefuses) continue
|
||||||
|
let said
|
||||||
|
try {
|
||||||
|
said = await action.demoRefuses(step.params || {})
|
||||||
|
} catch (err) {
|
||||||
|
log.error('demoRefuses failed', { action: action.id, message: err.message })
|
||||||
|
said = `"${action.label}" could not be checked, so it is turned off on the demo site.`
|
||||||
|
}
|
||||||
|
if (typeof said === 'string' && said.trim()) {
|
||||||
|
const message = said.trim()
|
||||||
|
return { ok: false, status: 403, code: DEMO_LOCKED, message, errors: [message] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dry-run a definition, and record the pass when there is a version to record it
|
* Dry-run a definition, and record the pass when there is a version to record it
|
||||||
* on (Phase 6).
|
* on (Phase 6).
|
||||||
@@ -373,6 +434,19 @@ async function verify(id, user) {
|
|||||||
|
|
||||||
const report = await verifier.verifySpec(target, { user })
|
const report = await verifier.verifySpec(target, { user })
|
||||||
|
|
||||||
|
// A pass on the draft is kept with the fingerprint of the spec it passed on,
|
||||||
|
// for publish to compare (W5). Fingerprinted from `validate`'s output, as
|
||||||
|
// publish fingerprints the spec it freezes; a draft that no longer validates
|
||||||
|
// could not be published anyway, so there is nothing to keep.
|
||||||
|
let draftRecorded = false
|
||||||
|
if (!version && report.ok) {
|
||||||
|
const checked = spec.validate(existing.spec, { knownActionIds: spec.actionIdsIn(existing.spec) })
|
||||||
|
if (checked.ok) {
|
||||||
|
await db.markDraftVerified(id, { userId: user?.id || null, hash: spec.fingerprint(checked.spec) })
|
||||||
|
draftRecorded = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (version && report.ok) {
|
if (version && report.ok) {
|
||||||
await versionsDb.markVerified(version.id, user?.id || null)
|
await versionsDb.markVerified(version.id, user?.id || null)
|
||||||
// Written to every run already pinned to this version, because that is where
|
// Written to every run already pinned to this version, because that is where
|
||||||
@@ -397,6 +471,9 @@ async function verify(id, user) {
|
|||||||
versionId: version?.id || null,
|
versionId: version?.id || null,
|
||||||
version: version?.version || null,
|
version: version?.version || null,
|
||||||
recorded: Boolean(version && report.ok),
|
recorded: Boolean(version && report.ok),
|
||||||
|
// A pass on the draft, kept so that publishing this spec unchanged makes a
|
||||||
|
// verified version (W5).
|
||||||
|
draftRecorded,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,6 +587,7 @@ module.exports = {
|
|||||||
archive,
|
archive,
|
||||||
verify,
|
verify,
|
||||||
checkRoleFloor,
|
checkRoleFloor,
|
||||||
|
checkDemoRefusals,
|
||||||
isTimezone,
|
isTimezone,
|
||||||
MIN_GRACE_SECONDS,
|
MIN_GRACE_SECONDS,
|
||||||
MAX_GRACE_SECONDS,
|
MAX_GRACE_SECONDS,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const { query } = require('../../utils/db')
|
|||||||
const COLUMNS = `
|
const COLUMNS = `
|
||||||
id, target_type, target_id, team_id, reporter_user_id, reporter_username,
|
id, target_type, target_id, team_id, reporter_user_id, reporter_username,
|
||||||
reason, detail, status, handled_by, handled_username, handled_note, handled_at,
|
reason, detail, status, handled_by, handled_username, handled_note, handled_at,
|
||||||
created_at`
|
created_at, snapshot, actioned_with`
|
||||||
|
|
||||||
const OPEN_STATUSES = ['open', 'reviewing']
|
const OPEN_STATUSES = ['open', 'reviewing']
|
||||||
|
|
||||||
@@ -28,13 +28,16 @@ const OPEN_STATUSES = ['open', 'reviewing']
|
|||||||
* comes back as a clean `null` so the caller can answer 409 without knowing what
|
* comes back as a clean `null` so the caller can answer 409 without knowing what
|
||||||
* a MySQL error code looks like.
|
* a MySQL error code looks like.
|
||||||
*/
|
*/
|
||||||
async function insert({ targetType, targetId, teamId, reporterUserId, reporterUsername, reason, detail }) {
|
async function insert({ targetType, targetId, teamId, reporterUserId, reporterUsername, reason, detail, snapshot }) {
|
||||||
try {
|
try {
|
||||||
const res = await query(
|
const res = await query(
|
||||||
`INSERT INTO content_reports
|
`INSERT INTO content_reports
|
||||||
(target_type, target_id, team_id, reporter_user_id, reporter_username, reason, detail)
|
(target_type, target_id, team_id, reporter_user_id, reporter_username, reason, detail, snapshot)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
[targetType, targetId, teamId ?? null, reporterUserId, reporterUsername, reason, detail ?? null],
|
[
|
||||||
|
targetType, targetId, teamId ?? null, reporterUserId, reporterUsername, reason, detail ?? null,
|
||||||
|
snapshot ? JSON.stringify(snapshot) : null,
|
||||||
|
],
|
||||||
)
|
)
|
||||||
return res.insertId
|
return res.insertId
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -93,13 +96,19 @@ async function openCount() {
|
|||||||
* `handled_*` is stamped for every status including `reviewing`, so "who has this"
|
* `handled_*` is stamped for every status including `reviewing`, so "who has this"
|
||||||
* is answerable while it is in progress and not only after it is closed — that is
|
* is answerable while it is in progress and not only after it is closed — that is
|
||||||
* what stops two staffers working the same report.
|
* what stops two staffers working the same report.
|
||||||
|
*
|
||||||
|
* `actionedWith` is written only when given (the queue's "Hide for everyone"):
|
||||||
|
* a later status change by hand records a new decision, and does not un-say
|
||||||
|
* that the item was hidden.
|
||||||
*/
|
*/
|
||||||
async function handle(id, { status, handledBy, handledUsername, note }) {
|
async function handle(id, { status, handledBy, handledUsername, note, actionedWith }) {
|
||||||
|
const withAction = actionedWith !== undefined
|
||||||
const res = await query(
|
const res = await query(
|
||||||
`UPDATE content_reports
|
`UPDATE content_reports
|
||||||
SET status = ?, handled_by = ?, handled_username = ?, handled_note = ?, handled_at = NOW()
|
SET status = ?, handled_by = ?, handled_username = ?, handled_note = ?, handled_at = NOW()
|
||||||
|
${withAction ? ', actioned_with = ?' : ''}
|
||||||
WHERE id = ?`,
|
WHERE id = ?`,
|
||||||
[status, handledBy, handledUsername, note ?? null, id],
|
[status, handledBy, handledUsername, note ?? null, ...(withAction ? [actionedWith] : []), id],
|
||||||
)
|
)
|
||||||
return res.affectedRows > 0
|
return res.affectedRows > 0
|
||||||
}
|
}
|
||||||
@@ -114,7 +123,7 @@ async function handle(id, { status, handledBy, handledUsername, note }) {
|
|||||||
async function threadsByIds(ids) {
|
async function threadsByIds(ids) {
|
||||||
if (!ids.length) return []
|
if (!ids.length) return []
|
||||||
return query(
|
return query(
|
||||||
`SELECT id, team_id, title, type, status, created_username FROM team_forum_threads
|
`SELECT id, team_id, title, type, status, created_by, created_username FROM team_forum_threads
|
||||||
WHERE id IN (${ids.map(() => '?').join(',')})`,
|
WHERE id IN (${ids.map(() => '?').join(',')})`,
|
||||||
ids,
|
ids,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -24,10 +24,24 @@
|
|||||||
// participant in one Team could file reports carrying another Team's id, and the
|
// participant in one Team could file reports carrying another Team's id, and the
|
||||||
// queue's per-Team filter would quietly be lying.
|
// queue's per-Team filter would quietly be lying.
|
||||||
|
|
||||||
|
//
|
||||||
|
// **Since 1.21.0 (USER_SAFETY.md §4.1) a target can be a module's** — a Rust chat
|
||||||
|
// line is `rust.chat` — and every report stores a `snapshot` of what the item
|
||||||
|
// said when it was reported. Who may see the item is now asked of one resolver
|
||||||
|
// (`model/safety/targets.js`) for every type, forum or module, so reaching
|
||||||
|
// `file()` through `/player/reports` without a Team is as safe as reaching it
|
||||||
|
// through a Team's forum route.
|
||||||
|
|
||||||
const reportsDb = require('./contentReports.db')
|
const reportsDb = require('./contentReports.db')
|
||||||
const forumDb = require('../teams/teamForum.db')
|
const forumDb = require('../teams/teamForum.db')
|
||||||
|
const forum = require('../teams/teamForum.model')
|
||||||
|
const targets = require('../safety/targets')
|
||||||
|
const registries = require('../../modules/registries')
|
||||||
|
const { displayAuthor, hasActor } = require('../../utils/displayAuthor')
|
||||||
|
|
||||||
const TARGET_TYPES = ['team_forum_thread', 'team_forum_post', 'team_forum_upload']
|
// Core's own types — what the forum's report route accepts. Module types are
|
||||||
|
// registered (registries.reportTarget) and checked by `targets.isReportable`.
|
||||||
|
const TARGET_TYPES = targets.FORUM_TYPES
|
||||||
const REASONS = ['spam', 'abuse', 'sexual', 'illegal', 'impersonation', 'other']
|
const REASONS = ['spam', 'abuse', 'sexual', 'illegal', 'impersonation', 'other']
|
||||||
const STATUSES = ['open', 'reviewing', 'actioned', 'dismissed']
|
const STATUSES = ['open', 'reviewing', 'actioned', 'dismissed']
|
||||||
|
|
||||||
@@ -67,6 +81,23 @@ async function targetTeamId(targetType, targetId) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What `content_reports.snapshot` keeps: the item as the reporter saw it, with
|
||||||
|
* its author. The author's account id is kept beside the name so the queue can
|
||||||
|
* put the name through displayAuthor's rule like every other snapshot.
|
||||||
|
*/
|
||||||
|
function snapshotOf(item) {
|
||||||
|
return {
|
||||||
|
...item.snapshot,
|
||||||
|
module: item.module || null,
|
||||||
|
author: {
|
||||||
|
name: item.author.name,
|
||||||
|
userId: item.author.userId,
|
||||||
|
identity: item.author.identity,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File a report.
|
* File a report.
|
||||||
*
|
*
|
||||||
@@ -75,27 +106,30 @@ async function targetTeamId(targetType, targetId) {
|
|||||||
* reports twice because nothing seemed to happen deserves to be told the first
|
* reports twice because nothing seemed to happen deserves to be told the first
|
||||||
* one is already in the queue.
|
* one is already in the queue.
|
||||||
*/
|
*/
|
||||||
async function file({ team, actor, targetType, targetId, reason, detail }) {
|
async function file({ team = null, actor, targetType, targetId, reason, detail }) {
|
||||||
if (!TARGET_TYPES.includes(targetType)) {
|
if (!targets.isReportable(targetType)) {
|
||||||
return { ok: false, status: 400, error: 'Unknown report target' }
|
return { ok: false, status: 400, error: 'Unknown report target' }
|
||||||
}
|
}
|
||||||
if (!REASONS.includes(reason)) {
|
if (!REASONS.includes(reason)) {
|
||||||
return { ok: false, status: 400, error: 'Unknown report reason' }
|
return { ok: false, status: 400, error: 'Unknown report reason' }
|
||||||
}
|
}
|
||||||
|
|
||||||
const owner = await targetTeamId(targetType, targetId)
|
// The reporter must be able to see what they report — the same resolver a
|
||||||
if (owner == null || owner !== team.id) {
|
// block uses, so "not there" and "not yours to see" are one answer (404).
|
||||||
return { ok: false, status: 404, error: 'Not found' }
|
const item = await targets.resolve({ targetType, targetId, viewer: actor })
|
||||||
}
|
if (!item) return { ok: false, status: 404, error: 'Not found' }
|
||||||
|
// Through a Team's forum route, the target must be in THAT Team.
|
||||||
|
if (team && item.teamId !== team.id) return { ok: false, status: 404, error: 'Not found' }
|
||||||
|
|
||||||
const id = await reportsDb.insert({
|
const id = await reportsDb.insert({
|
||||||
targetType,
|
targetType,
|
||||||
targetId,
|
targetId,
|
||||||
teamId: team.id,
|
teamId: item.teamId,
|
||||||
reporterUserId: actor.id,
|
reporterUserId: actor.id,
|
||||||
reporterUsername: actor.username,
|
reporterUsername: actor.username,
|
||||||
reason,
|
reason,
|
||||||
detail,
|
detail,
|
||||||
|
snapshot: snapshotOf(item),
|
||||||
})
|
})
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
return { ok: false, status: 409, error: 'You have already reported this. Staff are looking at it.' }
|
return { ok: false, status: 409, error: 'You have already reported this. Staff are looking at it.' }
|
||||||
@@ -116,7 +150,7 @@ async function file({ team, actor, targetType, targetId, reason, detail }) {
|
|||||||
* hide the pattern of a member deleting their own content the moment it is
|
* hide the pattern of a member deleting their own content the moment it is
|
||||||
* reported.
|
* reported.
|
||||||
*/
|
*/
|
||||||
async function queue({ status, teamId, limit, offset } = {}) {
|
async function queue({ status, teamId, limit, offset, viewer = null } = {}) {
|
||||||
const rows = await reportsDb.list({ status, teamId, limit, offset })
|
const rows = await reportsDb.list({ status, teamId, limit, offset })
|
||||||
if (!rows.length) return []
|
if (!rows.length) return []
|
||||||
|
|
||||||
@@ -132,9 +166,18 @@ async function queue({ status, teamId, limit, offset } = {}) {
|
|||||||
const postMap = byId(posts)
|
const postMap = byId(posts)
|
||||||
const uploadMap = byId(uploads)
|
const uploadMap = byId(uploads)
|
||||||
|
|
||||||
return rows.map((r) => ({ ...publicReport(r), target: describeTarget(r, { threadMap, postMap, uploadMap }) }))
|
return rows.map((r) => ({
|
||||||
|
...publicReport(r, viewer),
|
||||||
|
target: describeTarget(r, { threadMap, postMap, uploadMap }, viewer),
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A snapshot pair through displayAuthor's rule (ACCOUNT_DELETION.md AD5, AD6).
|
||||||
|
// The queue is staff-only by its route, so a staff viewer sees the stored name
|
||||||
|
// and the `*Deleted` flag marks it; the rule is still asked rather than assumed,
|
||||||
|
// so this file cannot become the place a member's view leaks a deleted name.
|
||||||
|
const shown = (userId, username, viewer) => displayAuthor({ userId, username }, viewer)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reported content, resolved.
|
* The reported content, resolved.
|
||||||
*
|
*
|
||||||
@@ -144,29 +187,33 @@ async function queue({ status, teamId, limit, offset } = {}) {
|
|||||||
* than as an explicit null, and the queue's own contract says nullable. A client
|
* than as an explicit null, and the queue's own contract says nullable. A client
|
||||||
* distinguishing "gone" from "not resolved yet" would get it wrong.
|
* distinguishing "gone" from "not resolved yet" would get it wrong.
|
||||||
*/
|
*/
|
||||||
function describeTarget(report, { threadMap, postMap, uploadMap }) {
|
function describeTarget(report, { threadMap, postMap, uploadMap }, viewer = null) {
|
||||||
const id = Number(report.target_id)
|
const id = Number(report.target_id)
|
||||||
if (report.target_type === 'team_forum_thread') {
|
if (report.target_type === 'team_forum_thread') {
|
||||||
const t = threadMap.get(id)
|
const t = threadMap.get(id)
|
||||||
if (!t) return null
|
if (!t) return null
|
||||||
|
const author = shown(t.created_by, t.created_username, viewer)
|
||||||
return {
|
return {
|
||||||
kind: 'thread',
|
kind: 'thread',
|
||||||
threadId: t.id,
|
threadId: t.id,
|
||||||
title: t.title,
|
title: t.title,
|
||||||
type: t.type,
|
type: t.type,
|
||||||
status: t.status,
|
status: t.status,
|
||||||
author: t.created_username,
|
author: author.name,
|
||||||
|
authorDeleted: author.deleted,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (report.target_type === 'team_forum_post') {
|
if (report.target_type === 'team_forum_post') {
|
||||||
const p = postMap.get(id)
|
const p = postMap.get(id)
|
||||||
if (!p) return null
|
if (!p) return null
|
||||||
|
const author = shown(p.author_user_id, p.author_username, viewer)
|
||||||
return {
|
return {
|
||||||
kind: 'post',
|
kind: 'post',
|
||||||
postId: p.id,
|
postId: p.id,
|
||||||
threadId: p.thread_id,
|
threadId: p.thread_id,
|
||||||
threadTitle: p.thread_title,
|
threadTitle: p.thread_title,
|
||||||
author: p.author_username,
|
author: author.name,
|
||||||
|
authorDeleted: author.deleted,
|
||||||
status: p.status,
|
status: p.status,
|
||||||
excerpt: excerpt(p.body_html),
|
excerpt: excerpt(p.body_html),
|
||||||
createdAt: p.created_at,
|
createdAt: p.created_at,
|
||||||
@@ -178,11 +225,13 @@ function describeTarget(report, { threadMap, postMap, uploadMap }) {
|
|||||||
// §5.6's fourth rule: uploader, size and the SNIFFED type, without hunting.
|
// §5.6's fourth rule: uploader, size and the SNIFFED type, without hunting.
|
||||||
// This is the payoff for §5.5.4's attribution table being load-bearing rather
|
// This is the payoff for §5.5.4's attribution table being load-bearing rather
|
||||||
// than bookkeeping.
|
// than bookkeeping.
|
||||||
|
const uploader = shown(u.uploader_user_id, u.uploader_username, viewer)
|
||||||
return {
|
return {
|
||||||
kind: 'upload',
|
kind: 'upload',
|
||||||
uploadId: u.id,
|
uploadId: u.id,
|
||||||
postId: u.post_id,
|
postId: u.post_id,
|
||||||
uploader: u.uploader_username,
|
uploader: uploader.name,
|
||||||
|
uploaderDeleted: uploader.deleted,
|
||||||
filename: u.filename,
|
filename: u.filename,
|
||||||
url: `/uploads/${u.filename}`,
|
url: `/uploads/${u.filename}`,
|
||||||
mimetype: u.mimetype,
|
mimetype: u.mimetype,
|
||||||
@@ -191,23 +240,86 @@ function describeTarget(report, { threadMap, postMap, uploadMap }) {
|
|||||||
deleted: u.deleted_at != null,
|
deleted: u.deleted_at != null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// A module's target (1.21.0). Core cannot read the module's rows, and does
|
||||||
|
// not need to: the snapshot taken when the report was filed is the target as
|
||||||
|
// the reporter saw it, and it outlives the module pruning its event log.
|
||||||
|
const target = registries.reportTarget(report.target_type)
|
||||||
|
const snap = parseSnapshot(report.snapshot)
|
||||||
|
if (target && snap) {
|
||||||
|
return {
|
||||||
|
kind: 'module',
|
||||||
|
module: target.owner,
|
||||||
|
label: target.label,
|
||||||
|
text: snap.text || null,
|
||||||
|
title: snap.title || null,
|
||||||
|
at: snap.at || null,
|
||||||
|
where: snap.where || {},
|
||||||
|
}
|
||||||
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
function publicReport(row) {
|
function parseSnapshot(raw) {
|
||||||
|
if (!raw) return null
|
||||||
|
if (typeof raw === 'object') return raw
|
||||||
|
try {
|
||||||
|
return JSON.parse(raw)
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The stored snapshot, for one viewer. The author's name goes through
|
||||||
|
* displayAuthor's rule like every other snapshot in the row; a game identity is
|
||||||
|
* staff's to see, and the queue is staff-only by its route.
|
||||||
|
*/
|
||||||
|
function publicSnapshot(raw, viewer) {
|
||||||
|
const snap = parseSnapshot(raw)
|
||||||
|
if (!snap) return null
|
||||||
|
const a = snap.author || {}
|
||||||
|
// An author with no account at all (an unlinked chat speaker) is not a deleted
|
||||||
|
// account: their name is the in-game one and shows as it is.
|
||||||
|
const author = a.userId == null && a.identity
|
||||||
|
? { name: a.name || null, deleted: false }
|
||||||
|
: displayAuthor({ userId: a.userId ?? null, username: a.name }, viewer)
|
||||||
|
return {
|
||||||
|
label: snap.label || null,
|
||||||
|
title: snap.title || null,
|
||||||
|
text: snap.text || null,
|
||||||
|
at: snap.at || null,
|
||||||
|
where: snap.where || {},
|
||||||
|
module: snap.module || null,
|
||||||
|
author: author.name,
|
||||||
|
authorDeleted: author.deleted,
|
||||||
|
authorIdentity: a.identity || null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function publicReport(row, viewer = null) {
|
||||||
|
const reporter = shown(row.reporter_user_id, row.reporter_username, viewer)
|
||||||
|
// Nobody has handled an open report, which is not the same as a deleted
|
||||||
|
// handler: only a pair that names someone goes through the rule.
|
||||||
|
const handler = hasActor(row.handled_by, row.handled_username)
|
||||||
|
? shown(row.handled_by, row.handled_username, viewer)
|
||||||
|
: null
|
||||||
return {
|
return {
|
||||||
id: row.id,
|
id: row.id,
|
||||||
targetType: row.target_type,
|
targetType: row.target_type,
|
||||||
targetId: Number(row.target_id),
|
targetId: Number(row.target_id),
|
||||||
teamId: row.team_id,
|
teamId: row.team_id,
|
||||||
reporter: row.reporter_username || '[deleted account]',
|
reporter: reporter.name,
|
||||||
reporterDeleted: row.reporter_user_id == null,
|
reporterDeleted: reporter.deleted,
|
||||||
reason: row.reason,
|
reason: row.reason,
|
||||||
detail: row.detail,
|
detail: row.detail,
|
||||||
status: row.status,
|
status: row.status,
|
||||||
handledBy: row.handled_username,
|
handledBy: handler ? handler.name : null,
|
||||||
|
handledByDeleted: handler ? handler.deleted : false,
|
||||||
handledNote: row.handled_note,
|
handledNote: row.handled_note,
|
||||||
handledAt: row.handled_at,
|
handledAt: row.handled_at,
|
||||||
|
actionedWith: row.actioned_with || null,
|
||||||
|
// Reports filed before 1.21.0 have none.
|
||||||
|
snapshot: publicSnapshot(row.snapshot, viewer),
|
||||||
createdAt: row.created_at,
|
createdAt: row.created_at,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,7 +338,85 @@ async function handle({ id, actor, status, note }) {
|
|||||||
handledUsername: actor.username,
|
handledUsername: actor.username,
|
||||||
note,
|
note,
|
||||||
})
|
})
|
||||||
return { ok: true, report: publicReport(await reportsDb.byId(id)) }
|
return { ok: true, report: publicReport(await reportsDb.byId(id), actor) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Hide for everyone" from the queue (USER_SAFETY.md §4.1, S3, S10). Staff-only
|
||||||
|
* by its route.
|
||||||
|
*
|
||||||
|
* The one queue action that DOES something to the content — which is why it is
|
||||||
|
* its own verb and not a status. It goes through the content's own hide, so
|
||||||
|
* nothing new can hide anything: a forum thread or post through the forum's
|
||||||
|
* moderation, recorded in its ledger as a staff action like a hide from the
|
||||||
|
* forum's own menu; a module's item through the module's `hide`. Then the
|
||||||
|
* report is actioned with `actioned_with = 'hide'`, so the queue says what was
|
||||||
|
* done and not only that something was decided.
|
||||||
|
*
|
||||||
|
* Undoing it is not here: the hidden item is still shown to staff, marked, where
|
||||||
|
* it lives (S10), and its own menu unhides it.
|
||||||
|
*
|
||||||
|
* Uploads cannot be hidden: an upload is shown inside a post, and hiding that
|
||||||
|
* post is the act.
|
||||||
|
*/
|
||||||
|
async function hideForEveryone({ id, actor, note }) {
|
||||||
|
const report = await reportsDb.byId(id)
|
||||||
|
if (!report) return { ok: false, status: 404, error: 'Report not found' }
|
||||||
|
const type = report.target_type
|
||||||
|
const targetId = Number(report.target_id)
|
||||||
|
|
||||||
|
if (type === 'team_forum_thread' || type === 'team_forum_post') {
|
||||||
|
const team = await forumTeamOf(type, targetId)
|
||||||
|
if (!team) return { ok: false, status: 404, error: 'That item no longer exists' }
|
||||||
|
const moderate = type === 'team_forum_thread' ? forum.moderateThread : forum.moderatePost
|
||||||
|
const result = await moderate({
|
||||||
|
team,
|
||||||
|
...(type === 'team_forum_thread' ? { threadId: targetId } : { postId: targetId }),
|
||||||
|
action: 'hide',
|
||||||
|
actor,
|
||||||
|
actorRole: 'staff',
|
||||||
|
reason: `Report #${id}`,
|
||||||
|
})
|
||||||
|
if (!result.ok) return result
|
||||||
|
} else {
|
||||||
|
const target = registries.reportTarget(type)
|
||||||
|
if (!target) {
|
||||||
|
return { ok: false, status: 400, error: type === 'team_forum_upload'
|
||||||
|
? 'An upload is hidden by hiding the post it is in'
|
||||||
|
: 'That kind of item cannot be hidden from here' }
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await targets.withTimeout(
|
||||||
|
() => target.hide({ targetId, actor: Object.freeze({ id: actor.id, username: actor.username, role: actor.role }) }),
|
||||||
|
targets.MODULE_TIMEOUT_MS,
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
return { ok: false, status: 503, error: 'The game module did not answer. Try again in a moment.' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await reportsDb.handle(id, {
|
||||||
|
status: 'actioned',
|
||||||
|
handledBy: actor.id,
|
||||||
|
handledUsername: actor.username,
|
||||||
|
note,
|
||||||
|
actionedWith: 'hide',
|
||||||
|
})
|
||||||
|
return { ok: true, report: publicReport(await reportsDb.byId(id), actor), teamId: report.team_id }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The Team a forum thread or post is in, by id — for the queue, which has no slug. */
|
||||||
|
async function forumTeamOf(type, targetId) {
|
||||||
|
let threadId = targetId
|
||||||
|
if (type === 'team_forum_post') {
|
||||||
|
const post = await forumDb.postById(targetId)
|
||||||
|
if (!post) return null
|
||||||
|
threadId = post.thread_id
|
||||||
|
}
|
||||||
|
const thread = await forumDb.threadById(threadId)
|
||||||
|
if (!thread) return null
|
||||||
|
// The forum model wants the Team row only for its id; the ledger names it.
|
||||||
|
return { id: thread.team_id }
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -237,6 +427,7 @@ module.exports = {
|
|||||||
file,
|
file,
|
||||||
queue,
|
queue,
|
||||||
handle,
|
handle,
|
||||||
|
hideForEveryone,
|
||||||
openCount: reportsDb.openCount,
|
openCount: reportsDb.openCount,
|
||||||
publicReport,
|
publicReport,
|
||||||
targetTeamId,
|
targetTeamId,
|
||||||
|
|||||||
217
server/src/model/safety/targets.js
Normal file
217
server/src/model/safety/targets.js
Normal file
@@ -0,0 +1,217 @@
|
|||||||
|
// ── What a reported, hidden or blocked item IS, for one reader ─────────────
|
||||||
|
//
|
||||||
|
// USER_SAFETY.md §4.1. Every report, every "Block author" and the Reports
|
||||||
|
// queue's "Hide for everyone" starts by asking one question about an item: what
|
||||||
|
// is it, who wrote it, and may this reader see it at all? This file answers it
|
||||||
|
// once, for core's forum types and for every module's registered types.
|
||||||
|
//
|
||||||
|
// **A reader who cannot see the item gets `null`, the same answer as an item
|
||||||
|
// that is not there.** Telling them apart would let anyone ask whether thread
|
||||||
|
// 812 exists in a private Team's forum, or who said chat line 4410 on a server
|
||||||
|
// whose presence is hidden from them (§5.5.1 of TEAMS.md, and the reason the
|
||||||
|
// forum answers 404 rather than 403).
|
||||||
|
//
|
||||||
|
// Core's forum types are answered here directly; a module's are answered by its
|
||||||
|
// own `snapshot`, under a time limit, because the module owns the content.
|
||||||
|
|
||||||
|
const forumDb = require('../teams/teamForum.db')
|
||||||
|
const teamsDb = require('../teams/teams.db')
|
||||||
|
const access = require('../teams/teamAccess.model')
|
||||||
|
const forumSettings = require('../teams/teamForumSettings.model')
|
||||||
|
const registries = require('../../modules/registries')
|
||||||
|
const log = require('../../utils/logger')('safety')
|
||||||
|
|
||||||
|
// Report types core owns. Uploads can be reported (the forum's own route takes
|
||||||
|
// them) but not hidden or blocked from: an upload is shown inside a post, so
|
||||||
|
// hiding the post, or blocking its author, is what hides it.
|
||||||
|
const FORUM_TYPES = ['team_forum_thread', 'team_forum_post', 'team_forum_upload']
|
||||||
|
const FORUM_HIDEABLE = ['team_forum_thread', 'team_forum_post']
|
||||||
|
|
||||||
|
// The forum's own "staff": who may moderate there (teamForum.controller.js).
|
||||||
|
const FORUM_STAFF_ROLES = ['admin', 'moderator']
|
||||||
|
|
||||||
|
const MODULE_TIMEOUT_MS = 5_000
|
||||||
|
const TEXT_CHARS = 500
|
||||||
|
|
||||||
|
const excerpt = (html) => String(html || '')
|
||||||
|
.replace(/<[^>]*>/g, ' ')
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
.trim()
|
||||||
|
.slice(0, TEXT_CHARS)
|
||||||
|
|
||||||
|
const clip = (value, n) => (value == null ? null : String(value).slice(0, n))
|
||||||
|
|
||||||
|
function withTimeout(fn, ms) {
|
||||||
|
let timer
|
||||||
|
const deadline = new Promise((_, reject) => {
|
||||||
|
timer = setTimeout(() => reject(new Error(`no answer within ${ms} ms`)), ms)
|
||||||
|
})
|
||||||
|
return Promise.race([Promise.resolve().then(fn), deadline]).finally(() => clearTimeout(timer))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Is this a type anybody can report — core's or a started module's? */
|
||||||
|
function isReportable(type) {
|
||||||
|
return FORUM_TYPES.includes(type) || registries.reportTarget(type) != null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Is this a type a member can hide for themself, or block the author of? */
|
||||||
|
function isHideable(type) {
|
||||||
|
return FORUM_HIDEABLE.includes(type) || registries.reportTarget(type) != null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The forum that holds a thread, and whether this reader may see it and
|
||||||
|
* moderate in it. Null when the forum is off, the Team is gone or the reader
|
||||||
|
* has no access — the forum controller's `resolveForum`, for a target found by
|
||||||
|
* id rather than reached through a slug.
|
||||||
|
*/
|
||||||
|
async function forumFor(teamId, viewer) {
|
||||||
|
if (!(await forumSettings.forumsEnabled())) return null
|
||||||
|
const team = await teamsDb.findById(teamId)
|
||||||
|
if (!team) return null
|
||||||
|
const resolved = await access.forumAccess(team.id, viewer.id)
|
||||||
|
const staff = FORUM_STAFF_ROLES.includes(viewer.role)
|
||||||
|
if (!resolved.allowed && !staff) return null
|
||||||
|
return { team, canModerate: resolved.isLeader || staff }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A forum thread, post or upload, for one reader. */
|
||||||
|
async function resolveForum(type, id, viewer) {
|
||||||
|
if (type === 'team_forum_thread') {
|
||||||
|
const t = await forumDb.threadById(id)
|
||||||
|
if (!t) return null
|
||||||
|
const forum = await forumFor(t.team_id, viewer)
|
||||||
|
if (!forum) return null
|
||||||
|
if (t.status !== 'visible' && !forum.canModerate) return null
|
||||||
|
const first = await forumDb.firstPostOf(t.id)
|
||||||
|
return {
|
||||||
|
type,
|
||||||
|
targetId: id,
|
||||||
|
teamId: t.team_id,
|
||||||
|
team: forum.team,
|
||||||
|
author: { userId: t.created_by ?? null, name: t.created_username || null, identity: null },
|
||||||
|
snapshot: {
|
||||||
|
label: 'Forum thread',
|
||||||
|
title: clip(t.title, 200),
|
||||||
|
text: first ? excerpt(first.body_html) : null,
|
||||||
|
at: t.created_at,
|
||||||
|
where: { teamId: t.team_id, team: forum.team.name, threadId: t.id },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (type === 'team_forum_post') {
|
||||||
|
const p = await forumDb.postById(id)
|
||||||
|
if (!p) return null
|
||||||
|
const t = await forumDb.threadById(p.thread_id)
|
||||||
|
if (!t) return null
|
||||||
|
const forum = await forumFor(t.team_id, viewer)
|
||||||
|
if (!forum) return null
|
||||||
|
if ((p.status !== 'visible' || t.status !== 'visible') && !forum.canModerate) return null
|
||||||
|
return {
|
||||||
|
type,
|
||||||
|
targetId: id,
|
||||||
|
teamId: t.team_id,
|
||||||
|
team: forum.team,
|
||||||
|
author: { userId: p.author_user_id ?? null, name: p.author_username || null, identity: null },
|
||||||
|
snapshot: {
|
||||||
|
label: 'Forum post',
|
||||||
|
title: clip(t.title, 200),
|
||||||
|
text: excerpt(p.body_html),
|
||||||
|
at: p.created_at,
|
||||||
|
where: { teamId: t.team_id, team: forum.team.name, threadId: t.id, postId: p.id },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (type === 'team_forum_upload') {
|
||||||
|
const u = await forumDb.uploadById(id)
|
||||||
|
if (!u) return null
|
||||||
|
const forum = await forumFor(u.team_id, viewer)
|
||||||
|
if (!forum) return null
|
||||||
|
return {
|
||||||
|
type,
|
||||||
|
targetId: id,
|
||||||
|
teamId: u.team_id,
|
||||||
|
team: forum.team,
|
||||||
|
author: { userId: u.uploader_user_id ?? null, name: u.uploader_username || null, identity: null },
|
||||||
|
snapshot: {
|
||||||
|
label: 'Forum upload',
|
||||||
|
title: null,
|
||||||
|
text: clip(u.filename, 200),
|
||||||
|
at: u.created_at,
|
||||||
|
where: { teamId: u.team_id, team: forum.team.name, postId: u.post_id },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A module's answer, checked. A module is trusted to describe its own content
|
||||||
|
* and nothing more: what reaches the queue is clipped to known fields, so a
|
||||||
|
* snapshot cannot carry markup or a megabyte of frame into `content_reports`.
|
||||||
|
*/
|
||||||
|
function shapeModuleSnapshot(target, raw) {
|
||||||
|
if (!raw || typeof raw !== 'object') return null
|
||||||
|
const a = raw.author && typeof raw.author === 'object' ? raw.author : {}
|
||||||
|
const ident = a.identity && typeof a.identity === 'object'
|
||||||
|
&& typeof a.identity.kind === 'string' && a.identity.id != null
|
||||||
|
? { kind: a.identity.kind, id: String(a.identity.id).slice(0, 64) }
|
||||||
|
: null
|
||||||
|
const userId = Number.isInteger(Number(a.userId)) && a.userId != null ? Number(a.userId) : null
|
||||||
|
const where = raw.where && typeof raw.where === 'object'
|
||||||
|
? Object.fromEntries(Object.entries(raw.where)
|
||||||
|
.filter(([, v]) => v == null || ['string', 'number', 'boolean'].includes(typeof v))
|
||||||
|
.slice(0, 8)
|
||||||
|
.map(([k, v]) => [String(k).slice(0, 32), typeof v === 'string' ? v.slice(0, 120) : v]))
|
||||||
|
: {}
|
||||||
|
return {
|
||||||
|
author: { userId, name: clip(a.name, 64), identity: ident },
|
||||||
|
snapshot: {
|
||||||
|
label: target.label,
|
||||||
|
title: clip(raw.title, 200),
|
||||||
|
text: clip(raw.text, TEXT_CHARS),
|
||||||
|
at: raw.at || null,
|
||||||
|
where,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The item, for this reader, or null.
|
||||||
|
*
|
||||||
|
* @param {{targetType: string, targetId: number, viewer: {id: number, role: string}}} q
|
||||||
|
* @returns {Promise<null | {type, targetId, teamId, team?, module?, author, snapshot}>}
|
||||||
|
*/
|
||||||
|
async function resolve({ targetType, targetId, viewer }) {
|
||||||
|
if (FORUM_TYPES.includes(targetType)) return resolveForum(targetType, targetId, viewer)
|
||||||
|
|
||||||
|
const target = registries.reportTarget(targetType)
|
||||||
|
if (!target) return null
|
||||||
|
let raw
|
||||||
|
try {
|
||||||
|
raw = await withTimeout(
|
||||||
|
() => target.snapshot({ targetId, viewer: Object.freeze({ userId: viewer.id, role: viewer.role }) }),
|
||||||
|
MODULE_TIMEOUT_MS,
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
log.error('report target snapshot failed', { module: target.owner, type: targetType, message: err.message })
|
||||||
|
const e = new Error('The game module did not answer')
|
||||||
|
e.status = 503
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
const shaped = shapeModuleSnapshot(target, raw)
|
||||||
|
if (!shaped) return null
|
||||||
|
return { type: targetType, targetId, teamId: null, module: target.owner, ...shaped }
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
FORUM_TYPES,
|
||||||
|
FORUM_HIDEABLE,
|
||||||
|
FORUM_STAFF_ROLES,
|
||||||
|
MODULE_TIMEOUT_MS,
|
||||||
|
isReportable,
|
||||||
|
isHideable,
|
||||||
|
resolve,
|
||||||
|
withTimeout,
|
||||||
|
_shapeModuleSnapshot: shapeModuleSnapshot,
|
||||||
|
}
|
||||||
175
server/src/model/safety/userSafety.db.js
Normal file
175
server/src/model/safety/userSafety.db.js
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
// SQL for a member's blocks and hides (USER_SAFETY.md §4.1).
|
||||||
|
//
|
||||||
|
// `user_blocks` holds two kinds of row — an account block and a game block —
|
||||||
|
// and `user_hidden_items` one row per item a member hid for themself. Nothing
|
||||||
|
// here decides who may block whom; that is the model's job (S8, S12, S14).
|
||||||
|
|
||||||
|
const { query } = require('../../utils/db')
|
||||||
|
|
||||||
|
const BLOCK_COLUMNS = `
|
||||||
|
b.id, b.blocker_user_id, b.blocked_user_id, b.module_id, b.identity_kind,
|
||||||
|
b.external_id, b.display_name, b.created_at`
|
||||||
|
|
||||||
|
const isDuplicate = (err) => Boolean(err && (err.code === 'ER_DUP_ENTRY' || err.errno === 1062))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A member's blocks, newest first, each account block with the blocked
|
||||||
|
* account's CURRENT username and role beside the snapshot.
|
||||||
|
*
|
||||||
|
* The role is read here rather than stored, because S8 is about who the target
|
||||||
|
* is now: a block on a player who later became a moderator stops applying.
|
||||||
|
*/
|
||||||
|
async function blocksFor(blockerUserId) {
|
||||||
|
return query(
|
||||||
|
`SELECT ${BLOCK_COLUMNS}, u.username AS blocked_username, u.role AS blocked_role
|
||||||
|
FROM user_blocks b
|
||||||
|
LEFT JOIN users u ON u.id = b.blocked_user_id
|
||||||
|
WHERE b.blocker_user_id = ?
|
||||||
|
ORDER BY b.created_at DESC, b.id DESC`,
|
||||||
|
[blockerUserId],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Block an account. Answers the new row's id, or null when the member had
|
||||||
|
* already blocked them — caught by the unique key, so two taps cannot race into
|
||||||
|
* two rows.
|
||||||
|
*/
|
||||||
|
async function insertAccountBlock({ blockerUserId, blockedUserId, displayName }) {
|
||||||
|
try {
|
||||||
|
const res = await query(
|
||||||
|
`INSERT INTO user_blocks (blocker_user_id, blocked_user_id, display_name) VALUES (?, ?, ?)`,
|
||||||
|
[blockerUserId, blockedUserId, displayName ?? null],
|
||||||
|
)
|
||||||
|
return res.insertId
|
||||||
|
} catch (err) {
|
||||||
|
if (isDuplicate(err)) return null
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Block an unlinked game identity. Null on a duplicate, as above. */
|
||||||
|
async function insertGameBlock({ blockerUserId, moduleId, kind, externalId, displayName }) {
|
||||||
|
try {
|
||||||
|
const res = await query(
|
||||||
|
`INSERT INTO user_blocks (blocker_user_id, module_id, identity_kind, external_id, display_name)
|
||||||
|
VALUES (?, ?, ?, ?, ?)`,
|
||||||
|
[blockerUserId, moduleId, kind, externalId, displayName ?? null],
|
||||||
|
)
|
||||||
|
return res.insertId
|
||||||
|
} catch (err) {
|
||||||
|
if (isDuplicate(err)) return null
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rewrite a game block as an account block (S14): its identity is linked now.
|
||||||
|
*
|
||||||
|
* When the member had ALSO blocked that account directly, the unique key refuses
|
||||||
|
* the rewrite, and the game row is then simply redundant — the account block
|
||||||
|
* already says everything it said — so it is deleted instead.
|
||||||
|
*/
|
||||||
|
async function convertToAccountBlock(id, blockedUserId) {
|
||||||
|
try {
|
||||||
|
await query(
|
||||||
|
`UPDATE user_blocks
|
||||||
|
SET blocked_user_id = ?, module_id = NULL, identity_kind = NULL, external_id = NULL
|
||||||
|
WHERE id = ?`,
|
||||||
|
[blockedUserId, id],
|
||||||
|
)
|
||||||
|
return 'converted'
|
||||||
|
} catch (err) {
|
||||||
|
if (!isDuplicate(err)) throw err
|
||||||
|
await query('DELETE FROM user_blocks WHERE id = ?', [id])
|
||||||
|
return 'merged'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Everyone who has blocked this account, as account blocks. The reverse of
|
||||||
|
* `blocksFor`, for the notification fan-out: a post goes out to a Team, and the
|
||||||
|
* members who block its author are the ones it must skip.
|
||||||
|
*/
|
||||||
|
async function blockersOf(blockedUserId) {
|
||||||
|
const rows = await query(
|
||||||
|
'SELECT blocker_user_id FROM user_blocks WHERE blocked_user_id = ?',
|
||||||
|
[blockedUserId],
|
||||||
|
)
|
||||||
|
return rows.map((r) => Number(r.blocker_user_id))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Undo one of this member's blocks. Scoped to the blocker, so an id is not a capability. */
|
||||||
|
async function deleteBlock(blockerUserId, id) {
|
||||||
|
const res = await query('DELETE FROM user_blocks WHERE id = ? AND blocker_user_id = ?', [id, blockerUserId])
|
||||||
|
return res.affectedRows > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Which of these accounts are staff (admin, editor, moderator). */
|
||||||
|
async function staffAmong(userIds, staffRoles) {
|
||||||
|
if (!userIds.length) return []
|
||||||
|
const rows = await query(
|
||||||
|
`SELECT id FROM users
|
||||||
|
WHERE id IN (${userIds.map(() => '?').join(',')})
|
||||||
|
AND role IN (${staffRoles.map(() => '?').join(',')})`,
|
||||||
|
[...userIds, ...staffRoles],
|
||||||
|
)
|
||||||
|
return rows.map((r) => Number(r.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One account's id, username and role — the target of a block. */
|
||||||
|
async function userById(id) {
|
||||||
|
const rows = await query('SELECT id, username, role FROM users WHERE id = ? LIMIT 1', [id])
|
||||||
|
return rows[0] || null
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── hide for me ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/** Every item this member hid, newest first; optionally of the given types only. */
|
||||||
|
async function hiddenFor(userId, types = null) {
|
||||||
|
if (types && !types.length) return []
|
||||||
|
const where = types ? ` AND target_type IN (${types.map(() => '?').join(',')})` : ''
|
||||||
|
return query(
|
||||||
|
`SELECT target_type, target_id, created_at FROM user_hidden_items
|
||||||
|
WHERE user_id = ?${where}
|
||||||
|
ORDER BY created_at DESC`,
|
||||||
|
[userId, ...(types || [])],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Hide one item. Idempotent: hiding twice is still hidden. */
|
||||||
|
async function insertHidden(userId, targetType, targetId) {
|
||||||
|
await query(
|
||||||
|
`INSERT IGNORE INTO user_hidden_items (user_id, target_type, target_id) VALUES (?, ?, ?)`,
|
||||||
|
[userId, targetType, targetId],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteHidden(userId, targetType, targetId) {
|
||||||
|
const res = await query(
|
||||||
|
'DELETE FROM user_hidden_items WHERE user_id = ? AND target_type = ? AND target_id = ?',
|
||||||
|
[userId, targetType, targetId],
|
||||||
|
)
|
||||||
|
return res.affectedRows > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Show every hidden item again. Answers how many there were. */
|
||||||
|
async function clearHidden(userId) {
|
||||||
|
const res = await query('DELETE FROM user_hidden_items WHERE user_id = ?', [userId])
|
||||||
|
return res.affectedRows
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
clearHidden,
|
||||||
|
blocksFor,
|
||||||
|
insertAccountBlock,
|
||||||
|
insertGameBlock,
|
||||||
|
convertToAccountBlock,
|
||||||
|
blockersOf,
|
||||||
|
deleteBlock,
|
||||||
|
staffAmong,
|
||||||
|
userById,
|
||||||
|
hiddenFor,
|
||||||
|
insertHidden,
|
||||||
|
deleteHidden,
|
||||||
|
}
|
||||||
326
server/src/model/safety/userSafety.model.js
Normal file
326
server/src/model/safety/userSafety.model.js
Normal file
@@ -0,0 +1,326 @@
|
|||||||
|
// ── Block and "Hide for me" (USER_SAFETY.md §1, §4.1) ──────────────────────
|
||||||
|
//
|
||||||
|
// A block lives on the blocker's ACCOUNT (S2), so it applies on the website and
|
||||||
|
// in the app, on every device. The rules that shape this file, each decided by
|
||||||
|
// the org lead:
|
||||||
|
//
|
||||||
|
// S12 A block names the author's WEBSITE ACCOUNT whenever there is one. A
|
||||||
|
// forum author always has one; a chat speaker has one when their game
|
||||||
|
// identity is linked. Only an unlinked game identity — most people in a
|
||||||
|
// Rust chat feed — is blocked as itself, a Steam id.
|
||||||
|
// S14 When that identity is later linked, the game block becomes an account
|
||||||
|
// block, the next time the member's blocks are read. From then on it hides
|
||||||
|
// the account's forum posts too.
|
||||||
|
// S8 Staff (admin, editor, moderator) cannot be blocked. Blocking one is
|
||||||
|
// refused. A block whose target LATER became staff — promoted, or a game
|
||||||
|
// block whose identity linked to a staff account — is kept but stops
|
||||||
|
// applying, and the Blocked page says why.
|
||||||
|
// S9 A block does nothing to the blocked person. They are not told.
|
||||||
|
//
|
||||||
|
// "Hide for me" is one item gone from one member's view; it files no report and
|
||||||
|
// changes nothing about the item (§1).
|
||||||
|
//
|
||||||
|
// Filtering happens on the server for every reader-specific read: core's forum
|
||||||
|
// here, and a module's per-viewer feeds through `ctx.safety.forViewer` (S11).
|
||||||
|
|
||||||
|
const db = require('./userSafety.db')
|
||||||
|
const targets = require('./targets')
|
||||||
|
const registries = require('../../modules/registries')
|
||||||
|
const { STAFF_ROLES } = require('../../utils/displayAuthor')
|
||||||
|
const log = require('../../utils/logger')('safety')
|
||||||
|
|
||||||
|
const isStaffRole = (role) => STAFF_ROLES.includes(role)
|
||||||
|
|
||||||
|
const refuse = (status, code, error) => ({ ok: false, status, code, error })
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This member's blocks, as they stand NOW.
|
||||||
|
*
|
||||||
|
* S14 runs here: every game block is checked against its module's links, and
|
||||||
|
* one whose identity is linked is rewritten as an account block before the list
|
||||||
|
* is answered. Reading is where it happens because a link is made in a module,
|
||||||
|
* which has no reason to tell core, and a block that waited for a notification
|
||||||
|
* would be a block that silently missed one.
|
||||||
|
*
|
||||||
|
* A module that does not answer leaves its game blocks as they are: they still
|
||||||
|
* apply to the Steam id, which is the block the member made.
|
||||||
|
*/
|
||||||
|
async function currentBlocks(userId) {
|
||||||
|
let rows = await db.blocksFor(userId)
|
||||||
|
const game = rows.filter((r) => r.blocked_user_id == null && r.module_id)
|
||||||
|
|
||||||
|
if (game.length) {
|
||||||
|
const groups = new Map()
|
||||||
|
for (const r of game) {
|
||||||
|
const key = `${r.module_id}:${r.identity_kind}`
|
||||||
|
if (!groups.has(key)) groups.set(key, [])
|
||||||
|
groups.get(key).push(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
let changed = false
|
||||||
|
for (const group of groups.values()) {
|
||||||
|
const ident = registries.gameIdentity(group[0].module_id, group[0].identity_kind)
|
||||||
|
if (!ident) continue
|
||||||
|
let owners = {}
|
||||||
|
try {
|
||||||
|
owners = (await targets.withTimeout(
|
||||||
|
() => ident.ownersOf(group.map((r) => r.external_id)),
|
||||||
|
targets.MODULE_TIMEOUT_MS,
|
||||||
|
)) || {}
|
||||||
|
} catch (err) {
|
||||||
|
log.warn('game identity lookup failed; game blocks left as they are', {
|
||||||
|
module: ident.owner, kind: ident.kind, message: err.message,
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for (const r of group) {
|
||||||
|
const owner = Number(owners[r.external_id])
|
||||||
|
if (!Number.isInteger(owner) || owner <= 0) continue
|
||||||
|
// The member blocked a Steam id that turned out to be their own. A block
|
||||||
|
// on yourself hides nothing worth hiding, so it is simply removed.
|
||||||
|
if (owner === Number(userId)) await db.deleteBlock(userId, r.id)
|
||||||
|
else await db.convertToAccountBlock(r.id, owner)
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed) rows = await db.blocksFor(userId)
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows.map((r) => ({
|
||||||
|
...r,
|
||||||
|
applies: r.blocked_user_id == null ? true : !isStaffRole(r.blocked_role),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One block as the member sees it on Account → Blocked. */
|
||||||
|
function publicBlock(row) {
|
||||||
|
const account = row.blocked_user_id != null
|
||||||
|
const ident = account ? null : registries.gameIdentity(row.module_id, row.identity_kind)
|
||||||
|
return {
|
||||||
|
id: row.id,
|
||||||
|
kind: account ? 'account' : 'game',
|
||||||
|
name: account ? (row.blocked_username || row.display_name) : row.display_name,
|
||||||
|
identity: account
|
||||||
|
? null
|
||||||
|
: {
|
||||||
|
module: row.module_id,
|
||||||
|
kind: row.identity_kind,
|
||||||
|
label: ident ? ident.label : row.identity_kind,
|
||||||
|
id: row.external_id,
|
||||||
|
},
|
||||||
|
applies: row.applies,
|
||||||
|
reason: row.applies ? null : 'staff',
|
||||||
|
createdAt: row.created_at,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function listBlocks(actor) {
|
||||||
|
return (await currentBlocks(actor.id)).map(publicBlock)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Block an account, after S8's check. */
|
||||||
|
async function blockAccount(actor, userId) {
|
||||||
|
if (Number(userId) === Number(actor.id)) return refuse(400, 'self', 'You can’t block yourself.')
|
||||||
|
const target = await db.userById(userId)
|
||||||
|
if (!target) return refuse(404, 'not_found', 'Not found')
|
||||||
|
if (isStaffRole(target.role)) return refuse(403, 'staff', 'You can’t block a staff member.')
|
||||||
|
const id = await db.insertAccountBlock({
|
||||||
|
blockerUserId: actor.id,
|
||||||
|
blockedUserId: target.id,
|
||||||
|
displayName: target.username,
|
||||||
|
})
|
||||||
|
if (id == null) return refuse(409, 'already_blocked', `You have already blocked ${target.username}.`)
|
||||||
|
return { ok: true, block: { id, kind: 'account', name: target.username, identity: null, applies: true, reason: null } }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Block the author of one item (S12).
|
||||||
|
*
|
||||||
|
* The client names the item, never the person: the server reads who wrote it,
|
||||||
|
* through the same resolver a report uses, so a member can only block someone
|
||||||
|
* whose words they could see, and the block lands on the account when there is
|
||||||
|
* one.
|
||||||
|
*/
|
||||||
|
async function blockAuthorOf({ actor, targetType, targetId }) {
|
||||||
|
if (!targets.isHideable(targetType)) return refuse(400, 'unknown_target', 'Unknown target')
|
||||||
|
const item = await targets.resolve({ targetType, targetId, viewer: actor })
|
||||||
|
if (!item) return refuse(404, 'not_found', 'Not found')
|
||||||
|
|
||||||
|
const { author } = item
|
||||||
|
if (author.userId != null) return blockAccount(actor, author.userId)
|
||||||
|
|
||||||
|
// No account on the item. A forum item with no account is a deleted one, and
|
||||||
|
// there is nobody left to block.
|
||||||
|
if (!item.module || !author.identity) {
|
||||||
|
return refuse(400, 'no_author', 'That account no longer exists.')
|
||||||
|
}
|
||||||
|
|
||||||
|
// A game identity. S12: its account first, when it has one.
|
||||||
|
const ident = registries.gameIdentity(item.module, author.identity.kind)
|
||||||
|
if (!ident) return refuse(400, 'no_author', 'This player can’t be blocked.')
|
||||||
|
let owners
|
||||||
|
try {
|
||||||
|
owners = (await targets.withTimeout(() => ident.ownersOf([author.identity.id]), targets.MODULE_TIMEOUT_MS)) || {}
|
||||||
|
} catch (err) {
|
||||||
|
log.error('game identity lookup failed', { module: ident.owner, kind: ident.kind, message: err.message })
|
||||||
|
return refuse(503, 'module_unavailable', 'The game module did not answer. Try again in a moment.')
|
||||||
|
}
|
||||||
|
const owner = Number(owners[author.identity.id])
|
||||||
|
if (Number.isInteger(owner) && owner > 0) return blockAccount(actor, owner)
|
||||||
|
|
||||||
|
const id = await db.insertGameBlock({
|
||||||
|
blockerUserId: actor.id,
|
||||||
|
moduleId: item.module,
|
||||||
|
kind: author.identity.kind,
|
||||||
|
externalId: author.identity.id,
|
||||||
|
displayName: author.name,
|
||||||
|
})
|
||||||
|
if (id == null) return refuse(409, 'already_blocked', `You have already blocked ${author.name || 'this player'}.`)
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
block: {
|
||||||
|
id,
|
||||||
|
kind: 'game',
|
||||||
|
name: author.name,
|
||||||
|
identity: { module: item.module, kind: ident.kind, label: ident.label, id: author.identity.id },
|
||||||
|
applies: true,
|
||||||
|
reason: null,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function unblock(actor, id) {
|
||||||
|
return (await db.deleteBlock(actor.id, id)) ? { ok: true } : refuse(404, 'not_found', 'Not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── hide for me ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide one item for this member. The type must be one a member can hide; the
|
||||||
|
* item is not looked up — see `user_hidden_items` in schema.sql for why a row for
|
||||||
|
* an id that does not exist is harmless and an existence check is not.
|
||||||
|
*/
|
||||||
|
async function hide(actor, targetType, targetId) {
|
||||||
|
if (!targets.isHideable(targetType)) return refuse(400, 'unknown_target', 'Unknown target')
|
||||||
|
await db.insertHidden(actor.id, targetType, targetId)
|
||||||
|
return { ok: true }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function unhide(actor, targetType, targetId) {
|
||||||
|
if (!targets.isHideable(targetType)) return refuse(400, 'unknown_target', 'Unknown target')
|
||||||
|
await db.deleteHidden(actor.id, targetType, targetId)
|
||||||
|
return { ok: true }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Account → Blocked's "Show them all again". */
|
||||||
|
async function clearHidden(actor) {
|
||||||
|
return db.clearHidden(actor.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function listHidden(actor) {
|
||||||
|
return (await db.hiddenFor(actor.id)).map((r) => ({
|
||||||
|
targetType: r.target_type,
|
||||||
|
targetId: Number(r.target_id),
|
||||||
|
createdAt: r.created_at,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── what one reader's reads leave out ──────────────────────────────────────
|
||||||
|
|
||||||
|
const EMPTY_FILTER = Object.freeze({
|
||||||
|
blockedUserIds: new Set(),
|
||||||
|
hidden: Object.freeze({ team_forum_thread: new Set(), team_forum_post: new Set() }),
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What core's forum leaves out for this reader: the accounts they block (that
|
||||||
|
* still apply) and the threads and posts they hid.
|
||||||
|
*/
|
||||||
|
async function forumFilter(userId) {
|
||||||
|
if (!userId) return EMPTY_FILTER
|
||||||
|
const [blocks, hidden] = await Promise.all([
|
||||||
|
currentBlocks(userId),
|
||||||
|
db.hiddenFor(userId, targets.FORUM_HIDEABLE),
|
||||||
|
])
|
||||||
|
const filter = {
|
||||||
|
blockedUserIds: new Set(blocks.filter((b) => b.applies && b.blocked_user_id != null).map((b) => Number(b.blocked_user_id))),
|
||||||
|
hidden: { team_forum_thread: new Set(), team_forum_post: new Set() },
|
||||||
|
}
|
||||||
|
for (const h of hidden) filter.hidden[h.target_type].add(Number(h.target_id))
|
||||||
|
return filter
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `ctx.safety.forViewer` (API 1.21.0, S11): what one reader has blocked and
|
||||||
|
* hidden, for the calling module.
|
||||||
|
*
|
||||||
|
* `blockedUserIds` — accounts, every module's concern: a speaker linked to one
|
||||||
|
* is hidden whichever module's feed they speak in. `blockedIdentities` — this
|
||||||
|
* module's own unlinked game blocks, by kind. `hidden` — this reader's hides on
|
||||||
|
* this module's report targets, by type. Ids are answered as arrays of the type
|
||||||
|
* the module gave them (numbers for target ids, strings for identities).
|
||||||
|
*/
|
||||||
|
async function forModuleViewer(moduleId, userId) {
|
||||||
|
const empty = { blockedUserIds: [], blockedIdentities: {}, hidden: {} }
|
||||||
|
if (!userId) return empty
|
||||||
|
const types = registries.allReportTargets().filter((t) => t.owner === moduleId).map((t) => t.id)
|
||||||
|
const [blocks, hidden] = await Promise.all([currentBlocks(userId), db.hiddenFor(userId, types)])
|
||||||
|
|
||||||
|
const out = { blockedUserIds: [], blockedIdentities: {}, hidden: {} }
|
||||||
|
for (const b of blocks) {
|
||||||
|
if (!b.applies) continue
|
||||||
|
if (b.blocked_user_id != null) out.blockedUserIds.push(Number(b.blocked_user_id))
|
||||||
|
else if (b.module_id === moduleId) {
|
||||||
|
if (!out.blockedIdentities[b.identity_kind]) out.blockedIdentities[b.identity_kind] = []
|
||||||
|
out.blockedIdentities[b.identity_kind].push(String(b.external_id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const t of types) out.hidden[t] = []
|
||||||
|
for (const h of hidden) out.hidden[h.target_type].push(Number(h.target_id))
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The members whose blocks cover this author, for a notification about something
|
||||||
|
* the author wrote: a forum post is pushed, mailed and put in the inbox of every
|
||||||
|
* member of its Team, and a member who blocks the author must not be told about it
|
||||||
|
* (the forum itself already leaves the post out for them).
|
||||||
|
*
|
||||||
|
* S8 applies here too: a staff author is blocked by nobody, so this answers empty
|
||||||
|
* and the post reaches everyone. Answers account blocks only. A game block on the
|
||||||
|
* author's Steam id that S14 has not yet rewritten counts from the next time its
|
||||||
|
* owner reads the forum or their blocks, which is when the rewrite happens.
|
||||||
|
*/
|
||||||
|
async function blockersOf(authorUserId) {
|
||||||
|
const id = Number(authorUserId)
|
||||||
|
if (!Number.isInteger(id) || id <= 0) return []
|
||||||
|
const author = await db.userById(id)
|
||||||
|
if (!author || isStaffRole(author.role)) return []
|
||||||
|
return db.blockersOf(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** `ctx.safety.staffAmong` (S13): which of these accounts are staff. */
|
||||||
|
async function staffAmong(userIds) {
|
||||||
|
const ids = [...new Set((Array.isArray(userIds) ? userIds : [])
|
||||||
|
.map(Number)
|
||||||
|
.filter((n) => Number.isInteger(n) && n > 0))]
|
||||||
|
.slice(0, 500)
|
||||||
|
return db.staffAmong(ids, STAFF_ROLES)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
currentBlocks,
|
||||||
|
listBlocks,
|
||||||
|
blockAuthorOf,
|
||||||
|
blockAccount,
|
||||||
|
unblock,
|
||||||
|
hide,
|
||||||
|
unhide,
|
||||||
|
listHidden,
|
||||||
|
clearHidden,
|
||||||
|
forumFilter,
|
||||||
|
forModuleViewer,
|
||||||
|
blockersOf,
|
||||||
|
staffAmong,
|
||||||
|
publicBlock,
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ const brand = require('../../config/brand')
|
|||||||
const { parseJsonSetting } = require('../../utils/settingsJson')
|
const { parseJsonSetting } = require('../../utils/settingsJson')
|
||||||
const { resolveThemeTokens } = require('../../utils/themeResolve')
|
const { resolveThemeTokens } = require('../../utils/themeResolve')
|
||||||
const { resolveBrandAssets } = require('../../utils/brandAssets')
|
const { resolveBrandAssets } = require('../../utils/brandAssets')
|
||||||
|
const { isDemo } = require('../../demo/mode')
|
||||||
|
|
||||||
// Keys safe to expose on the public site.
|
// Keys safe to expose on the public site.
|
||||||
const PUBLIC_KEYS = [
|
const PUBLIC_KEYS = [
|
||||||
@@ -215,9 +216,30 @@ async function getPublic() {
|
|||||||
// before doing so (the server would otherwise reject an unallowlisted one). The
|
// before doing so (the server would otherwise reject an unallowlisted one). The
|
||||||
// custom-scheme callback works regardless of this flag.
|
// custom-scheme callback works regardless of this flag.
|
||||||
out.mobileAppLinks = String(all[MOBILE_APP_LINKS_KEY]) === 'true'
|
out.mobileAppLinks = String(all[MOBILE_APP_LINKS_KEY]) === 'true'
|
||||||
|
// The public demo's banner and sign-in panel (DEMO_MODE.md §4, §6). Present
|
||||||
|
// only with DEMO_MODE on, so a real shard's payload is unchanged. Written by
|
||||||
|
// `seed:demo` at every wipe; the demo lock keeps `demo_*` out of PUT
|
||||||
|
// /admin/settings, so a visitor cannot rewrite the published passwords.
|
||||||
|
if (isDemo()) out.demo = demoBlock(all[DEMO_STATE_KEY])
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `demo_state` is one JSON object: `{ resetsAt, logins: [{ username, password,
|
||||||
|
// role }] }`. The passwords are public by design (§4) — the logins are printed
|
||||||
|
// on the sign-in page and on runicgateway.com/beta. Read forgivingly: a missing
|
||||||
|
// or broken row is a banner with no time and no logins, never a 500.
|
||||||
|
const DEMO_STATE_KEY = 'demo_state'
|
||||||
|
function demoBlock(raw) {
|
||||||
|
const state = parseJsonSetting(raw) || {}
|
||||||
|
const resetsAt = typeof state.resetsAt === 'string' && !Number.isNaN(Date.parse(state.resetsAt))
|
||||||
|
? state.resetsAt
|
||||||
|
: null
|
||||||
|
const logins = (Array.isArray(state.logins) ? state.logins : [])
|
||||||
|
.filter((l) => l && typeof l.username === 'string' && typeof l.password === 'string')
|
||||||
|
.map((l) => ({ username: l.username, password: l.password, role: typeof l.role === 'string' ? l.role : null }))
|
||||||
|
return { resetsAt, logins }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What the HTML shell needs, resolved exactly as getPublic() resolves it: the
|
* What the HTML shell needs, resolved exactly as getPublic() resolves it: the
|
||||||
* effective favicon and logo, plus the theme token map for the boot <style>
|
* effective favicon and logo, plus the theme token map for the boot <style>
|
||||||
@@ -285,4 +307,5 @@ module.exports = {
|
|||||||
registrationFlags,
|
registrationFlags,
|
||||||
MOBILE_APP_LINKS_KEY,
|
MOBILE_APP_LINKS_KEY,
|
||||||
isMobileAppLinksEnabled,
|
isMobileAppLinksEnabled,
|
||||||
|
DEMO_STATE_KEY,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,15 @@ async function rosterWithOverrides(teamId, { includeDeparted = false } = {}) {
|
|||||||
is_leader_synced: Boolean(m.is_leader),
|
is_leader_synced: Boolean(m.is_leader),
|
||||||
is_leader: override ? override.effect === 'grant' : Boolean(m.is_leader),
|
is_leader: override ? override.effect === 'grant' : Boolean(m.is_leader),
|
||||||
leader_override: override
|
leader_override: override
|
||||||
? { effect: override.effect, reason: override.reason, by: override.actor_username, at: override.created_at }
|
? {
|
||||||
|
effect: override.effect,
|
||||||
|
reason: override.reason,
|
||||||
|
by: override.actor_username,
|
||||||
|
// Staff-only (adminMember); a deleted actor keeps the stored name here,
|
||||||
|
// marked (ACCOUNT_DELETION.md AD6). The public roster never carries it.
|
||||||
|
byDeleted: override.actor_user_id == null && Boolean(override.actor_username),
|
||||||
|
at: override.created_at,
|
||||||
|
}
|
||||||
: null,
|
: null,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -79,6 +79,15 @@ async function postById(id) {
|
|||||||
return rows[0] || null
|
return rows[0] || null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A thread's opening post, whatever its status — what a report on the thread quotes. */
|
||||||
|
async function firstPostOf(threadId) {
|
||||||
|
const rows = await query(
|
||||||
|
`SELECT ${POST_COLUMNS} FROM team_forum_posts WHERE thread_id = ? ORDER BY created_at, id LIMIT 1`,
|
||||||
|
[threadId],
|
||||||
|
)
|
||||||
|
return rows[0] || null
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a post and move the thread's counters in the same breath.
|
* Append a post and move the thread's counters in the same breath.
|
||||||
*
|
*
|
||||||
@@ -275,6 +284,7 @@ module.exports = {
|
|||||||
setThreadFlags,
|
setThreadFlags,
|
||||||
postsByThread,
|
postsByThread,
|
||||||
postById,
|
postById,
|
||||||
|
firstPostOf,
|
||||||
insertPost,
|
insertPost,
|
||||||
setPostStatus,
|
setPostStatus,
|
||||||
updatePostBody,
|
updatePostBody,
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
const forumDb = require('./teamForum.db')
|
const forumDb = require('./teamForum.db')
|
||||||
const forumSettings = require('./teamForumSettings.model')
|
const forumSettings = require('./teamForumSettings.model')
|
||||||
const { cleanForumBody, renderForumBody } = require('../../utils/forumHtml')
|
const { cleanForumBody, renderForumBody } = require('../../utils/forumHtml')
|
||||||
|
const { displayAuthor, STAFF_ROLES } = require('../../utils/displayAuthor')
|
||||||
|
const safetyDb = require('../safety/userSafety.db')
|
||||||
|
|
||||||
// Announcements are leader-authored and take no replies; discussion threads are
|
// Announcements are leader-authored and take no replies; discussion threads are
|
||||||
// member-authored and do. Both have been in the enum since 5a — what phase 5
|
// member-authored and do. Both have been in the enum since 5a — what phase 5
|
||||||
@@ -42,8 +44,6 @@ const CREATABLE_TYPES_5A = ['announcement']
|
|||||||
// look like it would open replies on an announcement.
|
// look like it would open replies on an announcement.
|
||||||
const REPLYABLE_TYPES = ['discussion']
|
const REPLYABLE_TYPES = ['discussion']
|
||||||
|
|
||||||
const DELETED_AUTHOR = '[deleted account]'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moderation actions, and what each one does to the row.
|
* Moderation actions, and what each one does to the row.
|
||||||
*
|
*
|
||||||
@@ -74,13 +74,21 @@ const POST_ACTIONS = {
|
|||||||
restore: { status: 'visible' },
|
restore: { status: 'visible' },
|
||||||
}
|
}
|
||||||
|
|
||||||
function publicThread(row) {
|
/**
|
||||||
|
* One thread's list shape, for one viewer.
|
||||||
|
*
|
||||||
|
* `author` follows displayAuthor's rule: a deleted account's snapshot reads
|
||||||
|
* "[deleted player]" to a member and its stored name to staff, and
|
||||||
|
* `authorDeleted` says which case it is so the staff view can mark it.
|
||||||
|
*/
|
||||||
|
function publicThread(row, viewer = null) {
|
||||||
|
const author = displayAuthor({ userId: row.created_by, username: row.created_username }, viewer)
|
||||||
return {
|
return {
|
||||||
id: row.id,
|
id: row.id,
|
||||||
type: row.type,
|
type: row.type,
|
||||||
title: row.title,
|
title: row.title,
|
||||||
author: row.created_username || DELETED_AUTHOR,
|
author: author.name,
|
||||||
authorDeleted: row.created_by == null,
|
authorDeleted: author.deleted,
|
||||||
createdAt: row.created_at,
|
createdAt: row.created_at,
|
||||||
lastPostAt: row.last_post_at,
|
lastPostAt: row.last_post_at,
|
||||||
postCount: row.post_count,
|
postCount: row.post_count,
|
||||||
@@ -129,10 +137,11 @@ function editability(row, { userId = null, isStaff = false, windowMinutes = 0, n
|
|||||||
* said who is reading.
|
* said who is reading.
|
||||||
*/
|
*/
|
||||||
function renderPost(row, mode, viewer) {
|
function renderPost(row, mode, viewer) {
|
||||||
|
const author = displayAuthor({ userId: row.author_user_id, username: row.author_username }, viewer)
|
||||||
return {
|
return {
|
||||||
id: row.id,
|
id: row.id,
|
||||||
author: row.author_username || DELETED_AUTHOR,
|
author: author.name,
|
||||||
authorDeleted: row.author_user_id == null,
|
authorDeleted: author.deleted,
|
||||||
body: renderForumBody(row.body_html, mode),
|
body: renderForumBody(row.body_html, mode),
|
||||||
createdAt: row.created_at,
|
createdAt: row.created_at,
|
||||||
editedAt: row.edited_at,
|
editedAt: row.edited_at,
|
||||||
@@ -150,9 +159,42 @@ function renderPost(row, mode, viewer) {
|
|||||||
* same call answers both audiences without a second endpoint that could disagree
|
* same call answers both audiences without a second endpoint that could disagree
|
||||||
* with this one.
|
* with this one.
|
||||||
*/
|
*/
|
||||||
async function listThreads(teamId, { canModerate = false, limit = 50, offset = 0 } = {}) {
|
async function listThreads(teamId, { canModerate = false, viewer = null, filter = null, limit = 50, offset = 0 } = {}) {
|
||||||
const rows = await forumDb.threadsByTeam(teamId, { includeHidden: canModerate, limit, offset })
|
const rows = await forumDb.threadsByTeam(teamId, { includeHidden: canModerate, limit, offset })
|
||||||
return rows.map(publicThread)
|
return rows.filter((row) => !leftOutThread(row, filter)).map((row) => publicThread(row, viewer))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── one reader's blocks and hides (USER_SAFETY.md §4.1) ───────────────────
|
||||||
|
//
|
||||||
|
// `filter` is `userSafety.forumFilter(userId)`: the accounts this reader blocks
|
||||||
|
// and the threads and posts they hid. Applied on the server, to this reader's
|
||||||
|
// read only — nothing on disk changes, and nobody else's view does (S9).
|
||||||
|
|
||||||
|
/** Does this reader's filter leave this thread out? */
|
||||||
|
function leftOutThread(row, filter) {
|
||||||
|
if (!filter) return false
|
||||||
|
if (filter.hidden.team_forum_thread.has(Number(row.id))) return true
|
||||||
|
return row.created_by != null && filter.blockedUserIds.has(Number(row.created_by))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* May this reader block these authors? Decided here and handed to the client,
|
||||||
|
* like `canEdit`: not yourself, not a deleted account, and not staff (S8) —
|
||||||
|
* the menu does not offer what the server would refuse.
|
||||||
|
*/
|
||||||
|
async function blockable(viewer, authorIds) {
|
||||||
|
const me = viewer && viewer.userId
|
||||||
|
if (!me) return () => false
|
||||||
|
const ids = [...new Set(authorIds.filter((id) => id != null && id !== me).map(Number))]
|
||||||
|
const staff = new Set(ids.length ? await safetyDb.staffAmong(ids, STAFF_ROLES) : [])
|
||||||
|
return (id) => id != null && Number(id) !== Number(me) && !staff.has(Number(id))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Does this reader's filter leave this post out? */
|
||||||
|
function leftOutPost(row, filter) {
|
||||||
|
if (!filter) return false
|
||||||
|
if (filter.hidden.team_forum_post.has(Number(row.id))) return true
|
||||||
|
return row.author_user_id != null && filter.blockedUserIds.has(Number(row.author_user_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -164,7 +206,7 @@ async function listThreads(teamId, { canModerate = false, limit = 50, offset = 0
|
|||||||
* the window to the client and letting it compare timestamps — is the thing
|
* the window to the client and letting it compare timestamps — is the thing
|
||||||
* `editability` exists not to do.
|
* `editability` exists not to do.
|
||||||
*/
|
*/
|
||||||
async function getThread(teamId, threadId, { canModerate = false, viewer } = {}) {
|
async function getThread(teamId, threadId, { canModerate = false, viewer, filter = null } = {}) {
|
||||||
const thread = await forumDb.threadById(threadId)
|
const thread = await forumDb.threadById(threadId)
|
||||||
// The team check is here rather than in the SQL so a thread id from another
|
// The team check is here rather than in the SQL so a thread id from another
|
||||||
// Team reads as "not found" and not as "found, but not yours" — a forum is a
|
// Team reads as "not found" and not as "found, but not yours" — a forum is a
|
||||||
@@ -172,17 +214,23 @@ async function getThread(teamId, threadId, { canModerate = false, viewer } = {})
|
|||||||
if (!thread || thread.team_id !== teamId) return null
|
if (!thread || thread.team_id !== teamId) return null
|
||||||
if (thread.status === 'deleted' && !canModerate) return null
|
if (thread.status === 'deleted' && !canModerate) return null
|
||||||
if (thread.status === 'hidden' && !canModerate) return null
|
if (thread.status === 'hidden' && !canModerate) return null
|
||||||
|
// A thread this reader hid, or opened by someone they block, is gone from
|
||||||
|
// their view — a link to it included.
|
||||||
|
if (leftOutThread(thread, filter)) return null
|
||||||
|
|
||||||
const mode = await forumSettings.imageMode()
|
const mode = await forumSettings.imageMode()
|
||||||
const posts = await forumDb.postsByThread(threadId, { includeHidden: canModerate })
|
const posts = (await forumDb.postsByThread(threadId, { includeHidden: canModerate }))
|
||||||
|
.filter((p) => !leftOutPost(p, filter))
|
||||||
|
const canBlock = await blockable(viewer, [thread.created_by, ...posts.map((p) => p.author_user_id)])
|
||||||
return {
|
return {
|
||||||
...publicThread(thread),
|
...publicThread(thread, viewer),
|
||||||
|
canBlock: canBlock(thread.created_by),
|
||||||
// A reply control is offered when the TYPE takes replies and the thread is
|
// A reply control is offered when the TYPE takes replies and the thread is
|
||||||
// open. Both halves are reported separately (`type`, `locked`) so the UI can
|
// open. Both halves are reported separately (`type`, `locked`) so the UI can
|
||||||
// say which one is why, but the decision itself is made here — a client that
|
// say which one is why, but the decision itself is made here — a client that
|
||||||
// recomputed it would be a second place for the rule to live.
|
// recomputed it would be a second place for the rule to live.
|
||||||
canReply: REPLYABLE_TYPES.includes(thread.type) && !thread.locked && thread.status === 'visible',
|
canReply: REPLYABLE_TYPES.includes(thread.type) && !thread.locked && thread.status === 'visible',
|
||||||
posts: posts.map((p) => renderPost(p, mode, viewer)),
|
posts: posts.map((p) => ({ ...renderPost(p, mode, viewer), canBlock: canBlock(p.author_user_id) })),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +318,14 @@ async function createPost({ team, threadId, actor, body }) {
|
|||||||
// what a recipient needs to know is which conversation moved. `type` is always
|
// what a recipient needs to know is which conversation moved. `type` is always
|
||||||
// 'discussion' here (an announcement takes no replies) and is carried anyway so
|
// 'discussion' here (an announcement takes no replies) and is carried anyway so
|
||||||
// the controller has one shape to hand the fan-out from both routes.
|
// the controller has one shape to hand the fan-out from both routes.
|
||||||
return { ok: true, threadId, postId, notify: { threadId, title: thread.title, type: thread.type, bodyHtml: cleaned } }
|
return {
|
||||||
|
ok: true,
|
||||||
|
threadId,
|
||||||
|
postId,
|
||||||
|
// `threadAuthorUserId`: a member who blocks whoever started the thread cannot
|
||||||
|
// open it (leftOutThread), so they are not told about replies in it either.
|
||||||
|
notify: { threadId, title: thread.title, type: thread.type, bodyHtml: cleaned, threadAuthorUserId: thread.created_by ?? null },
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -434,4 +489,6 @@ module.exports = {
|
|||||||
publicThread,
|
publicThread,
|
||||||
renderPost,
|
renderPost,
|
||||||
editability,
|
editability,
|
||||||
|
leftOutThread,
|
||||||
|
leftOutPost,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const teamsDb = require('./teams.db')
|
|||||||
const access = require('./teamAccess.model')
|
const access = require('./teamAccess.model')
|
||||||
const usersDb = require('../users/users.db')
|
const usersDb = require('../users/users.db')
|
||||||
const settingsDb = require('../settings/settings.db')
|
const settingsDb = require('../settings/settings.db')
|
||||||
|
const { displayAuthor } = require('../../utils/displayAuthor')
|
||||||
|
|
||||||
// The per-Team ceiling on ACTIVE leader-issued grants. A leader admitting
|
// The per-Team ceiling on ACTIVE leader-issued grants. A leader admitting
|
||||||
// unlimited arbitrary accounts to a private space on the operator's host is a
|
// unlimited arbitrary accounts to a private space on the operator's host is a
|
||||||
@@ -136,19 +137,25 @@ async function revoke({ team, actor, userId, reason }) {
|
|||||||
* The subtraction is the §3.2 "Forum guests" list: someone who is both a member
|
* The subtraction is the §3.2 "Forum guests" list: someone who is both a member
|
||||||
* and a grantee is a member, listed on the roster, and appears here not at all.
|
* and a grantee is a member, listed on the roster, and appears here not at all.
|
||||||
* Both facts stay true in the ledger; only the presentation picks one.
|
* Both facts stay true in the ledger; only the presentation picks one.
|
||||||
|
*
|
||||||
|
* **A grant whose account was deleted is not listed** (ACCOUNT_DELETION.md AD13).
|
||||||
|
* Deleting an account clears `user_id` and leaves the row, so the grant would
|
||||||
|
* otherwise sit here as a guest nobody can be: a grant is checked by user id, and
|
||||||
|
* there is no id left to match it. The staff grant ledger still shows it, with the
|
||||||
|
* name. Who GRANTED it follows displayAuthor's rule for `viewer`.
|
||||||
*/
|
*/
|
||||||
async function forumGuests(teamId) {
|
async function forumGuests(teamId, viewer = null) {
|
||||||
const [grants, members] = await Promise.all([
|
const [grants, members] = await Promise.all([
|
||||||
accessDb.activeGrants(teamId),
|
accessDb.activeGrants(teamId),
|
||||||
teamsDb.membersByTeam(teamId, { includeDeparted: false }),
|
teamsDb.membersByTeam(teamId, { includeDeparted: false }),
|
||||||
])
|
])
|
||||||
const memberUserIds = new Set(members.map((m) => m.user_id).filter((id) => id != null))
|
const memberUserIds = new Set(members.map((m) => m.user_id).filter((id) => id != null))
|
||||||
return grants
|
return grants
|
||||||
.filter((g) => g.user_id == null || !memberUserIds.has(g.user_id))
|
.filter((g) => g.user_id != null && !memberUserIds.has(g.user_id))
|
||||||
.map((g) => ({
|
.map((g) => ({
|
||||||
userId: g.user_id,
|
userId: g.user_id,
|
||||||
username: g.username,
|
username: g.username,
|
||||||
grantedBy: g.granted_username,
|
grantedBy: displayAuthor({ userId: g.granted_by, username: g.granted_username }, viewer).name,
|
||||||
grantedAt: g.granted_at,
|
grantedAt: g.granted_at,
|
||||||
reason: g.reason,
|
reason: g.reason,
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -197,8 +197,8 @@ async function teamsWithForumActivitySince(since) {
|
|||||||
*/
|
*/
|
||||||
async function digestPostsSince(teamId, since, limit = 20) {
|
async function digestPostsSince(teamId, since, limit = 20) {
|
||||||
return query(
|
return query(
|
||||||
`SELECT po.id, po.thread_id, po.body_html, po.created_at, po.author_username,
|
`SELECT po.id, po.thread_id, po.body_html, po.created_at, po.author_user_id, po.author_username,
|
||||||
th.title, th.type
|
th.title, th.type, th.created_by AS thread_created_by
|
||||||
FROM team_forum_posts po
|
FROM team_forum_posts po
|
||||||
JOIN team_forum_threads th ON th.id = po.thread_id
|
JOIN team_forum_threads th ON th.id = po.thread_id
|
||||||
WHERE th.team_id = ?
|
WHERE th.team_id = ?
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ async function syncStatus() {
|
|||||||
configured: true,
|
configured: true,
|
||||||
lastSyncAt,
|
lastSyncAt,
|
||||||
// Never synced at all is stale: a page must not present an empty projection
|
// Never synced at all is stale: a page must not present an empty projection
|
||||||
// as a confirmed empty shard.
|
// as a confirmed empty one.
|
||||||
stale: ageS > intervalS * STALE_INTERVALS,
|
stale: ageS > intervalS * STALE_INTERVALS,
|
||||||
consecutiveFailures: state ? state.consecutive_failures : 0,
|
consecutiveFailures: state ? state.consecutive_failures : 0,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,21 +13,45 @@ async function findByProviderSubject(provider, subject) {
|
|||||||
// All identities linked to a given internal user (for the Account page).
|
// All identities linked to a given internal user (for the Account page).
|
||||||
async function listForUser(userId) {
|
async function listForUser(userId) {
|
||||||
return query(
|
return query(
|
||||||
'SELECT id, provider, subject, email, created_at FROM user_identities WHERE user_id = ? ORDER BY provider',
|
`SELECT id, provider, subject, email, display_name, avatar_url, created_at
|
||||||
|
FROM user_identities WHERE user_id = ? ORDER BY provider, created_at`,
|
||||||
[userId],
|
[userId],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function insert({ userId, provider, subject, email = null }) {
|
async function insert({ userId, provider, subject, email = null, displayName = null, avatarUrl = null }) {
|
||||||
const res = await query(
|
const res = await query(
|
||||||
'INSERT INTO user_identities (user_id, provider, subject, email) VALUES (?, ?, ?, ?)',
|
`INSERT INTO user_identities (user_id, provider, subject, email, display_name, avatar_url)
|
||||||
[userId, provider, subject, email],
|
VALUES (?, ?, ?, ?, ?, ?)`,
|
||||||
|
[userId, provider, subject, email, displayName, avatarUrl],
|
||||||
)
|
)
|
||||||
return res.insertId
|
return res.insertId
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove a user's link to a provider. Returns rows deleted.
|
// Refresh the name and avatar a provider reported at sign-in (Steam, D394). Only
|
||||||
async function deleteForUserProvider(userId, provider) {
|
// what the provider sent is written: a lookup that failed leaves the last good
|
||||||
|
// values in place rather than blanking them.
|
||||||
|
async function updateProfile(id, { displayName, avatarUrl }) {
|
||||||
|
const sets = []
|
||||||
|
const vals = []
|
||||||
|
if (displayName) { sets.push('display_name = ?'); vals.push(displayName) }
|
||||||
|
if (avatarUrl) { sets.push('avatar_url = ?'); vals.push(avatarUrl) }
|
||||||
|
if (!sets.length) return 0
|
||||||
|
const res = await query(`UPDATE user_identities SET ${sets.join(', ')} WHERE id = ?`, [...vals, id])
|
||||||
|
return Number(res.affectedRows || 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove a user's link to a provider — every identity of it, or, given an
|
||||||
|
// identity id, that one only (a user may hold several Steam accounts). Returns
|
||||||
|
// rows deleted.
|
||||||
|
async function deleteForUserProvider(userId, provider, identityId = null) {
|
||||||
|
if (identityId != null) {
|
||||||
|
const res = await query(
|
||||||
|
'DELETE FROM user_identities WHERE user_id = ? AND provider = ? AND id = ?',
|
||||||
|
[userId, provider, identityId],
|
||||||
|
)
|
||||||
|
return Number(res.affectedRows || 0)
|
||||||
|
}
|
||||||
const res = await query(
|
const res = await query(
|
||||||
'DELETE FROM user_identities WHERE user_id = ? AND provider = ?',
|
'DELETE FROM user_identities WHERE user_id = ? AND provider = ?',
|
||||||
[userId, provider],
|
[userId, provider],
|
||||||
@@ -35,4 +59,4 @@ async function deleteForUserProvider(userId, provider) {
|
|||||||
return Number(res.affectedRows || 0)
|
return Number(res.affectedRows || 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { findByProviderSubject, listForUser, insert, deleteForUserProvider }
|
module.exports = { findByProviderSubject, listForUser, insert, updateProfile, deleteForUserProvider }
|
||||||
|
|||||||
@@ -15,13 +15,21 @@ async function listForUser(userId) {
|
|||||||
|
|
||||||
// Link an external identity to an internal user. Returns the new row id. The
|
// Link an external identity to an internal user. Returns the new row id. The
|
||||||
// (provider, subject) UNIQUE constraint enforces one-identity-one-user at the DB.
|
// (provider, subject) UNIQUE constraint enforces one-identity-one-user at the DB.
|
||||||
async function link({ userId, provider, subject, email }) {
|
// `displayName` / `avatarUrl` are set by providers that report them (Steam);
|
||||||
return db.insert({ userId, provider, subject, email })
|
// the others leave them null.
|
||||||
|
async function link({ userId, provider, subject, email, displayName, avatarUrl }) {
|
||||||
|
return db.insert({ userId, provider, subject, email, displayName, avatarUrl })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlink a provider from a user. Returns rows removed (0 if nothing was linked).
|
// Refresh a linked identity's name and avatar from a sign-in's profile.
|
||||||
async function unlink(userId, provider) {
|
async function refreshProfile(identityId, { displayName, avatarUrl } = {}) {
|
||||||
return db.deleteForUserProvider(userId, provider)
|
return db.updateProfile(identityId, { displayName, avatarUrl })
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { findByProviderSubject, listForUser, link, unlink }
|
// Unlink a provider from a user: every identity of it, or the one `identityId`
|
||||||
|
// names. Returns rows removed (0 if nothing was linked).
|
||||||
|
async function unlink(userId, provider, identityId = null) {
|
||||||
|
return db.deleteForUserProvider(userId, provider, identityId)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { findByProviderSubject, listForUser, link, refreshProfile, unlink }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const { query } = require('../../utils/db')
|
const { query, transaction } = require('../../utils/db')
|
||||||
|
|
||||||
const PUBLIC_COLS =
|
const PUBLIC_COLS =
|
||||||
'id, username, role, status, email, email_verified, email_pending, totp_enabled, created_at, last_login_at'
|
'id, username, role, status, email, email_verified, email_pending, totp_enabled, created_at, last_login_at'
|
||||||
@@ -92,6 +92,31 @@ async function deleteUser(id) {
|
|||||||
return query('DELETE FROM users WHERE id = ?', [id])
|
return query('DELETE FROM users WHERE id = ?', [id])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete the account and, when `reserveName` is given, reserve it, as ONE
|
||||||
|
// transaction (ACCOUNT_DELETION.md §4.1 step 2): a staff name is never free for
|
||||||
|
// a moment between the two. `INSERT IGNORE` because a name already reserved
|
||||||
|
// (a second staff account renamed onto it cannot exist, but a hand-inserted row
|
||||||
|
// can) is the state wanted, not an error. Returns the rows deleted, 0 or 1.
|
||||||
|
async function deleteUserReserving(id, reserveName = null) {
|
||||||
|
return transaction(async (conn) => {
|
||||||
|
if (reserveName) {
|
||||||
|
await conn.query(
|
||||||
|
"INSERT IGNORE INTO reserved_usernames (username_norm, reason) VALUES (LOWER(?), 'deleted_staff')",
|
||||||
|
[reserveName],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const result = await conn.query('DELETE FROM users WHERE id = ?', [id])
|
||||||
|
return Number(result.affectedRows || 0)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// True when the name can never be taken again (AD9). The column's collation is
|
||||||
|
// users.username's, so this folds case exactly as the UNIQUE index does.
|
||||||
|
async function isUsernameReserved(username) {
|
||||||
|
const rows = await query('SELECT 1 FROM reserved_usernames WHERE username_norm = LOWER(?) LIMIT 1', [username])
|
||||||
|
return rows.length > 0
|
||||||
|
}
|
||||||
|
|
||||||
async function countUsers() {
|
async function countUsers() {
|
||||||
const rows = await query('SELECT COUNT(*) AS c FROM users')
|
const rows = await query('SELECT COUNT(*) AS c FROM users')
|
||||||
return Number(rows[0].c)
|
return Number(rows[0].c)
|
||||||
@@ -148,6 +173,8 @@ module.exports = {
|
|||||||
listUsers,
|
listUsers,
|
||||||
updateUser,
|
updateUser,
|
||||||
deleteUser,
|
deleteUser,
|
||||||
|
deleteUserReserving,
|
||||||
|
isUsernameReserved,
|
||||||
countUsers,
|
countUsers,
|
||||||
countAdmins,
|
countAdmins,
|
||||||
touchLastLogin,
|
touchLastLogin,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ function sanitize(user) {
|
|||||||
// password may be omitted/null — an SSO-provisioned player has no password until
|
// password may be omitted/null — an SSO-provisioned player has no password until
|
||||||
// they set one (a null hash makes password login impossible, see validatePassword).
|
// they set one (a null hash makes password login impossible, see validatePassword).
|
||||||
async function createUser({ username, password, role = 'admin', email = null, status = 'active', emailVerified = false }) {
|
async function createUser({ username, password, role = 'admin', email = null, status = 'active', emailVerified = false }) {
|
||||||
|
await refuseReserved(username)
|
||||||
const passwordHash = password ? await bcrypt.hash(password, SALT_ROUNDS) : null
|
const passwordHash = password ? await bcrypt.hash(password, SALT_ROUNDS) : null
|
||||||
const id = await usersDb.insertUser({ username, passwordHash, role, email, status, emailVerified })
|
const id = await usersDb.insertUser({ username, passwordHash, role, email, status, emailVerified })
|
||||||
return sanitize(await usersDb.findById(id))
|
return sanitize(await usersDb.findById(id))
|
||||||
@@ -63,9 +64,36 @@ function isDuplicateEmail(err) {
|
|||||||
// and nothing newly falls through to a 500. Only the case we can positively
|
// and nothing newly falls through to a 500. Only the case we can positively
|
||||||
// identify — email — is carved out.
|
// identify — email — is carved out.
|
||||||
function isDuplicateUsername(err) {
|
function isDuplicateUsername(err) {
|
||||||
|
if (err && err.code === USERNAME_RESERVED) return true
|
||||||
return isDuplicateKeyError(err) && !isDuplicateEmail(err)
|
return isDuplicateKeyError(err) && !isDuplicateEmail(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Reserved usernames (ACCOUNT_DELETION.md AD9) ───────────────────────────
|
||||||
|
//
|
||||||
|
// A deleted staff account's name can never be taken again. The refusal is
|
||||||
|
// raised HERE, in the two writes every username passes through, rather than in
|
||||||
|
// each of the six routes that create or rename an account: registration, an
|
||||||
|
// invite's acceptance, SSO provisioning, an admin creating or renaming a user,
|
||||||
|
// and a self-service change. Each of them already answers a duplicate username,
|
||||||
|
// and `isDuplicateUsername` above reports a reserved one as exactly that, so a
|
||||||
|
// reserved name reads as a taken one everywhere — the same 409, the same words,
|
||||||
|
// and SSO provisioning moves on to its next candidate.
|
||||||
|
//
|
||||||
|
// A check-then-write, so not atomic against a deletion committing in between.
|
||||||
|
// That window is one request wide and needs a staff account deleted at the same
|
||||||
|
// instant someone registers its name; the UNIQUE index still holds until the
|
||||||
|
// deletion commits.
|
||||||
|
const USERNAME_RESERVED = 'USERNAME_RESERVED'
|
||||||
|
|
||||||
|
async function refuseReserved(username) {
|
||||||
|
if (typeof username !== 'string' || !username) return
|
||||||
|
if (await usersDb.isUsernameReserved(username.trim())) {
|
||||||
|
const err = new Error('username is reserved')
|
||||||
|
err.code = USERNAME_RESERVED
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the raw row (incl. hash) — used by login only.
|
// Returns the raw row (incl. hash) — used by login only.
|
||||||
async function getRawByUsername(username) {
|
async function getRawByUsername(username) {
|
||||||
return usersDb.findByUsername(username)
|
return usersDb.findByUsername(username)
|
||||||
@@ -112,7 +140,10 @@ async function list() {
|
|||||||
|
|
||||||
async function update(id, { username, password, role, email, status, emailVerified }) {
|
async function update(id, { username, password, role, email, status, emailVerified }) {
|
||||||
const fields = {}
|
const fields = {}
|
||||||
if (username !== undefined) fields.username = username
|
if (username !== undefined) {
|
||||||
|
await refuseReserved(username)
|
||||||
|
fields.username = username
|
||||||
|
}
|
||||||
if (role !== undefined) fields.role = role
|
if (role !== undefined) fields.role = role
|
||||||
if (email !== undefined) fields.email = email
|
if (email !== undefined) fields.email = email
|
||||||
if (status !== undefined) fields.status = status
|
if (status !== undefined) fields.status = status
|
||||||
@@ -155,6 +186,15 @@ async function remove(id) {
|
|||||||
return usersDb.deleteUser(id)
|
return usersDb.deleteUser(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The deletion's own write: the row goes, and a staff name is reserved in the
|
||||||
|
// same transaction. Only auth/accountDeletion.js calls this; `remove` above is
|
||||||
|
// for undoing an account this request itself just created (a lost invite race).
|
||||||
|
async function removeReserving(id, reserveName = null) {
|
||||||
|
return usersDb.deleteUserReserving(id, reserveName)
|
||||||
|
}
|
||||||
|
|
||||||
|
const isUsernameReserved = (username) => usersDb.isUsernameReserved(username)
|
||||||
|
|
||||||
async function count() {
|
async function count() {
|
||||||
return usersDb.countUsers()
|
return usersDb.countUsers()
|
||||||
}
|
}
|
||||||
@@ -186,6 +226,9 @@ module.exports = {
|
|||||||
invalidateSessions,
|
invalidateSessions,
|
||||||
setSessionCutoff,
|
setSessionCutoff,
|
||||||
remove,
|
remove,
|
||||||
|
removeReserving,
|
||||||
|
isUsernameReserved,
|
||||||
|
USERNAME_RESERVED,
|
||||||
count,
|
count,
|
||||||
countAdmins,
|
countAdmins,
|
||||||
recordLogin,
|
recordLogin,
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ const { MODULE_API_VERSION } = require('./version')
|
|||||||
const semver = require('./semver')
|
const semver = require('./semver')
|
||||||
const registries = require('./registries')
|
const registries = require('./registries')
|
||||||
const { splitStatements } = require('../utils/sqlStatements')
|
const { splitStatements } = require('../utils/sqlStatements')
|
||||||
|
const demoPaths = require('../demo/paths')
|
||||||
|
const { isDemo } = require('../demo/mode')
|
||||||
|
|
||||||
const log = require('../utils/logger')('modules')
|
const log = require('../utils/logger')('modules')
|
||||||
|
|
||||||
@@ -62,9 +64,15 @@ const TIERS = ['public', 'admin', 'player']
|
|||||||
|
|
||||||
const MANIFEST_KEYS = new Set([
|
const MANIFEST_KEYS = new Set([
|
||||||
'id', 'name', 'version', 'coreApi', 'server', 'client',
|
'id', 'name', 'version', 'coreApi', 'server', 'client',
|
||||||
'schema', 'purge', 'mounts', 'extensions', 'capabilities',
|
'schema', 'purge', 'mounts', 'extensions', 'capabilities', 'demoLocks',
|
||||||
])
|
])
|
||||||
|
|
||||||
|
// What a `demoLocks` entry may lock (API 1.18.0, DEMO_MODE.md §3.2): writes
|
||||||
|
// only. Reads are never locked by declaration — the one read the demo refuses
|
||||||
|
// (a plugin config that holds credentials) depends on WHICH file is asked for,
|
||||||
|
// so the module decides it behind `ctx.demoMode` rather than by route.
|
||||||
|
const DEMO_LOCK_METHODS = ['POST', 'PUT', 'PATCH', 'DELETE']
|
||||||
|
|
||||||
// Extension slots are declared by core, at require time, in the router that owns
|
// Extension slots are declared by core, at require time, in the router that owns
|
||||||
// the resource (registries.declareSlot). The loader asks the registry which exist
|
// the resource (registries.declareSlot). The loader asks the registry which exist
|
||||||
// rather than keeping a list, for the same reason the prefix check probes the
|
// rather than keeping a list, for the same reason the prefix check probes the
|
||||||
@@ -311,6 +319,26 @@ function buildCtx(id, moduleRoot) {
|
|||||||
// exports creation, role changes and password handling, none of which is a
|
// exports creation, role changes and password handling, none of which is a
|
||||||
// module's business.
|
// module's business.
|
||||||
users: { getById: users.getById },
|
users: { getById: users.getById },
|
||||||
|
// API 1.17.0 (STEAM_SIGNIN.md §4). READ only, one provider at a time: what a
|
||||||
|
// user has linked, as core verified it — the Steam id a module can trust is
|
||||||
|
// the one Steam's own `check_authentication` proved, never one a player typed.
|
||||||
|
// Linking and unlinking stay core's (the hooks on `api` are how a module takes
|
||||||
|
// part), and the row id and email are core's business, so they are not here.
|
||||||
|
identities: {
|
||||||
|
list: async (userId, provider) => {
|
||||||
|
// eslint-disable-next-line global-require
|
||||||
|
const rows = await require('../model/userIdentities/userIdentities.model').listForUser(userId)
|
||||||
|
return rows
|
||||||
|
.filter((r) => r.provider === provider)
|
||||||
|
.map((r) => ({
|
||||||
|
provider: r.provider,
|
||||||
|
subject: r.subject,
|
||||||
|
displayName: r.display_name || null,
|
||||||
|
avatarUrl: r.avatar_url || null,
|
||||||
|
linkedAt: r.created_at,
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
},
|
||||||
// Where this deployment is reachable, for a module that has to build an
|
// Where this deployment is reachable, for a module that has to build an
|
||||||
// absolute link (an announcement carries one into a game window or a chat
|
// absolute link (an announcement carries one into a game window or a chat
|
||||||
// message, where a relative path means nothing). §2.7 forbids a module
|
// message, where a relative path means nothing). §2.7 forbids a module
|
||||||
@@ -318,6 +346,31 @@ function buildCtx(id, moduleRoot) {
|
|||||||
// configuration, so core answers it. A getter, not a captured string: the
|
// configuration, so core answers it. A getter, not a captured string: the
|
||||||
// value is read per call, so it cannot go stale against the env.
|
// value is read per call, so it cannot go stale against the env.
|
||||||
site: { get baseUrl() { return (process.env.APP_BASE_URL || 'http://localhost:5173').replace(/\/+$/, '') } },
|
site: { get baseUrl() { return (process.env.APP_BASE_URL || 'http://localhost:5173').replace(/\/+$/, '') } },
|
||||||
|
// API 1.21.0 (USER_SAFETY.md §4.1, S11). READ only. What one reader has
|
||||||
|
// blocked and hidden, so a module filters its own per-reader feeds on the
|
||||||
|
// server — a chat feed is already read per viewer, so the website and the app
|
||||||
|
// need no list of their own.
|
||||||
|
//
|
||||||
|
// `forViewer` is bound to the CALLING module: it answers the reader's account
|
||||||
|
// blocks (with any game block whose identity is now linked already folded in,
|
||||||
|
// S14, and staff dropped, S8), this module's own unlinked game blocks, and
|
||||||
|
// the reader's hides on this module's report targets. Another module's game
|
||||||
|
// blocks and hides are not its business. A signed-out reader has none.
|
||||||
|
//
|
||||||
|
// `staffAmong(userIds)` answers which of those accounts are staff, for a
|
||||||
|
// module that marks lines `canBlock` (S13).
|
||||||
|
safety: {
|
||||||
|
// eslint-disable-next-line global-require
|
||||||
|
forViewer: (userId) => require('../model/safety/userSafety.model').forModuleViewer(id, userId),
|
||||||
|
// eslint-disable-next-line global-require
|
||||||
|
staffAmong: (userIds) => require('../model/safety/userSafety.model').staffAmong(userIds),
|
||||||
|
},
|
||||||
|
// API 1.18.0 (DEMO_MODE.md §3.4, §3.5). True on the public demo. For the
|
||||||
|
// locks a route list cannot express — a console command by its first word,
|
||||||
|
// a config file by which plugin owns it — which the module enforces in its
|
||||||
|
// own handlers. A boolean, read once: the flag is the deployment's, and a
|
||||||
|
// deployment does not change what it is while it runs.
|
||||||
|
demoMode: isDemo(),
|
||||||
}
|
}
|
||||||
// A guard against accident, not against a hostile module — the boundary is
|
// A guard against accident, not against a hostile module — the boundary is
|
||||||
// organisational, not a security boundary (MODULE_SYSTEM.md §2.2).
|
// organisational, not a security boundary (MODULE_SYSTEM.md §2.2).
|
||||||
@@ -466,12 +519,50 @@ function buildApi(record) {
|
|||||||
once('registerEventTemplates')
|
once('registerEventTemplates')
|
||||||
record.staged.registerEventTemplates(templates)
|
record.staged.registerEventTemplates(templates)
|
||||||
},
|
},
|
||||||
|
// API 1.21.0 (USER_SAFETY.md §4.1). What of the module's content a member
|
||||||
|
// can report, hide for themself and block the author of, and the game
|
||||||
|
// identity those authors are known by. Both STAGE, and `once` for the reason
|
||||||
|
// every batch above takes it.
|
||||||
|
registerReportTargets(targets) {
|
||||||
|
once('registerReportTargets')
|
||||||
|
record.staged.registerReportTargets(targets)
|
||||||
|
},
|
||||||
|
registerGameIdentities(identities) {
|
||||||
|
once('registerGameIdentities')
|
||||||
|
record.staged.registerGameIdentities(identities)
|
||||||
|
},
|
||||||
// The two lifecycle hooks (§2.5). Registered here, dispatched from
|
// The two lifecycle hooks (§2.5). Registered here, dispatched from
|
||||||
// lifecycle.js — this file runs with no database and the hooks run with one.
|
// lifecycle.js — this file runs with no database and the hooks run with one.
|
||||||
// Both are optional: a module with no warm-up and nothing to close simply
|
// Both are optional: a module with no warm-up and nothing to close simply
|
||||||
// never calls them.
|
// never calls them.
|
||||||
onBoot: hook('onBoot'),
|
onBoot: hook('onBoot'),
|
||||||
onShutdown: hook('onShutdown'),
|
onShutdown: hook('onShutdown'),
|
||||||
|
// API 1.17.0 (STEAM_SIGNIN.md §4). Core calling the module about an external
|
||||||
|
// identity a signed-in user is linking, dispatched from auth/identityHooks.js.
|
||||||
|
//
|
||||||
|
// `onIdentityLinking` answers before anything is written and can only REFUSE
|
||||||
|
// (D396: a Steam id already another account's Rust link). It runs inside the
|
||||||
|
// link flow of a user who is already signed in, so it has no path to a session
|
||||||
|
// and cannot let through a link core would refuse. `onIdentityLinked` hears a
|
||||||
|
// link after it is written. There is no unlink hook: D393 leaves a module
|
||||||
|
// nothing to undo when a sign-in identity goes.
|
||||||
|
onIdentityLinking: hook('onIdentityLinking'),
|
||||||
|
onIdentityLinked: hook('onIdentityLinked'),
|
||||||
|
// API 1.18.0 (DEMO_MODE.md §7.3, DM15). Core's `seed:demo` handing the
|
||||||
|
// module its part of the seed fixture, so the module writes its own rows —
|
||||||
|
// a game server link, a player's game link — through its own model. Core
|
||||||
|
// never writes a module's tables. Called from the seed script only, never
|
||||||
|
// by the running server, and only with DEMO_MODE on.
|
||||||
|
onDemoSeed: hook('onDemoSeed'),
|
||||||
|
// API 1.20.0 (ACCOUNT_DELETION.md §4.1, AD10, AD11). Core telling the module
|
||||||
|
// an account is about to be deleted, dispatched from auth/accountDeletion.js
|
||||||
|
// BEFORE the row goes, so the module can still read the person's links and
|
||||||
|
// undo them through its own unlink — a cascade is not an unlink, and for UO
|
||||||
|
// the link lives on the shard. It cannot veto: a throw or a hook past core's
|
||||||
|
// time limit is logged and the deletion goes ahead, because a member's
|
||||||
|
// deletion request must be honoured. Whatever the module could not finish is
|
||||||
|
// its own pending work.
|
||||||
|
onUserDeleting: hook('onUserDeleting'),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -710,6 +801,8 @@ function readManifest(dir, id, tierRouters) {
|
|||||||
if (!registries.hasSlot(slot)) fail('extensions', `unknown extension slot "${slot}"`)
|
if (!registries.hasSlot(slot)) fail('extensions', `unknown extension slot "${slot}"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkDemoLocks(manifest)
|
||||||
|
|
||||||
if (manifest.client !== undefined) {
|
if (manifest.client !== undefined) {
|
||||||
if (typeof manifest.client !== 'object' || manifest.client === null || Array.isArray(manifest.client)) {
|
if (typeof manifest.client !== 'object' || manifest.client === null || Array.isArray(manifest.client)) {
|
||||||
fail('manifest', 'client must be an object')
|
fail('manifest', 'client must be an object')
|
||||||
@@ -730,6 +823,40 @@ function readManifest(dir, id, tierRouters) {
|
|||||||
return manifest
|
return manifest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate `demoLocks` (API 1.18.0, DEMO_MODE.md §3.2), on every boot and not
|
||||||
|
* only on the demo: a module whose declaration is wrong should find out on the
|
||||||
|
* developer's machine, not on the one deployment where it is read.
|
||||||
|
*
|
||||||
|
* Each entry is `{ method, path }`, the path relative to /api/v1 and under one
|
||||||
|
* of the module's own declared mounts — a module may lock its own routes and
|
||||||
|
* nobody else's, the same boundary `mounts` draws for serving them.
|
||||||
|
*/
|
||||||
|
function checkDemoLocks(manifest) {
|
||||||
|
if (manifest.demoLocks === undefined) return
|
||||||
|
if (!Array.isArray(manifest.demoLocks)) fail('manifest', 'demoLocks must be an array')
|
||||||
|
for (const entry of manifest.demoLocks) {
|
||||||
|
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
||||||
|
fail('manifest', 'each demoLocks entry must be an object')
|
||||||
|
}
|
||||||
|
for (const key of Object.keys(entry)) {
|
||||||
|
if (key !== 'method' && key !== 'path') fail('manifest', `unknown key "demoLocks.${key}" in module.json`)
|
||||||
|
}
|
||||||
|
if (!DEMO_LOCK_METHODS.includes(entry.method)) {
|
||||||
|
fail('manifest', `demoLocks method "${entry.method}" must be one of ${DEMO_LOCK_METHODS.join(', ')}`)
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
demoPaths.compile(entry.path)
|
||||||
|
} catch (err) {
|
||||||
|
fail('manifest', `demoLocks: ${err.message}`)
|
||||||
|
}
|
||||||
|
const [, tier, prefix] = entry.path.split('/')
|
||||||
|
if (!(manifest.mounts?.[tier] || []).includes(`/${prefix}`)) {
|
||||||
|
fail('mounts', `demoLocks path ${entry.path} is outside the module's mounts`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// What the module registered must equal what it declared — in both directions.
|
// What the module registered must equal what it declared — in both directions.
|
||||||
function checkDeclared(record) {
|
function checkDeclared(record) {
|
||||||
const declared = record.manifest.mounts || {}
|
const declared = record.manifest.mounts || {}
|
||||||
@@ -782,10 +909,26 @@ function load(tierRouters) {
|
|||||||
return // no modules directory is the normal case for a bare core
|
return // no modules directory is the normal case for a bare core
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// One module per site, at boot as at install (`install.js`, org lead
|
||||||
|
// 2026-09-23; W19 in Rust PLAN_LAST_FIXES, 2026-10-22). Install already
|
||||||
|
// refuses a second module, so two on the volume means someone copied one in by
|
||||||
|
// hand. The contract's singletons assume one: Module-uo and Module-Rust both
|
||||||
|
// fill `admin.users.detail`, and the second used to fail at register with a
|
||||||
|
// slot collision that named neither the rule nor the fix. Now the first in
|
||||||
|
// scan order is the site's module, whether or not it then loads, and every
|
||||||
|
// other is refused before a line of its code is required.
|
||||||
|
let holder = null
|
||||||
|
|
||||||
for (const id of entries) {
|
for (const id of entries) {
|
||||||
const dir = path.join(MODULES_DIR, id)
|
const dir = path.join(MODULES_DIR, id)
|
||||||
if (!fs.existsSync(path.join(dir, 'module.json'))) continue
|
if (!fs.existsSync(path.join(dir, 'module.json'))) continue
|
||||||
|
|
||||||
|
if (holder) {
|
||||||
|
refuseSecond(id, dir, holder)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
holder = id
|
||||||
|
|
||||||
const record = {
|
const record = {
|
||||||
id,
|
id,
|
||||||
dir,
|
dir,
|
||||||
@@ -794,7 +937,14 @@ function load(tierRouters) {
|
|||||||
staged: registries.stage(id),
|
staged: registries.stage(id),
|
||||||
tables: new Set(),
|
tables: new Set(),
|
||||||
called: new Set(),
|
called: new Set(),
|
||||||
hooks: { onBoot: null, onShutdown: null },
|
hooks: {
|
||||||
|
onBoot: null,
|
||||||
|
onShutdown: null,
|
||||||
|
onIdentityLinking: null,
|
||||||
|
onIdentityLinked: null,
|
||||||
|
onDemoSeed: null,
|
||||||
|
onUserDeleting: null,
|
||||||
|
},
|
||||||
client: null,
|
client: null,
|
||||||
ctx: null,
|
ctx: null,
|
||||||
state: 'installed',
|
state: 'installed',
|
||||||
@@ -855,8 +1005,10 @@ function load(tierRouters) {
|
|||||||
for (const record of modules.values()) {
|
for (const record of modules.values()) {
|
||||||
if (record.state !== 'registered') continue
|
if (record.state !== 'registered') continue
|
||||||
try {
|
try {
|
||||||
// Commit what this module staged. Collisions with core or with an earlier
|
// Commit what this module staged. Collisions with core surface here and
|
||||||
// module surface here, in scan order, and cost only this module.
|
// cost only this module. (An earlier module is no longer possible — one
|
||||||
|
// module per site, above — and the module-against-module checks stay as
|
||||||
|
// the second line behind that rule.)
|
||||||
registries.apply(record.staged.staged)
|
registries.apply(record.staged.staged)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
record.state = 'startup_failed'
|
record.state = 'startup_failed'
|
||||||
@@ -871,6 +1023,45 @@ function load(tierRouters) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Record a module refused because another already holds the site (W19).
|
||||||
|
*
|
||||||
|
* `startup_failed` at the `manifest` stage, like any module that never reached
|
||||||
|
* register: no routes, no nav, no tables, and Admin → Modules says why. The
|
||||||
|
* name and version are read for that panel and nothing else; a module.json that does not
|
||||||
|
* parse is still refused for the same reason, since the reason is not its
|
||||||
|
* contents.
|
||||||
|
*/
|
||||||
|
function refuseSecond(id, dir, holder) {
|
||||||
|
const manifest = { id, version: 'unknown' }
|
||||||
|
try {
|
||||||
|
const raw = JSON.parse(fs.readFileSync(path.join(dir, 'module.json'), 'utf8'))
|
||||||
|
if (raw && typeof raw.version === 'string') manifest.version = raw.version
|
||||||
|
if (raw && typeof raw.name === 'string') manifest.name = raw.name
|
||||||
|
} catch {
|
||||||
|
// the panel shows "unknown"; the refusal stands either way
|
||||||
|
}
|
||||||
|
const reason =
|
||||||
|
`this site already runs the module "${holder}", and a site runs one module. ` +
|
||||||
|
`Remove "${id}" or "${holder}" from the modules directory; the one that sorts first by name is the one that starts.`
|
||||||
|
modules.set(id, {
|
||||||
|
id,
|
||||||
|
dir,
|
||||||
|
manifest,
|
||||||
|
routes: { public: new Map(), admin: new Map(), player: new Map() },
|
||||||
|
staged: null,
|
||||||
|
tables: new Set(),
|
||||||
|
called: new Set(),
|
||||||
|
hooks: { onBoot: null, onShutdown: null, onIdentityLinking: null, onIdentityLinked: null, onUserDeleting: null },
|
||||||
|
client: null,
|
||||||
|
ctx: null,
|
||||||
|
state: 'startup_failed',
|
||||||
|
stage: 'manifest',
|
||||||
|
reason,
|
||||||
|
})
|
||||||
|
log.error(`module "${id}" was not started — continuing without it`, { stage: 'manifest', reason })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mount one module's routers onto the tier routers, behind the dispatch guard.
|
* Mount one module's routers onto the tier routers, behind the dispatch guard.
|
||||||
*
|
*
|
||||||
@@ -1022,6 +1213,90 @@ function shutdownHooks() {
|
|||||||
.reverse()
|
.reverse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The identity hooks of one name (`onIdentityLinking` | `onIdentityLinked`), in
|
||||||
|
* registration order (API 1.17.0).
|
||||||
|
*
|
||||||
|
* `started` only, the rule every dispatch here follows: a module that is
|
||||||
|
* disabled, or whose `onBoot` threw, is not serving and has no say in a link.
|
||||||
|
* Empty in a process that never loaded modules (the seed script, unit tests), so
|
||||||
|
* the link flow there behaves exactly as a bare core.
|
||||||
|
*
|
||||||
|
* @returns {{id: string, hook: Function}[]}
|
||||||
|
*/
|
||||||
|
function identityHooks(name) {
|
||||||
|
if (!loaded) return []
|
||||||
|
return [...modules.values()]
|
||||||
|
.filter((r) => r.state === 'started' && r.hooks[name])
|
||||||
|
.map((r) => ({ id: r.id, hook: r.hooks[name] }))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `onUserDeleting` hooks, in registration order (API 1.20.0,
|
||||||
|
* ACCOUNT_DELETION.md AD10).
|
||||||
|
*
|
||||||
|
* `started` only, like the identity hooks above: a disabled module, or one whose
|
||||||
|
* `onBoot` threw, is not serving and holds no link it could undo now. Empty in a
|
||||||
|
* process that never loaded modules, so a deletion there is core's alone.
|
||||||
|
*
|
||||||
|
* @returns {{id: string, hook: Function}[]}
|
||||||
|
*/
|
||||||
|
function userDeletingHooks() {
|
||||||
|
if (!loaded) return []
|
||||||
|
return [...modules.values()]
|
||||||
|
.filter((r) => r.state === 'started' && r.hooks.onUserDeleting)
|
||||||
|
.map((r) => ({ id: r.id, hook: r.hooks.onUserDeleting }))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every installed module's `demoLocks`, compiled, for the demo lock in
|
||||||
|
* demo/locks.js (API 1.18.0).
|
||||||
|
*
|
||||||
|
* Every module whose manifest validated, whatever its state. A disabled or
|
||||||
|
* failed module's routes already answer 404 or 503, so its locks change
|
||||||
|
* nothing — and a lock that disappeared whenever its module was between states
|
||||||
|
* is a lock with a gap in it. Empty before load() has run, rather than throwing:
|
||||||
|
* the middleware is mounted before the loader and asks per request.
|
||||||
|
*
|
||||||
|
* @returns {{methods: string[], path: string, compiled: object, source: string}[]}
|
||||||
|
*/
|
||||||
|
let demoLockCache = null
|
||||||
|
function demoLocks() {
|
||||||
|
if (!loaded) return []
|
||||||
|
// Manifests are read once, in load(), which is synchronous — so the answer
|
||||||
|
// cannot change after the first request asks, and is compiled once.
|
||||||
|
if (demoLockCache) return demoLockCache
|
||||||
|
const out = []
|
||||||
|
for (const record of modules.values()) {
|
||||||
|
for (const entry of record.manifest?.demoLocks || []) {
|
||||||
|
out.push({
|
||||||
|
methods: [entry.method],
|
||||||
|
path: entry.path,
|
||||||
|
compiled: demoPaths.compile(entry.path),
|
||||||
|
source: record.id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
demoLockCache = out
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `onDemoSeed` hooks, for `npm run seed:demo` (API 1.18.0, DM15).
|
||||||
|
*
|
||||||
|
* `registered` or `started`: the seed is its own process, where nothing calls
|
||||||
|
* onBoot, so its modules never get past `registered`. A module that failed to
|
||||||
|
* load is not handed a fixture for tables it may not have.
|
||||||
|
*
|
||||||
|
* @returns {{id: string, hook: Function, ctx: object}[]}
|
||||||
|
*/
|
||||||
|
function demoSeedHooks() {
|
||||||
|
assertLoaded('demoSeedHooks')
|
||||||
|
return [...modules.values()]
|
||||||
|
.filter((r) => (r.state === 'registered' || r.state === 'started') && r.hooks.onDemoSeed)
|
||||||
|
.map((r) => ({ id: r.id, hook: r.hooks.onDemoSeed, ctx: r.ctx }))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One module's `onShutdown`, for stopping it on its own rather than at exit.
|
* One module's `onShutdown`, for stopping it on its own rather than at exit.
|
||||||
*
|
*
|
||||||
@@ -1147,6 +1422,10 @@ module.exports = {
|
|||||||
fragments,
|
fragments,
|
||||||
bootable,
|
bootable,
|
||||||
shutdownHooks,
|
shutdownHooks,
|
||||||
|
identityHooks,
|
||||||
|
userDeletingHooks,
|
||||||
|
demoLocks,
|
||||||
|
demoSeedHooks,
|
||||||
stopHook,
|
stopHook,
|
||||||
clientChunks,
|
clientChunks,
|
||||||
clientEntryUrls,
|
clientEntryUrls,
|
||||||
|
|||||||
@@ -97,6 +97,26 @@ const postHooks = new Map()
|
|||||||
// second registration is a collision rather than an addition.
|
// second registration is a collision rather than an addition.
|
||||||
let teamProvider = null
|
let teamProvider = null
|
||||||
|
|
||||||
|
// report target type → { owner, id, label, snapshot, hide, unhide } (API 1.21.0,
|
||||||
|
// USER_SAFETY.md §4.1). A module's content that a member can report, hide for
|
||||||
|
// themself, and block the author of — and that staff can hide for everyone. Core
|
||||||
|
// files the report and keeps the snapshot; the module owns the content and its
|
||||||
|
// hidden flag, so `hide`/`unhide` are the module's.
|
||||||
|
//
|
||||||
|
// Core's own forum types are NOT in this map: they predate it and their reads
|
||||||
|
// are core's, so `model/safety/targets.js` answers them directly. Registering
|
||||||
|
// them here would put core's forum behind a call core makes to itself.
|
||||||
|
const reportTargets = new Map()
|
||||||
|
|
||||||
|
// `${owner}:${kind}` → { owner, kind, label, ownersOf } (API 1.21.0, S12, S14).
|
||||||
|
// A game identity a module's report targets name as their author — for Rust, a
|
||||||
|
// Steam id. `ownersOf(externalIds)` answers which website account each is linked
|
||||||
|
// to, which is how a block on a chat speaker lands on their ACCOUNT when they
|
||||||
|
// have one, and how a block on an unlinked id becomes an account block once it
|
||||||
|
// is linked. Keyed by owner as well as kind: two modules may both speak of
|
||||||
|
// Steam ids, and each answers only for its own links.
|
||||||
|
const gameIdentities = new Map()
|
||||||
|
|
||||||
// command name → { owner, name, description, options, access, handler }. Slash
|
// command name → { owner, name, description, options, access, handler }. Slash
|
||||||
// commands a registrant has published for the chat platform (API 1.6.0,
|
// commands a registrant has published for the chat platform (API 1.6.0,
|
||||||
// TEAMS.md §7.1).
|
// TEAMS.md §7.1).
|
||||||
@@ -361,6 +381,17 @@ const registeredTeamProvider = () => teamProvider
|
|||||||
/** Is there a Team provider at all? Read by the reconciler and the read API. */
|
/** Is there a Team provider at all? Read by the reconciler and the read API. */
|
||||||
const hasTeamProvider = () => teamProvider !== null
|
const hasTeamProvider = () => teamProvider !== null
|
||||||
|
|
||||||
|
// ── Report targets and game identities (USER_SAFETY.md §4.1) ──────────────
|
||||||
|
|
||||||
|
/** One module report target, or null. Core's forum types are never here. */
|
||||||
|
const reportTarget = (type) => reportTargets.get(type) || null
|
||||||
|
|
||||||
|
/** Every module report target, in registration order. */
|
||||||
|
const allReportTargets = () => [...reportTargets.values()]
|
||||||
|
|
||||||
|
/** One module's game identity of one kind, or null. */
|
||||||
|
const gameIdentity = (owner, kind) => gameIdentities.get(`${owner}:${kind}`) || null
|
||||||
|
|
||||||
// ── Slash commands (TEAMS.md §7.1) ─────────────────────────────────────────
|
// ── Slash commands (TEAMS.md §7.1) ─────────────────────────────────────────
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -445,14 +476,14 @@ async function resolveAudience(id, params = {}) {
|
|||||||
/**
|
/**
|
||||||
* Every declaration WITHOUT its callables — what the admin catalog serves.
|
* Every declaration WITHOUT its callables — what the admin catalog serves.
|
||||||
*
|
*
|
||||||
* `perform`, `revert`, `reconcile`, `cost` and `progress` are stripped for the same reason `resolve` is
|
* `perform`, `revert`, `reconcile`, `cost`, `progress` and `demoRefuses` are stripped for the same reason `resolve` is
|
||||||
* stripped from an audience and `handler` from a slash command: this is the
|
* stripped from an audience and `handler` from a slash command: this is the
|
||||||
* object that leaves the process, and the browser's whole relationship with an
|
* object that leaves the process, and the browser's whole relationship with an
|
||||||
* action is naming one by id. §F's "a module registers actions server-side and
|
* action is naming one by id. §F's "a module registers actions server-side and
|
||||||
* adds no routes for them" is only true if the functions never ride out.
|
* adds no routes for them" is only true if the functions never ride out.
|
||||||
*/
|
*/
|
||||||
const allEventActions = () =>
|
const allEventActions = () =>
|
||||||
[...eventActions.values()].map(({ perform, revert, reconcile, cost, progress, ...rest }) => rest)
|
[...eventActions.values()].map(({ perform, revert, reconcile, cost, progress, demoRefuses, ...rest }) => rest)
|
||||||
|
|
||||||
/** One declaration, callables included. The runner's lookup (Phase 2). */
|
/** One declaration, callables included. The runner's lookup (Phase 2). */
|
||||||
const eventAction = (id) => eventActions.get(id) || null
|
const eventAction = (id) => eventActions.get(id) || null
|
||||||
@@ -682,6 +713,55 @@ function checkTeamProviderShape(entry) {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A report target (API 1.21.0, USER_SAFETY.md §4.1). The copy is explicit, like
|
||||||
|
// the team provider's: what core calls is what is named here.
|
||||||
|
//
|
||||||
|
// snapshot({ targetId, viewer }) → { author, text, at, where } | null
|
||||||
|
// What the item is, for THIS viewer. `null` when it is gone or the viewer
|
||||||
|
// may not see it — core answers 404 either way, so a report, a block or a
|
||||||
|
// snapshot can never confirm an item the viewer could not have seen.
|
||||||
|
// `author` is { name, userId|null, identity: { kind, id }|null }.
|
||||||
|
// hide({ targetId, actor }) / unhide({ targetId, actor })
|
||||||
|
// Staff's hide for everyone (S3, S10), called from the Reports queue.
|
||||||
|
const REPORT_TARGET_ID = /^[a-z][a-z0-9-]*\.[a-z0-9][a-z0-9_.-]{0,22}$/
|
||||||
|
|
||||||
|
function checkReportTargetShape(entry) {
|
||||||
|
const t = entry || {}
|
||||||
|
if (typeof t.id !== 'string' || !REPORT_TARGET_ID.test(t.id) || t.id.length > 32) {
|
||||||
|
throw new Error(`registerReportTargets: bad id "${t.id}"`)
|
||||||
|
}
|
||||||
|
if (typeof t.label !== 'string' || !t.label.trim() || t.label.length > 40) {
|
||||||
|
throw new Error(`registerReportTargets: ${t.id} needs a label of at most 40 characters`)
|
||||||
|
}
|
||||||
|
for (const name of ['snapshot', 'hide', 'unhide']) {
|
||||||
|
if (typeof t[name] !== 'function') {
|
||||||
|
throw new Error(`registerReportTargets: ${t.id}.${name}() is missing or not a function`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { id: t.id, label: t.label.trim(), snapshot: t.snapshot, hide: t.hide, unhide: t.unhide }
|
||||||
|
}
|
||||||
|
|
||||||
|
// A game identity (API 1.21.0, S12, S14).
|
||||||
|
//
|
||||||
|
// ownersOf(externalIds) → { [externalId]: userId }
|
||||||
|
// The website account each id is linked to, through THIS module's links.
|
||||||
|
// An id with no account is left out.
|
||||||
|
const IDENTITY_KIND = /^[a-z][a-z0-9-]{1,31}$/
|
||||||
|
|
||||||
|
function checkGameIdentityShape(entry) {
|
||||||
|
const g = entry || {}
|
||||||
|
if (typeof g.kind !== 'string' || !IDENTITY_KIND.test(g.kind)) {
|
||||||
|
throw new Error(`registerGameIdentities: bad kind "${g.kind}"`)
|
||||||
|
}
|
||||||
|
if (typeof g.label !== 'string' || !g.label.trim() || g.label.length > 40) {
|
||||||
|
throw new Error(`registerGameIdentities: ${g.kind} needs a label of at most 40 characters`)
|
||||||
|
}
|
||||||
|
if (typeof g.ownersOf !== 'function') {
|
||||||
|
throw new Error(`registerGameIdentities: ${g.kind}.ownersOf() is missing or not a function`)
|
||||||
|
}
|
||||||
|
return { kind: g.kind, label: g.label.trim(), ownersOf: g.ownersOf }
|
||||||
|
}
|
||||||
|
|
||||||
// `pageUrlTemplate` is the fifth member and OPTIONAL (TEAMS.md §6.4, phase 6).
|
// `pageUrlTemplate` is the fifth member and OPTIONAL (TEAMS.md §6.4, phase 6).
|
||||||
//
|
//
|
||||||
// **Why a module has to supply this at all.** Teams are a contract primitive with
|
// **Why a module has to supply this at all.** Teams are a contract primitive with
|
||||||
@@ -1128,7 +1208,7 @@ function checkActionParam(actionId, entry, seen, call = 'registerEventActions')
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `registerEventActions([{ id, label, risk, reversible, version, budgetMs, cost, params, perform, revert, reconcile, progress }])`.
|
* `registerEventActions([{ id, label, risk, reversible, version, budgetMs, cost, params, perform, revert, reconcile, progress, demoRefuses }])`.
|
||||||
*
|
*
|
||||||
* A typed verb core may ask a registrant to carry out. Everything decidable from
|
* A typed verb core may ask a registrant to carry out. Everything decidable from
|
||||||
* the argument alone is decided here, at the call; the collision — is this id
|
* the argument alone is decided here, at the call; the collision — is this id
|
||||||
@@ -1211,6 +1291,13 @@ function checkEventActionShape(entry) {
|
|||||||
if (a.progress !== undefined && typeof a.progress !== 'function') {
|
if (a.progress !== undefined && typeof a.progress !== 'function') {
|
||||||
throw new Error(`registerEventActions: ${a.id} progress must be a function`)
|
throw new Error(`registerEventActions: ${a.id} progress must be a function`)
|
||||||
}
|
}
|
||||||
|
// 1.19.0, optional: the public demo's save-time refusal (DEMO_MODE.md §3.4,
|
||||||
|
// DM18). Asked only with DEMO_MODE on, by the definition save path; a
|
||||||
|
// sentence back refuses the save `403 DEMO_LOCKED`. The module still checks
|
||||||
|
// at run, because a definition can predate the list it is checked against.
|
||||||
|
if (a.demoRefuses !== undefined && typeof a.demoRefuses !== 'function') {
|
||||||
|
throw new Error(`registerEventActions: ${a.id} demoRefuses must be a function of its params`)
|
||||||
|
}
|
||||||
|
|
||||||
const version = a.version === undefined ? 1 : a.version
|
const version = a.version === undefined ? 1 : a.version
|
||||||
if (!Number.isInteger(version) || version < 1) {
|
if (!Number.isInteger(version) || version < 1) {
|
||||||
@@ -1244,6 +1331,7 @@ function checkEventActionShape(entry) {
|
|||||||
revert: a.revert || null,
|
revert: a.revert || null,
|
||||||
reconcile: a.reconcile || null,
|
reconcile: a.reconcile || null,
|
||||||
progress: a.progress || null,
|
progress: a.progress || null,
|
||||||
|
demoRefuses: a.demoRefuses || null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1780,6 +1868,8 @@ function stage(owner) {
|
|||||||
eventLeases: [],
|
eventLeases: [],
|
||||||
eventOptionSources: [],
|
eventOptionSources: [],
|
||||||
eventTemplates: [],
|
eventTemplates: [],
|
||||||
|
reportTargets: [],
|
||||||
|
gameIdentities: [],
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
staged,
|
staged,
|
||||||
@@ -1847,6 +1937,16 @@ function stage(owner) {
|
|||||||
registerEngagementSeeds(entry) {
|
registerEngagementSeeds(entry) {
|
||||||
staged.engagementSeeds.push(checkEngagementSeeds(owner, entry))
|
staged.engagementSeeds.push(checkEngagementSeeds(owner, entry))
|
||||||
},
|
},
|
||||||
|
// MODULE_API 1.21.0 (USER_SAFETY.md §4.1). Core registers none: its forum
|
||||||
|
// types are answered by core directly (see `reportTargets` above).
|
||||||
|
registerReportTargets(entries) {
|
||||||
|
if (!Array.isArray(entries)) throw new Error('registerReportTargets: expected an array')
|
||||||
|
for (const e of entries) staged.reportTargets.push(checkReportTargetShape(e))
|
||||||
|
},
|
||||||
|
registerGameIdentities(entries) {
|
||||||
|
if (!Array.isArray(entries)) throw new Error('registerGameIdentities: expected an array')
|
||||||
|
for (const e of entries) staged.gameIdentities.push(checkGameIdentityShape(e))
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1875,6 +1975,8 @@ function apply({
|
|||||||
eventOptionSources: newEventOptionSources = [],
|
eventOptionSources: newEventOptionSources = [],
|
||||||
eventTemplates: newEventTemplates = [],
|
eventTemplates: newEventTemplates = [],
|
||||||
engagementSeeds: newSeeds = [],
|
engagementSeeds: newSeeds = [],
|
||||||
|
reportTargets: newReportTargets = [],
|
||||||
|
gameIdentities: newGameIdentities = [],
|
||||||
}) {
|
}) {
|
||||||
// ── validate ──
|
// ── validate ──
|
||||||
const seenStreams = new Set()
|
const seenStreams = new Set()
|
||||||
@@ -2000,6 +2102,30 @@ function apply({
|
|||||||
seenSources.add(s.id)
|
seenSources.add(s.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Report targets: their own id space, namespaced, no legacy allowlist. Core's
|
||||||
|
// forum types are unprefixed and are not in this map, so a module can never
|
||||||
|
// claim one — `team_forum_post` fails the prefix rule before it gets here.
|
||||||
|
const seenReportTargets = new Set()
|
||||||
|
for (const t of newReportTargets) {
|
||||||
|
const held = reportTargets.get(t.id)
|
||||||
|
if (held) throw new Error(`report target "${t.id}" is already registered by "${held.owner}"`)
|
||||||
|
if (seenReportTargets.has(t.id)) throw new Error(`report target "${t.id}" registered twice`)
|
||||||
|
if (!namespaced(owner, t.id, {})) {
|
||||||
|
throw new Error(`report target "${t.id}" is not namespaced "${owner}."`)
|
||||||
|
}
|
||||||
|
seenReportTargets.add(t.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Game identities are per owner, so the only collision is a module naming the
|
||||||
|
// same kind twice.
|
||||||
|
const seenKinds = new Set()
|
||||||
|
for (const g of newGameIdentities) {
|
||||||
|
if (seenKinds.has(g.kind) || gameIdentities.has(`${owner}:${g.kind}`)) {
|
||||||
|
throw new Error(`game identity "${g.kind}" registered twice by "${owner}"`)
|
||||||
|
}
|
||||||
|
seenKinds.add(g.kind)
|
||||||
|
}
|
||||||
|
|
||||||
const seenLegs = new Set()
|
const seenLegs = new Set()
|
||||||
for (const l of newLegs) {
|
for (const l of newLegs) {
|
||||||
const held = legs.get(l.leg)
|
const held = legs.get(l.leg)
|
||||||
@@ -2070,6 +2196,8 @@ function apply({
|
|||||||
for (const s of newEventOptionSources) eventOptionSources.set(s.id, { owner, ...s })
|
for (const s of newEventOptionSources) eventOptionSources.set(s.id, { owner, ...s })
|
||||||
for (const t of newEventTemplates) eventTemplates.set(t.id, { owner, ...t })
|
for (const t of newEventTemplates) eventTemplates.set(t.id, { owner, ...t })
|
||||||
for (const seeds of newSeeds) engagementSeeds.set(owner, seeds)
|
for (const seeds of newSeeds) engagementSeeds.set(owner, seeds)
|
||||||
|
for (const t of newReportTargets) reportTargets.set(t.id, { owner, ...t })
|
||||||
|
for (const g of newGameIdentities) gameIdentities.set(`${owner}:${g.kind}`, { owner, ...g })
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Core's own registrations ───────────────────────────────────────────────
|
// ── Core's own registrations ───────────────────────────────────────────────
|
||||||
@@ -2166,6 +2294,8 @@ function _reset() {
|
|||||||
eventOptionSources.clear()
|
eventOptionSources.clear()
|
||||||
eventTemplates.clear()
|
eventTemplates.clear()
|
||||||
engagementSeeds.clear()
|
engagementSeeds.clear()
|
||||||
|
reportTargets.clear()
|
||||||
|
gameIdentities.clear()
|
||||||
coreRegistered = false
|
coreRegistered = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2185,6 +2315,9 @@ module.exports = {
|
|||||||
dispatchPostHook,
|
dispatchPostHook,
|
||||||
registeredTeamProvider,
|
registeredTeamProvider,
|
||||||
hasTeamProvider,
|
hasTeamProvider,
|
||||||
|
reportTarget,
|
||||||
|
allReportTargets,
|
||||||
|
gameIdentity,
|
||||||
slashCommandDefinitions,
|
slashCommandDefinitions,
|
||||||
slashCommand,
|
slashCommand,
|
||||||
allTriggers,
|
allTriggers,
|
||||||
|
|||||||
@@ -9,6 +9,85 @@
|
|||||||
// Deliberately separate from PROTOCOL_VERSION (which versions the shard wire and
|
// Deliberately separate from PROTOCOL_VERSION (which versions the shard wire and
|
||||||
// has nothing to say about a website module) and from any module's own version.
|
// has nothing to say about a website module) and from any module's own version.
|
||||||
|
|
||||||
|
// 1.21.0 — report, block and hide reach a module's content
|
||||||
|
// (docs/website/USER_SAFETY.md §4.1, S11-S14). Four additions, each optional:
|
||||||
|
// • `api.registerReportTargets([{ id, label, snapshot, hide, unhide }])` — a
|
||||||
|
// type of the module's content a member can report, hide for themself and
|
||||||
|
// block the author of, and that staff can hide for everyone from the
|
||||||
|
// Reports queue. `snapshot({ targetId, viewer })` answers what the item is
|
||||||
|
// FOR THAT VIEWER, or null when it is gone or they may not see it;
|
||||||
|
// • `api.registerGameIdentities([{ kind, label, ownersOf }])` — the game
|
||||||
|
// identity those authors are known by (Rust: a Steam id), and which website
|
||||||
|
// account each is linked to. A block lands on the account when there is one
|
||||||
|
// (S12), and a block on an unlinked id becomes an account block once it is
|
||||||
|
// linked (S14);
|
||||||
|
// • `ctx.safety.forViewer(userId)` — one reader's blocks and hides, so the
|
||||||
|
// module filters its own per-viewer feeds on the server (S11);
|
||||||
|
// • `ctx.safety.staffAmong(userIds)` — which accounts are staff, for marking
|
||||||
|
// the lines a reader cannot block (S8, S13).
|
||||||
|
// Additions only, so minor. Module-uo declares `^1.10.0` and registers none.
|
||||||
|
// Module-Rust's `rust.chat` is the first user.
|
||||||
|
//
|
||||||
|
// 1.20.0 — a module hears that an account is about to be deleted
|
||||||
|
// (docs/website/ACCOUNT_DELETION.md §4.1, AD10, AD11). One addition, optional:
|
||||||
|
// • `api.onUserDeleting(async ({ userId, deletedBy }) => {})`, where
|
||||||
|
// `deletedBy` is 'self' | 'staff'. Called BEFORE the users row goes, while
|
||||||
|
// the module can still read the person's links, so it unlinks each game link
|
||||||
|
// through its own unlink and cleans up anything it keeps without a foreign
|
||||||
|
// key. It cannot veto: a throw, or running past core's ten seconds, is logged
|
||||||
|
// and the deletion goes ahead. A module that could not finish keeps its own
|
||||||
|
// record of what is left and retries.
|
||||||
|
// Additions only, so minor. Module-uo declares `^1.10.0` and registers none
|
||||||
|
// until its own PR: with no hook, a deletion is core's cascade alone, exactly as
|
||||||
|
// the admin route's delete was. USER_SAFETY.md's `reportTargets` moves to 1.21.0.
|
||||||
|
//
|
||||||
|
// 1.19.0 — the public demo refuses a step at SAVE (docs/website/DEMO_MODE.md
|
||||||
|
// §3.4, DM18). An event action may declare `demoRefuses(params)`, returning a
|
||||||
|
// sentence or null. With DEMO_MODE on, core asks it for every step when a
|
||||||
|
// definition is created, saved or published, and a sentence refuses the whole
|
||||||
|
// write `403 DEMO_LOCKED` with that sentence as `message`; a hook that throws
|
||||||
|
// refuses too. Off the demo it is validated and never called. One optional
|
||||||
|
// action member, so minor. Module-uo declares `^1.10.0` and declares none.
|
||||||
|
// Module-Rust's console-command deny list is the first user.
|
||||||
|
//
|
||||||
|
// 1.18.0 — the public demo (docs/website/DEMO_MODE.md §3.2, §3.4, §7.3; website#222).
|
||||||
|
// Three additions, each optional:
|
||||||
|
// • `demoLocks` in module.json — `[{ method, path }]`, writes only, each path
|
||||||
|
// under one of the module's own mounts. With DEMO_MODE on, core answers a
|
||||||
|
// matching request `403 DEMO_LOCKED` before the module's handler runs; with
|
||||||
|
// it off the list is validated and otherwise unread;
|
||||||
|
// • `ctx.demoMode` — true on the demo, for the locks a route cannot express,
|
||||||
|
// which the module enforces in its own handlers;
|
||||||
|
// • `api.onDemoSeed(fn)` — `npm run seed:demo` hands the module its part of
|
||||||
|
// the seed fixture (DM15), so it writes its own rows.
|
||||||
|
// Additions only, so minor. Module-uo declares `^1.10.0` and uses none of them.
|
||||||
|
// A module that DECLARES `demoLocks` needs `^1.18.0`, because older cores refuse
|
||||||
|
// a manifest key they do not know.
|
||||||
|
//
|
||||||
|
// 1.17.0 — a module may take part in linking an external sign-in identity
|
||||||
|
// (docs/website/STEAM_SIGNIN.md §4; Rust PLAN_REDESIGNS §15, D392 and D396).
|
||||||
|
// Three additions, each optional:
|
||||||
|
// • `ctx.identities.list(userId, provider)` — the identities a user has linked
|
||||||
|
// for one provider, as core verified them (a Steam id proved by Steam's own
|
||||||
|
// `check_authentication`), with the display name and avatar when there are;
|
||||||
|
// • `api.onIdentityLinking(fn)` — asked before a link is written, and able only
|
||||||
|
// to refuse it: `{ ok: false, reason }`, where `reason: 'in_use'` reads to the
|
||||||
|
// player as "already linked to another account" and anything else as a
|
||||||
|
// plain refusal. A module's own text is logged, never shown;
|
||||||
|
// • `api.onIdentityLinked(fn)` — told after a link is written.
|
||||||
|
// No unlink hook (D393). Additions only, so minor. Module-uo declares `^1.10.0`
|
||||||
|
// and uses none of them: with no hook registered a link is checked and written
|
||||||
|
// exactly as before.
|
||||||
|
//
|
||||||
|
// 1.16.0 — a dry run carries a module's advice: an action that answers
|
||||||
|
// `verify: true` with `{ ok: true, detail: { warnings: [...] } }` has each line
|
||||||
|
// shown as a WARNING finding (code `advice`) that does not fail the dry run
|
||||||
|
// (Rust PLAN_REDESIGNS §11.4, D391: a raid base's spot is checked against the
|
||||||
|
// world as it stands now, which may change before the run). Strings only, at most
|
||||||
|
// ten, each cut at 500 characters. One optional reading of an existing member, so
|
||||||
|
// minor. Module-uo declares `^1.10.0` and says no warnings: its dry runs read
|
||||||
|
// exactly as they did. STEAM_SIGNIN.md's claim moves to the next minor again.
|
||||||
|
//
|
||||||
// 1.15.0 — a failed step may say when to try again: `{ ok: false, retry: true,
|
// 1.15.0 — a failed step may say when to try again: `{ ok: false, retry: true,
|
||||||
// retryAfterMs }` (Rust PLAN_REDESIGNS §14.3.13, D371; docs/website/EVENTS.md §F).
|
// retryAfterMs }` (Rust PLAN_REDESIGNS §14.3.13, D371; docs/website/EVENTS.md §F).
|
||||||
// Clamped to one minute–thirty minutes, never refused; absent, the flat
|
// Clamped to one minute–thirty minutes, never refused; absent, the flat
|
||||||
@@ -207,6 +286,6 @@
|
|||||||
// an admin action a module performs belongs in core's one audit log, the
|
// an admin action a module performs belongs in core's one audit log, the
|
||||||
// extension slot needs the user its prefix names, and §2.7 forbids a module
|
// extension slot needs the user its prefix names, and §2.7 forbids a module
|
||||||
// reading core's `APP_BASE_URL` for itself. Additions only, so minor.
|
// reading core's `APP_BASE_URL` for itself. Additions only, so minor.
|
||||||
const MODULE_API_VERSION = '1.15.0'
|
const MODULE_API_VERSION = '1.21.0'
|
||||||
|
|
||||||
module.exports = { MODULE_API_VERSION }
|
module.exports = { MODULE_API_VERSION }
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ const users = require('../../../model/users/users.model')
|
|||||||
const activity = require('../../../model/activity/activity.model')
|
const activity = require('../../../model/activity/activity.model')
|
||||||
const trustedDevices = require('../../../model/trustedDevices/trustedDevices.model')
|
const trustedDevices = require('../../../model/trustedDevices/trustedDevices.model')
|
||||||
const recoveryCodes = require('../../../model/recoveryCodes/recoveryCodes.model')
|
const recoveryCodes = require('../../../model/recoveryCodes/recoveryCodes.model')
|
||||||
|
const accountDeletion = require('../../../auth/accountDeletion')
|
||||||
|
const { refuse: demoRefuse } = require('../../../demo/locks')
|
||||||
const registries = require('../../../modules/registries')
|
const registries = require('../../../modules/registries')
|
||||||
const announceJobs = require('../../../model/announceJobs/announceJobs.model')
|
const announceJobs = require('../../../model/announceJobs/announceJobs.model')
|
||||||
const emailConfig = require('../../../model/emailConfig/emailConfig.model')
|
const emailConfig = require('../../../model/emailConfig/emailConfig.model')
|
||||||
@@ -1028,19 +1030,21 @@ async function updateUser(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The same procedure a member's own deletion runs (auth/accountDeletion.js):
|
||||||
|
// modules unlink their game links first, a staff name is reserved, and the
|
||||||
|
// account's owner is mailed. The refusals keep this route's 400s.
|
||||||
async function deleteUser(req, res) {
|
async function deleteUser(req, res) {
|
||||||
const id = Number(req.params.id)
|
const id = Number(req.params.id)
|
||||||
try {
|
try {
|
||||||
if (id === req.user.id) {
|
if (id === req.user.id) {
|
||||||
return res.status(400).json({ message: 'You cannot delete your own account' })
|
return res.status(400).json({ message: 'You cannot delete your own account' })
|
||||||
}
|
}
|
||||||
const target = await users.getById(id)
|
const result = await accountDeletion.deleteAccount(id, { by: 'staff', req })
|
||||||
if (!target) return res.status(404).json({ message: 'Not found' })
|
if (!result.ok) {
|
||||||
if (target.role === 'admin' && (await users.countAdmins()) <= 1) {
|
if (result.reason === 'not_found') return res.status(404).json({ message: 'Not found' })
|
||||||
return res.status(400).json({ message: 'Cannot delete the last admin' })
|
if (result.reason === 'last_admin') return res.status(400).json({ message: 'Cannot delete the last admin' })
|
||||||
|
if (result.reason === 'demo') return demoRefuse(res)
|
||||||
}
|
}
|
||||||
await users.remove(id)
|
|
||||||
await activity.log({ req, action: 'user.delete', detail: { id } })
|
|
||||||
return res.json({ id })
|
return res.json({ id })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error('deleteUser', err)
|
log.error('deleteUser', err)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// ── Admin: auth provider configuration ─────────────────────────────────────
|
// ── Admin: auth provider configuration ─────────────────────────────────────
|
||||||
//
|
//
|
||||||
// CRUD for SSO providers. Built-ins (google, discord) are configured here too but
|
// CRUD for SSO providers. Built-ins (google, discord, steam) are configured here too but
|
||||||
// can only be enabled/disabled and given a client id/secret — their kind, name,
|
// can only be enabled/disabled and given a client id/secret — their kind, name,
|
||||||
// and endpoints are fixed in code and cannot be edited or deleted. Custom
|
// and endpoints are fixed in code and cannot be edited or deleted. Custom
|
||||||
// (oidc/oauth2) providers are fully editable.
|
// (oidc/oauth2) providers are fully editable.
|
||||||
@@ -80,6 +80,18 @@ async function update(req, res) {
|
|||||||
// Built-ins: kind/name/priority are fixed; only enable + credentials change.
|
// Built-ins: kind/name/priority are fixed; only enable + credentials change.
|
||||||
const meta = registry.BUILTINS.find((x) => x.id === id)
|
const meta = registry.BUILTINS.find((x) => x.id === id)
|
||||||
fields = { kind: meta.kind, name: meta.name, priority: meta.priority, enabled: b.enabled, clientId: b.clientId, secret: b.secret }
|
fields = { kind: meta.kind, name: meta.name, priority: meta.priority, enabled: b.enabled, clientId: b.clientId, secret: b.secret }
|
||||||
|
if (meta.kind === 'steam') {
|
||||||
|
// Steam has no client id; its secret is the Steam Web API key, and it
|
||||||
|
// cannot be enabled without one (D394) — refused here, with a sentence,
|
||||||
|
// rather than saved as an "Incomplete" provider nobody can use.
|
||||||
|
fields.clientId = undefined
|
||||||
|
if (b.enabled === true && !b.secret) {
|
||||||
|
const current = await authProviders.get(id)
|
||||||
|
if (!current || !current.client_secret_enc) {
|
||||||
|
return res.status(400).json({ message: 'Steam needs a Steam Web API key before it can be enabled.' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!(await authProviders.get(id))) {
|
if (!(await authProviders.get(id))) {
|
||||||
return res.status(404).json({ message: 'Provider not found.' })
|
return res.status(404).json({ message: 'Provider not found.' })
|
||||||
|
|||||||
@@ -59,11 +59,12 @@ providersRouter.put(
|
|||||||
'/providers/:id',
|
'/providers/:id',
|
||||||
// #swagger.tags = ['Admin · Auth Providers']
|
// #swagger.tags = ['Admin · Auth Providers']
|
||||||
// #swagger.summary = 'Update an SSO provider (admin only)'
|
// #swagger.summary = 'Update an SSO provider (admin only)'
|
||||||
|
// #swagger.description = 'Built-ins (google, discord, steam) take only enabled + credentials. Steam has no client id: its secret is a Steam Web API key, and enabling Steam without one stored or given is refused with 400 (STEAM_SIGNIN.md D394).'
|
||||||
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
// #swagger.parameters['id'] = { in: 'path', required: true, schema: { type: 'string' }, description: 'Provider id.' }
|
// #swagger.parameters['id'] = { in: 'path', required: true, schema: { type: 'string' }, description: 'Provider id.' }
|
||||||
/* #swagger.requestBody = { content: { "application/json": { schema: { $ref: "#/components/schemas/ProviderCreateRequest" } } } } */
|
/* #swagger.requestBody = { content: { "application/json": { schema: { $ref: "#/components/schemas/ProviderCreateRequest" } } } } */
|
||||||
/* #swagger.responses[200] = { description: 'Updated provider', content: { "application/json": { schema: { $ref: "#/components/schemas/ProviderConfig" } } } } */
|
/* #swagger.responses[200] = { description: 'Updated provider', content: { "application/json": { schema: { $ref: "#/components/schemas/ProviderConfig" } } } } */
|
||||||
/* #swagger.responses[400] = { description: 'Validation error', content: { "application/json": { schema: { $ref: "#/components/schemas/ValidationError" } } } } */
|
/* #swagger.responses[400] = { description: 'Validation error, or Steam enabled without a Steam Web API key', content: { "application/json": { schema: { $ref: "#/components/schemas/ValidationError" } } } } */
|
||||||
/* #swagger.responses[401] = { description: 'Not authenticated', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
/* #swagger.responses[401] = { description: 'Not authenticated', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
/* #swagger.responses[403] = { description: 'Admin role required', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
/* #swagger.responses[403] = { description: 'Admin role required', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
/* #swagger.responses[404] = { description: 'Provider not found', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
/* #swagger.responses[404] = { description: 'Provider not found', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
|||||||
@@ -42,6 +42,16 @@ const asId = (raw) => {
|
|||||||
return Number.isInteger(n) && n > 0 ? n : null
|
return Number.isInteger(n) && n > 0 ? n : null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A refused save's body: the errors, plus `code` and `message` when the model
|
||||||
|
* set them. The demo's step refusal does (DM18), so the client's one
|
||||||
|
* `DEMO_LOCKED` toast fires as it does for a route lock.
|
||||||
|
*/
|
||||||
|
const refusal = (result) => ({
|
||||||
|
errors: result.errors,
|
||||||
|
...(result.code ? { code: result.code, message: result.message } : {}),
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The shape a definition takes on the wire.
|
* The shape a definition takes on the wire.
|
||||||
*
|
*
|
||||||
@@ -413,7 +423,7 @@ exports.listVersions = async (req, res) => {
|
|||||||
/** POST /api/v1/admin/events */
|
/** POST /api/v1/admin/events */
|
||||||
exports.create = async (req, res) => {
|
exports.create = async (req, res) => {
|
||||||
const result = await definitions.create(req.body, req.user.id, { role: req.user.role })
|
const result = await definitions.create(req.body, req.user.id, { role: req.user.role })
|
||||||
if (!result.ok) return res.status(result.status || 400).json({ errors: result.errors })
|
if (!result.ok) return res.status(result.status || 400).json(refusal(result))
|
||||||
await activity.log({
|
await activity.log({
|
||||||
req,
|
req,
|
||||||
action: 'event.definition.created',
|
action: 'event.definition.created',
|
||||||
@@ -427,7 +437,7 @@ exports.update = async (req, res) => {
|
|||||||
const id = asId(req.params.id)
|
const id = asId(req.params.id)
|
||||||
if (!id) return res.status(400).json({ error: 'bad event id' })
|
if (!id) return res.status(400).json({ error: 'bad event id' })
|
||||||
const result = await definitions.save(id, req.body, req.user.id, { role: req.user.role })
|
const result = await definitions.save(id, req.body, req.user.id, { role: req.user.role })
|
||||||
if (!result.ok) return res.status(result.status || 400).json({ errors: result.errors })
|
if (!result.ok) return res.status(result.status || 400).json(refusal(result))
|
||||||
await activity.log({
|
await activity.log({
|
||||||
req,
|
req,
|
||||||
action: 'event.definition.updated',
|
action: 'event.definition.updated',
|
||||||
@@ -441,11 +451,17 @@ exports.publish = async (req, res) => {
|
|||||||
const id = asId(req.params.id)
|
const id = asId(req.params.id)
|
||||||
if (!id) return res.status(400).json({ error: 'bad event id' })
|
if (!id) return res.status(400).json({ error: 'bad event id' })
|
||||||
const result = await definitions.publish(id, req.user.id)
|
const result = await definitions.publish(id, req.user.id)
|
||||||
if (!result.ok) return res.status(result.status || 400).json({ errors: result.errors })
|
if (!result.ok) return res.status(result.status || 400).json(refusal(result))
|
||||||
await activity.log({
|
await activity.log({
|
||||||
req,
|
req,
|
||||||
action: 'event.definition.published',
|
action: 'event.definition.published',
|
||||||
detail: { id, version: result.version, versionId: result.versionId, repinned: result.repinned },
|
detail: {
|
||||||
|
id,
|
||||||
|
version: result.version,
|
||||||
|
versionId: result.versionId,
|
||||||
|
repinned: result.repinned,
|
||||||
|
verified: result.verified,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
return res.json({
|
return res.json({
|
||||||
event: await shapeEditable(result.definition),
|
event: await shapeEditable(result.definition),
|
||||||
@@ -455,6 +471,9 @@ exports.publish = async (req, res) => {
|
|||||||
// screen says so, because "my fix did not reach next Friday" is otherwise
|
// screen says so, because "my fix did not reach next Friday" is otherwise
|
||||||
// found out on Friday.
|
// found out on Friday.
|
||||||
repinned: result.repinned,
|
repinned: result.repinned,
|
||||||
|
// Whether a dry run that passed on this exact draft made the version
|
||||||
|
// verified at birth (W5), so the screen can say it needs no second one.
|
||||||
|
verified: result.verified,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,6 +511,7 @@ exports.verify = async (req, res) => {
|
|||||||
versionId: result.versionId,
|
versionId: result.versionId,
|
||||||
version: result.version,
|
version: result.version,
|
||||||
recorded: result.recorded,
|
recorded: result.recorded,
|
||||||
|
draftRecorded: result.draftRecorded,
|
||||||
report: result.report,
|
report: result.report,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -475,9 +475,9 @@ eventsRouter.post(
|
|||||||
'/:id/verify',
|
'/:id/verify',
|
||||||
// #swagger.tags = ['Admin · Events']
|
// #swagger.tags = ['Admin · Events']
|
||||||
// #swagger.summary = 'Dry run: dispatch every step with verify true, change nothing, and report the cost against the caps'
|
// #swagger.summary = 'Dry run: dispatch every step with verify true, change nothing, and report the cost against the caps'
|
||||||
// #swagger.description = 'EVENTS.md I. admin AND editor rather than admin, deliberately: a dry run dispatches nothing, and the author who wrote the definition is exactly who should be able to price it before asking an admin to publish it. What is verified follows the state -- a ready definition is checked against its PUBLISHED version, which is the only thing that ever actually runs, and a draft against the working spec the author is still holding; `target` says which. A pass against a version is RECORDED on it, and that is EVENTS.md K last bound: a scheduled occurrence of a version that has never been verified is held rather than started unattended. Findings come back with a 200 -- the request succeeded, the plan has problems -- and the whole-plan cost check is the one thing no other path makes: three steps each spawning 15 under a cap of 30 pass every individual check and breach it on the third, at two in the morning, with the world half-changed.'
|
// #swagger.description = 'EVENTS.md I. admin AND editor rather than admin, deliberately: a dry run dispatches nothing, and the author who wrote the definition is exactly who should be able to price it before asking an admin to publish it. What is verified follows the state -- a ready definition is checked against its PUBLISHED version, which is the only thing that ever actually runs, and a draft against the working spec the author is still holding; `target` says which. A pass against a version is RECORDED on it, and that is EVENTS.md K last bound: a scheduled occurrence of a version that has never been verified is held rather than started unattended. A pass against a draft is kept with the fingerprint of the spec it passed on (`draftRecorded`), and publishing that spec unchanged makes a version that is verified from the start; an edit in between changes the fingerprint, and nothing carries over. Findings come back with a 200 -- the request succeeded, the plan has problems -- and the whole-plan cost check is the one thing no other path makes: three steps each spawning 15 under a cap of 30 pass every individual check and breach it on the third, at two in the morning, with the world half-changed.'
|
||||||
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
/* #swagger.responses[200] = { description: 'The report: findings per step, and the total cost per budget dimension', content: { "application/json": { schema: { type: "object", properties: { target: { type: "string", example: "version" }, versionId: { type: "integer" }, version: { type: "integer" }, recorded: { type: "boolean" }, report: { type: "object", properties: { ok: { type: "boolean" }, steps: { type: "integer" }, findings: { type: "array", items: { type: "object", additionalProperties: true } }, cost: { type: "array", items: { type: "object", additionalProperties: true } } } } } } } } } */
|
/* #swagger.responses[200] = { description: 'The report: findings per step, and the total cost per budget dimension', content: { "application/json": { schema: { type: "object", properties: { target: { type: "string", example: "version" }, versionId: { type: "integer" }, version: { type: "integer" }, recorded: { type: "boolean" }, draftRecorded: { type: "boolean" }, report: { type: "object", properties: { ok: { type: "boolean" }, steps: { type: "integer" }, findings: { type: "array", items: { type: "object", additionalProperties: true } }, cost: { type: "array", items: { type: "object", additionalProperties: true } } } } } } } } } */
|
||||||
/* #swagger.responses[404] = { description: 'No such definition', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
/* #swagger.responses[404] = { description: 'No such definition', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
/* #swagger.responses[409] = { description: 'The definition is archived, or has no phases to verify', content: { "application/json": { schema: { type: "object", properties: { errors: { type: "array", items: { type: "string" } } } } } } } */
|
/* #swagger.responses[409] = { description: 'The definition is archived, or has no phases to verify', content: { "application/json": { schema: { type: "object", properties: { errors: { type: "array", items: { type: "string" } } } } } } } */
|
||||||
/* #swagger.responses[403] = { description: 'Not an admin or editor', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
/* #swagger.responses[403] = { description: 'Not an admin or editor', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
@@ -489,9 +489,9 @@ eventsRouter.post(
|
|||||||
'/:id/publish',
|
'/:id/publish',
|
||||||
// #swagger.tags = ['Admin · Events']
|
// #swagger.tags = ['Admin · Events']
|
||||||
// #swagger.summary = 'Snapshot the working spec into an immutable version and mark the definition ready'
|
// #swagger.summary = 'Snapshot the working spec into an immutable version and mark the definition ready'
|
||||||
// #swagger.description = 'Admin only, deliberately, and not the same gate as the live run controls: publishing commits a definition that a schedule will later start unattended. The spec is re-validated against the registries as they stand right now rather than trusted from the save that wrote it, so a module uninstalled in between blocks the publish instead of producing a run that fails at dispatch. Publishing also RE-PINS every occurrence of this definition that is still scheduled and has not started, and `repinned` says how many moved: occurrences are materialised a fortnight ahead, so without this an edit would reach none of the runs already on the calendar. A run that has begun keeps the version it pinned.'
|
// #swagger.description = 'Admin only, deliberately, and not the same gate as the live run controls: publishing commits a definition that a schedule will later start unattended. The spec is re-validated against the registries as they stand right now rather than trusted from the save that wrote it, so a module uninstalled in between blocks the publish instead of producing a run that fails at dispatch. Publishing also RE-PINS every occurrence of this definition that is still scheduled and has not started, and `repinned` says how many moved: occurrences are materialised a fortnight ahead, so without this an edit would reach none of the runs already on the calendar. A run that has begun keeps the version it pinned. `verified` is true when a dry run that passed on this exact draft made the new version verified, with that dry run reviewer and time, so it needs no second dry run before it starts unattended.'
|
||||||
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
/* #swagger.responses[200] = { description: 'The definition, now ready, the version that was cut, and how many scheduled occurrences moved to it', content: { "application/json": { schema: { type: "object", properties: { event: { type: "object", additionalProperties: true }, version: { type: "integer" }, versionId: { type: "integer" }, repinned: { type: "integer" } } } } } } */
|
/* #swagger.responses[200] = { description: 'The definition, now ready, the version that was cut, and how many scheduled occurrences moved to it', content: { "application/json": { schema: { type: "object", properties: { event: { type: "object", additionalProperties: true }, version: { type: "integer" }, versionId: { type: "integer" }, repinned: { type: "integer" }, verified: { type: "boolean" } } } } } } */
|
||||||
/* #swagger.responses[400] = { description: 'The spec is invalid, or no phase has any steps', content: { "application/json": { schema: { type: "object", properties: { errors: { type: "array", items: { type: "string" } } } } } } } */
|
/* #swagger.responses[400] = { description: 'The spec is invalid, or no phase has any steps', content: { "application/json": { schema: { type: "object", properties: { errors: { type: "array", items: { type: "string" } } } } } } } */
|
||||||
/* #swagger.responses[409] = { description: 'A step names an action no module registers, or the definition is archived', content: { "application/json": { schema: { type: "object", properties: { errors: { type: "array", items: { type: "string" } } } } } } } */
|
/* #swagger.responses[409] = { description: 'A step names an action no module registers, or the definition is archived', content: { "application/json": { schema: { type: "object", properties: { errors: { type: "array", items: { type: "string" } } } } } } } */
|
||||||
/* #swagger.responses[403] = { description: 'Not an admin', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
/* #swagger.responses[403] = { description: 'Not an admin', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ async function getContentReports(req, res) {
|
|||||||
}
|
}
|
||||||
const teamId = Number(req.query.teamId) || undefined
|
const teamId = Number(req.query.teamId) || undefined
|
||||||
return res.json({
|
return res.json({
|
||||||
reports: await contentReports.queue({ status, teamId, limit, offset }),
|
reports: await contentReports.queue({ status, teamId, limit, offset, viewer: req.user }),
|
||||||
openCount: await contentReports.openCount(),
|
openCount: await contentReports.openCount(),
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -358,6 +358,34 @@ async function handleContentReport(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide the reported item for everyone, and action the report (USER_SAFETY.md
|
||||||
|
* §4.1). The item goes through its own hide — the forum's moderation, or the
|
||||||
|
* module's — so this is a staff moderation of the content and is audited as one.
|
||||||
|
*/
|
||||||
|
async function hideReportedItem(req, res) {
|
||||||
|
try {
|
||||||
|
const result = await contentReports.hideForEveryone({
|
||||||
|
id: Number(req.params.id),
|
||||||
|
actor: req.user,
|
||||||
|
note: req.body.note,
|
||||||
|
})
|
||||||
|
if (!result.ok) return res.status(result.status || 400).json({ message: result.error })
|
||||||
|
|
||||||
|
const r = result.report
|
||||||
|
await activity.log({
|
||||||
|
req,
|
||||||
|
action: 'moderation.report.hide',
|
||||||
|
detail: `${req.user.username} (#${req.user.id}) hid ${r.targetType} #${r.targetId} for everyone `
|
||||||
|
+ `from report #${req.params.id}${req.body.note ? `: "${req.body.note}"` : ''}`,
|
||||||
|
})
|
||||||
|
return res.json(r)
|
||||||
|
} catch (err) {
|
||||||
|
log.error('hideReportedItem failed', { error: err.message })
|
||||||
|
return res.status(500).json({ message: 'Internal Server Error' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getSummary,
|
getSummary,
|
||||||
getRecent,
|
getRecent,
|
||||||
@@ -376,4 +404,5 @@ module.exports = {
|
|||||||
getUserAppeals,
|
getUserAppeals,
|
||||||
getContentReports,
|
getContentReports,
|
||||||
handleContentReport,
|
handleContentReport,
|
||||||
|
hideReportedItem,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,5 +202,22 @@ moderationRouter.post(
|
|||||||
validate,
|
validate,
|
||||||
moderation.handleContentReport,
|
moderation.handleContentReport,
|
||||||
)
|
)
|
||||||
|
moderationRouter.post(
|
||||||
|
'/reports/:id/hide',
|
||||||
|
// #swagger.tags = ['Admin · Moderation']
|
||||||
|
// #swagger.summary = 'Hide the reported item for everyone, and action the report'
|
||||||
|
// #swagger.description = 'USER_SAFETY.md §4.1 (MODULE_API 1.21.0). The one queue action that changes the content. A forum thread or post is hidden through the forum’s own moderation (a staff row in its ledger); a game module’s item (e.g. a `rust.chat` line) through the module’s own hide. Staff still see the item where it lives, marked hidden by staff, and undo it there. The report becomes `actioned` with `actionedWith: "hide"`, and activity_log records it. An upload cannot be hidden from here: hide the post it is in.'
|
||||||
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
|
// #swagger.parameters['id'] = { in: 'path', required: true, schema: { type: 'integer' }, description: 'Report id.' }
|
||||||
|
/* #swagger.requestBody = { required: false, content: { "application/json": { schema: { type: 'object', properties: { note: { type: 'string', maxLength: 500 } } } } } } */
|
||||||
|
/* #swagger.responses[200] = { description: 'The actioned report', content: { "application/json": { schema: { $ref: "#/components/schemas/ContentReport" } } } } */
|
||||||
|
/* #swagger.responses[400] = { description: 'The item cannot be hidden from here (an upload)', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
/* #swagger.responses[404] = { description: 'No such report, or its item is gone', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
/* #swagger.responses[503] = { description: 'The game module that owns the item did not answer', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
param('id').isInt({ min: 1 }),
|
||||||
|
body('note').optional({ values: 'falsy' }).isString().trim().isLength({ max: 500 }),
|
||||||
|
validate,
|
||||||
|
moderation.hideReportedItem,
|
||||||
|
)
|
||||||
|
|
||||||
module.exports = moderationRouter
|
module.exports = moderationRouter
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ const trustedDevices = require('../../../model/trustedDevices/trustedDevices.mod
|
|||||||
const recoveryCodes = require('../../../model/recoveryCodes/recoveryCodes.model')
|
const recoveryCodes = require('../../../model/recoveryCodes/recoveryCodes.model')
|
||||||
const sessionService = require('../../../auth/session.service')
|
const sessionService = require('../../../auth/session.service')
|
||||||
const { establishTrust } = require('./trustDevice.helper')
|
const { establishTrust } = require('./trustDevice.helper')
|
||||||
const { setAuthCookie, setTrustCookie, clearTrustCookie } = require('../../../auth/token')
|
const { setAuthCookie, setTrustCookie, clearTrustCookie, clearAuthCookie } = require('../../../auth/token')
|
||||||
|
const accountDeletion = require('../../../auth/accountDeletion')
|
||||||
|
const { refuse: demoRefuse } = require('../../../demo/locks')
|
||||||
const usernamePolicy = require('../../../auth/usernamePolicy')
|
const usernamePolicy = require('../../../auth/usernamePolicy')
|
||||||
const loginProtection = require('../../../middleware/loginProtection')
|
const loginProtection = require('../../../middleware/loginProtection')
|
||||||
const botScore = require('../../../middleware/botScore')
|
const botScore = require('../../../middleware/botScore')
|
||||||
@@ -339,20 +341,36 @@ async function totpDisable(req, res) {
|
|||||||
async function listIdentities(req, res) {
|
async function listIdentities(req, res) {
|
||||||
try {
|
try {
|
||||||
const rows = await userIdentities.listForUser(req.user.id)
|
const rows = await userIdentities.listForUser(req.user.id)
|
||||||
return res.json(rows.map((r) => ({ provider: r.provider, email: r.email, linked_at: r.created_at })))
|
// `id` lets one identity be unlinked when a provider has several (a player
|
||||||
|
// may link more than one Steam account). `subject` is the user's OWN external
|
||||||
|
// id — for Steam, the SteamID64 shown beside the persona name (D394).
|
||||||
|
return res.json(
|
||||||
|
rows.map((r) => ({
|
||||||
|
id: r.id,
|
||||||
|
provider: r.provider,
|
||||||
|
subject: r.subject,
|
||||||
|
email: r.email,
|
||||||
|
display_name: r.display_name || null,
|
||||||
|
avatar_url: r.avatar_url || null,
|
||||||
|
linked_at: r.created_at,
|
||||||
|
})),
|
||||||
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error('listIdentities', err)
|
log.error('listIdentities', err)
|
||||||
return res.status(500).json({ message: 'Internal Server Error' })
|
return res.status(500).json({ message: 'Internal Server Error' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove a linked SSO identity from the current user's account.
|
// Remove a linked SSO identity from the current user's account: every identity
|
||||||
|
// of that provider, or with `?id=` the one identity named. Only the sign-in goes —
|
||||||
|
// a module's own link made from it (Rust's, D392) is the module's to remove (D393).
|
||||||
async function unlinkIdentity(req, res) {
|
async function unlinkIdentity(req, res) {
|
||||||
const { provider } = req.params
|
const { provider } = req.params
|
||||||
|
const identityId = req.query.id != null ? Number(req.query.id) : null
|
||||||
try {
|
try {
|
||||||
const removed = await userIdentities.unlink(req.user.id, provider)
|
const removed = await userIdentities.unlink(req.user.id, provider, identityId)
|
||||||
if (!removed) return res.status(404).json({ message: 'No linked account for that provider.' })
|
if (!removed) return res.status(404).json({ message: 'No linked account for that provider.' })
|
||||||
await activity.log({ req, action: 'auth.sso.unlink', detail: { provider } })
|
await activity.log({ req, action: 'auth.sso.unlink', detail: { provider, ...(identityId != null ? { identityId } : {}) } })
|
||||||
log.info('sso identity unlinked', { provider, id: req.user.id })
|
log.info('sso identity unlinked', { provider, id: req.user.id })
|
||||||
return res.json({ unlinked: true })
|
return res.json({ unlinked: true })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -522,7 +540,88 @@ async function generateRecoveryCodes(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Deleting your own account (ACCOUNT_DELETION.md §4.1) ───────────────────
|
||||||
|
//
|
||||||
|
// DELETE /account. The proof is the password, always (AD7): signing in with
|
||||||
|
// Google, Discord or Steam is a convenience on an account that already has its
|
||||||
|
// own password. A two-factor code or a recovery code is asked for too when 2FA is
|
||||||
|
// on, and the typed username guards against a mis-tap on a phone.
|
||||||
|
//
|
||||||
|
// **A wrong password or code is 400, not 401** (AD12). Every self-service
|
||||||
|
// password check here answers 400, and the app's TokenAuthenticator reads a 401
|
||||||
|
// on a signed-in call as an expired session: it would spend the refresh token and
|
||||||
|
// replay the DELETE, making two password attempts out of one typo.
|
||||||
|
//
|
||||||
|
// Each refusal carries a `code` the screens switch on; the words are for a
|
||||||
|
// client that does not know the code.
|
||||||
|
async function deleteAccount(req, res) {
|
||||||
|
try {
|
||||||
|
const raw = await users.getRawById(req.user.id)
|
||||||
|
if (!raw) return res.status(401).json({ message: 'Unauthorized' })
|
||||||
|
|
||||||
|
const typed = String(req.body.username || '').trim()
|
||||||
|
if (typed.toLowerCase() !== String(raw.username).toLowerCase()) {
|
||||||
|
return res.status(400).json({ code: 'username_mismatch', message: 'Type your username exactly as it is shown.' })
|
||||||
|
}
|
||||||
|
if (!raw.password_hash) {
|
||||||
|
return res.status(409).json({
|
||||||
|
code: 'password_required',
|
||||||
|
message: 'This account has no password yet. Set one above, then delete the account.',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const passwordOk = await users.validatePassword(raw, req.body.password || '')
|
||||||
|
if (!passwordOk) {
|
||||||
|
// Credential-guessing on an open session, like a wrong current password.
|
||||||
|
loginProtection.recordFailure(req.ip)
|
||||||
|
botScore.recordLoginFailure(req.ip)
|
||||||
|
log.warn('deleteAccount wrong password', { id: raw.id, ip: req.ip })
|
||||||
|
return res.status(400).json({ code: 'wrong_password', message: 'Your password is incorrect.' })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (raw.totp_enabled) {
|
||||||
|
const code = String(req.body.code || '').trim()
|
||||||
|
const recovery = String(req.body.recoveryCode || '').trim()
|
||||||
|
if (!code && !recovery) {
|
||||||
|
return res.status(400).json({ code: 'code_required', message: 'Enter a code from your authenticator app, or a recovery code.' })
|
||||||
|
}
|
||||||
|
// A recovery code is spent here even though the account is about to go:
|
||||||
|
// the deletion can still be refused below, and a code that worked once must
|
||||||
|
// not work twice.
|
||||||
|
const passed = code ? totp.verifyCode(raw.totp_secret, code) : await recoveryCodes.consumeForUser(raw.id, recovery)
|
||||||
|
if (!passed) {
|
||||||
|
loginProtection.recordFailure(req.ip)
|
||||||
|
botScore.recordLoginFailure(req.ip)
|
||||||
|
log.warn('deleteAccount wrong second factor', { id: raw.id, ip: req.ip, recovery: Boolean(!code) })
|
||||||
|
return res.status(400).json({ code: 'wrong_code', message: 'That code is not valid. Try again.' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await accountDeletion.deleteAccount(raw.id, { by: 'self', req })
|
||||||
|
if (!result.ok) {
|
||||||
|
if (result.reason === 'last_admin') {
|
||||||
|
return res.status(409).json({
|
||||||
|
code: 'last_admin',
|
||||||
|
message: 'You are the only admin. Make someone else an admin before you delete your account.',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (result.reason === 'demo') return demoRefuse(res)
|
||||||
|
return res.status(401).json({ message: 'Unauthorized' })
|
||||||
|
}
|
||||||
|
|
||||||
|
// The server has already dropped every session, trusted device and push
|
||||||
|
// registration with the row. These two cookies are this browser's copies.
|
||||||
|
clearAuthCookie(req, res)
|
||||||
|
clearTrustCookie(req, res)
|
||||||
|
return res.json({ deleted: true })
|
||||||
|
} catch (err) {
|
||||||
|
log.error('deleteAccount', err)
|
||||||
|
return res.status(500).json({ message: 'Internal Server Error' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
deleteAccount,
|
||||||
changeEmail,
|
changeEmail,
|
||||||
resendEmailVerification,
|
resendEmailVerification,
|
||||||
cancelEmailChange,
|
cancelEmailChange,
|
||||||
|
|||||||
@@ -18,13 +18,14 @@
|
|||||||
// expect. Mounted at /me by auth/index.js, so paths below are /auth/me/account*.
|
// expect. Mounted at /me by auth/index.js, so paths below are /auth/me/account*.
|
||||||
|
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const { body, param } = require('express-validator')
|
const { body, param, query } = require('express-validator')
|
||||||
|
|
||||||
const account = require('./account.controller')
|
const account = require('./account.controller')
|
||||||
|
const safetyCtrl = require('./safety.controller')
|
||||||
const { requireAuth } = require('../../../auth/session.middleware')
|
const { requireAuth } = require('../../../auth/session.middleware')
|
||||||
const noindex = require('../../../middleware/noindex')
|
const noindex = require('../../../middleware/noindex')
|
||||||
const validate = require('../../../middleware/validate')
|
const validate = require('../../../middleware/validate')
|
||||||
const { accountChangeLimiter } = require('../../../middleware/rateLimit')
|
const { accountChangeLimiter, makeLimiter } = require('../../../middleware/rateLimit')
|
||||||
const { slowLogin, backoffGuard } = require('../../../middleware/loginProtection')
|
const { slowLogin, backoffGuard } = require('../../../middleware/loginProtection')
|
||||||
|
|
||||||
const meRouter = express.Router()
|
const meRouter = express.Router()
|
||||||
@@ -79,6 +80,151 @@ meRouter.patch(
|
|||||||
account.changePassword,
|
account.changePassword,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Deleting your own account (ACCOUNT_DELETION.md §4.1). Behind the login backoff
|
||||||
|
// and bot guards as well as the change limiter, because a wrong password here is
|
||||||
|
// credential-guessing exactly as it is on the recovery-codes route.
|
||||||
|
meRouter.delete(
|
||||||
|
'/account',
|
||||||
|
// #swagger.tags = ['Auth · Me']
|
||||||
|
// #swagger.summary = 'Delete the current account (self, any role)'
|
||||||
|
// #swagger.description = 'Deletes the account at once (no grace period). Requires the typed username (case-insensitive), the account password, and — when two-factor sign-in is on — an authenticator code or a recovery code. Before the row goes, every installed game module unlinks the account’s game links through its own unlink (MODULE_API 1.20.0 onUserDeleting); a module that cannot finish never stops the deletion. Every session, trusted device, push registration, linked sign-in and game link goes with the account. What the member wrote stays and other members see it as "[deleted player]"; staff keep the name and the activity log for moderation. A deleted staff account’s username can never be registered again. A wrong password or code is a 400 (not 401), so a native client’s refresh-on-401 never replays it. Refused with 403 DEMO_LOCKED for the demo’s shared logins.'
|
||||||
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
|
/* #swagger.requestBody = { required: true, content: { "application/json": { schema: { $ref: "#/components/schemas/DeleteAccountRequest" } } } } */
|
||||||
|
/* #swagger.responses[200] = { description: 'Deleted; this browser’s session and trust cookies are cleared', content: { "application/json": { schema: { type: "object", properties: { deleted: { type: "boolean", example: true } } } } } } */
|
||||||
|
/* #swagger.responses[400] = { description: 'username_mismatch, wrong_password, code_required or wrong_code', content: { "application/json": { schema: { $ref: "#/components/schemas/DeleteAccountRefusal" } } } } */
|
||||||
|
/* #swagger.responses[401] = { description: 'Not authenticated', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
/* #swagger.responses[403] = { description: 'Demo login (DEMO_LOCKED)', content: { "application/json": { schema: { $ref: "#/components/schemas/DemoLocked" } } } } */
|
||||||
|
/* #swagger.responses[409] = { description: 'password_required (the account has no password yet) or last_admin', content: { "application/json": { schema: { $ref: "#/components/schemas/DeleteAccountRefusal" } } } } */
|
||||||
|
/* #swagger.responses[429] = { description: 'Too many attempts (rate limited)', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
backoffGuard,
|
||||||
|
slowLogin,
|
||||||
|
accountChangeLimiter,
|
||||||
|
body('username').isString().trim().isLength({ min: 1, max: 64 }),
|
||||||
|
body('password').optional({ values: 'falsy' }).isString().isLength({ max: 128 }),
|
||||||
|
body('code').optional({ values: 'falsy' }).isString().trim().isLength({ max: 16 }),
|
||||||
|
body('recoveryCode').optional({ values: 'falsy' }).isString().trim().isLength({ max: 64 }),
|
||||||
|
validate,
|
||||||
|
account.deleteAccount,
|
||||||
|
)
|
||||||
|
|
||||||
|
// ── Block and "Hide for me" (USER_SAFETY.md §4.1) ─────────────────────────
|
||||||
|
//
|
||||||
|
// Saved on the account, so they apply on the website and in the app on every
|
||||||
|
// device (S2). A block names an ITEM, never a person: the server reads who wrote
|
||||||
|
// it, so a member can only block someone whose words they could see, and the
|
||||||
|
// block lands on the author's account whenever they have one (S12).
|
||||||
|
|
||||||
|
const safetyLimiter = makeLimiter({
|
||||||
|
windowMs: 10 * 60 * 1000,
|
||||||
|
max: 60,
|
||||||
|
label: 'user-safety',
|
||||||
|
message: 'Too many changes. Please slow down.',
|
||||||
|
})
|
||||||
|
|
||||||
|
meRouter.get(
|
||||||
|
'/blocks',
|
||||||
|
// #swagger.tags = ['Auth · Me']
|
||||||
|
// #swagger.summary = 'List the accounts and players this account has blocked'
|
||||||
|
// #swagger.description = 'Each block is an account block or, for a game identity no account has linked (a Steam id in a chat feed), a game block. A game block whose identity has since been linked is answered — and stored — as an account block (S14). A block on an account that is now staff does not apply, and says so (S8).'
|
||||||
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
|
/* #swagger.responses[200] = { description: 'The blocks, newest first', content: { "application/json": { schema: { type: 'object', properties: { blocks: { type: 'array', items: { $ref: "#/components/schemas/UserBlock" } } } } } } } */
|
||||||
|
/* #swagger.responses[401] = { description: 'Not authenticated', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
safetyCtrl.listBlocks,
|
||||||
|
)
|
||||||
|
|
||||||
|
meRouter.post(
|
||||||
|
'/blocks',
|
||||||
|
// #swagger.tags = ['Auth · Me']
|
||||||
|
// #swagger.summary = 'Block the author of an item'
|
||||||
|
// #swagger.description = 'Names the item (a forum thread or post, or a game module’s item such as a `rust.chat` line), never the person. The block lands on the author’s website account; a chat speaker with no linked account is blocked by their game identity. Everything the blocked author writes then disappears from this account’s view, on the website and in the app. The blocked person is not told (S9). Staff cannot be blocked (S8). An item this account cannot see answers 404.'
|
||||||
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
|
/* #swagger.requestBody = { required: true, content: { "application/json": { schema: { $ref: "#/components/schemas/SafetyTarget" } } } } */
|
||||||
|
/* #swagger.responses[201] = { description: 'Blocked', content: { "application/json": { schema: { type: 'object', properties: { block: { $ref: "#/components/schemas/UserBlock" } } } } } } */
|
||||||
|
/* #swagger.responses[400] = { description: 'unknown_target, self or no_author', content: { "application/json": { schema: { $ref: "#/components/schemas/SafetyRefusal" } } } } */
|
||||||
|
/* #swagger.responses[401] = { description: 'Not authenticated', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
/* #swagger.responses[403] = { description: 'staff — a staff member cannot be blocked', content: { "application/json": { schema: { $ref: "#/components/schemas/SafetyRefusal" } } } } */
|
||||||
|
/* #swagger.responses[404] = { description: 'No such item, or not one this account can see', content: { "application/json": { schema: { $ref: "#/components/schemas/SafetyRefusal" } } } } */
|
||||||
|
/* #swagger.responses[409] = { description: 'already_blocked', content: { "application/json": { schema: { $ref: "#/components/schemas/SafetyRefusal" } } } } */
|
||||||
|
/* #swagger.responses[429] = { description: 'Too many changes (rate limited)', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
/* #swagger.responses[503] = { description: 'module_unavailable — the game module did not answer', content: { "application/json": { schema: { $ref: "#/components/schemas/SafetyRefusal" } } } } */
|
||||||
|
safetyLimiter,
|
||||||
|
body('targetType').isString().trim().isLength({ min: 1, max: 32 }),
|
||||||
|
body('targetId').isInt({ min: 1 }).toInt(),
|
||||||
|
validate,
|
||||||
|
safetyCtrl.createBlock,
|
||||||
|
)
|
||||||
|
|
||||||
|
meRouter.delete(
|
||||||
|
'/blocks/:id',
|
||||||
|
// #swagger.tags = ['Auth · Me']
|
||||||
|
// #swagger.summary = 'Undo a block'
|
||||||
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
|
// #swagger.parameters['id'] = { in: 'path', required: true, schema: { type: 'integer' } }
|
||||||
|
/* #swagger.responses[200] = { description: 'Unblocked', content: { "application/json": { schema: { $ref: "#/components/schemas/OkFlag" } } } } */
|
||||||
|
/* #swagger.responses[401] = { description: 'Not authenticated', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
/* #swagger.responses[404] = { description: 'Not one of this account’s blocks', content: { "application/json": { schema: { $ref: "#/components/schemas/SafetyRefusal" } } } } */
|
||||||
|
safetyLimiter,
|
||||||
|
param('id').isInt({ min: 1 }),
|
||||||
|
validate,
|
||||||
|
safetyCtrl.deleteBlock,
|
||||||
|
)
|
||||||
|
|
||||||
|
meRouter.get(
|
||||||
|
'/hidden',
|
||||||
|
// #swagger.tags = ['Auth · Me']
|
||||||
|
// #swagger.summary = 'List the items this account hid for itself'
|
||||||
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
|
/* #swagger.responses[200] = { description: 'The hidden items, newest first', content: { "application/json": { schema: { type: 'object', properties: { hidden: { type: 'array', items: { type: 'object', properties: { targetType: { type: 'string' }, targetId: { type: 'integer' }, createdAt: { type: 'string', format: 'date-time' } } } } } } } } } */
|
||||||
|
/* #swagger.responses[401] = { description: 'Not authenticated', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
safetyCtrl.listHidden,
|
||||||
|
)
|
||||||
|
|
||||||
|
meRouter.post(
|
||||||
|
'/hidden',
|
||||||
|
// #swagger.tags = ['Auth · Me']
|
||||||
|
// #swagger.summary = 'Hide one item for this account'
|
||||||
|
// #swagger.description = 'The item disappears from this account’s own view, on the website and in the app. No report is filed and nothing about the item changes. Hiding twice is still hidden.'
|
||||||
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
|
/* #swagger.requestBody = { required: true, content: { "application/json": { schema: { $ref: "#/components/schemas/SafetyTarget" } } } } */
|
||||||
|
/* #swagger.responses[200] = { description: 'Hidden', content: { "application/json": { schema: { $ref: "#/components/schemas/OkFlag" } } } } */
|
||||||
|
/* #swagger.responses[400] = { description: 'unknown_target', content: { "application/json": { schema: { $ref: "#/components/schemas/SafetyRefusal" } } } } */
|
||||||
|
/* #swagger.responses[401] = { description: 'Not authenticated', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
/* #swagger.responses[429] = { description: 'Too many changes (rate limited)', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
safetyLimiter,
|
||||||
|
body('targetType').isString().trim().isLength({ min: 1, max: 32 }),
|
||||||
|
body('targetId').isInt({ min: 1 }).toInt(),
|
||||||
|
validate,
|
||||||
|
safetyCtrl.createHidden,
|
||||||
|
)
|
||||||
|
|
||||||
|
meRouter.delete(
|
||||||
|
'/hidden',
|
||||||
|
// #swagger.tags = ['Auth · Me']
|
||||||
|
// #swagger.summary = 'Show every hidden item again'
|
||||||
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
|
/* #swagger.responses[200] = { description: 'Cleared', content: { "application/json": { schema: { type: 'object', properties: { ok: { type: 'boolean' }, cleared: { type: 'integer' } } } } } } */
|
||||||
|
/* #swagger.responses[401] = { description: 'Not authenticated', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
safetyLimiter,
|
||||||
|
safetyCtrl.clearHidden,
|
||||||
|
)
|
||||||
|
|
||||||
|
meRouter.delete(
|
||||||
|
'/hidden/:targetType/:targetId',
|
||||||
|
// #swagger.tags = ['Auth · Me']
|
||||||
|
// #swagger.summary = 'Show one hidden item again'
|
||||||
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
|
// #swagger.parameters['targetType'] = { in: 'path', required: true, schema: { type: 'string' }, example: 'rust.chat' }
|
||||||
|
// #swagger.parameters['targetId'] = { in: 'path', required: true, schema: { type: 'integer' } }
|
||||||
|
/* #swagger.responses[200] = { description: 'Shown again', content: { "application/json": { schema: { $ref: "#/components/schemas/OkFlag" } } } } */
|
||||||
|
/* #swagger.responses[400] = { description: 'unknown_target', content: { "application/json": { schema: { $ref: "#/components/schemas/SafetyRefusal" } } } } */
|
||||||
|
/* #swagger.responses[401] = { description: 'Not authenticated', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
|
safetyLimiter,
|
||||||
|
param('targetType').isString().isLength({ min: 1, max: 32 }),
|
||||||
|
param('targetId').isInt({ min: 1 }),
|
||||||
|
validate,
|
||||||
|
safetyCtrl.deleteHidden,
|
||||||
|
)
|
||||||
|
|
||||||
// Email address (engagement Phase 1b). The change is STAGED and only a tokened
|
// Email address (engagement Phase 1b). The change is STAGED and only a tokened
|
||||||
// link installs it, so these three routes never alter the address that is
|
// link installs it, so these three routes never alter the address that is
|
||||||
// currently receiving mail. The confirm half is public and lives at
|
// currently receiving mail. The confirm half is public and lives at
|
||||||
@@ -177,10 +323,14 @@ meRouter.delete(
|
|||||||
// #swagger.tags = ['Auth · Me']
|
// #swagger.tags = ['Auth · Me']
|
||||||
// #swagger.summary = 'Unlink an SSO identity (self)'
|
// #swagger.summary = 'Unlink an SSO identity (self)'
|
||||||
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
// #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }]
|
||||||
|
// #swagger.description = 'Removes every identity of the provider, or with ?id= the one identity named (a user may link several Steam accounts). Only the sign-in identity goes: a game module link made from it stays (STEAM_SIGNIN.md D393).'
|
||||||
// #swagger.parameters['provider'] = { in: 'path', required: true, schema: { type: 'string' }, description: 'Provider id.' }
|
// #swagger.parameters['provider'] = { in: 'path', required: true, schema: { type: 'string' }, description: 'Provider id.' }
|
||||||
|
// #swagger.parameters['id'] = { in: 'query', required: false, schema: { type: 'integer' }, description: 'One identity to unlink (its id from GET /auth/me/account/identities).' }
|
||||||
/* #swagger.responses[200] = { description: 'Unlinked', content: { "application/json": { schema: { $ref: "#/components/schemas/UnlinkedFlag" } } } } */
|
/* #swagger.responses[200] = { description: 'Unlinked', content: { "application/json": { schema: { $ref: "#/components/schemas/UnlinkedFlag" } } } } */
|
||||||
|
/* #swagger.responses[400] = { description: 'Validation error', content: { "application/json": { schema: { $ref: "#/components/schemas/ValidationError" } } } } */
|
||||||
/* #swagger.responses[404] = { description: 'No linked account for that provider', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
/* #swagger.responses[404] = { description: 'No linked account for that provider', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */
|
||||||
param('provider').matches(/^[a-z0-9-]+$/),
|
param('provider').matches(/^[a-z0-9-]+$/),
|
||||||
|
query('id').optional().isInt({ min: 1 }),
|
||||||
validate,
|
validate,
|
||||||
account.unlinkIdentity,
|
account.unlinkIdentity,
|
||||||
)
|
)
|
||||||
|
|||||||
85
server/src/router/v1/auth/safety.controller.js
Normal file
85
server/src/router/v1/auth/safety.controller.js
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
// /auth/me/blocks and /auth/me/hidden — a member's own blocks and hides
|
||||||
|
// (USER_SAFETY.md §4.1). Self-scoped on req.user.id; requireAuth is the group's.
|
||||||
|
|
||||||
|
const safety = require('../../../model/safety/userSafety.model')
|
||||||
|
const log = require('../../../utils/logger')('safety')
|
||||||
|
|
||||||
|
const fail = (res, err, what) => {
|
||||||
|
if (err && err.status === 503) {
|
||||||
|
return res.status(503).json({ code: 'module_unavailable', message: 'The game module did not answer. Try again in a moment.' })
|
||||||
|
}
|
||||||
|
log.error(`${what} failed`, { message: err.message })
|
||||||
|
return res.status(500).json({ message: 'Internal Server Error' })
|
||||||
|
}
|
||||||
|
|
||||||
|
const refused = (res, result) => res.status(result.status || 400).json({ code: result.code, message: result.error })
|
||||||
|
|
||||||
|
async function listBlocks(req, res) {
|
||||||
|
try {
|
||||||
|
return res.json({ blocks: await safety.listBlocks(req.user) })
|
||||||
|
} catch (err) {
|
||||||
|
return fail(res, err, 'list blocks')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createBlock(req, res) {
|
||||||
|
try {
|
||||||
|
const result = await safety.blockAuthorOf({
|
||||||
|
actor: req.user,
|
||||||
|
targetType: req.body.targetType,
|
||||||
|
targetId: req.body.targetId,
|
||||||
|
})
|
||||||
|
if (!result.ok) return refused(res, result)
|
||||||
|
return res.status(201).json({ block: result.block })
|
||||||
|
} catch (err) {
|
||||||
|
return fail(res, err, 'create block')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteBlock(req, res) {
|
||||||
|
try {
|
||||||
|
const result = await safety.unblock(req.user, Number(req.params.id))
|
||||||
|
if (!result.ok) return refused(res, result)
|
||||||
|
return res.json({ ok: true })
|
||||||
|
} catch (err) {
|
||||||
|
return fail(res, err, 'delete block')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function listHidden(req, res) {
|
||||||
|
try {
|
||||||
|
return res.json({ hidden: await safety.listHidden(req.user) })
|
||||||
|
} catch (err) {
|
||||||
|
return fail(res, err, 'list hidden')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createHidden(req, res) {
|
||||||
|
try {
|
||||||
|
const result = await safety.hide(req.user, req.body.targetType, req.body.targetId)
|
||||||
|
if (!result.ok) return refused(res, result)
|
||||||
|
return res.json({ ok: true })
|
||||||
|
} catch (err) {
|
||||||
|
return fail(res, err, 'hide item')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteHidden(req, res) {
|
||||||
|
try {
|
||||||
|
const result = await safety.unhide(req.user, req.params.targetType, Number(req.params.targetId))
|
||||||
|
if (!result.ok) return refused(res, result)
|
||||||
|
return res.json({ ok: true })
|
||||||
|
} catch (err) {
|
||||||
|
return fail(res, err, 'unhide item')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function clearHidden(req, res) {
|
||||||
|
try {
|
||||||
|
return res.json({ ok: true, cleared: await safety.clearHidden(req.user) })
|
||||||
|
} catch (err) {
|
||||||
|
return fail(res, err, 'clear hidden')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { listBlocks, createBlock, deleteBlock, listHidden, createHidden, deleteHidden, clearHidden }
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
// ── SSO (OAuth2 / OIDC) controller ─────────────────────────────────────────
|
// ── SSO (OAuth2 / OIDC) controller ─────────────────────────────────────────
|
||||||
//
|
//
|
||||||
// Drives the redirect flow for built-in (Google, Discord) and custom providers:
|
// Drives the redirect flow for built-in (Google, Discord, Steam) and custom
|
||||||
|
// providers. Steam is OpenID 2.0 rather than OAuth2 (STEAM_SIGNIN.md §3); the
|
||||||
|
// difference is confined to readCallback() and the provider class:
|
||||||
// GET /auth/providers → public discovery (enabled + valid providers)
|
// GET /auth/providers → public discovery (enabled + valid providers)
|
||||||
// GET /auth/sso/:provider/start → begin login (redirect to the IdP)
|
// GET /auth/sso/:provider/start → begin login (redirect to the IdP)
|
||||||
// GET /auth/sso/:provider/link → begin account linking (requireAuth)
|
// GET /auth/sso/:provider/link → begin account linking (requireAuth)
|
||||||
@@ -17,6 +19,8 @@ const authProviders = require('../../../model/authProviders/authProviders.model'
|
|||||||
const userIdentities = require('../../../model/userIdentities/userIdentities.model')
|
const userIdentities = require('../../../model/userIdentities/userIdentities.model')
|
||||||
const settings = require('../../../model/settings/settings.model')
|
const settings = require('../../../model/settings/settings.model')
|
||||||
const registry = require('../../../auth/providers/registry')
|
const registry = require('../../../auth/providers/registry')
|
||||||
|
const SteamProvider = require('../../../auth/providers/steam.provider')
|
||||||
|
const identityHooks = require('../../../auth/identityHooks')
|
||||||
const sessionService = require('../../../auth/session.service')
|
const sessionService = require('../../../auth/session.service')
|
||||||
const mobileBridge = require('../../../model/mobileAuthBridge/mobileAuthBridge.model')
|
const mobileBridge = require('../../../model/mobileAuthBridge/mobileAuthBridge.model')
|
||||||
const ssoState = require('../../../auth/ssoState')
|
const ssoState = require('../../../auth/ssoState')
|
||||||
@@ -148,20 +152,43 @@ async function beginFlow(req, res, mode) {
|
|||||||
const start = (req, res) => beginFlow(req, res, 'login')
|
const start = (req, res) => beginFlow(req, res, 'login')
|
||||||
const linkStart = (req, res) => beginFlow(req, res, 'link')
|
const linkStart = (req, res) => beginFlow(req, res, 'link')
|
||||||
|
|
||||||
|
// The callback's own answer from the IdP, read the way its protocol writes it.
|
||||||
|
// OAuth2/OIDC sends `code` (or `error`); Steam's OpenID 2.0 sends `openid.*`
|
||||||
|
// fields, with `openid.mode=cancel` when the person declined (STEAM_SIGNIN.md §3).
|
||||||
|
// Our `state` arrives as a query parameter either way — for Steam because it
|
||||||
|
// rides inside the `return_to` we sent.
|
||||||
|
function readCallback(req, providerId) {
|
||||||
|
const q = req.query || {}
|
||||||
|
if (registry.isOpenId(providerId)) {
|
||||||
|
const mode = typeof q['openid.mode'] === 'string' ? q['openid.mode'] : ''
|
||||||
|
return { state: q.state, denied: mode === 'cancel' || mode === 'error', present: mode === 'id_res' }
|
||||||
|
}
|
||||||
|
return { state: q.state, denied: Boolean(q.error), present: Boolean(q.code), error: q.error }
|
||||||
|
}
|
||||||
|
|
||||||
|
// What the provider's handleCallback needs. Steam takes the whole query, and its
|
||||||
|
// `return_to` must match what we sent (the callback URL plus this very state)
|
||||||
|
// byte for byte; OAuth2 takes the code and the PKCE verifier.
|
||||||
|
function callbackParams(req, providerId, tx, answer) {
|
||||||
|
const redirectUri = redirectUriFor(req, providerId)
|
||||||
|
if (registry.isOpenId(providerId)) return { query: req.query, redirectUri, state: answer.state }
|
||||||
|
return { code: req.query.code, redirectUri, codeVerifier: tx.verifier }
|
||||||
|
}
|
||||||
|
|
||||||
// GET /auth/sso/:provider/callback
|
// GET /auth/sso/:provider/callback
|
||||||
async function callback(req, res) {
|
async function callback(req, res) {
|
||||||
const providerId = req.params.provider
|
const providerId = req.params.provider
|
||||||
const txToken = req.cookies && req.cookies[ssoState.TX_COOKIE]
|
const txToken = req.cookies && req.cookies[ssoState.TX_COOKIE]
|
||||||
const { code, state, error: oauthError } = req.query
|
const answer = readCallback(req, providerId)
|
||||||
// The tx cookie is single-use — clear it no matter the outcome.
|
// The tx cookie is single-use — clear it no matter the outcome.
|
||||||
res.clearCookie(ssoState.TX_COOKIE, token.cookieOptions(req))
|
res.clearCookie(ssoState.TX_COOKIE, token.cookieOptions(req))
|
||||||
|
|
||||||
if (oauthError) {
|
if (answer.denied) {
|
||||||
log.warn('sso callback: provider returned error', { provider: providerId, error: String(oauthError).slice(0, 60) })
|
log.warn('sso callback: provider returned error', { provider: providerId, error: String(answer.error || 'cancel').slice(0, 60) })
|
||||||
return res.redirect(loginError('denied'))
|
return res.redirect(loginError('denied'))
|
||||||
}
|
}
|
||||||
const tx = ssoState.verifyTx(txToken, state)
|
const tx = ssoState.verifyTx(txToken, answer.state)
|
||||||
if (!tx || tx.provider !== providerId || !code) {
|
if (!tx || tx.provider !== providerId || !answer.present) {
|
||||||
log.warn('sso callback: bad state', { provider: providerId })
|
log.warn('sso callback: bad state', { provider: providerId })
|
||||||
return res.redirect(loginError('bad_state'))
|
return res.redirect(loginError('bad_state'))
|
||||||
}
|
}
|
||||||
@@ -175,20 +202,34 @@ async function callback(req, res) {
|
|||||||
return res.redirect(failFor('unavailable'))
|
return res.redirect(failFor('unavailable'))
|
||||||
}
|
}
|
||||||
const provider = registry.instantiate(row)
|
const provider = registry.instantiate(row)
|
||||||
const profile = await provider.handleCallback({
|
const profile = await provider.handleCallback(callbackParams(req, providerId, tx, answer))
|
||||||
code,
|
|
||||||
redirectUri: redirectUriFor(req, providerId),
|
|
||||||
codeVerifier: tx.verifier,
|
|
||||||
})
|
|
||||||
if (tx.mode === 'link') return finishLink(req, res, providerId, tx, profile)
|
if (tx.mode === 'link') return finishLink(req, res, providerId, tx, profile)
|
||||||
if (tx.mode === 'mobile') return finishMobileLogin(req, res, providerId, row.kind, tx, profile)
|
if (tx.mode === 'mobile') return finishMobileLogin(req, res, providerId, row.kind, tx, profile)
|
||||||
return finishLogin(req, res, providerId, row.kind, tx, profile)
|
return finishLogin(req, res, providerId, row.kind, tx, profile)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// A Steam assertion that failed one of the §3 checks is a refused sign-in, not
|
||||||
|
// a server fault: it is what a replayed, forged or tampered callback looks like.
|
||||||
|
if (err instanceof SteamProvider.SteamAssertionError) {
|
||||||
|
log.warn('sso callback: steam assertion refused', { provider: providerId, reason: err.reason })
|
||||||
|
return res.redirect(failFor('bad_state'))
|
||||||
|
}
|
||||||
log.error('sso callback', err)
|
log.error('sso callback', err)
|
||||||
return res.redirect(failFor('error'))
|
return res.redirect(failFor('error'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A profile's name and avatar written back onto an identity the user already
|
||||||
|
// holds, when the provider reports them (Steam, at every sign-in). Decoration:
|
||||||
|
// a failure here is logged and never stops the sign-in it rides on.
|
||||||
|
async function refreshIdentityProfile(identity, profile) {
|
||||||
|
if (!identity || !(profile.displayName || profile.avatarUrl)) return
|
||||||
|
try {
|
||||||
|
await userIdentities.refreshProfile(identity.id, { displayName: profile.displayName, avatarUrl: profile.avatarUrl })
|
||||||
|
} catch (err) {
|
||||||
|
log.warn('sso: could not refresh a linked identity profile', { provider: identity.provider, message: err.message })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Auto-provision a `player` from an SSO profile when no identity is linked yet
|
// Auto-provision a `player` from an SSO profile when no identity is linked yet
|
||||||
// and registration allows SSO sign-up. Derives a unique username (reserved-name
|
// and registration allows SSO sign-up. Derives a unique username (reserved-name
|
||||||
// safe) with a bounded retry against the UNIQUE index, captures the provider
|
// safe) with a bounded retry against the UNIQUE index, captures the provider
|
||||||
@@ -288,10 +329,12 @@ async function finishLogin(req, res, providerId, kind, tx, profile) {
|
|||||||
if (identity) {
|
if (identity) {
|
||||||
user = await users.getById(identity.user_id)
|
user = await users.getById(identity.user_id)
|
||||||
if (!user) return res.redirect(loginError('not_linked', portal))
|
if (!user) return res.redirect(loginError('not_linked', portal))
|
||||||
|
await refreshIdentityProfile(identity, profile)
|
||||||
} else {
|
} else {
|
||||||
// Unknown identity: auto-provision only if registration opts into SSO sign-up.
|
// Unknown identity: auto-provision only if registration opts into SSO sign-up,
|
||||||
|
// and never through a provider that signs nobody up (Steam, D395).
|
||||||
const mode = await settings.getRegistrationMode()
|
const mode = await settings.getRegistrationMode()
|
||||||
if (mode !== 'sso' && mode !== 'both') {
|
if ((mode !== 'sso' && mode !== 'both') || registry.neverProvisions(kind)) {
|
||||||
log.warn('sso login refused: no linked account', { provider: providerId })
|
log.warn('sso login refused: no linked account', { provider: providerId })
|
||||||
return res.redirect(loginError('not_linked', portal))
|
return res.redirect(loginError('not_linked', portal))
|
||||||
}
|
}
|
||||||
@@ -397,7 +440,7 @@ async function requireValidBridgeSession(res, tx, providerId) {
|
|||||||
// Resolve the linked user for a mobile SSO login (link-only, with opt-in
|
// Resolve the linked user for a mobile SSO login (link-only, with opt-in
|
||||||
// provisioning when registration mode allows it). On refusal, sends the redirect
|
// provisioning when registration mode allows it). On refusal, sends the redirect
|
||||||
// and returns null.
|
// and returns null.
|
||||||
async function resolveMobileSsoUser(req, res, sess, providerId, profile) {
|
async function resolveMobileSsoUser(req, res, sess, providerId, kind, profile) {
|
||||||
const identity = await userIdentities.findByProviderSubject(providerId, profile.subject)
|
const identity = await userIdentities.findByProviderSubject(providerId, profile.subject)
|
||||||
if (identity) {
|
if (identity) {
|
||||||
const user = await users.getById(identity.user_id)
|
const user = await users.getById(identity.user_id)
|
||||||
@@ -405,10 +448,11 @@ async function resolveMobileSsoUser(req, res, sess, providerId, profile) {
|
|||||||
res.redirect(appError(sess, 'not_linked'))
|
res.redirect(appError(sess, 'not_linked'))
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
await refreshIdentityProfile(identity, profile)
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
const mode = await settings.getRegistrationMode()
|
const mode = await settings.getRegistrationMode()
|
||||||
if (mode !== 'sso' && mode !== 'both') {
|
if ((mode !== 'sso' && mode !== 'both') || registry.neverProvisions(kind)) {
|
||||||
log.warn('mobile sso login refused: no linked account', { provider: providerId })
|
log.warn('mobile sso login refused: no linked account', { provider: providerId })
|
||||||
res.redirect(appError(sess, 'not_linked'))
|
res.redirect(appError(sess, 'not_linked'))
|
||||||
return null
|
return null
|
||||||
@@ -425,7 +469,7 @@ async function finishMobileLogin(req, res, providerId, kind, tx, profile) {
|
|||||||
const sess = await requireValidBridgeSession(res, tx, providerId)
|
const sess = await requireValidBridgeSession(res, tx, providerId)
|
||||||
if (!sess) return
|
if (!sess) return
|
||||||
|
|
||||||
const user = await resolveMobileSsoUser(req, res, sess, providerId, profile)
|
const user = await resolveMobileSsoUser(req, res, sess, providerId, kind, profile)
|
||||||
if (!user) return
|
if (!user) return
|
||||||
|
|
||||||
if (user.status && user.status !== 'active') {
|
if (user.status && user.status !== 'active') {
|
||||||
@@ -555,11 +599,38 @@ async function finishLink(req, res, providerId, tx, profile) {
|
|||||||
if (existing && existing.user_id !== userId) {
|
if (existing && existing.user_id !== userId) {
|
||||||
return res.redirect(accountError('in_use', portal)) // external identity belongs to another account
|
return res.redirect(accountError('in_use', portal)) // external identity belongs to another account
|
||||||
}
|
}
|
||||||
if (!existing) {
|
if (existing) {
|
||||||
await userIdentities.link({ userId, provider: providerId, subject: profile.subject, email: profile.email })
|
// Already theirs: linking twice is not an error, and it is a fresh look at
|
||||||
await activity.log({ req, userId, action: 'auth.sso.link', detail: { provider: providerId } })
|
// the name and avatar.
|
||||||
log.info('sso account linked', { provider: providerId, userId })
|
await refreshIdentityProfile(existing, profile)
|
||||||
|
return res.redirect(`${accountPath(portal)}?linked=${providerId}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Modules may refuse before anything is written (API 1.17.0) — Rust, for a
|
||||||
|
// Steam id that is already another account's Rust link (D396). Only ever a
|
||||||
|
// refusal: this user is already signed in, and this decides a link, not a session.
|
||||||
|
const check = await identityHooks.checkLink({ userId, provider: providerId, subject: profile.subject })
|
||||||
|
if (!check.ok) {
|
||||||
|
await activity.log({ req, userId, action: 'auth.sso.link.refused', detail: { provider: providerId, module: check.module, reason: check.reason } })
|
||||||
|
return res.redirect(accountError(check.reason, portal))
|
||||||
|
}
|
||||||
|
|
||||||
|
await userIdentities.link({
|
||||||
|
userId,
|
||||||
|
provider: providerId,
|
||||||
|
subject: profile.subject,
|
||||||
|
email: profile.email,
|
||||||
|
displayName: profile.displayName || null,
|
||||||
|
avatarUrl: profile.avatarUrl || null,
|
||||||
|
})
|
||||||
|
await activity.log({ req, userId, action: 'auth.sso.link', detail: { provider: providerId } })
|
||||||
|
log.info('sso account linked', { provider: providerId, userId })
|
||||||
|
await identityHooks.notifyLinked({
|
||||||
|
userId,
|
||||||
|
provider: providerId,
|
||||||
|
subject: profile.subject,
|
||||||
|
displayName: profile.displayName || null,
|
||||||
|
})
|
||||||
return res.redirect(`${accountPath(portal)}?linked=${providerId}`)
|
return res.redirect(`${accountPath(portal)}?linked=${providerId}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,10 +52,13 @@ ssoRouter.get(
|
|||||||
'/sso/:provider/callback',
|
'/sso/:provider/callback',
|
||||||
// #swagger.tags = ['Auth · SSO']
|
// #swagger.tags = ['Auth · SSO']
|
||||||
// #swagger.summary = 'OAuth redirect target — completes login or linking'
|
// #swagger.summary = 'OAuth redirect target — completes login or linking'
|
||||||
// #swagger.description = 'The provider redirects here with code + state. On success sets the session cookie (login) or links the identity (link), then 302-redirects into /admin. Login is link-only: unknown identities are refused (sso_error=not_linked).'
|
// #swagger.description = 'The provider redirects here with code + state. On success sets the session cookie (login) or links the identity (link), then 302-redirects into /admin. Login is link-only: unknown identities are refused (sso_error=not_linked). Steam (OpenID 2.0) sends openid.* fields instead of code; the server verifies them with Steam (check_authentication) before anything else, and Steam never signs anybody up (STEAM_SIGNIN.md D395). A module may refuse a link (link_error=in_use or refused; MODULE_API 1.17.0).'
|
||||||
// #swagger.parameters['provider'] = { in: 'path', required: true, schema: { type: 'string' }, description: 'Provider id (e.g. google, discord).' }
|
// #swagger.parameters['provider'] = { in: 'path', required: true, schema: { type: 'string' }, description: 'Provider id (e.g. google, discord, steam).' }
|
||||||
// #swagger.parameters['code'] = { in: 'query', required: false, schema: { type: 'string' }, description: 'OAuth authorization code.' }
|
// #swagger.parameters['code'] = { in: 'query', required: false, schema: { type: 'string' }, description: 'OAuth authorization code (OAuth2/OIDC providers).' }
|
||||||
// #swagger.parameters['state'] = { in: 'query', required: false, schema: { type: 'string' }, description: 'OAuth state (matched against the tx cookie).' }
|
// #swagger.parameters['state'] = { in: 'query', required: false, schema: { type: 'string' }, description: 'OAuth state (matched against the tx cookie). For Steam it rides inside openid.return_to and comes back as this parameter.' }
|
||||||
|
// #swagger.parameters['error'] = { in: 'query', required: false, schema: { type: 'string' }, description: 'OAuth error (the user declined, or the IdP refused).' }
|
||||||
|
// #swagger.parameters['openid.mode'] = { in: 'query', required: false, schema: { type: 'string', enum: ['id_res', 'cancel'] }, description: 'Steam only: id_res with an assertion, or cancel. The other openid.* fields of the assertion (ns, op_endpoint, claimed_id, identity, return_to, response_nonce, assoc_handle, signed, sig) are passed back to Steam to verify.' }
|
||||||
|
// #swagger.parameters['openid.claimed_id'] = { in: 'query', required: false, schema: { type: 'string' }, description: 'Steam only: https://steamcommunity.com/openid/id/<SteamID64>.' }
|
||||||
/* #swagger.responses[302] = { description: 'Redirect into /admin on success, or back to login/account with an error code' } */
|
/* #swagger.responses[302] = { description: 'Redirect into /admin on success, or back to login/account with an error code' } */
|
||||||
ctrl.callback,
|
ctrl.callback,
|
||||||
)
|
)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user