fix(cms): resolve admin dogfood findings on auth, content editing, and UX
修复 CMS / Admin 后台 dogfood 专项测试发现的阻塞性与体验性问题: - 登录后无限重定向(Secure Cookie + Edge Runtime JWT 兼容) - 内容新增/编辑保存 400/500(默认不加密请求体、自动生成唯一 slug) - 编辑时提交 status 导致验证错误 - 原生 confirm 阻塞自动化测试,改为 AlertDialog - 表单字段可访问性(id/htmlFor/fieldset) - JSON 数组标签字段新增 TagInput 组件 - 操作反馈统一使用 Sonner Toast - 后台隐藏营销 Cookie 横幅 - 媒体库空状态优化 添加 dogfood-cms-regression 与 dogfood-cms-output 报告、截图及工作流路由测试。
This commit is contained in:
1 parent
f6f5766bb9
commit
d9c0e5f2c1
48 files changed
+1445
-106
No files matched your search
@@ -0,0 +1,93 @@
|
||||
import { NextRequest } from 'next/server';
|
||||
import { prisma } from '@/lib/db';
|
||||
import { requirePermission } from '@/lib/permissions';
|
||||
import {
|
||||
submitForReview,
|
||||
approve,
|
||||
reject,
|
||||
archive,
|
||||
type WorkflowAction,
|
||||
} from '@/lib/cms/workflow';
|
||||
import {
|
||||
success,
|
||||
notFound,
|
||||
validationError,
|
||||
internalError,
|
||||
forbidden,
|
||||
} from '@/lib/api-response';
|
||||
|
||||
function parseItem(item: { data: string; [key: string]: unknown }) {
|
||||
return { ...item, data: JSON.parse(item.data as string) };
|
||||
}
|
||||
|
||||
interface WorkflowBody {
|
||||
action: WorkflowAction;
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
const ACTION_PERMISSION: Record<WorkflowAction, 'update' | 'publish'> = {
|
||||
submit: 'update',
|
||||
approve: 'publish',
|
||||
reject: 'publish',
|
||||
archive: 'publish',
|
||||
};
|
||||
|
||||
export async function POST(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const { id } = await params;
|
||||
|
||||
try {
|
||||
const body = (await request.json()) as WorkflowBody;
|
||||
const { action, reason } = body;
|
||||
|
||||
if (!action) {
|
||||
return validationError('缺少 action 参数');
|
||||
}
|
||||
|
||||
if (!['submit', 'approve', 'reject', 'archive'].includes(action)) {
|
||||
return validationError(`非法的 action: ${action}`);
|
||||
}
|
||||
|
||||
const existing = await prisma.contentItem.findUnique({ where: { id } });
|
||||
if (!existing) return notFound('内容不存在');
|
||||
|
||||
const requiredAction = ACTION_PERMISSION[action];
|
||||
const permission = await requirePermission(request, existing.modelCode, requiredAction);
|
||||
if ('response' in permission) return permission.response;
|
||||
|
||||
const user = { userId: permission.user.userId, username: permission.user.username };
|
||||
|
||||
switch (action) {
|
||||
case 'submit':
|
||||
await submitForReview(id, user);
|
||||
break;
|
||||
case 'approve':
|
||||
await approve(id, user);
|
||||
break;
|
||||
case 'reject':
|
||||
await reject(id, user, reason);
|
||||
break;
|
||||
case 'archive':
|
||||
await archive(id, user);
|
||||
break;
|
||||
}
|
||||
|
||||
return success(parseItem(await prisma.contentItem.findUniqueOrThrow({ where: { id } })));
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
if (error.message.includes('内容不存在')) {
|
||||
return notFound(error.message);
|
||||
}
|
||||
if (error.message.includes('当前状态') || error.message.includes('不允许')) {
|
||||
return validationError(error.message);
|
||||
}
|
||||
if (error.message.includes('无权限')) {
|
||||
return forbidden(error.message);
|
||||
}
|
||||
}
|
||||
console.error('Workflow error:', error);
|
||||
return internalError();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user