feat: 就地通过评审,并为已过审用户提供默认可关的免审发布

帖/评管理入口可直接通过;站点默认信任已有 published 内容的用户后续直发。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-16 05:37:57 +08:00
parent b0170a99fd
commit f3145b24ff
14 changed files with 330 additions and 40 deletions

View File

@@ -3,8 +3,8 @@
import { useState, useEffect, useRef } from "react";
import { useRouter } from "next/navigation";
import Link from "next/link";
import { Pencil, Trash2, Pin, Star, SlidersHorizontal, ChevronDown, Check } from "lucide-react";
import { apiMe, apiDeletePost, apiTogglePin, apiToggleRecommend, type User } from "@/lib/api";
import { Pencil, Trash2, Pin, Star, SlidersHorizontal, ChevronDown, Check, BadgeCheck } from "lucide-react";
import { apiMe, apiDeletePost, apiTogglePin, apiToggleRecommend, apiAdminApprovePost, type User } from "@/lib/api";
import { canModerateBoard, isAdminOrAbove } from "@/lib/roles";
import { toast } from "@/lib/toast";
import ConfirmDialog from "@/components/ConfirmDialog";
@@ -15,9 +15,18 @@ interface PostActionsProps {
boardId: number;
pinned: number;
recommended: boolean;
/** 帖子审核状态:pending 时对可审者显示「通过评审」 */
status: string;
}
export default function PostActions({ postId, authorId, boardId, pinned, recommended }: PostActionsProps) {
export default function PostActions({
postId,
authorId,
boardId,
pinned,
recommended,
status,
}: PostActionsProps) {
const router = useRouter();
const [user, setUser] = useState<User | null>(null);
const [open, setOpen] = useState(false);
@@ -54,6 +63,7 @@ export default function PostActions({ postId, authorId, boardId, pinned, recomme
// 作者本人或有该板块审核权的管理团队可管理;置顶/加精仅管理员及以上
const canManage = !!user && (user.id === authorId || canModerateBoard(user, boardId));
const isAdmin = !!user && isAdminOrAbove(user.role);
const canApprove = !!user && status === "pending" && canModerateBoard(user, boardId);
const handleDelete = async () => {
setDeleting(true);
@@ -73,6 +83,20 @@ export default function PostActions({ postId, authorId, boardId, pinned, recomme
}
};
const handleApprove = async () => {
setActing(true);
setOpen(false);
try {
await apiAdminApprovePost(Number(postId));
toast("已通过评审", "ok");
router.refresh();
} catch (e) {
toast(e instanceof Error ? e.message : "通过评审失败");
} finally {
setActing(false);
}
};
const handlePin = async () => {
setActing(true);
setOpen(false);
@@ -137,6 +161,21 @@ export default function PostActions({ postId, authorId, boardId, pinned, recomme
boxShadow: "var(--shadow-lg)",
}}
>
{canApprove && (
<>
<button
type="button"
role="menuitem"
onClick={handleApprove}
className={itemCls}
style={{ color: "var(--accent)" }}
>
<BadgeCheck size={14} className="shrink-0" />
<span className="flex-1 text-left">通过评审</span>
</button>
<div style={{ height: 1, background: "var(--line)" }} />
</>
)}
{isAdmin && (
<>
<button