Skip to content

Commit

Permalink
Add Access Control role text and ContentWithQuestion (oceanbase#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
TianWuwt authored and lizzy-0323 committed Sep 26, 2024
1 parent 356cc3c commit bf1307d
Show file tree
Hide file tree
Showing 5 changed files with 2,702 additions and 3,936 deletions.
49 changes: 38 additions & 11 deletions ui/src/components/customModal/HandleRoleModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { access } from '@/api';
import type { AcCreateRoleParam, AcPolicy, AcRole } from '@/api/generated';
import { ACCESS_ROLES_LIST } from '@/constants/access';
import { Type } from '@/pages/Access/type';
import { intl } from '@/utils/intl';
import { ContentWithQuestion } from '@oceanbase/ui';
import { findByValue } from '@oceanbase/util';
import { useModel } from '@umijs/max';
import type { CheckboxProps } from 'antd';
import { Checkbox, Col, Form, Input, Row, message } from 'antd';
Expand Down Expand Up @@ -123,7 +126,15 @@ function PermissionSelect({
{fetchData.map((item, index) => (
<div key={index}>
<Row gutter={[8, 16]}>
<Col span={8}> {item.domain}</Col>
<Col span={8}>
<ContentWithQuestion
content={findByValue(ACCESS_ROLES_LIST, item.domain).label}
tooltip={{
title: findByValue(ACCESS_ROLES_LIST, item.domain)
.descriptions,
}}
/>
</Col>
<Col span={16}>
<Checkbox.Group
options={options}
Expand Down Expand Up @@ -156,7 +167,7 @@ export default function HandleRoleModal({
try {
await form.validateFields();
form.submit();
} catch (err) {}
} catch (err) { }
};
const allPolicies = uniqBy(initialState?.policies, 'domain') || [];
const defaultValue = allPolicies.map((item) => {
Expand All @@ -183,9 +194,9 @@ export default function HandleRoleModal({
type === Type.CREATE
? await access.createRole(formData)
: await access.patchRole(
editValue!.name,
pick(formData, ['description', 'permissions']),
);
editValue!.name,
pick(formData, ['description', 'permissions']),
);
if (res.successful) {
if (type == Type.EDIT) {
await refresh();
Expand Down Expand Up @@ -222,13 +233,13 @@ export default function HandleRoleModal({
ConditionalExpression0:
type === Type.EDIT
? intl.formatMessage({
id: 'src.components.customModal.1920004B',
defaultMessage: '编辑',
})
id: 'src.components.customModal.1920004B',
defaultMessage: '编辑',
})
: intl.formatMessage({
id: 'src.components.customModal.D7653D14',
defaultMessage: '创建',
}),
id: 'src.components.customModal.D7653D14',
defaultMessage: '创建',
}),
},
)}
open={visible}
Expand Down Expand Up @@ -294,6 +305,22 @@ export default function HandleRoleModal({
id: 'src.components.customModal.D24B8F5C',
defaultMessage: '权限',
})}
rules={[
{
validator: (_, permissions) => {
if (!permissions || !permissions.length) {
return Promise.reject(
intl.formatMessage({
id: 'src.components.customModal.2389B108',
defaultMessage: '权限不能为空!',
}),
);
}
return Promise.resolve();
},
validateTrigger: 'onBlur',
},
]}
name={'permissions'}
>
<PermissionSelect
Expand Down
61 changes: 61 additions & 0 deletions ui/src/constants/access.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { intl } from '@/utils/intl';

export const ACCESS_ROLES_LIST = [
{
label: intl.formatMessage({
id: 'src.constants.D057DB4A',
defaultMessage: '集群与租户',
}),
value: 'obcluster',
descriptions: intl.formatMessage({
id: 'src.components.customModal.783C8ED3',
defaultMessage:
'集群与租户: 读权限涉及OB集群、租户的获取,写权限涉及集群和租户的创建、更新和删除',
}),
},
{
label: intl.formatMessage({
id: 'src.constants.9E29D52E',
defaultMessage: '系统信息',
}),
value: 'system',
descriptions: intl.formatMessage({
id: 'src.components.customModal.EA420EE1',
defaultMessage:
'系统信息: 读权限涉及监控指标和监控数据的获取,k8s集群节点、事件、命名空间、存储类的获取,写权限涉及命名空间的创建和系统配置的修改',
}),
},
{
label: intl.formatMessage({
id: 'src.constants.4EBEFDA8',
defaultMessage: '监控告警',
}),
value: 'alarm',
descriptions: {
id: 'src.components.customModal.CC80EAD4',
defaultMessage:
'监控告警: 读权限涉及告警、Silencer、Rule、Receiver和Route的读取,写权限则涉及它们的着创建、更新和删除',
},
},
{
label: 'OBProxy',
value: 'obproxy',
descriptions: {
id: 'src.components.customModal.C97E041E',
defaultMessage:
'OBProxy: 读权限涉及OBProxy的获取,写权限涉及OBProxy的创建、更新和删除',
},
},
{
label: intl.formatMessage({
id: 'src.constants.939130EF',
defaultMessage: '权限控制',
}),
value: 'ac',
descriptions: {
id: 'src.components.customModal.2169D3CC',
defaultMessage:
'权限控制: 读权限涉及账号和角色的获取,写权限涉及它们的创建、更新和删除',
},
},
];
16 changes: 15 additions & 1 deletion ui/src/i18n/strings/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1142,5 +1142,19 @@
"src.constants.22EDA0DC": "Requires kernel version> = 4.2.1.4 (except 4.2.2.x)",
"src.components.customModal.F7DD1D45": "Scaling Zone",
"src.components.customModal.08DC5F92": "Role already exists",
"src.api.5D7E1724": "new password is the same as the old password"
"src.api.5D7E1724": "new password is the same as the old password",
"src.constants.D057DB4A": "Clusters and Tenants",
"src.constants.9E29D52E": "System Info",
"src.constants.4EBEFDA8": "Alarm",
"src.constants.939130EF": "Access Control",
"src.components.customModal.783C8ED3": "obcluster: read permission involves obtaining OB clusters, tenants and minitoring metrics of them, and write permission involves creating, updating, and deleting clusters and tenants",
"src.components.customModal.EA420EE1": "system: read permission involves obtaining k8s cluster nodes, events, namespaces, and storage classes, and write permission involves creating namespaces and modifying system configurations",
"src.components.customModal.CC80EAD4": "alarm: read permission involves reading alarms, Silencers, Rules, Receivers, and Routes, and write permission involves creating, updating, and deleting them",
"src.components.customModal.C97E041E": "obproxy: read permission involves obtaining OBProxy, and write permission involves creating, updating, and deleting OBProxy",
"src.components.customModal.2169D3CC": "ac: read permission involves obtaining accounts and roles, and write permission involves creating, updating, and deleting them",
"src.pages.Tenant.Detail.Overview.5DFC5EF2": "Unlimited",
"src.components.customModal.2389B108": "Permissions cannot be empty!",
"src.components.TopoComponent.04F971F3": "Unlimited",
"src.components.TopoComponent.BA2B454B": "Unlimited"

}
15 changes: 14 additions & 1 deletion ui/src/i18n/strings/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1141,5 +1141,18 @@
"src.constants.22EDA0DC": "要求内核版本 >= 4.2.1.4 (4.2.2.x 除外)",
"src.components.customModal.F7DD1D45": "扩缩容Zone",
"src.components.customModal.08DC5F92": "角色已存在",
"src.api.5D7E1724": "新密码不能和当前密码一致"
"src.api.5D7E1724": "新密码不能和当前密码一致",
"src.pages.Tenant.Detail.Overview.5DFC5EF2": "无限制",
"src.constants.D057DB4A": "集群与租户",
"src.constants.9E29D52E": "系统信息",
"src.constants.4EBEFDA8": "监控告警",
"src.constants.939130EF": "权限控制",
"src.components.customModal.783C8ED3": "集群与租户: 读权限涉及OB集群、租户的获取,写权限涉及集群和租户的创建、更新和删除",
"src.components.customModal.EA420EE1": "系统信息: 读权限涉及监控指标和监控数据的获取,k8s集群节点、事件、命名空间、存储类的获取,写权限涉及命名空间的创建和系统配置的修改",
"src.components.customModal.CC80EAD4": "监控告警: 读权限涉及告警、Silencer、Rule、Receiver和Route的读取,写权限则涉及它们的着创建、更新和删除",
"src.components.customModal.C97E041E": "OBProxy: 读权限涉及OBProxy的获取,写权限涉及OBProxy的创建、更新和删除",
"src.components.customModal.2169D3CC": "权限控制: 读权限涉及账号和角色的获取,写权限涉及它们的创建、更新和删除",
"src.components.customModal.2389B108": "权限不能为空!",
"src.components.TopoComponent.04F971F3": "无限制",
"src.components.TopoComponent.BA2B454B": "无限制"
}
Loading

0 comments on commit bf1307d

Please sign in to comment.