feat(cms): improve catalog, editorial recovery and operations
This commit is contained in:
1 parent
2fead134e6
commit
c389c3893d
122 files changed
+8137
-703
No files matched your search
@@ -6,6 +6,7 @@ import { deleteArticle, updateArticle } from "@/actions/admin-articles";
|
||||
import { ArticleForm } from "@/components/admin/article-form";
|
||||
import Link from "@/components/link";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { articleEditToken } from "@/lib/article-edit-token";
|
||||
import { db, WebsiteArticles } from "@/lib/db";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
|
||||
@@ -62,6 +63,8 @@ export default async function EditArticle({
|
||||
</p>
|
||||
) : null}
|
||||
<ArticleForm
|
||||
articleKey={String(article.id)}
|
||||
baseToken={articleEditToken(article)}
|
||||
action={async (fd) => {
|
||||
"use server";
|
||||
fd.set("id", String(article.id));
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
"use client";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useFormStatus } from "react-dom";
|
||||
import { Button } from "@/components/ui/button";
|
||||
export function ArticleListSubmit() {
|
||||
const { pending } = useFormStatus();
|
||||
const t = useTranslations("pages.admin.articles");
|
||||
return (
|
||||
<Button type="submit" disabled={pending} aria-busy={pending}>
|
||||
{pending ? t("listLoading") : t("listApply")}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
+141
-77
File diff suppressed because it is too large.
Load diff
@@ -10,6 +10,7 @@ import {
|
||||
OnlineUsersWidget,
|
||||
StatusCard,
|
||||
} from "@/components/admin/dashboard";
|
||||
import { OperationsInbox } from "@/components/admin/operations-inbox";
|
||||
import Link from "@/components/link";
|
||||
import { env } from "@/env";
|
||||
import { fetchOpsHealth } from "@/lib/admin/ops-health";
|
||||
@@ -126,6 +127,7 @@ export default async function CommandoCentrum() {
|
||||
</Link>
|
||||
) : null}
|
||||
</div>
|
||||
<OperationsInbox />
|
||||
{/* ── Live status ────────────────────────────────────────── */}
|
||||
<div
|
||||
className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-3.5 mb-6"
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { expect, it, vi } from "vitest";
|
||||
import { beforeEach, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
guard: vi.fn(),
|
||||
resolve: vi.fn(),
|
||||
assign: vi.fn(),
|
||||
audit: vi.fn(),
|
||||
}));
|
||||
vi.mock("@/lib/admin/guard", () => ({ requirePermission: mocks.guard }));
|
||||
vi.mock("@/lib/error-monitor", () => ({
|
||||
ErrorStore: class {
|
||||
resolve = mocks.resolve;
|
||||
assign = mocks.assign;
|
||||
},
|
||||
}));
|
||||
vi.mock("@/lib/permissions", () => ({
|
||||
@@ -17,7 +19,7 @@ vi.mock("@/lib/permissions", () => ({
|
||||
vi.mock("@/lib/services/audit", () => ({ logAudit: mocks.audit }));
|
||||
vi.mock("next/cache", () => ({ revalidatePath: vi.fn() }));
|
||||
|
||||
import { resolveCmsError } from "./actions";
|
||||
import { assignCmsError, resolveCmsError } from "./actions";
|
||||
|
||||
it("requires edit permission before resolving or auditing", async () => {
|
||||
mocks.guard.mockRejectedValue(new Error("denied"));
|
||||
@@ -37,3 +39,33 @@ it("records who resolved the problem", async () => {
|
||||
expect.objectContaining({ userId: 42, action: "cms.error.resolve" }),
|
||||
);
|
||||
});
|
||||
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
it("requires edit permission before assigning", async () => {
|
||||
mocks.guard.mockRejectedValue(new Error("denied"));
|
||||
await expect(assignCmsError(new FormData())).rejects.toThrow("denied");
|
||||
expect(mocks.assign).not.toHaveBeenCalled();
|
||||
});
|
||||
it("assigns only the authenticated staff member, ignoring submitted user IDs", async () => {
|
||||
mocks.guard.mockResolvedValue({ id: 42 });
|
||||
const data = new FormData();
|
||||
data.set("fingerprint", "aabbccddeeff0011");
|
||||
data.set("assignment", "self");
|
||||
data.set("userId", "999");
|
||||
await assignCmsError(data);
|
||||
expect(mocks.guard).toHaveBeenCalledWith("admin.devops.edit");
|
||||
expect(mocks.assign).toHaveBeenCalledWith("aabbccddeeff0011", 42);
|
||||
expect(mocks.audit).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ userId: 42, action: "cms.error.assign" }),
|
||||
);
|
||||
data.set("assignment", "clear");
|
||||
await assignCmsError(data);
|
||||
expect(mocks.assign).toHaveBeenLastCalledWith("aabbccddeeff0011", null);
|
||||
});
|
||||
it("rejects unsupported assignment commands", async () => {
|
||||
mocks.guard.mockResolvedValue({ id: 42 });
|
||||
const data = new FormData();
|
||||
data.set("assignment", "other");
|
||||
await expect(assignCmsError(data)).rejects.toThrow("Invalid assignment");
|
||||
expect(mocks.assign).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -15,3 +15,20 @@ export async function resolveCmsError(data: FormData) {
|
||||
});
|
||||
revalidatePath("/admin/devops/cms-errors");
|
||||
}
|
||||
|
||||
export async function assignCmsError(data: FormData) {
|
||||
const staff = await requirePermission(PERMS.DEVOPS_EDIT);
|
||||
const mode = data.get("assignment");
|
||||
if (mode !== "self" && mode !== "clear")
|
||||
throw new Error("Invalid assignment operation");
|
||||
const fingerprint = String(data.get("fingerprint") ?? "");
|
||||
const userId = mode === "self" ? staff.id : null;
|
||||
await new ErrorStore().assign(fingerprint, userId);
|
||||
await logAudit({
|
||||
userId: staff.id,
|
||||
action: "cms.error.assign",
|
||||
target: "cms-error",
|
||||
after: { fingerprint, assignedUserId: userId },
|
||||
});
|
||||
revalidatePath("/admin/devops/cms-errors");
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,30 @@
|
||||
import { expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ inspect: vi.fn(), access: vi.fn() }));
|
||||
vi.mock("@/lib/permissions", () => ({
|
||||
getAdminContext: async () => ({
|
||||
session: { user: { rank: 1 } },
|
||||
permissions: {},
|
||||
}),
|
||||
canAccess: mocks.access,
|
||||
PERMS: { DEVOPS_VIEW: "devops.view" },
|
||||
}));
|
||||
vi.mock("next/navigation", () => ({
|
||||
redirect: () => {
|
||||
throw Error("redirect");
|
||||
},
|
||||
}));
|
||||
vi.mock("@/lib/admin/installation", () => ({
|
||||
inspectInstallation: mocks.inspect,
|
||||
}));
|
||||
vi.mock("../../commandocentrum/refresh-status", () => ({
|
||||
RefreshStatus: () => null,
|
||||
}));
|
||||
|
||||
import Page from "./page";
|
||||
|
||||
it("rejects unauthorized access before checking database, filesystem or worker", async () => {
|
||||
mocks.access.mockReturnValue(false);
|
||||
await expect(Page()).rejects.toThrow("redirect");
|
||||
expect(mocks.inspect).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { inspectInstallation } from "@/lib/admin/installation";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { RefreshStatus } from "../../commandocentrum/refresh-status";
|
||||
export default async function InstallationPage() {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.DEVOPS_VIEW, session.user.rank))
|
||||
redirect("/admin");
|
||||
const t = await getTranslations("pages.admin.installation");
|
||||
const result = await inspectInstallation();
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
<h1 className="text-2xl font-semibold">{t("title")}</h1>
|
||||
<p>{t("hint")}</p>
|
||||
<p className="text-sm text-[var(--admin-text-muted)]">
|
||||
{t("checked", {
|
||||
time: formatDate(new Date(result.checkedAt), "datetime-seconds"),
|
||||
ms: result.durationMs,
|
||||
})}
|
||||
</p>
|
||||
<RefreshStatus label={t("recheck")} />
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
{result.rows.map((row) => (
|
||||
<section key={row.key} className="admin-card space-y-2 min-w-0">
|
||||
<h2 className="font-semibold">{t(row.key)}</h2>
|
||||
<p
|
||||
className={
|
||||
row.state === "failed"
|
||||
? "text-destructive"
|
||||
: row.state === "ok"
|
||||
? "text-[var(--admin-success)]"
|
||||
: "text-[var(--admin-text-muted)]"
|
||||
}
|
||||
>
|
||||
{t(row.state)}
|
||||
</p>
|
||||
{row.detail ? (
|
||||
<code className="block break-all text-xs">{row.detail}</code>
|
||||
) : null}
|
||||
<p className="text-sm text-[var(--admin-text-muted)]">
|
||||
{t(`${row.key}Hint`)}
|
||||
</p>
|
||||
</section>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -53,12 +53,16 @@ export default async function DevOpsPage() {
|
||||
|
||||
const t = await getTranslations("pages.admin.devops");
|
||||
const data = await getDevOpsData();
|
||||
const installation = await getTranslations("pages.admin.installation");
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<a href="/admin/devops/cms-errors" className="btn btn-outline">
|
||||
{t("cmsErrors")}
|
||||
</a>
|
||||
<Link href="/admin/devops/installation" className="btn btn-outline">
|
||||
{installation("title")}
|
||||
</Link>
|
||||
{/* Status cards */}
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-5">
|
||||
<Card>
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
"use client";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { type FormEvent, useTransition } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
|
||||
const keys = ["actor", "action", "from", "to"] as const;
|
||||
export function AuditFilters() {
|
||||
const t = useTranslations("pages.admin.logs.audit");
|
||||
const params = useSearchParams();
|
||||
const router = useRouter();
|
||||
const [pending, startTransition] = useTransition();
|
||||
function apply(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
const values = new FormData(event.currentTarget);
|
||||
const next = new URLSearchParams(params.toString());
|
||||
for (const key of keys) {
|
||||
const value = String(values.get(key) ?? "").trim();
|
||||
if (value) next.set(key, value);
|
||||
else next.delete(key);
|
||||
}
|
||||
next.set("page", "1");
|
||||
startTransition(() => router.replace(`?${next}`, { scroll: false }));
|
||||
}
|
||||
function clear() {
|
||||
const next = new URLSearchParams(params.toString());
|
||||
for (const key of keys) next.delete(key);
|
||||
next.set("page", "1");
|
||||
startTransition(() => router.replace(`?${next}`, { scroll: false }));
|
||||
}
|
||||
return (
|
||||
<form onSubmit={apply} key={params.toString()} aria-busy={pending}>
|
||||
<fieldset disabled={pending} className="space-y-3 rounded-xl border p-4">
|
||||
<legend className="px-1 text-sm font-medium">
|
||||
{t("filtersTitle")}
|
||||
</legend>
|
||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
||||
{keys.map((key) => (
|
||||
<label
|
||||
htmlFor={`audit-${key}`}
|
||||
key={key}
|
||||
className="space-y-1 text-sm"
|
||||
>
|
||||
<span>{t(`filter${key[0].toUpperCase()}${key.slice(1)}`)}</span>
|
||||
<Input
|
||||
id={`audit-${key}`}
|
||||
name={key}
|
||||
type={key === "from" || key === "to" ? "date" : "text"}
|
||||
maxLength={191}
|
||||
defaultValue={params.get(key) ?? ""}
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">{t("filtersHint")}</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button type="submit" size="sm">
|
||||
{t("applyFilters")}
|
||||
</Button>
|
||||
<Button type="button" variant="outline" size="sm" onClick={clear}>
|
||||
{t("resetFilters")}
|
||||
</Button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -21,7 +21,15 @@ export default async function AuditLogsPage({
|
||||
const sp = new URLSearchParams(params);
|
||||
const { search, perPage, page } = parseListParams(sp);
|
||||
|
||||
const result = await getAuditLogs({ search, page, perPage });
|
||||
const result = await getAuditLogs({
|
||||
search,
|
||||
page,
|
||||
perPage,
|
||||
actor: sp.get("actor") ?? undefined,
|
||||
action: sp.get("action") ?? undefined,
|
||||
from: sp.get("from") ?? undefined,
|
||||
to: sp.get("to") ?? undefined,
|
||||
});
|
||||
|
||||
const pagination = calcPagination(result.total, result.page, result.perPage);
|
||||
|
||||
@@ -32,6 +40,8 @@ export default async function AuditLogsPage({
|
||||
target: r.target,
|
||||
targetId: r.targetId,
|
||||
diff: r.diff,
|
||||
before: r.before,
|
||||
after: r.after,
|
||||
createdAt: r.createdAt,
|
||||
}));
|
||||
|
||||
|
||||
Reference in new issue
Block a user