yap-blog/src/app/admin/(panel)/posts/new/page.tsx
matt 35fb33c5a7 Add granular author permissions, admin-tag persistence, own-password change
Each author account now carries five grantable permissions, editable on
the Users page: publish posts, unpublish posts, delete posts (all three
scoped to the author's own posts), create tags, and approve comments
(scoped to comments on the author's posts, without delete). A bare
author writes and edits their own drafts only. Permission checks gate
the status TRANSITION, so editing an already-published post never
requires the publish permission, and the editor's status dropdown only
offers what the account may do. Tags an author creates are granted to
them automatically, and "creating" an existing off-grant tag is
refused (it would be a self-grant loophole). Existing author accounts
keep publish+unpublish via migration backfill.

Tags the admin attaches outside an author's grants now survive the
author's edits: the form shows them checked-and-locked and the server
re-attaches them on every save.

Every account can change its own password on the new /admin/account
page (current password required); the username in the admin header
links there.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-05 12:58:19 -04:00

31 lines
1 KiB
TypeScript

import type { Metadata } from "next";
import { createPostAction } from "@/actions/posts";
import { PostForm } from "@/components/admin/PostForm";
import { requireUser } from "@/lib/auth/dal";
import { listAllTags } from "@/lib/services/tags";
import { getUserWithTags } from "@/lib/services/users";
export const metadata: Metadata = { title: "New post" };
export default async function NewPostPage() {
const user = await requireUser();
const isAdmin = user.role === "admin";
// Authors only ever see (and can only use) their granted tags.
const allTags = isAdmin
? await listAllTags()
: ((await getUserWithTags(user.id))?.tags ?? []);
return (
<div>
<h1 className="mb-6 text-2xl font-bold tracking-tight text-ink-bright">New post</h1>
<PostForm
allTags={allTags}
defaultAuthor={user.username}
canCreateTags={user.permissions.createTags}
statusOptions={user.permissions.publishPosts ? ["draft", "published"] : ["draft"]}
action={createPostAction}
/>
</div>
);
}