refactor: 收口 Admin 会话与授权边界

This commit is contained in:
que01 committed 2026-10-19 10:13:13 +08:00
1 parent 0788480ce3
commit 4ef4be2071
67 files changed
+1890 -392

No files matched your search

+2 -2
View File
@@ -25,8 +25,8 @@ API 地址通过 `API_BASE_URL` 设置,品牌通过 `BRAND_SLUG` 设置。H5
## 构建
```sh
pnpm --filter @personal-brand/taro build:h5
pnpm --filter @personal-brand/taro build:weapp
TEMPLATE_KEY=acheng-campus-food pnpm --filter @personal-brand/taro build:h5
TEMPLATE_KEY=acheng-campus-food pnpm --filter @personal-brand/taro build:weapp
TEMPLATE_KEY=linjing-editorial pnpm --filter @personal-brand/taro build:h5
TEMPLATE_KEY=linjing-editorial pnpm --filter @personal-brand/taro build:weapp
```
+1 -1
View File
@@ -81,7 +81,7 @@ function resolveTargets(envType, preview) {
if (process.env.MINIAPP_OUTPUT_ROOT)
return [path.resolve(taroRoot, process.env.MINIAPP_OUTPUT_ROOT)];
// 单模板构建默认使用餐饮试点;多模板预览必须显式 --preview。
const templateKey = process.env.TEMPLATE_KEY ?? "acheng-campus-food";
const templateKey = process.env.TEMPLATE_KEY;
if (!templateKey) throw new Error("TEMPLATE_KEY is required for non-preview masking");
return [path.join(taroRoot, "dist", templateKey, envType)];
}
+1
View File
@@ -1,6 +1,7 @@
{
"name": "@personal-brand/taro",
"private": true,
"type": "module",
"scripts": {
"dev:h5": "taro build --type h5 --watch",
"dev:preview": "PREVIEW_ALL_TEMPLATES=true taro build --type h5 --watch",
+38 -4
View File
@@ -235,6 +235,7 @@ runtimeWorkspace.trustItems.push(...additionalFoodTrust);
test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ page }) => {
test.setTimeout(60000);
let rejectOfferingSave = false;
let sessionAuthenticated = false;
await page.setViewportSize({ width: 1920, height: 1000 });
await page.route("http://localhost:3001/public/workspace**", (route) =>
route.fulfill({ json: runtimeWorkspace }),
@@ -243,15 +244,31 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
const request = route.request();
const url = new URL(request.url());
url.pathname = url.pathname.replace(/^\/api/, "");
if (url.pathname === "/admin/session/login")
if (url.pathname === "/admin/session/current") {
if (!sessionAuthenticated) {
return route.fulfill({ status: 401, json: { error: { message: "未登录" } } });
}
return route.fulfill({
json: {
token: "fixture-token",
authenticated: true,
displayName: "测试管理员",
role: "owner",
mustChangePassword: false,
platformTemplateRole: "none",
},
});
}
if (url.pathname === "/admin/session/login") {
sessionAuthenticated = true;
return route.fulfill({
json: {
displayName: "测试管理员",
role: "owner",
mustChangePassword: false,
platformTemplateRole: "none",
},
});
}
if (url.pathname === "/admin/brands")
return route.fulfill({ json: [{ id: brand.id, role: "owner", brand }] });
if (url.pathname === "/admin/config/brand" && request.method() === "PATCH") {
@@ -636,6 +653,7 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
test("林境模板支持首页和主理人区域点选", async ({ page }) => {
test.setTimeout(60000);
let sessionAuthenticated = false;
await page.setViewportSize({ width: 1600, height: 900 });
const editorialBrand = {
...structuredClone(brand),
@@ -730,10 +748,26 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
await page.route("**/api/**", (route) => {
const url = new URL(route.request().url());
const path = url.pathname.replace(/^\/api/, "");
if (path === "/admin/session/login")
if (path === "/admin/session/current") {
if (!sessionAuthenticated) {
return route.fulfill({ status: 401, json: { error: { message: "未登录" } } });
}
return route.fulfill({
json: { token: "fixture-token", displayName: "测试管理员", role: "owner" },
json: {
authenticated: true,
displayName: "测试管理员",
role: "owner",
mustChangePassword: false,
platformTemplateRole: "none",
},
});
}
if (path === "/admin/session/login") {
sessionAuthenticated = true;
return route.fulfill({
json: { displayName: "测试管理员", role: "owner", mustChangePassword: false },
});
}
if (path === "/admin/brands")
return route.fulfill({
json: [{ id: editorialBrand.id, role: "owner", brand: editorialBrand }],
@@ -94,10 +94,11 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
await page.route("**/api/**", async (route) => {
const url = new URL(route.request().url());
const path = url.pathname.replace(/^\/api/, "");
if (path === "/admin/session/current")
return route.fulfill({ status: 401, json: { error: { message: "未登录" } } });
if (path === "/admin/session/login")
return route.fulfill({
json: {
token: "fixture-token",
displayName: "测试管理员",
role: "owner",
mustChangePassword: false,
@@ -57,9 +57,19 @@ test("模板管理可重试预览,并切换我的、详情和禁止提交的
),
);
await page.setViewportSize({ width: 1440, height: 1000 });
await page.addInitScript(() => {
localStorage.setItem("adminToken", "fixture-token");
localStorage.setItem("adminPlatformTemplateRole", "template_admin");
await page.route("**/api/**", (route) => {
const url = new URL(route.request().url());
if (url.pathname.endsWith("/admin/session/current"))
return route.fulfill({
json: {
authenticated: true,
displayName: "模板管理员",
role: "owner",
mustChangePassword: false,
platformTemplateRole: "template_admin",
},
});
return route.fulfill({ json: {} });
});
let attempts = 0;
const writes: string[] = [];
@@ -71,6 +81,16 @@ test("模板管理可重试预览,并切换我的、详情和禁止提交的
};
await page.route("**/api/**", async (route) => {
const url = new URL(route.request().url());
if (url.pathname.endsWith("/admin/session/current"))
return route.fulfill({
json: {
authenticated: true,
displayName: "模板管理员",
role: "owner",
mustChangePassword: false,
platformTemplateRole: "template_admin",
},
});
if (route.request().method() !== "GET") writes.push(url.pathname);
if (url.pathname.endsWith("/preview")) {
attempts++;
@@ -161,9 +161,19 @@ test("导入包预览矩阵展示身份、资源和完整媒体槽位", async ({
await test.step(`${mediaCase.packageKey}/${mediaCase.industry}`, async () => {
const { preview, version } = await buildPreviewFixture(mediaCase);
assert.ok(version);
await page.addInitScript(() => {
localStorage.setItem("adminToken", "fixture-token");
localStorage.setItem("adminPlatformTemplateRole", "template_admin");
await page.route("**/api/**", (route) => {
const url = new URL(route.request().url());
if (url.pathname.endsWith("/admin/session/current"))
return route.fulfill({
json: {
authenticated: true,
displayName: "模板管理员",
role: "owner",
mustChangePassword: false,
platformTemplateRole: "template_admin",
},
});
return route.fulfill({ json: {} });
});
const emptyPreview = structuredClone(preview);
emptyPreview.workspace.offerings = [];
@@ -175,6 +185,16 @@ test("导入包预览矩阵展示身份、资源和完整媒体槽位", async ({
const writes: string[] = [];
await page.route("**/api/**", async (route) => {
const url = new URL(route.request().url());
if (url.pathname.endsWith("/admin/session/current"))
return route.fulfill({
json: {
authenticated: true,
displayName: "模板管理员",
role: "owner",
mustChangePassword: false,
platformTemplateRole: "template_admin",
},
});
if (route.request().method() !== "GET") writes.push(url.pathname);
if (url.pathname.endsWith("/preview")) {
attempts += 1;