Skip to content

Commit

Permalink
[Bugfix]修复未勾选系统管理查看权限,但是依然可以查看系统管理的问题 (#1105)
Browse files Browse the repository at this point in the history
请不要在没有先创建Issue的情况下创建Pull Request。

## 变更的目的是什么
修复未勾选系统管理查看权限,但是依然可以查看系统管理的问题
## 简短的更新日志
修复未勾选系统管理查看权限,但是依然可以查看系统管理的问题
## 验证这一变化
### 权限表
<img width="587" alt="image"
src="https://github.com/didi/KnowStreaming/assets/43955116/497fea54-3216-4ae7-8dab-304a07e81209">

### 效果
<img width="1500" alt="image"
src="https://github.com/didi/KnowStreaming/assets/43955116/1e4a8260-336e-4c15-a244-5f768107a990">

请遵循此清单,以帮助我们快速轻松地整合您的贡献:

* [x] 一个 PR(Pull Request的简写)只解决一个问题,禁止一个 PR 解决多个问题;
* [x] 确保 PR 有对应的 Issue(通常在您开始处理之前创建),除非是书写错误之类的琐碎更改不需要 Issue ;
* [x] 格式化 PR 及 Commit-Log 的标题及内容,例如 #861 。PS:Commit-Log 需要在 Git Commit
代码时进行填写,在 GitHub 上修改不了;
* [x] 编写足够详细的 PR 描述,以了解 PR 的作用、方式和原因;
* [x] 编写必要的单元测试来验证您的逻辑更正。如果提交了新功能或重大更改,请记住在 test 模块中添加 integration-test;
* [x] 确保编译通过,集成测试通过;

Co-authored-by: suzj <[email protected]>
  • Loading branch information
HZSUZJ and suzj authored Oct 20, 2023
1 parent f6becbd commit 59e8a41
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
35 changes: 21 additions & 14 deletions km-console/packages/layout-clusters-fe/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getLicenseInfo } from './constants/common';
import api from './api';
import ClusterContainer from './pages/index';
import ksLogo from './assets/ks-logo.png';
import {ClustersPermissionMap} from "./pages/CommonConfig";

interface ILocaleMap {
[index: string]: any;
Expand Down Expand Up @@ -116,6 +117,8 @@ const AppContent = (props: { setlanguage: (language: string) => void }) => {
const userInfo = localStorage.getItem('userInfo');
const [curActiveAppName, setCurActiveAppName] = useState('');
const [versionInfo, setVersionInfo] = useState<VersionInfo>();
const [global] = AppContainer.useGlobalValue();
const quickEntries=[];

useEffect(() => {
if (pathname.startsWith('/config')) {
Expand All @@ -132,6 +135,23 @@ const AppContent = (props: { setlanguage: (language: string) => void }) => {
});
}, []);

if (global.hasPermission && global.hasPermission(ClustersPermissionMap.CLUSTERS_MANAGE_VIEW)){
quickEntries.push({
icon: <IconFont type="icon-duojiqunguanli"/>,
txt: '多集群管理',
ident: '',
active: curActiveAppName === 'cluster',
});
}
if (global.hasPermission && global.hasPermission(ClustersPermissionMap.SYS_MANAGE_VIEW)){
quickEntries.push({
icon: <IconFont type="icon-xitongguanli" />,
txt: '系统管理',
ident: 'config',
active: curActiveAppName === 'config',
});
}

return (
<DProLayout.Container
headerProps={{
Expand All @@ -142,20 +162,7 @@ const AppContent = (props: { setlanguage: (language: string) => void }) => {
),
username: userInfo ? JSON.parse(userInfo)?.userName : '',
icon: <DotChartOutlined />,
quickEntries: [
{
icon: <IconFont type="icon-duojiqunguanli" />,
txt: '多集群管理',
ident: '',
active: curActiveAppName === 'cluster',
},
{
icon: <IconFont type="icon-xitongguanli" />,
txt: '系统管理',
ident: 'config',
active: curActiveAppName === 'config',
},
],
quickEntries: quickEntries,
isFixed: false,
userDropMenuItems: [
<Menu.Item key={0}>
Expand Down
10 changes: 10 additions & 0 deletions km-console/packages/layout-clusters-fe/src/pages/CommonConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { goLogin } from '@src/constants/axiosConfig';
export enum ClustersPermissionMap {
CLUSTERS_MANAGE = '多集群管理',
CLUSTERS_MANAGE_VIEW = '多集群管理查看',
//仅用作隐藏掉系统管理菜单
SYS_MANAGE = '系统管理',
SYS_MANAGE_VIEW = '系统管理查看',
// Cluster
CLUSTER_ADD = '接入集群',
CLUSTER_DEL = '删除集群',
Expand Down Expand Up @@ -94,6 +97,13 @@ const CommonConfig = () => {
clustersPermissions &&
clustersPermissions.childList.forEach((node: PermissionNode) => node.has && userPermissions.push(node.permissionName));

// 获取用户在系统管理拥有的权限
const configPermissions = userPermissionTree.find(
(sys: PermissionNode) => sys.permissionName === ClustersPermissionMap.SYS_MANAGE
);
configPermissions &&
configPermissions.childList.forEach((node: PermissionNode) => node.has && userPermissions.push(node.permissionName));

const hasPermission = (permissionName: ClustersPermissionMap) => permissionName && userPermissions.includes(permissionName);

setGlobal((curState: any) => ({ ...curState, permissions: allPermissions, userPermissions, hasPermission, userInfo }));
Expand Down

0 comments on commit 59e8a41

Please sign in to comment.