Wiki pages gain a Draft flag pinned to their original creator. A draft is visible only to its creator, wiki moderators and admins: the collection's read access returns a where clause so the REST/local API filters drafts, and every frontend query ANDs the same clause (they run with overrideAccess). Publishing is one-way. A page whose stored draft is false is rejected (403) when sent draft: true, both in the service and in access.update. UI: amber DraftBanner on the detail page, a Draft chip in WikiRow, and a Draft switch in the editor that disables once the page is published.
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import { Suspense } from "react";
|
|
import config from "@payload-config";
|
|
import { headers as nextHeaders } from "next/headers";
|
|
import { getPayload } from "payload";
|
|
import { BookOpenIcon } from "lucide-react";
|
|
import { WikiIndex } from "@/components/frontend/wiki/WikiIndex";
|
|
import { mapWikiPageToEntry } from "@/lib/wiki/indexView";
|
|
import { canViewAllDrafts, draftVisibilityWhere } from "@/lib/wiki/service";
|
|
import { hasIntelligenceQualification } from "@/utils/access-control/hasIntelligenceQualification";
|
|
|
|
export const metadata = {
|
|
title: "Wiki: Polaris Task Force",
|
|
};
|
|
|
|
export default async function WikiPage() {
|
|
const headers = await nextHeaders();
|
|
const payload = await getPayload({ config });
|
|
const { user } = await payload.auth({
|
|
headers,
|
|
canSetHeaders: false,
|
|
});
|
|
|
|
const canViewAll = await canViewAllDrafts(payload, user);
|
|
const where = draftVisibilityWhere(user, canViewAll);
|
|
const [pagesResult, isModerator] = await Promise.all([
|
|
payload.find({
|
|
collection: "wiki-pages",
|
|
where: where ?? {},
|
|
sort: "-updatedAt",
|
|
limit: 200,
|
|
depth: 1,
|
|
overrideAccess: true,
|
|
}),
|
|
hasIntelligenceQualification(payload, user),
|
|
]);
|
|
|
|
const pages = pagesResult.docs.map(mapWikiPageToEntry);
|
|
|
|
return (
|
|
<div className="flex flex-col gap-6 p-5">
|
|
<div className="flex flex-col gap-1">
|
|
<div className="flex items-center gap-2">
|
|
<BookOpenIcon className="size-5 text-muted-foreground" />
|
|
<h1 className="text-lg font-semibold">Wiki</h1>
|
|
</div>
|
|
<p className="text-sm text-muted-foreground">
|
|
A shared field guide for campaigns, characters, places, and the stories around them.
|
|
</p>
|
|
</div>
|
|
|
|
<Suspense>
|
|
<WikiIndex pages={pages} isModerator={isModerator} />
|
|
</Suspense>
|
|
</div>
|
|
);
|
|
}
|