Add account restrictions, appeals, and admin moderation tools
This commit is contained in:
243
components/AccountAppeal.tsx
Normal file
243
components/AccountAppeal.tsx
Normal file
@@ -0,0 +1,243 @@
|
||||
"use client";
|
||||
import Link from "next/link";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { api } from "@/lib/client-api";
|
||||
import { useI18n } from "./I18nProvider";
|
||||
import type {
|
||||
ManagedAccount,
|
||||
AccountAppealRecord,
|
||||
} from "@/shared/account-controls";
|
||||
import styles from "@/app/ban/appeal/page.module.css";
|
||||
|
||||
export function AccountAppeal() {
|
||||
const { locale } = useI18n();
|
||||
const l = (en: string, ru: string) => (locale === "ru" ? ru : en);
|
||||
const [data, setData] = useState<{
|
||||
account: ManagedAccount;
|
||||
appeals: AccountAppealRecord[];
|
||||
} | null>(null);
|
||||
const [error, setError] = useState("");
|
||||
const [message, setMessage] = useState("");
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [reason, setReason] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const lock = useRef(false);
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
api<{ account: ManagedAccount; appeals: AccountAppealRecord[] }>(
|
||||
"ban/appeal",
|
||||
)
|
||||
.then((result) => {
|
||||
if (active) setData(result);
|
||||
})
|
||||
.catch((e) => {
|
||||
if (active) setError((e as Error).message);
|
||||
})
|
||||
.finally(() => {
|
||||
if (active) setLoading(false);
|
||||
});
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, []);
|
||||
async function run(operation: () => Promise<void>) {
|
||||
if (lock.current) return;
|
||||
lock.current = true;
|
||||
setBusy(true);
|
||||
setError("");
|
||||
try {
|
||||
await operation();
|
||||
} catch (e) {
|
||||
setError((e as Error).message);
|
||||
} finally {
|
||||
lock.current = false;
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
async function reload() {
|
||||
setData(await api("ban/appeal"));
|
||||
setLoading(false);
|
||||
}
|
||||
const current = data?.appeals.find(
|
||||
(a) => a.status_version === data.account.status_version,
|
||||
);
|
||||
return (
|
||||
<section
|
||||
aria-label={l(
|
||||
"Account access and appeals",
|
||||
"Доступ к аккаунту и апелляции",
|
||||
)}
|
||||
>
|
||||
{error && (
|
||||
<p className="error-message" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{message && (
|
||||
<p className="muted" role="status">
|
||||
{message}
|
||||
</p>
|
||||
)}
|
||||
{loading && !error && (
|
||||
<p role="status">
|
||||
{l("Loading account status…", "Загрузка состояния аккаунта…")}
|
||||
</p>
|
||||
)}
|
||||
<div className={styles.actions}>
|
||||
<button
|
||||
className="button"
|
||||
disabled={busy}
|
||||
onClick={() => void run(reload)}
|
||||
>
|
||||
{l("Refresh status", "Обновить статус")}
|
||||
</button>
|
||||
<button
|
||||
className="button"
|
||||
disabled={busy}
|
||||
onClick={() =>
|
||||
void run(async () => {
|
||||
await api("auth/logout", {});
|
||||
window.location.assign("/log-in");
|
||||
})
|
||||
}
|
||||
>
|
||||
{l("Log out", "Выйти")}
|
||||
</button>
|
||||
<Link className="button" href="/docs?page=account-bans">
|
||||
{l("Read the guide", "Открыть руководство")}
|
||||
</Link>
|
||||
</div>
|
||||
{data && (
|
||||
<>
|
||||
<div className={styles.record} style={{ marginTop: 32 }}>
|
||||
<h2>
|
||||
{data.account.account_status === "active"
|
||||
? l("Your account is active", "Ваш аккаунт активен")
|
||||
: data.account.account_status === "banned"
|
||||
? l("Your account is banned", "Ваш аккаунт заблокирован")
|
||||
: data.account.account_status === "deleting"
|
||||
? l(
|
||||
"Account deletion is pending",
|
||||
"Ожидается удаление аккаунта",
|
||||
)
|
||||
: l(
|
||||
"Your account is deactivated",
|
||||
"Ваш аккаунт деактивирован",
|
||||
)}
|
||||
</h2>
|
||||
{data.account.account_reason && (
|
||||
<>
|
||||
<strong>{l("Reason", "Причина")}</strong>
|
||||
<p className={styles.reason}>{data.account.account_reason}</p>
|
||||
</>
|
||||
)}
|
||||
{data.account.account_status === "active" ? (
|
||||
<Link className="button primary" href="/servers">
|
||||
{l("Continue playing", "Продолжить играть")}
|
||||
</Link>
|
||||
) : (
|
||||
<p>
|
||||
{l(
|
||||
"Normal account access, uploads and API keys are blocked. You can still read the docs, view this page and sign out.",
|
||||
"Обычный доступ к аккаунту, загрузки и ключи API заблокированы. Вы можете читать документацию, открывать эту страницу и выходить из аккаунта.",
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{data.account.account_status === "deactivated" && (
|
||||
<p>
|
||||
{l(
|
||||
"An Admin must restore a deactivated account. Ban appeals are available only for banned accounts. Contact the team through the community links below.",
|
||||
"Деактивированный аккаунт может восстановить только администратор. Апелляции доступны только при блокировке. Свяжитесь с командой через ссылки сообщества внизу.",
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{data.account.account_status === "deleting" && (
|
||||
<p>
|
||||
{l(
|
||||
"An Admin must finish this action. A deleted account cannot be appealed or recovered here.",
|
||||
"Администратор должен завершить это действие. Удалённый аккаунт нельзя восстановить или обжаловать здесь.",
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{data.account.account_status === "banned" && !current && (
|
||||
<form
|
||||
className={styles.confirm}
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void run(async () => {
|
||||
await api("ban/appeal", { reason });
|
||||
setReason("");
|
||||
setMessage(
|
||||
l(
|
||||
"Appeal sent. A Moderator or Admin will review it.",
|
||||
"Апелляция отправлена. Её рассмотрит модератор или администратор.",
|
||||
),
|
||||
);
|
||||
await reload();
|
||||
});
|
||||
}}
|
||||
>
|
||||
<h2>{l("Appeal this ban", "Обжаловать блокировку")}</h2>
|
||||
<p>
|
||||
{l(
|
||||
"Explain what happened and why the ban should be reconsidered. You can submit one appeal for each ban. Staff will leave their decision here.",
|
||||
"Расскажите, что произошло и почему блокировку стоит пересмотреть. Для каждой блокировки можно подать одну апелляцию. Решение команды появится здесь.",
|
||||
)}
|
||||
</p>
|
||||
<label className="field">
|
||||
{l(
|
||||
"Your explanation (10–2000 characters)",
|
||||
"Ваше объяснение (10–2000 символов)",
|
||||
)}
|
||||
<textarea
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={2000}
|
||||
rows={6}
|
||||
disabled={busy}
|
||||
value={reason}
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
className="button primary"
|
||||
disabled={busy || reason.trim().length < 10}
|
||||
>
|
||||
{busy
|
||||
? l("Sending…", "Отправка…")
|
||||
: l("Send appeal", "Отправить апелляцию")}
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
{data.appeals.length > 0 && (
|
||||
<div className={styles.list}>
|
||||
<h2>{l("Your appeals", "Ваши апелляции")}</h2>
|
||||
{data.appeals.map((appeal) => (
|
||||
<article className={styles.record} key={appeal.id}>
|
||||
<span className="badge">
|
||||
{appeal.state === "open"
|
||||
? l("Awaiting review", "Ожидает рассмотрения")
|
||||
: appeal.state === "approved"
|
||||
? l("Approved", "Одобрена")
|
||||
: l("Rejected", "Отклонена")}
|
||||
</span>
|
||||
<p className="muted">
|
||||
{new Date(appeal.created_at).toLocaleString(locale)}
|
||||
</p>
|
||||
<p className={styles.reason}>{appeal.reason}</p>
|
||||
{appeal.review_reason && (
|
||||
<>
|
||||
<strong>{l("Staff decision", "Решение команды")}</strong>
|
||||
<p className={styles.reason}>{appeal.review_reason}</p>
|
||||
</>
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
418
components/AccountControls.tsx
Normal file
418
components/AccountControls.tsx
Normal file
@@ -0,0 +1,418 @@
|
||||
"use client";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { ShieldCheck, Users, RefreshCw } from "lucide-react";
|
||||
import { api } from "@/lib/client-api";
|
||||
import { useI18n } from "./I18nProvider";
|
||||
import type {
|
||||
ManagedAccount,
|
||||
AccountAppealRecord,
|
||||
} from "@/shared/account-controls";
|
||||
import styles from "@/app/ban/appeal/page.module.css";
|
||||
|
||||
export function AccountControls({
|
||||
administrator,
|
||||
showAppeals = true,
|
||||
}: {
|
||||
administrator: boolean;
|
||||
showAppeals?: boolean;
|
||||
}) {
|
||||
const { locale } = useI18n();
|
||||
const l = (en: string, ru: string) => (locale === "ru" ? ru : en);
|
||||
const [query, setQuery] = useState("");
|
||||
const [users, setUsers] = useState<ManagedAccount[]>([]);
|
||||
const [viewer, setViewer] = useState("");
|
||||
const [searched, setSearched] = useState(false);
|
||||
const [appeals, setAppeals] = useState<AccountAppealRecord[]>([]);
|
||||
const [loading, setLoading] = useState(showAppeals);
|
||||
const [error, setError] = useState("");
|
||||
const [message, setMessage] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const lock = useRef(false);
|
||||
const [selected, setSelected] = useState<{
|
||||
account: ManagedAccount;
|
||||
action: "deactivate" | "ban" | "restore" | "delete";
|
||||
} | null>(null);
|
||||
const [reason, setReason] = useState("");
|
||||
const [confirmation, setConfirmation] = useState("");
|
||||
const [reviewReasons, setReviewReasons] = useState<Record<string, string>>(
|
||||
{},
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!showAppeals) return;
|
||||
let active = true;
|
||||
api<{ appeals: AccountAppealRecord[] }>("moderation/account-appeals")
|
||||
.then((data) => {
|
||||
if (active) setAppeals(data.appeals);
|
||||
})
|
||||
.catch((e) => {
|
||||
if (active) setError((e as Error).message);
|
||||
})
|
||||
.finally(() => {
|
||||
if (active) setLoading(false);
|
||||
});
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [showAppeals]);
|
||||
async function run(operation: () => Promise<void>) {
|
||||
if (lock.current) return;
|
||||
lock.current = true;
|
||||
setBusy(true);
|
||||
setError("");
|
||||
setMessage("");
|
||||
try {
|
||||
await operation();
|
||||
} catch (e) {
|
||||
setError((e as Error).message);
|
||||
} finally {
|
||||
lock.current = false;
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
async function find() {
|
||||
const result = await api<{ users: ManagedAccount[]; viewerId: string }>(
|
||||
"moderation/accounts?q=" + encodeURIComponent(query),
|
||||
);
|
||||
setUsers(result.users);
|
||||
setViewer(result.viewerId);
|
||||
setSearched(true);
|
||||
}
|
||||
async function refreshAppeals() {
|
||||
if (!showAppeals) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
setAppeals(
|
||||
(
|
||||
await api<{ appeals: AccountAppealRecord[] }>(
|
||||
"moderation/account-appeals",
|
||||
)
|
||||
).appeals,
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
async function save(event: React.FormEvent) {
|
||||
event.preventDefault();
|
||||
if (!selected) return;
|
||||
const chosen = selected;
|
||||
await run(async () => {
|
||||
await api("moderation/accounts/" + chosen.account.id, {
|
||||
action: chosen.action,
|
||||
reason,
|
||||
...(chosen.action === "delete" ? { confirmation } : {}),
|
||||
});
|
||||
setSelected(null);
|
||||
setReason("");
|
||||
setConfirmation("");
|
||||
await find();
|
||||
await refreshAppeals();
|
||||
setMessage(
|
||||
l("Account action completed.", "Действие с аккаунтом выполнено."),
|
||||
);
|
||||
});
|
||||
}
|
||||
const stateLabel = (status: string) =>
|
||||
({
|
||||
active: l("Active", "Активен"),
|
||||
deactivated: l("Deactivated", "Деактивирован"),
|
||||
banned: l("Banned", "Заблокирован"),
|
||||
deleting: l("Deletion pending", "Ожидает удаления"),
|
||||
})[status] ?? status;
|
||||
const actionLabel = (action: string) =>
|
||||
({
|
||||
deactivate: l("Deactivate", "Деактивировать"),
|
||||
ban: l("Ban", "Заблокировать"),
|
||||
restore: l("Restore access", "Восстановить доступ"),
|
||||
delete: l("Delete permanently", "Удалить навсегда"),
|
||||
})[action] ?? action;
|
||||
return (
|
||||
<>
|
||||
{error && (
|
||||
<p className="error-message" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{message && (
|
||||
<p className="muted" role="status">
|
||||
{message}
|
||||
</p>
|
||||
)}
|
||||
{administrator && (
|
||||
<section className="tool-card" aria-labelledby="account-controls-title">
|
||||
<div className={styles.heading}>
|
||||
<Users size={24} aria-hidden="true" />
|
||||
<h2 id="account-controls-title">
|
||||
{l("Account management", "Управление аккаунтами")}
|
||||
</h2>
|
||||
</div>
|
||||
<p>
|
||||
{l(
|
||||
"Deactivate access temporarily, ban with a reason, restore access, or permanently delete an account. Admin accounts are protected.",
|
||||
"Временно отключайте доступ, блокируйте с указанием причины, восстанавливайте доступ или удаляйте аккаунты навсегда. Аккаунты администраторов защищены.",
|
||||
)}
|
||||
</p>
|
||||
<form
|
||||
className={styles.search}
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void run(find);
|
||||
}}
|
||||
>
|
||||
<label className="field">
|
||||
{l("Player name or account ID", "Имя игрока или ID аккаунта")}
|
||||
<input
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
maxLength={80}
|
||||
disabled={busy}
|
||||
/>
|
||||
</label>
|
||||
<button className="button" disabled={busy}>
|
||||
{l("Find accounts", "Найти аккаунты")}
|
||||
</button>
|
||||
</form>
|
||||
{searched && users.length === 0 && (
|
||||
<p>{l("No accounts found.", "Аккаунты не найдены.")}</p>
|
||||
)}
|
||||
<div className={styles.list}>
|
||||
{users.map((account) => (
|
||||
<article className={styles.record} key={account.id}>
|
||||
<div className={styles.heading}>
|
||||
<h3>{account.display_name}</h3>
|
||||
<span className="badge">
|
||||
{stateLabel(account.account_status)}
|
||||
</span>
|
||||
</div>
|
||||
<p>
|
||||
<code>{account.id}</code> · {account.role}
|
||||
</p>
|
||||
{account.account_reason && <p>{account.account_reason}</p>}
|
||||
{account.role === "admin" || account.id === viewer ? (
|
||||
<p className="muted">
|
||||
{l("This account is protected.", "Этот аккаунт защищён.")}
|
||||
</p>
|
||||
) : (
|
||||
<div className={styles.actions}>
|
||||
{(["deactivate", "ban", "restore", "delete"] as const).map(
|
||||
(action) => (
|
||||
<button
|
||||
className="button"
|
||||
type="button"
|
||||
key={action}
|
||||
disabled={
|
||||
busy ||
|
||||
(action === "restore" &&
|
||||
["active", "deleting"].includes(
|
||||
account.account_status,
|
||||
)) ||
|
||||
(action === "deactivate" &&
|
||||
account.account_status !== "active") ||
|
||||
(action === "ban" &&
|
||||
["banned", "deleting"].includes(
|
||||
account.account_status,
|
||||
))
|
||||
}
|
||||
onClick={() => {
|
||||
setSelected({ account, action });
|
||||
setReason("");
|
||||
setConfirmation("");
|
||||
setMessage("");
|
||||
}}
|
||||
>
|
||||
{actionLabel(action)}
|
||||
</button>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{selected?.account.id === account.id && (
|
||||
<form
|
||||
className={styles.confirm}
|
||||
onSubmit={(e) => void save(e)}
|
||||
>
|
||||
<h3>
|
||||
{actionLabel(selected.action)}: {account.display_name}
|
||||
</h3>
|
||||
<p>
|
||||
{selected.action === "delete"
|
||||
? l(
|
||||
"Permanent deletion removes sign-in, profile, credentials and account appeals. Shared maps and community history remain without an account owner. This cannot be undone.",
|
||||
"Удаление навсегда убирает вход, профиль, ключи и апелляции аккаунта. Общие карты и история сообщества сохраняются без владельца аккаунта. Отменить удаление нельзя.",
|
||||
)
|
||||
: l(
|
||||
"The player will see your reason. Restricting access revokes existing keys and ends existing games and multiplayer participation.",
|
||||
"Игрок увидит указанную причину. Ограничение доступа отзывает ключи и завершает текущие игры и участие в мультиплеере.",
|
||||
)}
|
||||
</p>
|
||||
<label className="field">
|
||||
{l(
|
||||
"Reason (10–2000 characters)",
|
||||
"Причина (10–2000 символов)",
|
||||
)}
|
||||
<textarea
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={2000}
|
||||
rows={3}
|
||||
value={reason}
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
disabled={busy}
|
||||
/>
|
||||
</label>
|
||||
{selected.action === "delete" && (
|
||||
<label className="field">
|
||||
{l(
|
||||
"Type the account ID to confirm",
|
||||
"Введите ID аккаунта для подтверждения",
|
||||
)}
|
||||
<input
|
||||
required
|
||||
value={confirmation}
|
||||
onChange={(e) => setConfirmation(e.target.value)}
|
||||
autoComplete="off"
|
||||
disabled={busy}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
<div className={styles.actions}>
|
||||
<button
|
||||
className="button primary"
|
||||
disabled={
|
||||
busy ||
|
||||
reason.trim().length < 10 ||
|
||||
(selected.action === "delete" &&
|
||||
confirmation !== account.id)
|
||||
}
|
||||
>
|
||||
{busy
|
||||
? l("Working…", "Подождите…")
|
||||
: l("Confirm action", "Подтвердить действие")}
|
||||
</button>
|
||||
<button
|
||||
className="button"
|
||||
type="button"
|
||||
disabled={busy}
|
||||
onClick={() => setSelected(null)}
|
||||
>
|
||||
{l("Cancel", "Отмена")}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
{showAppeals && (
|
||||
<section className="tool-card" aria-labelledby="account-appeals-title">
|
||||
<div className={styles.heading}>
|
||||
<ShieldCheck size={24} aria-hidden="true" />
|
||||
<h2 id="account-appeals-title">
|
||||
{l("Account ban appeals", "Апелляции блокировок аккаунтов")}
|
||||
</h2>
|
||||
</div>
|
||||
<p>
|
||||
{l(
|
||||
"Moderators and Admins can review appeals. Approving an appeal restores access for that ban. Deactivation and deletion remain Admin controls.",
|
||||
"Модераторы и администраторы могут рассматривать апелляции. Одобрение восстанавливает доступ после этой блокировки. Деактивация и удаление доступны только администраторам.",
|
||||
)}
|
||||
</p>
|
||||
<button
|
||||
className="button"
|
||||
disabled={busy || loading}
|
||||
onClick={() => void run(refreshAppeals)}
|
||||
>
|
||||
<RefreshCw size={16} aria-hidden="true" />
|
||||
{l("Refresh appeals", "Обновить апелляции")}
|
||||
</button>
|
||||
{loading && (
|
||||
<p role="status">{l("Loading appeals…", "Загрузка апелляций…")}</p>
|
||||
)}
|
||||
{!loading && !error && appeals.length === 0 && (
|
||||
<p>
|
||||
{l(
|
||||
"No appeals awaiting review.",
|
||||
"Нет апелляций, ожидающих рассмотрения.",
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
<div className={styles.list}>
|
||||
{appeals.map((appeal) => (
|
||||
<article className={styles.record} key={appeal.id}>
|
||||
<h3>{appeal.display_name}</h3>
|
||||
<p className="muted">
|
||||
<code>{appeal.owner_id}</code> ·{" "}
|
||||
{new Date(appeal.created_at).toLocaleString(locale)}
|
||||
</p>
|
||||
{appeal.ban_reason && (
|
||||
<p>
|
||||
<strong>{l("Ban reason: ", "Причина блокировки: ")}</strong>
|
||||
{appeal.ban_reason}
|
||||
</p>
|
||||
)}
|
||||
<p className={styles.reason}>{appeal.reason}</p>
|
||||
<label className="field">
|
||||
{l(
|
||||
"Decision reason (10–2000 characters)",
|
||||
"Причина решения (10–2000 символов)",
|
||||
)}
|
||||
<textarea
|
||||
minLength={10}
|
||||
maxLength={2000}
|
||||
rows={3}
|
||||
value={reviewReasons[appeal.id] ?? ""}
|
||||
onChange={(e) =>
|
||||
setReviewReasons((current) => ({
|
||||
...current,
|
||||
[appeal.id]: e.target.value,
|
||||
}))
|
||||
}
|
||||
disabled={busy}
|
||||
/>
|
||||
</label>
|
||||
<div className={styles.actions}>
|
||||
{(["approve", "reject"] as const).map((decision) => (
|
||||
<button
|
||||
className="button"
|
||||
key={decision}
|
||||
disabled={
|
||||
busy ||
|
||||
(reviewReasons[appeal.id] ?? "").trim().length < 10
|
||||
}
|
||||
onClick={() =>
|
||||
void run(async () => {
|
||||
await api("moderation/account-appeals/" + appeal.id, {
|
||||
decision,
|
||||
reason: reviewReasons[appeal.id],
|
||||
});
|
||||
await refreshAppeals();
|
||||
if (administrator && searched) await find();
|
||||
setMessage(
|
||||
l("Appeal reviewed.", "Апелляция рассмотрена."),
|
||||
);
|
||||
})
|
||||
}
|
||||
>
|
||||
{decision === "approve"
|
||||
? l(
|
||||
"Approve · restore access",
|
||||
"Одобрить · восстановить доступ",
|
||||
)
|
||||
: l(
|
||||
"Reject · keep ban",
|
||||
"Отклонить · оставить блокировку",
|
||||
)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import { ModeratorSettings } from "./ModeratorSettings";
|
||||
import { ModeratorPrefixes } from "./ModeratorPrefixes";
|
||||
import { isAdministrator, type StaffRole } from "@/shared/permissions";
|
||||
import { DiscordIntegration } from "./DiscordIntegration";
|
||||
import { AccountControls } from "./AccountControls";
|
||||
import { PrometheusIntegration } from "./PrometheusIntegration";
|
||||
type ReviewMap = {
|
||||
id: string;
|
||||
@@ -26,7 +27,11 @@ type ReviewMap = {
|
||||
report_strikes: number;
|
||||
banned_at: string | null;
|
||||
};
|
||||
export function Moderation() {
|
||||
export function Moderation({
|
||||
mode = "moderation",
|
||||
}: {
|
||||
mode?: "moderation" | "admin";
|
||||
}) {
|
||||
const { t, locale } = useI18n();
|
||||
const [maps, setMaps] = useState<ReviewMap[]>([]),
|
||||
[reports, setReports] = useState<
|
||||
@@ -49,7 +54,7 @@ export function Moderation() {
|
||||
const [preview, setPreview] = useState<string | null>(null),
|
||||
[loading, setLoading] = useState(true);
|
||||
const [role, setRole] = useState<StaffRole | null>(null);
|
||||
const administrator = isAdministrator(role ?? undefined);
|
||||
const administrator = mode === "admin" && isAdministrator(role ?? undefined);
|
||||
const [reportPreview, setReportPreview] = useState<{
|
||||
id: string;
|
||||
panorama: string | null;
|
||||
@@ -61,7 +66,7 @@ export function Moderation() {
|
||||
maps: ReviewMap[];
|
||||
reports: typeof reports;
|
||||
appeals: Appeal[];
|
||||
}>("moderation");
|
||||
}>(mode === "admin" ? "moderation?view=admin" : "moderation");
|
||||
setMaps(d.maps);
|
||||
setRole(d.role);
|
||||
setReports(d.reports);
|
||||
@@ -103,7 +108,7 @@ export function Moderation() {
|
||||
}
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
}, [mode]);
|
||||
async function decide(datasetId: string, decision: string) {
|
||||
setBusy(true);
|
||||
setError("");
|
||||
@@ -122,6 +127,12 @@ export function Moderation() {
|
||||
}
|
||||
return (
|
||||
<>
|
||||
{role && (
|
||||
<AccountControls
|
||||
administrator={administrator}
|
||||
showAppeals={mode === "moderation"}
|
||||
/>
|
||||
)}
|
||||
{administrator && <ModeratorSettings />}
|
||||
{administrator && <ModeratorPrefixes />}
|
||||
{administrator && <DiscordIntegration />}
|
||||
@@ -129,7 +140,7 @@ export function Moderation() {
|
||||
{role === "moderator" && (
|
||||
<p className="muted">
|
||||
{t(
|
||||
"Moderators can inspect and review pending maps and updates. Other controls require Admin permission.",
|
||||
"Moderators can review pending maps, updates and account ban appeals. Other controls require Admin permission.",
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
@@ -142,78 +153,81 @@ export function Moderation() {
|
||||
{!loading && !maps.length && !error && (
|
||||
<p className="muted">{t("The review queue is clear.")}</p>
|
||||
)}
|
||||
{maps.map((m) => (
|
||||
<article className="tool-card" key={m.id}>
|
||||
<span className="badge">{t(statusMessage(m.state))}</span>
|
||||
{m.update_state === "review" && (
|
||||
<span className="badge">{t("Map update awaiting review")}</span>
|
||||
)}
|
||||
<h2>{m.name}</h2>
|
||||
{m.report_strikes > 0 && (
|
||||
<p className={m.banned_at ? "error-message" : "muted"}>
|
||||
{m.report_strikes}
|
||||
{t("/3 confirmed reports")}
|
||||
{m.banned_at ? t(" · Banned; owner appeal required") : ""}
|
||||
{maps
|
||||
.filter((m) => mode !== "admin" || m.state !== "review")
|
||||
.map((m) => (
|
||||
<article className="tool-card" key={m.id}>
|
||||
<span className="badge">{t(statusMessage(m.state))}</span>
|
||||
{m.update_state === "review" && (
|
||||
<span className="badge">{t("Map update awaiting review")}</span>
|
||||
)}
|
||||
<h2>{m.name}</h2>
|
||||
{m.report_strikes > 0 && (
|
||||
<p className={m.banned_at ? "error-message" : "muted"}>
|
||||
{m.report_strikes}
|
||||
{t("/3 confirmed reports")}
|
||||
{m.banned_at ? t(" · Banned; owner appeal required") : ""}
|
||||
</p>
|
||||
)}
|
||||
<p className="muted">
|
||||
{m.source} · {m.panorama_count} {t("locations ·")} {m.description}
|
||||
</p>
|
||||
)}
|
||||
<p className="muted">
|
||||
{m.source} · {m.panorama_count} {t("locations ·")} {m.description}
|
||||
</p>
|
||||
{m.map && (
|
||||
<Image
|
||||
src={m.map}
|
||||
width={512}
|
||||
height={512}
|
||||
alt={t("Map for moderator review")}
|
||||
unoptimized
|
||||
style={{ maxWidth: "100%", height: "auto" }}
|
||||
/>
|
||||
)}
|
||||
<label className="field">
|
||||
{t("Review reason")}
|
||||
<textarea
|
||||
value={reasons[m.id] || ""}
|
||||
onChange={(e) =>
|
||||
setReasons((s) => ({ ...s, [m.id]: e.target.value }))
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<div className="inline-actions">
|
||||
<button className="button" onClick={() => setPreview(m.id)}>
|
||||
{t("Inspect 360° locations")}
|
||||
</button>
|
||||
{m.state === "review" || m.update_state === "review" ? (
|
||||
<>
|
||||
<button
|
||||
className="button primary"
|
||||
disabled={busy}
|
||||
onClick={() => decide(m.id, "approve")}
|
||||
>
|
||||
{m.update_state === "review"
|
||||
? t("Approve update")
|
||||
: t("Approve map")}
|
||||
</button>
|
||||
{m.map && (
|
||||
<Image
|
||||
src={m.map}
|
||||
width={512}
|
||||
height={512}
|
||||
alt={t("Map for moderator review")}
|
||||
unoptimized
|
||||
style={{ maxWidth: "100%", height: "auto" }}
|
||||
/>
|
||||
)}
|
||||
<label className="field">
|
||||
{t("Review reason")}
|
||||
<textarea
|
||||
value={reasons[m.id] || ""}
|
||||
onChange={(e) =>
|
||||
setReasons((s) => ({ ...s, [m.id]: e.target.value }))
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<div className="inline-actions">
|
||||
<button className="button" onClick={() => setPreview(m.id)}>
|
||||
{t("Inspect 360° locations")}
|
||||
</button>
|
||||
{mode === "moderation" &&
|
||||
(m.state === "review" || m.update_state === "review") ? (
|
||||
<>
|
||||
<button
|
||||
className="button primary"
|
||||
disabled={busy}
|
||||
onClick={() => decide(m.id, "approve")}
|
||||
>
|
||||
{m.update_state === "review"
|
||||
? t("Approve update")
|
||||
: t("Approve map")}
|
||||
</button>
|
||||
<button
|
||||
className="button"
|
||||
disabled={busy || !reasons[m.id]?.trim()}
|
||||
onClick={() => decide(m.id, "reject")}
|
||||
>
|
||||
{t("Return with feedback")}
|
||||
</button>
|
||||
</>
|
||||
) : null}
|
||||
{administrator && m.state === "published" && (
|
||||
<button
|
||||
className="button"
|
||||
disabled={busy || !reasons[m.id]?.trim()}
|
||||
onClick={() => decide(m.id, "reject")}
|
||||
disabled={busy}
|
||||
onClick={() => decide(m.id, "unpublish")}
|
||||
>
|
||||
{t("Return with feedback")}
|
||||
{t("Unpublish")}
|
||||
</button>
|
||||
</>
|
||||
) : null}
|
||||
{administrator && m.state === "published" && (
|
||||
<button
|
||||
className="button"
|
||||
disabled={busy}
|
||||
onClick={() => decide(m.id, "unpublish")}
|
||||
>
|
||||
{t("Unpublish")}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
)}
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
{administrator && reports.length > 0 && (
|
||||
<section className="token-box">
|
||||
<h2>{t("Community reports")}</h2>
|
||||
|
||||
@@ -3,7 +3,8 @@ import "server-only";
|
||||
import Link from "next/link";
|
||||
import { Compass, ArrowUpRight } from "lucide-react";
|
||||
import { LanguageSwitcher } from "./LanguageSwitcher";
|
||||
import { user } from "@/lib/supabase";
|
||||
import { rawUser, admin, required } from "@/lib/supabase";
|
||||
import { canReviewMaps, isAdministrator } from "@/shared/permissions";
|
||||
import { Brand } from "./Brand";
|
||||
import { SiteNav } from "./SiteNav";
|
||||
import { ReportBugButton } from "./ReportBugButton";
|
||||
@@ -12,7 +13,7 @@ import { CommunityLinks } from "./CommunityLinks";
|
||||
import { forumUrl } from "@/lib/forum";
|
||||
export async function Header() {
|
||||
const { t } = await getI18n();
|
||||
const account = await user();
|
||||
const account = await rawUser();
|
||||
return (
|
||||
<header className="site-header">
|
||||
<div className="header-inner">
|
||||
@@ -35,6 +36,17 @@ export async function Header() {
|
||||
export async function Footer() {
|
||||
const { t } = await getI18n();
|
||||
const forum = forumUrl();
|
||||
const account = await rawUser();
|
||||
const result = account
|
||||
? await admin()
|
||||
.from("profiles")
|
||||
.select("role,account_status")
|
||||
.eq("id", account.id)
|
||||
.maybeSingle()
|
||||
: null;
|
||||
if (result?.error) required(result);
|
||||
const role =
|
||||
result?.data?.account_status === "active" ? result.data.role : undefined;
|
||||
return (
|
||||
<footer className="site-footer">
|
||||
<div>
|
||||
@@ -60,7 +72,10 @@ export async function Footer() {
|
||||
{t("Status")}
|
||||
</a>
|
||||
<Link href="/leaderboard">{t("Leaderboard")}</Link>
|
||||
<Link href="/moderation">{t("Moderation")}</Link>
|
||||
{canReviewMaps(role) && (
|
||||
<Link href="/moderation">{t("Moderation Tools")}</Link>
|
||||
)}
|
||||
{isAdministrator(role) && <Link href="/admin">{t("Admin Tools")}</Link>}
|
||||
</div>
|
||||
<p className="disclaimer">
|
||||
{t(
|
||||
|
||||
Reference in New Issue
Block a user