mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/1Panel-dev/1Panel.git
synced 2026-09-20 08:03:55 +08:00
fix: align frontend permission checks with access mode (#12723)
This commit is contained in:
committed by
zhengkunwang223
parent
d522d837ff
commit
03fc9302d6
@@ -110,7 +110,6 @@ const applyPermission = (el: HTMLElement, binding: DirectiveBinding<PermissionBi
|
|||||||
const controller = getComponentPermissionController(vnode);
|
const controller = getComponentPermissionController(vnode);
|
||||||
|
|
||||||
if (controller?.setPermissionDisabled) {
|
if (controller?.setPermissionDisabled) {
|
||||||
enableElement(el);
|
|
||||||
controller.setPermissionDisabled(disabled);
|
controller.setPermissionDisabled(disabled);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,27 +41,23 @@ export const toPermissionList = (value: PermissionBindingValue) => {
|
|||||||
return routePermission ? [routePermission] : [];
|
return routePermission ? [routePermission] : [];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const hasManagePermissionAccess = (value?: PermissionBindingValue) => {
|
const hasPermissionAccessByMode = (mode: PermissionMode, value?: PermissionBindingValue) => {
|
||||||
const globalStore = GlobalStore();
|
const globalStore = GlobalStore();
|
||||||
if (globalStore.isAdmin || globalStore.isNodeAdmin) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
const permissions = toPermissionList(value).map(toManagePermission).filter(Boolean);
|
|
||||||
if (permissions.length === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return permissions.every((permission) => globalStore.hasPermission(permission));
|
|
||||||
};
|
|
||||||
|
|
||||||
export const hasPermissionAccess = (value?: PermissionBindingValue) => {
|
|
||||||
const globalStore = GlobalStore();
|
|
||||||
|
|
||||||
if (globalStore.isAdmin || globalStore.isNodeAdmin) {
|
if (globalStore.isAdmin || globalStore.isNodeAdmin) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const permissions = toPermissionList(value);
|
const permissions = toPermissionList(value);
|
||||||
if (permissions.length === 0) {
|
const normalizedPermissions = mode === 'manage' ? permissions.map(toManagePermission).filter(Boolean) : permissions;
|
||||||
|
if (normalizedPermissions.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return permissions.every((permission) => globalStore.hasPermission(permission));
|
return normalizedPermissions.every((permission) => globalStore.hasPermission(permission));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const hasManagePermissionAccess = (value?: PermissionBindingValue) => {
|
||||||
|
return hasPermissionAccessByMode('manage', value);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const hasPermissionAccess = (value?: PermissionBindingValue) => {
|
||||||
|
return hasPermissionAccessByMode('view', value);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,9 +38,7 @@
|
|||||||
"build/**/*.ts",
|
"build/**/*.ts",
|
||||||
"build/**/*.d.ts",
|
"build/**/*.d.ts",
|
||||||
"vite.config.ts",
|
"vite.config.ts",
|
||||||
"auto-imports.d.ts",
|
"auto-imports.d.ts"
|
||||||
"components.d.ts",
|
|
||||||
"vite-env.d.ts"
|
|
||||||
],
|
],
|
||||||
"exclude": ["node_modules", "dist", "**/*.js", "*.json", "*.md"]
|
"exclude": ["node_modules", "dist", "**/*.js", "*.json", "*.md"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user