Skip to content

Commit

Permalink
The error message is not user-friendly when adding duplicate permissi…
Browse files Browse the repository at this point in the history
…ons. (alibaba#12773)
  • Loading branch information
littlesparklet committed Oct 31, 2024
1 parent e2d44f2 commit 99e3eaf
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions console-ui/src/locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ const I18N_CONF = {
defaultFuzzyd: 'Default fuzzy query mode opened',
fuzzyd: "Add wildcard '*' for fuzzy query",
query: 'Search',
checkPermission: 'This role permission already exists!',
},
NewPermissions: {
addPermission: 'Add Permission',
Expand Down
1 change: 1 addition & 0 deletions console-ui/src/locales/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ const I18N_CONF = {
defaultFuzzyd: '已开启默认模糊查询',
fuzzyd: "添加通配符'*'进行模糊查询",
query: '查询',
checkPermission: '此角色权限已存在!',
},
NewPermissions: {
addPermission: '添加权限',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ import {
Form,
Input,
Switch,
Message,
} from '@alifd/next';
import { connect } from 'react-redux';
import { getPermissions, createPermission, deletePermission } from '../../../reducers/authority';
import {
getPermissions,
checkPermission,
createPermission,
deletePermission,
} from '../../../reducers/authority';
import { getNamespaces } from '../../../reducers/namespace';
import RegionGroup from '../../../components/RegionGroup';
import NewPermissions from './NewPermissions';
Expand Down Expand Up @@ -217,9 +223,17 @@ class PermissionsManagement extends React.Component {
<NewPermissions
visible={createPermissionVisible}
onOk={permission =>
createPermission(permission).then(res => {
this.setState({ pageNo: 1 }, () => this.getPermissions());
return res;
checkPermission(permission).then(res => {
if (res) {
Message.error({
content: locale.checkPermission,
});
} else {
createPermission(permission).then(res => {
this.setState({ pageNo: 1 }, () => this.getPermissions());
return res;
});
}
})
}
onCancel={() => this.colseCreatePermission()}
Expand Down
10 changes: 10 additions & 0 deletions console-ui/src/reducers/authority.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ const getPermissions = params => dispatch =>
.get('v1/auth/permissions', { params })
.then(data => dispatch({ type: PERMISSIONS_LIST, data }));

/**
* 添加权限前置校验
* @param {*} param0
*/
const checkPermission = ([role, resource, action]) => {
const params = { role, resource, action };
return request.get('v1/auth/permissions', { params }).then(res => res);
};

/**
* 给角色添加权限
* @param {*} param0
Expand Down Expand Up @@ -157,6 +166,7 @@ export {
createRole,
deleteRole,
getPermissions,
checkPermission,
createPermission,
deletePermission,
};
4 changes: 2 additions & 2 deletions console/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<link rel="stylesheet" type="text/css" href="console-ui/public/css/icon.css">
<link rel="stylesheet" type="text/css" href="console-ui/public/css/font-awesome.css">
<!-- 第三方css结束 -->
<link href="./css/main.css?1ef6e417bc5403fb7b6c" rel="stylesheet"></head>
<link href="./css/main.css?be606327c742ceaabb05" rel="stylesheet"></head>

<body>
<div id="root" style="overflow:hidden"></div>
Expand All @@ -56,6 +56,6 @@
<script src="console-ui/public/js/merge.js"></script>
<script src="console-ui/public/js/loader.js"></script>
<!-- 第三方js结束 -->
<script type="text/javascript" src="./js/main.js?1ef6e417bc5403fb7b6c"></script></body>
<script type="text/javascript" src="./js/main.js?be606327c742ceaabb05"></script></body>

</html>
14 changes: 7 additions & 7 deletions console/src/main/resources/static/js/main.js

Large diffs are not rendered by default.

0 comments on commit 99e3eaf

Please sign in to comment.