Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The error message is not user-friendly when adding duplicate permissi… #12803

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -673,6 +673,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 @@ -668,6 +668,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,
};