feat: 帖子分级置顶(板块/全站)与板块管理员置顶权限、消息管理权限调整
This commit is contained in:
42
frontend/app/admin/pinned/page.tsx
Normal file
42
frontend/app/admin/pinned/page.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { Metadata } from "next";
|
||||
import { cookies } from "next/headers";
|
||||
import { authCookieHeader } from "@/lib/cookies";
|
||||
import { fetchBoards, type BoardWithCount } from "@/lib/api";
|
||||
import { getMeCached } from "@/lib/serverData";
|
||||
import { canModerateAny, isAdminOrAbove } from "@/lib/roles";
|
||||
import Forbidden from "../Forbidden";
|
||||
import PinnedAdmin from "./PinnedAdmin";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "置顶管理",
|
||||
};
|
||||
|
||||
export default async function AdminPinnedPage() {
|
||||
const cookie = authCookieHeader(await cookies());
|
||||
const me = await getMeCached(cookie || undefined);
|
||||
|
||||
// 管理员及以上排全站置顶;板块管理员排自己授权板块的板块置顶
|
||||
if (!me.user || !canModerateAny(me.user)) {
|
||||
return <Forbidden text="你所在的角色没有置顶管理权限,或尚未被授权任何板块。" />;
|
||||
}
|
||||
|
||||
// 板块管理员只能看到自己被授权的板块
|
||||
let boards: BoardWithCount[] = [];
|
||||
try {
|
||||
const r = await fetchBoards();
|
||||
boards = r.boards ?? [];
|
||||
} catch {
|
||||
boards = [];
|
||||
}
|
||||
if (!isAdminOrAbove(me.user.role)) {
|
||||
const ids = new Set(me.user.board_ids ?? []);
|
||||
boards = boards.filter((b) => ids.has(b.id));
|
||||
}
|
||||
|
||||
return (
|
||||
<PinnedAdmin
|
||||
boards={boards.map((b) => ({ id: b.id, name: b.name }))}
|
||||
canGlobal={isAdminOrAbove(me.user.role)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user