mirror of https://github.com/halo-dev/halo
fix: permission logic of super administrator
Signed-off-by: Ryan Wang <i@ryanc.cc>pull/3445/head
parent
d5c1e3e428
commit
24e1a3c4f7
|
@ -4,8 +4,7 @@ import { hasPermission } from "../permission";
|
||||||
describe("hasPermission", () => {
|
describe("hasPermission", () => {
|
||||||
it("should return true if user has permission", () => {
|
it("should return true if user has permission", () => {
|
||||||
const uiPermissions = ["system:post:manage", "system:post:view"];
|
const uiPermissions = ["system:post:manage", "system:post:view"];
|
||||||
expect(hasPermission(uiPermissions, ["*"], false)).toBe(true);
|
|
||||||
expect(hasPermission(uiPermissions, ["*"], true)).toBe(true);
|
|
||||||
expect(hasPermission(uiPermissions, ["system:post:manage"], false)).toBe(
|
expect(hasPermission(uiPermissions, ["system:post:manage"], false)).toBe(
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@ -27,5 +26,11 @@ describe("hasPermission", () => {
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
|
|
||||||
|
// super admin has all permissions
|
||||||
|
expect(hasPermission(["*"], ["system:post:manage"], false)).toBe(true);
|
||||||
|
expect(
|
||||||
|
hasPermission(["*"], ["system:post:manage", "system:links:manage"], true)
|
||||||
|
).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,12 +5,12 @@ export function hasPermission(
|
||||||
targetPermissions: Array<string>,
|
targetPermissions: Array<string>,
|
||||||
any: boolean
|
any: boolean
|
||||||
): boolean {
|
): boolean {
|
||||||
if (!targetPermissions || !targetPermissions.length) {
|
// super admin has all permissions
|
||||||
|
if (uiPermissions.includes("*")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// super admin has all permissions
|
if (!targetPermissions || !targetPermissions.length) {
|
||||||
if (targetPermissions.includes("*")) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue