feat: 完成多品牌隔离专项验收
This commit is contained in:
1 parent
1a2f179e15
commit
dcb40f629b
16 files changed
+197
-51
No files matched your search
@@ -0,0 +1,20 @@
|
|||||||
|
# 多品牌隔离专项验收
|
||||||
|
|
||||||
|
## 目标
|
||||||
|
|
||||||
|
验证并固化多品牌场景下的身份、后台配置、公共 Runtime Workspace、业务提供项、动态表单和客户提交隔离,确保行业模板可以在同一平台上安全复用。
|
||||||
|
|
||||||
|
## 范围
|
||||||
|
|
||||||
|
- 覆盖管理员品牌切换与 membership 授权;
|
||||||
|
- 覆盖公共内容按品牌解析;
|
||||||
|
- 覆盖业务数据和客户数据的品牌边界;
|
||||||
|
- 统一默认品牌 fallback 的使用边界;
|
||||||
|
- 不在本 Epic 中新增行业业务能力。
|
||||||
|
|
||||||
|
## 完成标准
|
||||||
|
|
||||||
|
- 每个隔离边界都有自动化成功和失败测试;
|
||||||
|
- API、Admin、Miniapp 相关门禁通过;
|
||||||
|
- 发现的架构问题形成代码修复或 ADR 记录;
|
||||||
|
- `SUBTASKS.csv` 所有子任务为 `DONE`。
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# 进度
|
||||||
|
|
||||||
|
- 任务:多品牌隔离专项验收
|
||||||
|
- 形态:epic
|
||||||
|
- 进度:3/3
|
||||||
|
- 当前:多品牌隔离专项验收完成
|
||||||
|
- 真相文件:`SUBTASKS.csv`
|
||||||
|
|
||||||
|
## 恢复信息
|
||||||
|
|
||||||
|
- 已完成前置:多品牌工作区、品牌切换、Controller 拆分、小程序格式门禁治理。
|
||||||
|
- 已完成:品牌切换后的后台品牌配置、业务提供项和公共 Runtime Workspace 隔离测试,API 28/28 通过。
|
||||||
|
- 已完成:新增 `PublicBrandContextService`,统一公共接口的品牌解析,并保留 `DEFAULT_BRAND_ID` 开发 fallback。
|
||||||
|
- 下一步:运行全量门禁,记录根级检查结果并完成提交。
|
||||||
|
- 全量门禁已通过:`format:check`、`lint`、`typecheck`、Admin build、Miniapp fixture/visual fixture、API integration `28/28`。
|
||||||
|
- API lint 保留 6 个既有测试文件 `any` warning,无 error。
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
id,title,task_type,depends_on,status,task_dir,acceptance_criteria,validation_command,notes
|
||||||
|
1,多品牌隔离测试基线,single-full,,DONE,tasks/isolation-tests,覆盖切换、授权、公共工作区和业务数据隔离,pnpm --filter @personal-brand/api test:integration,新增品牌切换隔离测试;API 28/28 通过
|
||||||
|
2,品牌上下文解析边界,single-full,1,DONE,tasks/context-resolver,公共接口品牌解析规则统一且保留开发 fallback,pnpm --filter @personal-brand/api typecheck && pnpm --filter @personal-brand/api test:integration,新增 PublicBrandContextService,公共品牌、信任内容、业务提供项、表单和 Runtime Workspace 支持 brandSlug
|
||||||
|
3,全量回归与文档收口,single-full,1;2,DONE,tasks/regression,所有门禁通过且进度与 ADR 完整,pnpm format:check && pnpm lint && pnpm typecheck && pnpm --filter @personal-brand/api test:integration,format、lint、typecheck、API 28/28、Admin build、Miniapp fixture 全部通过;API 测试保留 6 个既有 any warning
|
||||||
|
@@ -10,7 +10,7 @@ export function QueryState({
|
|||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
error?: unknown;
|
error?: unknown;
|
||||||
onRetry?: () => void;
|
onRetry?: () => void;
|
||||||
children: ReactNode;
|
children?: ReactNode;
|
||||||
}) {
|
}) {
|
||||||
if (loading)
|
if (loading)
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { Alert, Button, Card, Form, Input, Select, Space, Table, Tag, message } from "antd";
|
import { Alert, Button, Card, Form, Input, Select, Table, Tag, message } from "antd";
|
||||||
import type { CapabilityInstallation } from "@personal-brand/api-client";
|
import type { CapabilityInstallation } from "@personal-brand/api-client";
|
||||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||||
import { QueryState } from "../../components/QueryState.js";
|
import { QueryState } from "../../components/QueryState.js";
|
||||||
@@ -28,11 +28,11 @@ export function CapabilitiesPage() {
|
|||||||
createApiClient().updateAdminCapability(key, {
|
createApiClient().updateAdminCapability(key, {
|
||||||
capabilityVersion: values.capabilityVersion,
|
capabilityVersion: values.capabilityVersion,
|
||||||
status: values.status,
|
status: values.status,
|
||||||
config: values.configText ? JSON.parse(values.configText) : {},
|
config: values.configText ? (JSON.parse(values.configText) as Record<string, unknown>) : {},
|
||||||
}),
|
}),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
message.success("能力配置已更新");
|
message.success("能力配置已更新");
|
||||||
queryClient.invalidateQueries({ queryKey: ["admin", "capabilities"] });
|
void queryClient.invalidateQueries({ queryKey: ["admin", "capabilities"] });
|
||||||
},
|
},
|
||||||
onError: (error) => message.error(error instanceof Error ? error.message : "更新失败"),
|
onError: (error) => message.error(error instanceof Error ? error.message : "更新失败"),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -222,12 +222,14 @@ export function InquiriesPage() {
|
|||||||
{
|
{
|
||||||
title: "来源业务",
|
title: "来源业务",
|
||||||
dataIndex: ["offering", "name"],
|
dataIndex: ["offering", "name"],
|
||||||
render: (value) => value || "品牌咨询",
|
render: (value: string | null | undefined) => value || "品牌咨询",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "状态",
|
title: "状态",
|
||||||
dataIndex: "status",
|
dataIndex: "status",
|
||||||
render: (value) => <Tag>{inquiryLabels[value] ?? value}</Tag>,
|
render: (value: InquirySubmission["status"]) => (
|
||||||
|
<Tag>{inquiryLabels[value] ?? value}</Tag>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{ title: "版本", dataIndex: "formVersion", render: (value) => `v${value}` },
|
{ title: "版本", dataIndex: "formVersion", render: (value) => `v${value}` },
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,12 +14,7 @@ import {
|
|||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { createApiClient } from "../../lib/api.js";
|
import { createApiClient } from "../../lib/api.js";
|
||||||
import { ApiClientError } from "@personal-brand/api-client";
|
import { ApiClientError } from "@personal-brand/api-client";
|
||||||
import type {
|
import type { BrandFieldDefinition, BrandModule, InquiryForm } from "@personal-brand/api-client";
|
||||||
BrandFieldDefinition,
|
|
||||||
BrandModule,
|
|
||||||
InquiryForm,
|
|
||||||
PublicWorkspace,
|
|
||||||
} from "@personal-brand/api-client";
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||||
import { MutationError } from "../../components/QueryState.js";
|
import { MutationError } from "../../components/QueryState.js";
|
||||||
@@ -32,7 +27,7 @@ export function WorkspacePage() {
|
|||||||
const [editingForm, setEditingForm] = useState<InquiryForm | null>(null);
|
const [editingForm, setEditingForm] = useState<InquiryForm | null>(null);
|
||||||
const [visualTarget, setVisualTarget] = useState<string | null>(null);
|
const [visualTarget, setVisualTarget] = useState<string | null>(null);
|
||||||
const [industryTarget, setIndustryTarget] = useState<{
|
const [industryTarget, setIndustryTarget] = useState<{
|
||||||
key: "personal" | "food";
|
key: "personal" | "food" | "doors";
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
capabilities: string[];
|
capabilities: string[];
|
||||||
@@ -82,7 +77,7 @@ export function WorkspacePage() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
const install = useMutation({
|
const install = useMutation({
|
||||||
mutationFn: (key: "personal" | "food") => client.installAdminTemplate(key),
|
mutationFn: (key: "personal" | "food" | "doors") => client.installAdminTemplate(key),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
message.success("模板已安装");
|
message.success("模板已安装");
|
||||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||||
@@ -150,7 +145,12 @@ export function WorkspacePage() {
|
|||||||
});
|
});
|
||||||
const updateForm = useMutation({
|
const updateForm = useMutation({
|
||||||
mutationFn: ({ id, body }: { id: string; body: Partial<InquiryForm> }) =>
|
mutationFn: ({ id, body }: { id: string; body: Partial<InquiryForm> }) =>
|
||||||
client.updateAdminInquiryForm(id, body),
|
client.updateAdminInquiryForm(id, {
|
||||||
|
...(body.name === undefined ? {} : { name: body.name }),
|
||||||
|
...(body.offeringId == null ? {} : { offeringId: body.offeringId }),
|
||||||
|
...(body.fieldsSnapshot === undefined ? {} : { fieldsSnapshot: body.fieldsSnapshot }),
|
||||||
|
...(body.isEnabled === undefined ? {} : { isEnabled: body.isEnabled }),
|
||||||
|
}),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
message.success("咨询表单已更新");
|
message.success("咨询表单已更新");
|
||||||
setFormOpen(false);
|
setFormOpen(false);
|
||||||
@@ -673,13 +673,20 @@ export function WorkspacePage() {
|
|||||||
layout="vertical"
|
layout="vertical"
|
||||||
onFinish={(values) =>
|
onFinish={(values) =>
|
||||||
(() => {
|
(() => {
|
||||||
|
const rawPurpose = String(values.purpose);
|
||||||
|
const purpose: InquiryForm["purpose"] =
|
||||||
|
rawPurpose === "booking" || rawPurpose === "quote-request" ? rawPurpose : "inquiry";
|
||||||
|
const targetType: InquiryForm["targetType"] = values.offeringId
|
||||||
|
? "offering"
|
||||||
|
: "brand";
|
||||||
|
const submissionAction: InquiryForm["submissionAction"] =
|
||||||
|
purpose === "quote-request" ? "create-quote" : "create-inquiry";
|
||||||
const body = {
|
const body = {
|
||||||
name: typeof values.name === "string" ? values.name : "",
|
name: typeof values.name === "string" ? values.name : "",
|
||||||
offeringId: typeof values.offeringId === "string" ? values.offeringId : undefined,
|
...(typeof values.offeringId === "string" ? { offeringId: values.offeringId } : {}),
|
||||||
purpose: values.purpose as InquiryForm["purpose"],
|
purpose,
|
||||||
targetType: values.offeringId ? "offering" : "brand",
|
targetType,
|
||||||
submissionAction:
|
submissionAction,
|
||||||
values.purpose === "quote-request" ? "create-quote" : "create-inquiry",
|
|
||||||
fieldsSnapshot: (Array.isArray(values.fieldsSnapshot)
|
fieldsSnapshot: (Array.isArray(values.fieldsSnapshot)
|
||||||
? values.fieldsSnapshot
|
? values.fieldsSnapshot
|
||||||
: []
|
: []
|
||||||
@@ -687,8 +694,9 @@ export function WorkspacePage() {
|
|||||||
const item = field as Record<string, unknown>;
|
const item = field as Record<string, unknown>;
|
||||||
if (typeof item.optionsText !== "string") return item;
|
if (typeof item.optionsText !== "string") return item;
|
||||||
try {
|
try {
|
||||||
const options = JSON.parse(item.optionsText);
|
const options = JSON.parse(item.optionsText) as unknown;
|
||||||
const { optionsText: _optionsText, ...rest } = item;
|
const { optionsText, ...rest } = item;
|
||||||
|
void optionsText;
|
||||||
return { ...rest, options };
|
return { ...rest, options };
|
||||||
} catch {
|
} catch {
|
||||||
return item;
|
return item;
|
||||||
@@ -759,7 +767,7 @@ export function WorkspacePage() {
|
|||||||
<Form.Item noStyle shouldUpdate>
|
<Form.Item noStyle shouldUpdate>
|
||||||
{({ getFieldValue }) =>
|
{({ getFieldValue }) =>
|
||||||
["select", "radio"].includes(
|
["select", "radio"].includes(
|
||||||
getFieldValue(["fieldsSnapshot", name, "type"]),
|
String(getFieldValue(["fieldsSnapshot", name, "type"])),
|
||||||
) ? (
|
) ? (
|
||||||
<Form.Item {...restField} name={[name, "optionsText"]}>
|
<Form.Item {...restField} name={[name, "optionsText"]}>
|
||||||
<Input placeholder="选项 JSON" />
|
<Input placeholder="选项 JSON" />
|
||||||
|
|||||||
@@ -146,7 +146,9 @@ function Dashboard({ onLogout }: { onLogout: () => void }) {
|
|||||||
size="small"
|
size="small"
|
||||||
value={brand.data?.id}
|
value={brand.data?.id}
|
||||||
loading={memberships.isLoading}
|
loading={memberships.isLoading}
|
||||||
onChange={(value) => void switchBrand(value)}
|
onChange={(value) => {
|
||||||
|
if (value) void switchBrand(value);
|
||||||
|
}}
|
||||||
options={(memberships.data ?? []).map((item) => ({
|
options={(memberships.data ?? []).map((item) => ({
|
||||||
value: item.brand.id,
|
value: item.brand.id,
|
||||||
label: item.brand.name,
|
label: item.brand.name,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { AdminAuthService } from "./admin-auth.service.js";
|
|||||||
import { ApiExceptionFilter, RequestIdMiddleware } from "./http.js";
|
import { ApiExceptionFilter, RequestIdMiddleware } from "./http.js";
|
||||||
import { AdminWorkspaceController } from "./admin-workspace.controller.js";
|
import { AdminWorkspaceController } from "./admin-workspace.controller.js";
|
||||||
import { PublicWorkspaceController } from "./modules/public/public-workspace.controller.js";
|
import { PublicWorkspaceController } from "./modules/public/public-workspace.controller.js";
|
||||||
|
import { PublicBrandContextService } from "./modules/public/public-brand-context.service.js";
|
||||||
import { AdminConfigController } from "./modules/admin/admin-config.controller.js";
|
import { AdminConfigController } from "./modules/admin/admin-config.controller.js";
|
||||||
import { PublicOfferingController } from "./modules/public/public-offering.controller.js";
|
import { PublicOfferingController } from "./modules/public/public-offering.controller.js";
|
||||||
import { PublicInquiryFormController } from "./modules/public/public-inquiry-form.controller.js";
|
import { PublicInquiryFormController } from "./modules/public/public-inquiry-form.controller.js";
|
||||||
@@ -62,6 +63,7 @@ export class HealthController {
|
|||||||
TemplateWorkspaceService,
|
TemplateWorkspaceService,
|
||||||
AdminAccessService,
|
AdminAccessService,
|
||||||
AdminMembershipGuard,
|
AdminMembershipGuard,
|
||||||
|
PublicBrandContextService,
|
||||||
],
|
],
|
||||||
exports: [PrismaService, WechatAuthService],
|
exports: [PrismaService, WechatAuthService],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||||
|
import { PrismaService } from "../../prisma.service.js";
|
||||||
|
|
||||||
|
const FALLBACK_BRAND_ID = "00000000-0000-0000-0000-000000000001";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class PublicBrandContextService {
|
||||||
|
constructor(private readonly prisma: PrismaService) {}
|
||||||
|
|
||||||
|
async resolveId(brandSlug?: string): Promise<string> {
|
||||||
|
if (!brandSlug) return process.env.DEFAULT_BRAND_ID ?? FALLBACK_BRAND_ID;
|
||||||
|
const brand = await this.prisma.brandProfile.findUnique({
|
||||||
|
where: { slug: brandSlug },
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
|
if (!brand) throw new NotFoundException("品牌不存在");
|
||||||
|
return brand.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,19 @@
|
|||||||
import { BadRequestException, Controller, Get, Param } from "@nestjs/common";
|
import { BadRequestException, Controller, Get, Param, Query } from "@nestjs/common";
|
||||||
import { PrismaService } from "../../prisma.service.js";
|
import { PrismaService } from "../../prisma.service.js";
|
||||||
|
import { PublicBrandContextService } from "./public-brand-context.service.js";
|
||||||
|
|
||||||
@Controller("public/inquiry-forms")
|
@Controller("public/inquiry-forms")
|
||||||
export class PublicInquiryFormController {
|
export class PublicInquiryFormController {
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
constructor(
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
private readonly brandContext: PublicBrandContextService,
|
||||||
|
) {}
|
||||||
@Get(":id")
|
@Get(":id")
|
||||||
async get(@Param("id") id: string): Promise<unknown> {
|
async get(@Param("id") id: string, @Query("brandSlug") brandSlug?: string): Promise<unknown> {
|
||||||
const form = await this.prisma.inquiryForm.findFirst({
|
const form = await this.prisma.inquiryForm.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id,
|
id,
|
||||||
brandId: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
|
brandId: await this.brandContext.resolveId(brandSlug),
|
||||||
isEnabled: true,
|
isEnabled: true,
|
||||||
OR: [{ offeringId: null }, { offering: { isEnabled: true } }],
|
OR: [{ offeringId: null }, { offering: { isEnabled: true } }],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
import { BadRequestException, Controller, Get, Param } from "@nestjs/common";
|
import { BadRequestException, Controller, Get, Param, Query } from "@nestjs/common";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { PrismaService } from "../../prisma.service.js";
|
import { PrismaService } from "../../prisma.service.js";
|
||||||
|
import { PublicBrandContextService } from "./public-brand-context.service.js";
|
||||||
|
|
||||||
@Controller("public/offerings")
|
@Controller("public/offerings")
|
||||||
export class PublicOfferingController {
|
export class PublicOfferingController {
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
constructor(
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
private readonly brandContext: PublicBrandContextService,
|
||||||
|
) {}
|
||||||
@Get()
|
@Get()
|
||||||
async list(): Promise<unknown> {
|
async list(@Query("brandSlug") brandSlug?: string): Promise<unknown> {
|
||||||
const brandId = process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001";
|
const brandId = await this.brandContext.resolveId(brandSlug);
|
||||||
const items = await this.prisma.offering.findMany({
|
const items = await this.prisma.offering.findMany({
|
||||||
where: { brandId, isEnabled: true },
|
where: { brandId, isEnabled: true },
|
||||||
orderBy: { sortOrder: "asc" },
|
orderBy: { sortOrder: "asc" },
|
||||||
@@ -22,11 +26,12 @@ export class PublicOfferingController {
|
|||||||
return items.map((item) => this.present(item));
|
return items.map((item) => this.present(item));
|
||||||
}
|
}
|
||||||
@Get(":id")
|
@Get(":id")
|
||||||
async get(@Param("id") id: string): Promise<unknown> {
|
async get(@Param("id") id: string, @Query("brandSlug") brandSlug?: string): Promise<unknown> {
|
||||||
|
const brandId = await this.brandContext.resolveId(brandSlug);
|
||||||
const item = await this.prisma.offering.findFirst({
|
const item = await this.prisma.offering.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id,
|
id,
|
||||||
brandId: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
|
brandId,
|
||||||
isEnabled: true,
|
isEnabled: true,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Controller, Get, NotFoundException, Query } from "@nestjs/common";
|
import { Controller, Get, Query } from "@nestjs/common";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { PrismaService } from "../../prisma.service.js";
|
import { PrismaService } from "../../prisma.service.js";
|
||||||
|
import { PublicBrandContextService } from "./public-brand-context.service.js";
|
||||||
import {
|
import {
|
||||||
getBrandTemplate,
|
getBrandTemplate,
|
||||||
getVisualTemplate,
|
getVisualTemplate,
|
||||||
@@ -16,19 +17,14 @@ import type {
|
|||||||
|
|
||||||
@Controller("public/workspace")
|
@Controller("public/workspace")
|
||||||
export class PublicWorkspaceController {
|
export class PublicWorkspaceController {
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
constructor(
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
private readonly brandContext: PublicBrandContextService,
|
||||||
|
) {}
|
||||||
private readonly cache = new Map<string, { expiresAt: number; value: unknown }>();
|
private readonly cache = new Map<string, { expiresAt: number; value: unknown }>();
|
||||||
@Get()
|
@Get()
|
||||||
async get(@Query("brandSlug") brandSlug?: string): Promise<unknown> {
|
async get(@Query("brandSlug") brandSlug?: string): Promise<unknown> {
|
||||||
const configuredId = process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001";
|
const brandId = await this.brandContext.resolveId(brandSlug);
|
||||||
const selected = brandSlug
|
|
||||||
? await this.prisma.brandProfile.findUnique({
|
|
||||||
where: { slug: brandSlug },
|
|
||||||
select: { id: true },
|
|
||||||
})
|
|
||||||
: null;
|
|
||||||
if (brandSlug && !selected) throw new NotFoundException("品牌不存在");
|
|
||||||
const brandId = selected?.id ?? configuredId;
|
|
||||||
const cached = process.env.NODE_ENV === "test" ? undefined : this.cache.get(brandId);
|
const cached = process.env.NODE_ENV === "test" ? undefined : this.cache.get(brandId);
|
||||||
if (cached && cached.expiresAt > Date.now()) return cached.value;
|
if (cached && cached.expiresAt > Date.now()) return cached.value;
|
||||||
const [
|
const [
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { BadRequestException, Controller, Get, Param, Query } from "@nestjs/common";
|
import { BadRequestException, Controller, Get, Param, Query } from "@nestjs/common";
|
||||||
import { PrismaService } from "../../prisma.service.js";
|
import { PrismaService } from "../../prisma.service.js";
|
||||||
|
import { PublicBrandContextService } from "./public-brand-context.service.js";
|
||||||
import {
|
import {
|
||||||
brandTemplates,
|
brandTemplates,
|
||||||
getBrandTemplate,
|
getBrandTemplate,
|
||||||
@@ -10,13 +11,16 @@ import {
|
|||||||
|
|
||||||
@Controller("public")
|
@Controller("public")
|
||||||
export class PublicController {
|
export class PublicController {
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
constructor(
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
private readonly brandContext: PublicBrandContextService,
|
||||||
|
) {}
|
||||||
|
|
||||||
@Get("brand")
|
@Get("brand")
|
||||||
async brand(): Promise<unknown> {
|
async brand(@Query("brandSlug") brandSlug?: string): Promise<unknown> {
|
||||||
return this.prisma.brandProfile.findUnique({
|
return this.prisma.brandProfile.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
|
id: await this.brandContext.resolveId(brandSlug),
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -38,13 +42,16 @@ export class PublicController {
|
|||||||
|
|
||||||
@Controller("public/trust-content")
|
@Controller("public/trust-content")
|
||||||
export class PublicTrustContentController {
|
export class PublicTrustContentController {
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
constructor(
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
private readonly brandContext: PublicBrandContextService,
|
||||||
|
) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
list(): Promise<unknown> {
|
async list(@Query("brandSlug") brandSlug?: string): Promise<unknown> {
|
||||||
return this.prisma.trustContent.findMany({
|
return this.prisma.trustContent.findMany({
|
||||||
where: {
|
where: {
|
||||||
brandId: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
|
brandId: await this.brandContext.resolveId(brandSlug),
|
||||||
isPublished: true,
|
isPublished: true,
|
||||||
},
|
},
|
||||||
orderBy: [{ type: "asc" }, { sortOrder: "asc" }],
|
orderBy: [{ type: "asc" }, { sortOrder: "asc" }],
|
||||||
|
|||||||
@@ -790,6 +790,61 @@ test("admin can list and switch only enabled brand memberships", async () => {
|
|||||||
assert.equal(denied.statusCode, 403);
|
assert.equal(denied.statusCode, 403);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("brand switching isolates admin configuration, offerings, and public workspace", async () => {
|
||||||
|
const login = await request("/admin/session/login", {
|
||||||
|
method: "POST",
|
||||||
|
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||||
|
});
|
||||||
|
assert.equal(login.statusCode, 201);
|
||||||
|
const defaultToken = JSON.parse(login.body).token;
|
||||||
|
const memberships = JSON.parse(
|
||||||
|
(
|
||||||
|
await request("/admin/brands", {
|
||||||
|
headers: { authorization: `Bearer ${defaultToken}` },
|
||||||
|
})
|
||||||
|
).body,
|
||||||
|
);
|
||||||
|
const doorsBrand = memberships.find((item) => item.brand.slug === "linjing-doors")?.brand;
|
||||||
|
assert.ok(doorsBrand);
|
||||||
|
|
||||||
|
const switched = await request(`/admin/brands/${doorsBrand.id}/switch`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { authorization: `Bearer ${defaultToken}` },
|
||||||
|
});
|
||||||
|
assert.equal(switched.statusCode, 201);
|
||||||
|
const doorsToken = JSON.parse(switched.body).token;
|
||||||
|
|
||||||
|
const [defaultConfig, doorsConfig, defaultOfferings, doorsOfferings, doorsWorkspace] =
|
||||||
|
await Promise.all([
|
||||||
|
request("/admin/config/brand", {
|
||||||
|
headers: { authorization: `Bearer ${defaultToken}` },
|
||||||
|
}),
|
||||||
|
request("/admin/config/brand", {
|
||||||
|
headers: { authorization: `Bearer ${doorsToken}` },
|
||||||
|
}),
|
||||||
|
request("/admin/workspace/offerings", {
|
||||||
|
headers: { authorization: `Bearer ${defaultToken}` },
|
||||||
|
}),
|
||||||
|
request("/admin/workspace/offerings", {
|
||||||
|
headers: { authorization: `Bearer ${doorsToken}` },
|
||||||
|
}),
|
||||||
|
request("/public/workspace?brandSlug=linjing-doors"),
|
||||||
|
]);
|
||||||
|
assert.equal(defaultConfig.statusCode, 200);
|
||||||
|
assert.equal(doorsConfig.statusCode, 200);
|
||||||
|
assert.equal(JSON.parse(defaultConfig.body).id, brandId);
|
||||||
|
assert.equal(JSON.parse(doorsConfig.body).id, doorsBrand.id);
|
||||||
|
assert.equal(defaultOfferings.statusCode, 200);
|
||||||
|
assert.equal(doorsOfferings.statusCode, 200);
|
||||||
|
assert.notDeepEqual(
|
||||||
|
JSON.parse(defaultOfferings.body).map((item) => item.id),
|
||||||
|
JSON.parse(doorsOfferings.body).map((item) => item.id),
|
||||||
|
);
|
||||||
|
assert.equal(doorsWorkspace.statusCode, 200);
|
||||||
|
assert.equal(JSON.parse(doorsWorkspace.body).brand.id, doorsBrand.id);
|
||||||
|
assert.equal(JSON.parse(doorsWorkspace.body).template.key, "doors");
|
||||||
|
});
|
||||||
|
|
||||||
test("disabled brand membership blocks existing admin token", async () => {
|
test("disabled brand membership blocks existing admin token", async () => {
|
||||||
const login = await request("/admin/session/login", {
|
const login = await request("/admin/session/login", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
@@ -575,6 +575,9 @@ export class ApiClient {
|
|||||||
offeringId?: string;
|
offeringId?: string;
|
||||||
fieldsSnapshot: unknown[];
|
fieldsSnapshot: unknown[];
|
||||||
isEnabled?: boolean;
|
isEnabled?: boolean;
|
||||||
|
purpose?: InquiryForm["purpose"];
|
||||||
|
targetType?: InquiryForm["targetType"];
|
||||||
|
submissionAction?: InquiryForm["submissionAction"];
|
||||||
}): Promise<InquiryForm> {
|
}): Promise<InquiryForm> {
|
||||||
return this.request("/admin/workspace/forms", { method: "POST", body });
|
return this.request("/admin/workspace/forms", { method: "POST", body });
|
||||||
}
|
}
|
||||||
@@ -585,6 +588,9 @@ export class ApiClient {
|
|||||||
offeringId: string;
|
offeringId: string;
|
||||||
fieldsSnapshot: unknown[];
|
fieldsSnapshot: unknown[];
|
||||||
isEnabled: boolean;
|
isEnabled: boolean;
|
||||||
|
purpose?: InquiryForm["purpose"];
|
||||||
|
targetType?: InquiryForm["targetType"];
|
||||||
|
submissionAction?: InquiryForm["submissionAction"];
|
||||||
}>,
|
}>,
|
||||||
): Promise<InquiryForm> {
|
): Promise<InquiryForm> {
|
||||||
return this.request(`/admin/workspace/forms/${encodeURIComponent(id)}`, {
|
return this.request(`/admin/workspace/forms/${encodeURIComponent(id)}`, {
|
||||||
|
|||||||
Reference in new issue
Block a user