refactor: 拆分模板工作区服务并统一后台访问控制
This commit is contained in:
1 parent
5051839986
commit
b4e3e86dcd
13 files changed
+441
-329
No files matched your search
@@ -5123,6 +5123,71 @@ test("disabled brand membership blocks existing admin token", async () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("booking endpoints share the brand access policy", async () => {
|
||||
const username = `booking-policy-${randomUUID()}`;
|
||||
const password = "booking-policy-password-123";
|
||||
const user = await prisma.adminUser.create({
|
||||
data: {
|
||||
username,
|
||||
passwordHash: await bcrypt.hash(password, 12),
|
||||
displayName: "预订策略测试管理员",
|
||||
mustChangePassword: true,
|
||||
},
|
||||
});
|
||||
const membership = await prisma.brandMembership.create({
|
||||
data: { brandId, adminUserId: user.id, role: "admin", isEnabled: true },
|
||||
});
|
||||
try {
|
||||
const login = await request("/admin/session/login", {
|
||||
method: "POST",
|
||||
payload: { username, password },
|
||||
});
|
||||
assert.equal(login.statusCode, 201, login.body);
|
||||
const headers = { authorization: `Bearer ${sessionToken(login)}` };
|
||||
const routes = [
|
||||
{ method: "GET", url: "/admin/bookings" },
|
||||
{ method: "GET", url: "/admin/bookings/unread-count" },
|
||||
{ method: "GET", url: "/admin/bookings/tags" },
|
||||
{ method: "POST", url: "/admin/bookings/tags", payload: { name: "策略测试标签" } },
|
||||
];
|
||||
|
||||
// 初始密码未修改时,预订路由必须与其他后台路由一样被拒绝。
|
||||
for (const route of routes) {
|
||||
const response = await request(route.url, {
|
||||
method: route.method,
|
||||
headers,
|
||||
...(route.payload ? { payload: route.payload } : {}),
|
||||
});
|
||||
assert.equal(response.statusCode, 403, `${route.method} ${route.url}: ${response.body}`);
|
||||
}
|
||||
|
||||
// 品牌成员被停用后,同一 token 也不能再访问预订数据。
|
||||
await prisma.adminUser.update({ where: { id: user.id }, data: { mustChangePassword: false } });
|
||||
const changed = await request("/admin/session/login", {
|
||||
method: "POST",
|
||||
payload: { username, password },
|
||||
});
|
||||
assert.equal(changed.statusCode, 201, changed.body);
|
||||
const activeHeaders = { authorization: `Bearer ${sessionToken(changed)}` };
|
||||
assert.equal((await request("/admin/bookings", { headers: activeHeaders })).statusCode, 200);
|
||||
|
||||
await prisma.brandMembership.update({
|
||||
where: { id: membership.id },
|
||||
data: { isEnabled: false },
|
||||
});
|
||||
for (const route of routes) {
|
||||
const response = await request(route.url, {
|
||||
method: route.method,
|
||||
headers: activeHeaders,
|
||||
...(route.payload ? { payload: route.payload } : {}),
|
||||
});
|
||||
assert.equal(response.statusCode, 403, `${route.method} ${route.url}: ${response.body}`);
|
||||
}
|
||||
} finally {
|
||||
await prisma.adminUser.delete({ where: { id: user.id } });
|
||||
}
|
||||
});
|
||||
|
||||
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