Skip to content

Commit 07bd00d

Browse files
authored
[Optimize]security下的users、acls接入进权限管理(#1089) (#1154)
请不要在没有先创建Issue的情况下创建Pull Request。 ## 变更的目的是什么 XXXXX ## 简短的更新日志 XX ## 验证这一变化 XXXX 请遵循此清单,以帮助我们快速轻松地整合您的贡献: * [ ] 一个 PR(Pull Request的简写)只解决一个问题,禁止一个 PR 解决多个问题; * [ ] 确保 PR 有对应的 Issue(通常在您开始处理之前创建),除非是书写错误之类的琐碎更改不需要 Issue ; * [ ] 格式化 PR 及 Commit-Log 的标题及内容,例如 #861 。PS:Commit-Log 需要在 Git Commit 代码时进行填写,在 GitHub 上修改不了; * [ ] 编写足够详细的 PR 描述,以了解 PR 的作用、方式和原因; * [ ] 编写必要的单元测试来验证您的逻辑更正。如果提交了新功能或重大更改,请记住在 test 模块中添加 integration-test; * [ ] 确保编译通过,集成测试通过;
1 parent 1adfa63 commit 07bd00d

File tree

3 files changed

+63
-37
lines changed

3 files changed

+63
-37
lines changed

km-console/packages/layout-clusters-fe/src/pages/CommonConfig.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ export enum ClustersPermissionMap {
4545
CONNECTOR_DELETE = 'Connector-删除',
4646
CONNECTOR_RESTART = 'Connector-重启',
4747
CONNECTOR_STOP_RESUME = 'Connector-暂停&恢复',
48+
// Security
49+
SECURITY_ACL_ADD = 'Security-ACL新增',
50+
SECURITY_ACL_DELETE = 'Security-ACL删除',
51+
SECURITY_USER_ADD = 'Security-User新增',
52+
SECURITY_USER_DELETE = 'Security-User删除',
53+
SECURITY_USER_EDIT_PASSWORD = 'Security-User修改密码',
4854
}
4955

5056
export interface PermissionNode {

km-console/packages/layout-clusters-fe/src/pages/SecurityACLs/index.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import AddACLDrawer, {
1414
RESOURCE_TO_OPERATIONS_MAP,
1515
RESOURCE_MAP_KEYS,
1616
} from './EditDrawer';
17+
import { ClustersPermissionMap } from '../CommonConfig';
1718
import './index.less';
1819

1920
const { confirm } = Modal;
@@ -105,7 +106,7 @@ const SecurityACLs = (): JSX.Element => {
105106
};
106107

107108
const columns = () => {
108-
const baseColumns = [
109+
const baseColumns: any = [
109110
{
110111
title: 'Principal',
111112
dataIndex: 'kafkaUser',
@@ -143,7 +144,9 @@ const SecurityACLs = (): JSX.Element => {
143144
title: 'Host',
144145
dataIndex: 'aclClientHost',
145146
},
146-
{
147+
];
148+
if (global.hasPermission && global.hasPermission(ClustersPermissionMap.SECURITY_ACL_DELETE)) {
149+
baseColumns.push({
147150
title: '操作',
148151
dataIndex: '',
149152
width: 120,
@@ -156,8 +159,8 @@ const SecurityACLs = (): JSX.Element => {
156159
</>
157160
);
158161
},
159-
},
160-
];
162+
});
163+
}
161164

162165
return baseColumns;
163166
};
@@ -238,15 +241,19 @@ const SecurityACLs = (): JSX.Element => {
238241
</Form.Item>
239242
</Form>
240243
</div>
241-
<div className={`${tableHeaderPrefix}-right`}>
242-
<Button
243-
type="primary"
244-
// icon={<PlusOutlined />}
245-
onClick={() => editDrawerRef.current.onOpen(true, getACLs)}
246-
>
247-
新增ACL
248-
</Button>
249-
</div>
244+
{global.hasPermission && global.hasPermission(ClustersPermissionMap.SECURITY_ACL_ADD) ? (
245+
<div className={`${tableHeaderPrefix}-right`}>
246+
<Button
247+
type="primary"
248+
// icon={<PlusOutlined />}
249+
onClick={() => editDrawerRef.current.onOpen(true, getACLs)}
250+
>
251+
新增ACL
252+
</Button>
253+
</div>
254+
) : (
255+
<></>
256+
)}
250257
</div>
251258
<ProTable
252259
tableProps={{

km-console/packages/layout-clusters-fe/src/pages/SecurityUsers/index.tsx

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import api from '@src/api';
2323
import { useParams } from 'react-router-dom';
2424
import { regKafkaPassword } from '@src/constants/reg';
2525
import { tableHeaderPrefix } from '@src/constants/common';
26-
26+
import { ClustersPermissionMap } from '../CommonConfig';
2727
export const randomString = (len = 32, chars = 'abcdefghijklmnopqrstuvwxyz1234567890'): string => {
2828
const maxPos = chars.length;
2929
let str = '';
@@ -323,7 +323,7 @@ const SecurityUsers = (): JSX.Element => {
323323
};
324324

325325
const columns = () => {
326-
const baseColumns = [
326+
const baseColumns: any = [
327327
{
328328
title: 'KafkaUser',
329329
dataIndex: 'name',
@@ -348,30 +348,39 @@ const SecurityUsers = (): JSX.Element => {
348348
return <PasswordContent clusterId={clusterId} name={record.name} />;
349349
},
350350
},
351-
{
351+
];
352+
if (global.hasPermission) {
353+
baseColumns.push({
352354
title: '操作',
353355
dataIndex: '',
354356
width: 240,
355357
render(record: UsersProps) {
356358
return (
357359
<>
358-
<Button
359-
type="link"
360-
size="small"
361-
style={{ paddingLeft: 0 }}
362-
onClick={() => editDrawerRef.current.onOpen(true, UsersOperate.ChangePassword, getKafkaUserList, record)}
363-
>
364-
修改密码
365-
</Button>
366-
<Button type="link" size="small" onClick={() => onDelete(record)}>
367-
删除
368-
</Button>
360+
{global.hasPermission(ClustersPermissionMap.SECURITY_USER_EDIT_PASSWORD) ? (
361+
<Button
362+
type="link"
363+
size="small"
364+
style={{ paddingLeft: 0 }}
365+
onClick={() => editDrawerRef.current.onOpen(true, UsersOperate.ChangePassword, getKafkaUserList, record)}
366+
>
367+
修改密码
368+
</Button>
369+
) : (
370+
<></>
371+
)}
372+
{global.hasPermission(ClustersPermissionMap.SECURITY_USER_DELETE) ? (
373+
<Button type="link" size="small" onClick={() => onDelete(record)}>
374+
删除
375+
</Button>
376+
) : (
377+
<></>
378+
)}
369379
</>
370380
);
371381
},
372-
},
373-
];
374-
382+
});
383+
}
375384
return baseColumns;
376385
};
377386

@@ -454,13 +463,17 @@ const SecurityUsers = (): JSX.Element => {
454463
setSearchKeywordsInput(e.target.value);
455464
}}
456465
/>
457-
<Button
458-
type="primary"
459-
// icon={<PlusOutlined />}
460-
onClick={() => editDrawerRef.current.onOpen(true, UsersOperate.Add, getKafkaUserList)}
461-
>
462-
新增KafkaUser
463-
</Button>
466+
{global.hasPermission && global.hasPermission(ClustersPermissionMap.SECURITY_USER_ADD) ? (
467+
<Button
468+
type="primary"
469+
// icon={<PlusOutlined />}
470+
onClick={() => editDrawerRef.current.onOpen(true, UsersOperate.Add, getKafkaUserList)}
471+
>
472+
新增KafkaUser
473+
</Button>
474+
) : (
475+
<></>
476+
)}
464477
</div>
465478
</div>
466479

0 commit comments

Comments
 (0)