feat: 完成管理员品牌 membership 守卫
This commit is contained in:
1 parent
1afa7626cf
commit
e89b751572
4 files changed
+65
-2
No files matched your search
@@ -191,6 +191,16 @@ test("admin can install doors industry template through the shared runtime contr
|
||||
});
|
||||
|
||||
test("admin can preview and import sample content idempotently", async () => {
|
||||
await prisma.offering.deleteMany({
|
||||
where: {
|
||||
brandId,
|
||||
name: { in: ["序章·入户门", "庭院·边界门", "室内·静谧门", "一对一门系统设计咨询"] },
|
||||
},
|
||||
});
|
||||
await prisma.trustContent.deleteMany({
|
||||
where: { brandId, content: "示例内容,待品牌主理人完善。" },
|
||||
});
|
||||
await prisma.brandFieldDefinition.deleteMany({ where: { brandId, source: "sample" } });
|
||||
const login = await request("/admin/session/login", {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
@@ -619,6 +629,32 @@ test("admin login validates credentials", async () => {
|
||||
assert.equal(response.statusCode, 401);
|
||||
});
|
||||
|
||||
test("disabled brand membership blocks existing admin token", async () => {
|
||||
const login = await request("/admin/session/login", {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const admin = await prisma.adminUser.findUnique({ where: { username: "admin" } });
|
||||
assert.ok(admin);
|
||||
const membership = await prisma.brandMembership.findUnique({
|
||||
where: { adminUserId_brandId: { adminUserId: admin.id, brandId } },
|
||||
});
|
||||
assert.ok(membership);
|
||||
await prisma.brandMembership.update({ where: { id: membership.id }, data: { isEnabled: false } });
|
||||
try {
|
||||
const response = await request("/admin/workspace", {
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
});
|
||||
assert.equal(response.statusCode, 403);
|
||||
} finally {
|
||||
await prisma.brandMembership.update({
|
||||
where: { id: membership.id },
|
||||
data: { isEnabled: true },
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("admin can read and update brand and service configuration", async () => {
|
||||
const login = await request("/admin/session/login", {
|
||||
method: "POST",
|
||||
|
||||
Reference in new issue
Block a user