Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
3b1c6e2
feat(encyclopedia): define immutable editorial workflow and quality c…
baba-dev Nov 22, 2026
03a33ae
feat(encyclopedia): add isolated additive PostgreSQL editorial schema…
baba-dev Nov 22, 2026
209f503
feat(encyclopedia): secure reviewed publishing gateway and public-onl…
baba-dev Nov 22, 2026
dc5cedc
feat(encyclopedia): add restricted Atlas editorial dashboard and serv…
baba-dev Nov 22, 2026
4c5c271
feat(encyclopedia): polish Atlas Editorial Studio with source review,…
baba-dev Nov 22, 2026
ba86a4d
feat(encyclopedia): add idempotent unreviewed catalogue candidate que…
baba-dev Nov 22, 2026
d73af54
feat(encyclopedia): add public-only search pagination, citation displ…
baba-dev Nov 22, 2026
b030296
feat(encyclopedia): connect reviewed Atlas content to SSR, search, me…
baba-dev Nov 22, 2026
b8aa394
test(encyclopedia): assert private PostgreSQL gates and published-onl…
baba-dev Nov 22, 2026
efb5ff9
merge(main): reconcile receipt migration and reserve encyclopedia 011…
baba-dev Nov 22, 2026
19b5d37
style(encyclopedia): apply pinned Prettier to editor and P2 documenta…
baba-dev Nov 22, 2026
850281e
style(encyclopedia): apply pinned Prettier to admin pages (2/5)
baba-dev Nov 22, 2026
0130b5a
style(encyclopedia): apply pinned Prettier to Atlas public routes (3/5)
baba-dev Nov 22, 2026
2d1f250
style(encyclopedia): apply pinned Prettier to schema and services (4/5)
baba-dev Nov 22, 2026
fe0d848
style(encyclopedia): complete pinned formatting for tests and editori…
baba-dev Nov 22, 2026
c7e24fe
fix(encyclopedia): remove unused editorial type import flagged by ESLint
baba-dev Nov 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/food-encyclopedia/P2-EDITORIAL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# P2 — Food Encyclopedia Editorial Engine

Work package [#367](https://github.com/baba-dev/menuminute/issues/367), based on approved Atlas P1 [#364](https://github.com/baba-dev/menuminute/pull/364).

## Safety-first workflow

Draft -> Submit for review -> Distinct human superadmin approval -> Publish immutable revision. Saving after publication creates a new draft, leaving the old published revision intact. Restoring a previously approved revision is an audited publication. No automatically published AI, OCR or dish-catalogue data. Unverified foods must never be marked allergen-safe. Each publication requires a named reviewer and a separately authenticated publishing action.

## Migration ownership and dependency

- P2 reserves **0118_food_encyclopedia_editorial**. Concurrent Tiffin [PR #366](https://github.com/baba-dev/menuminute/pull/366) contains 0115 and 0116.
- The migration journal and final SHA **must be reconciled after #366** before merging P2. P2 cannot be merged/deployed against a migration history that skips 0115/0116. Do not force-merge around the ledger.
- All P2 SQL is additive; app/worker have no direct table privileges. Existing merchant schemas, orders, checkout and ERP remain untouched. The migration owner installs only reviewed SQL after a verified encrypted off-host backup.
- Reviews use session + active 2FA + one-use step-up via app_private.require_step_up(), with source and actor audit in the same transaction. A reviewer cannot approve their own authored revision.

## Public and advertising

- Published content is a whitelisted JSON projection from a narrow SECURITY DEFINER read gateway; drafts and internal notes cannot be fetched on public endpoints.
- SSR search and sitemap consider only published revisions. Preview-only P1 fixtures remain noindex and never become published without independent review.
- AdSense is disabled. Publication is **not** consent/ads activation.
- A missing migration or read failure never leaks private data or incorrectly flags an unpublished entry as indexed.

## Validation

Use frozen-lockfile install, TypeScript, lint/Prettier, Vitest integration, ARM64 Next compile, Playwright and independent database privilege review. Production releases require v7 helper, schema+media backups, exact-SHA checks, ERP coexistence checks and forward-only migration safety. A green PR is not production deployment.

## P2 implementation update

- Eight logical commits delivered on the PR branch, plus QA corrections as required.
- Real database published pages supersede P1 sample previews. In production, no sample article is indexable or served as a substitute for reviewed content.
- Public pages fail closed on missing migration or empty editorial store. Search excludes unapproved data, ad slots remain inactive.
- The editorial form requires manual explicit Save with step-up; unattended autosave is intentionally not enabled, to avoid bypassing one-use administrator verification.
- A separate independently approved superadmin is necessary to approve an author's submission; never self-approve.
- **Migration dependency**: PR #366 has 0115/0116 but another branch added 0115 receipt UPI to current main. Coordinate migration renumbering and journal sequence before merging P2; no merge/deploy until conflict resolved.
2 changes: 2 additions & 0 deletions src/app/admin/admin-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
SlidersHorizontal,
Lock,
LifeBuoy,
BookOpenText,
ArrowLeft,
} from "lucide-react";

Expand All @@ -33,6 +34,7 @@ const navItems: NavItem[] = [
{ href: "/admin/payments", label: "Payments & Grants", icon: CreditCard },
{ href: "/admin/kitchen", label: "Kitchen Control Desk", icon: ChefHat },
{ href: "/admin/support", label: "Support Desk", icon: LifeBuoy },
{ href: "/admin/encyclopedia", label: "Food Encyclopedia", icon: BookOpenText },
{ href: "/admin/security", label: "Security & Audits", icon: Lock },
];

Expand Down
27 changes: 27 additions & 0 deletions src/app/admin/encyclopedia/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { verifySuperAdmin } from "@/lib/admin-guard";
import { getEditorialDetail } from "@/modules/food-encyclopedia/editorial-service";
import { newEditorialDraft } from "@/modules/food-encyclopedia/editorial-template";
import { EditorialEditor } from "../editor";
export const dynamic = "force-dynamic";
export const metadata: Metadata = {
title: "Edit food guide | Editorial Studio",
robots: { index: false },
};
export default async function FoodEditorialPage({ params }: { params: Promise<{ id: string }> }) {
const actor = await verifySuperAdmin();
const { id } = await params;
const entry = await getEditorialDetail(actor, id);
if (!entry) notFound();
return (
<EditorialEditor
initial={entry.draft ?? newEditorialDraft(entry.kind, entry.slug)}
id={id}
version={entry.version}
status={entry.status}
versions={entry.versions}
publishedRevisionId={entry.publishedRevisionId}
/>
);
}
80 changes: 80 additions & 0 deletions src/app/admin/encyclopedia/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"use server";

import { revalidatePath } from "next/cache";
import { z } from "zod";
import { verifySuperAdmin } from "@/lib/admin-guard";
import { FoodDraftSchema, FoodEditorialActionSchema } from "@/modules/food-encyclopedia/editorial-contracts";
import { runEditorialCommand } from "@/modules/food-encyclopedia/editorial-service";

const requestSchema = z
.object({
action: z.union([FoodEditorialActionSchema, z.literal("media.approve"), z.literal("import")]),
target: z.string().max(100).min(1),
expectedVersion: z.number().int().min(0).optional(),
content: FoodDraftSchema.optional(),
revisionId: z.string().uuid().optional(),
path: z.string().max(240).optional(),
license: z.enum(["owned", "commissioned", "cc0", "cc-by", "licensed"]).optional(),
attribution: z.string().max(240).optional(),
requestKey: z.string().uuid(),
})
.strict();
export type EditorialActionRequest = z.infer<typeof requestSchema>;
export type EditorialActionResponse =
{ ok: true; id: string; status?: string; version?: number } | { ok: false; error: string };

export async function submitEditorialAction(
input: EditorialActionRequest
): Promise<EditorialActionResponse> {
const actor = await verifySuperAdmin();
const parsed = requestSchema.safeParse(input);
if (!parsed.success)
return { ok: false, error: "Invalid editorial fields. Review the form and retry." };
const p = parsed.data;
try {
const receipt = await runEditorialCommand(
actor,
p.action,
p.target,
{
...(p.content ? { content: p.content } : {}),
...(p.expectedVersion !== undefined ? { expectedVersion: p.expectedVersion } : {}),
...(p.revisionId ? { revisionId: p.revisionId } : {}),
...(p.path ? { path: p.path } : {}),
...(p.license ? { license: p.license } : {}),
...(p.attribution !== undefined ? { attribution: p.attribution } : {}),
},
p.requestKey
);
revalidatePath("/admin/encyclopedia");
revalidatePath("/explore");
revalidatePath("/explore/browse");
revalidatePath("/explore/search");
revalidatePath("/sitemap.xml");
if (p.content) revalidatePath("/explore/" + p.content.kind + "/" + p.content.slug);
return { ok: true, id: receipt.id, status: receipt.status, version: receipt.version };
} catch (e) {
const code = (e as { code?: string })?.code;
if (code === "42501")
return {
ok: false,
error:
"Administrator verification or a fresh password/TOTP step-up is required; a different person must approve authored revisions.",
};
if (code === "40001" || code === "23505")
return {
ok: false,
error: "The entry changed or the request key conflicts. Reload before retrying.",
};
if (code === "22023")
return {
ok: false,
error:
"Editorial rules blocked this action. Review source, length, and workflow requirements.",
};
return {
ok: false,
error: "The editorial request could not be completed. No changes were published.",
};
}
}
Loading
Loading