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
#12803)

* The error message is not user-friendly when adding duplicate permissions. (#12773)

* The error message is not user-friendly when adding duplicate permissions.(#12773)
  • Loading branch information
littlesparklet authored Dec 5, 2024
1 parent 66705e3 commit 4961191
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 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 @@ -672,6 +672,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 @@ -667,6 +667,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.data);
};

/**
* 给角色添加权限
* @param {*} param0
Expand Down Expand Up @@ -157,6 +166,7 @@ export {
createRole,
deleteRole,
getPermissions,
checkPermission,
createPermission,
deletePermission,
};

0 comments on commit 4961191

Please sign in to comment.