fix: support legacy rank permission schema
This commit is contained in:
1 parent
384ede19c4
commit
37ad27c5f3
2 files changed
+60
-31
No files matched your search
@@ -87,8 +87,7 @@ describe("RANK_GENERAL_FIELDS", () => {
|
||||
});
|
||||
|
||||
describe("fetchEmulatorRankForEdit", () => {
|
||||
it("repairs a missing permission_definitions column before loading an existing rank", async () => {
|
||||
let hasRankColumn = false;
|
||||
it("loads permissions from the legacy table when permission_definitions is absent", async () => {
|
||||
const db = {
|
||||
execute: async (query: SQL | string) => {
|
||||
const text = queryText(query);
|
||||
@@ -105,15 +104,21 @@ describe("fetchEmulatorRankForEdit", () => {
|
||||
];
|
||||
}
|
||||
if (text.includes("FROM information_schema.columns")) {
|
||||
return [[{ c: hasRankColumn ? 1 : 0 }], []];
|
||||
return [[], []];
|
||||
}
|
||||
if (text.includes("ALTER TABLE permission_definitions")) {
|
||||
hasRankColumn = true;
|
||||
return [{ affectedRows: 0 }, []];
|
||||
}
|
||||
if (text.includes("FROM permission_definitions")) {
|
||||
if (!hasRankColumn) throw new Error("Unknown column 'rank_11'");
|
||||
return [[{ permission_key: "cmd_ban", max_value: 1, value: 0 }], []];
|
||||
if (text.includes("FROM permissions")) {
|
||||
return [
|
||||
[
|
||||
{
|
||||
id: 11,
|
||||
rank_name: "Developer",
|
||||
level: 11,
|
||||
cmd_ban: 1,
|
||||
cmd_owner: 2,
|
||||
},
|
||||
],
|
||||
[],
|
||||
];
|
||||
}
|
||||
throw new Error(`Unexpected query: ${text}`);
|
||||
},
|
||||
@@ -126,8 +131,8 @@ describe("fetchEmulatorRankForEdit", () => {
|
||||
fetchEmulatorRankForEdit(db as never, 11),
|
||||
).resolves.toMatchObject({
|
||||
id: 11,
|
||||
permissions: { cmd_ban: "0" },
|
||||
permissions: { cmd_ban: "1", cmd_owner: "2" },
|
||||
permissionMaxValues: { cmd_ban: 1, cmd_owner: 2 },
|
||||
});
|
||||
expect(hasRankColumn).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user