fix: 收口模板契约与安全门禁
统一模板包 visual 契约并补齐完成证据;修复 release 版本一致性、管理员 token 撤销、CORS 与默认品牌配置;收敛依赖安全风险并完成全量回归验证。
This commit is contained in:
1 parent
456171aa85
commit
4f0b50c7f1
84 files changed
+7367
-5180
No files matched your search
@@ -6,6 +6,7 @@ export type AdminIdentity = {
|
||||
subject: string;
|
||||
brandId: string;
|
||||
role: "admin";
|
||||
tokenVersion: number;
|
||||
};
|
||||
|
||||
export function requireAdminIdentity(request: FastifyRequest): AdminIdentity {
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
} from "@personal-brand/config";
|
||||
import { validateFieldSnapshot } from "@personal-brand/validation";
|
||||
import { PrismaService } from "../../prisma.service.js";
|
||||
import { TemplateWorkspaceService } from "../../template-workspace.service.js";
|
||||
|
||||
type BootstrapSource = {
|
||||
kind: "package_version";
|
||||
@@ -74,10 +73,7 @@ function asJson(value: unknown): Prisma.InputJsonValue {
|
||||
|
||||
@Injectable()
|
||||
export class AdminSampleContentService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
_templateWorkspace: TemplateWorkspaceService,
|
||||
) {}
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async preview(brandId: string, query?: { templatePackageVersionId?: string }) {
|
||||
const { brand, source, visualTemplateKey } = await this.resolveSource(
|
||||
@@ -222,10 +218,10 @@ export class AdminSampleContentService {
|
||||
await tx.templateBootstrapImport.create({
|
||||
data: {
|
||||
brandId,
|
||||
templatePackageVersionId: source.version!.id,
|
||||
packageKey: source.version!.packageKey,
|
||||
packageVersion: source.version!.version,
|
||||
contentChecksum: source.version!.contentChecksum,
|
||||
templatePackageVersionId: source.version.id,
|
||||
packageKey: source.version.packageKey,
|
||||
packageVersion: source.version.version,
|
||||
contentChecksum: source.version.contentChecksum,
|
||||
actorId,
|
||||
strategy: "missing_only",
|
||||
status: "imported",
|
||||
@@ -294,7 +290,9 @@ export class AdminSampleContentService {
|
||||
throw new BadRequestException("sampleContent 行业与品牌不匹配");
|
||||
const fieldIssues = validateFieldSnapshot(source.sample.fields);
|
||||
if (fieldIssues.length)
|
||||
throw new BadRequestException(`bootstrap 表单字段无效:${fieldIssues.join(";")}`);
|
||||
throw new BadRequestException(
|
||||
`bootstrap 表单字段无效:${fieldIssues.map((issue) => `${issue.path}: ${issue.message}`).join(";")}`,
|
||||
);
|
||||
return { brand, source, visualTemplateKey };
|
||||
}
|
||||
|
||||
|
||||
@@ -2,16 +2,11 @@ import { Body, Controller, Get, Post, Req } from "@nestjs/common";
|
||||
import type { FastifyRequest } from "fastify";
|
||||
import { RollbackTemplateDto, UpgradeTemplateDto } from "../../admin.dto.js";
|
||||
import { TemplateWorkspaceService } from "../../template-workspace.service.js";
|
||||
import { PrismaService } from "../../prisma.service.js";
|
||||
import { recordTemplateOperationFailure } from "../admin/template-operation-failure.js";
|
||||
import { requireAdminIdentity } from "./admin-access.identity.js";
|
||||
|
||||
@Controller("admin/workspace")
|
||||
class AdminTemplateController {
|
||||
constructor(
|
||||
private readonly templateWorkspace: TemplateWorkspaceService,
|
||||
private readonly prisma: PrismaService,
|
||||
) {}
|
||||
constructor(private readonly templateWorkspace: TemplateWorkspaceService) {}
|
||||
|
||||
@Get("template/preview")
|
||||
preview(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
@@ -25,26 +20,7 @@ class AdminTemplateController {
|
||||
): Promise<unknown> {
|
||||
const identity = requireAdminIdentity(request);
|
||||
const requestId = request.headers["x-request-id"]?.toString() ?? request.id;
|
||||
try {
|
||||
return await this.templateWorkspace.upgrade(
|
||||
identity.brandId,
|
||||
body,
|
||||
identity.subject,
|
||||
requestId,
|
||||
);
|
||||
} catch (error) {
|
||||
await recordTemplateOperationFailure(this.prisma, {
|
||||
action:
|
||||
error instanceof Error && error.name.includes("Conflict")
|
||||
? "install_conflict"
|
||||
: "upgrade",
|
||||
error,
|
||||
requestId,
|
||||
actorId: identity.subject,
|
||||
brandId: identity.brandId,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
return this.templateWorkspace.upgrade(identity.brandId, body, identity.subject, requestId);
|
||||
}
|
||||
|
||||
@Post("template/rollback")
|
||||
@@ -54,23 +30,7 @@ class AdminTemplateController {
|
||||
): Promise<unknown> {
|
||||
const identity = requireAdminIdentity(request);
|
||||
const requestId = request.headers["x-request-id"]?.toString() ?? request.id;
|
||||
try {
|
||||
return await this.templateWorkspace.rollback(
|
||||
identity.brandId,
|
||||
identity.subject,
|
||||
body,
|
||||
requestId,
|
||||
);
|
||||
} catch (error) {
|
||||
await recordTemplateOperationFailure(this.prisma, {
|
||||
action: "rollback",
|
||||
error,
|
||||
requestId,
|
||||
actorId: identity.subject,
|
||||
brandId: identity.brandId,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
return this.templateWorkspace.rollback(identity.brandId, identity.subject, body, requestId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,15 +4,12 @@ import { InstallTemplateDto, SelectTemplateVersionDto } from "../../admin.dto.js
|
||||
import { TemplateWorkspaceService } from "../../template-workspace.service.js";
|
||||
import { requireAdminIdentity } from "./admin-access.identity.js";
|
||||
import { AdminWorkspaceService } from "./admin-workspace.service.js";
|
||||
import { PrismaService } from "../../prisma.service.js";
|
||||
import { recordTemplateOperationFailure } from "../admin/template-operation-failure.js";
|
||||
|
||||
@Controller("admin/workspace")
|
||||
class AdminWorkspacePreviewController {
|
||||
constructor(
|
||||
private readonly workspaceService: AdminWorkspaceService,
|
||||
private readonly templateWorkspace: TemplateWorkspaceService,
|
||||
private readonly prisma: PrismaService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@@ -32,25 +29,13 @@ class AdminWorkspacePreviewController {
|
||||
): Promise<unknown> {
|
||||
const identity = requireAdminIdentity(request);
|
||||
const requestId = request.headers["x-request-id"]?.toString() ?? request.id;
|
||||
try {
|
||||
return await this.templateWorkspace.install(
|
||||
identity.brandId,
|
||||
body.templateKey,
|
||||
body.templatePackageVersionId,
|
||||
);
|
||||
} catch (error) {
|
||||
await recordTemplateOperationFailure(this.prisma, {
|
||||
action:
|
||||
error instanceof Error && error.name.includes("Conflict")
|
||||
? "install_conflict"
|
||||
: "install",
|
||||
error,
|
||||
requestId,
|
||||
actorId: identity.subject,
|
||||
brandId: identity.brandId,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
return this.templateWorkspace.install(
|
||||
identity.brandId,
|
||||
body.templateKey,
|
||||
body.templatePackageVersionId,
|
||||
identity.subject,
|
||||
requestId,
|
||||
);
|
||||
}
|
||||
|
||||
@Post("template/select-version")
|
||||
|
||||
Reference in new issue
Block a user