From b6999ea0a1f9d9f19df8c44227c47ecba5e94aa7 Mon Sep 17 00:00:00 2001 From: "Jingwei.Zhang" Date: Tue, 7 Jun 2022 11:44:37 +0800 Subject: [PATCH] refactor: Refactor user group 1. Refactor group store 2. Refactor create group: add domain prop when create 3. Refactor edit group 4. Refactor user group manage user 5. Refactor group detail 6. Suppport actions in role detail 7. Refactor group list: add project/role column && domain dolumn; remove user number column Change-Id: If8f250da3ac27e5050c9fd4d31ad9954177ed0fe --- src/components/FormItem/Label/index.jsx | 4 + src/locales/en.json | 6 +- src/locales/zh.json | 6 +- .../identity/containers/Role/Detail/index.jsx | 5 + .../containers/UserGroup/Detail/index.jsx | 65 +-- .../containers/UserGroup/actions/Create.jsx | 201 +------- .../UserGroup/actions/DomainPermission.jsx | 12 +- .../containers/UserGroup/actions/Edit.jsx | 17 +- .../UserGroup/actions/ManageUser.jsx | 145 ++++++ .../UserGroup/actions/SystemPermission.jsx | 12 +- .../UserGroup/actions/UserManager.jsx | 182 ------- .../containers/UserGroup/actions/index.jsx | 4 +- .../identity/containers/UserGroup/index.jsx | 219 +++++--- src/resources/keystone/domain.jsx | 60 +++ src/stores/keystone/user-group.js | 472 ++++-------------- src/stores/keystone/user.js | 28 +- 16 files changed, 544 insertions(+), 894 deletions(-) create mode 100644 src/pages/identity/containers/UserGroup/actions/ManageUser.jsx delete mode 100644 src/pages/identity/containers/UserGroup/actions/UserManager.jsx diff --git a/src/components/FormItem/Label/index.jsx b/src/components/FormItem/Label/index.jsx index 5e604858..6f1e5244 100644 --- a/src/components/FormItem/Label/index.jsx +++ b/src/components/FormItem/Label/index.jsx @@ -34,6 +34,8 @@ import { HddOutlined, CloudServerOutlined, LoadingOutlined, + TeamOutlined, + ProjectOutlined, } from '@ant-design/icons'; import styles from './index.less'; @@ -66,6 +68,8 @@ const iconTypeMap = { host: , security: SecurityIcon, lb: LBIcon, + group: , + project: , }; export default class index extends Component { diff --git a/src/locales/en.json b/src/locales/en.json index 8b0e637b..f866d52d 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1345,6 +1345,7 @@ "Manage User": "Manage User", "Manage User Group": "Manage User Group", "Manage host": "Manage host", + "Manage user": "Manage user", "Manageable": "Manageable", "Management": "Management", "Management Reason": "Management Reason", @@ -1620,7 +1621,6 @@ "Pending Create": "Pending Create", "Pending Delete": "Pending Delete", "Pending Update": "Pending Update", - "People Num": "People Num", "Perform a consistent hash operation on the source IP address of the request to obtain a specific value. At the same time, the back-end server is numbered, and the request is distributed to the server with the corresponding number according to the calculation result. This can enable load distribution of visits from different source IPs, and at the same time enable requests from the same client IP to always be dispatched to a specific server. This method is suitable for load balancing TCP protocol without cookie function.": "Perform a consistent hash operation on the source IP address of the request to obtain a specific value. At the same time, the back-end server is numbered, and the request is distributed to the server with the corresponding number according to the calculation result. This can enable load distribution of visits from different source IPs, and at the same time enable requests from the same client IP to always be dispatched to a specific server. This method is suitable for load balancing TCP protocol without cookie function.", "Permanent": "Permanent", "Persistent": "Persistent", @@ -1759,6 +1759,7 @@ "Project Range": "Project Range", "Project Reader": "Project Reader", "Project Scope": "Project Scope", + "Project Scope (Project Name: Role Names)": "Project Scope (Project Name: Role Names)", "Project User": "Project User", "Project User Group": "Project User Group", "Projects": "Projects", @@ -1955,7 +1956,6 @@ "Select Project Role": "Select Project Role", "Select Snapshot": "Select Snapshot", "Select System Role": "Select System Role", - "Select User": "Select User", "Select User Group": "Select User Group", "Select a domain": "Select a domain", "Select a region": "Select a region", @@ -2159,7 +2159,6 @@ "System Load": "System Load", "System Reader": "System Reader", "System Running Time": "System Running Time", - "System Scope": "System Scope", "System is error, please try again later.": "System is error, please try again later.", "TCP": "TCP", "TCP Connections": "TCP Connections", @@ -2392,7 +2391,6 @@ "User Detail": "User Detail", "User Edit": "User Edit", "User Group Detail": "User Group Detail", - "User Group ID": "User Group ID", "User Group ID/Name": "User Group ID/Name", "User Group Name": "User Group Name", "User Group Num": "User Group Num", diff --git a/src/locales/zh.json b/src/locales/zh.json index 751c9c9b..0dd66c9c 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -1345,6 +1345,7 @@ "Manage User": "管理用户", "Manage User Group": "管理用户组", "Manage host": "管理主机", + "Manage user": "管理用户", "Manageable": "可管理", "Management": "维护", "Management Reason": "维护原因", @@ -1620,7 +1621,6 @@ "Pending Create": "等待创建", "Pending Delete": "等待删除", "Pending Update": "等待更新", - "People Num": "", "Perform a consistent hash operation on the source IP address of the request to obtain a specific value. At the same time, the back-end server is numbered, and the request is distributed to the server with the corresponding number according to the calculation result. This can enable load distribution of visits from different source IPs, and at the same time enable requests from the same client IP to always be dispatched to a specific server. This method is suitable for load balancing TCP protocol without cookie function.": "将请求的源IP地址进行一致性Hash运算,得到一个具体的数值,同时对后端服务器进行编号,按照运算结果将请求分发到对应编号的服务器上。这可以使得对不同源IP的访问进行负载分发,同时使得同一个客户端IP的请求始终被派发至某特定的服务器。该方式适合负载均衡无cookie功能的TCP协议。", "Permanent": "长期保留", "Persistent": "持久性", @@ -1759,6 +1759,7 @@ "Project Range": "项目范围", "Project Reader": "项目只读权限", "Project Scope": "所属项目", + "Project Scope (Project Name: Role Names)": "所属项目(项目名称:角色名称)", "Project User": "项目用户", "Project User Group": "项目用户组", "Projects": "项目", @@ -1955,7 +1956,6 @@ "Select Project Role": "选择项目角色", "Select Snapshot": "选择快照", "Select System Role": "选择系统角色", - "Select User": "选择用户", "Select User Group": "选择用户组", "Select a domain": "请选择Domain", "Select a region": "请选择Region", @@ -2159,7 +2159,6 @@ "System Load": "系统负载", "System Reader": "系统只读权限", "System Running Time": "", - "System Scope": "绑定系统范围", "System is error, please try again later.": "系统出错,请稍后再试。", "TCP": "", "TCP Connections": "TCP连接数", @@ -2392,7 +2391,6 @@ "User Detail": "用户详情", "User Edit": "编辑用户", "User Group Detail": "用户组详情", - "User Group ID": "用户组ID", "User Group ID/Name": "用户组ID/名称", "User Group Name": "用户组名称", "User Group Num": "用户组数", diff --git a/src/pages/identity/containers/Role/Detail/index.jsx b/src/pages/identity/containers/Role/Detail/index.jsx index 18b17751..e34ed22e 100644 --- a/src/pages/identity/containers/Role/Detail/index.jsx +++ b/src/pages/identity/containers/Role/Detail/index.jsx @@ -18,6 +18,7 @@ import Base from 'containers/TabDetail'; import User from '../../User'; import Group from '../../UserGroup'; import impliedRole from './BaseDetail'; +import actionConfigs from '../actions'; export class RoleDetail extends Base { get name() { @@ -32,6 +33,10 @@ export class RoleDetail extends Base { return this.getRoutePath('role'); } + get actionConfigs() { + return actionConfigs; + } + init() { this.store = new RoleStore(); } diff --git a/src/pages/identity/containers/UserGroup/Detail/index.jsx b/src/pages/identity/containers/UserGroup/Detail/index.jsx index 604d9f6a..f12fa292 100644 --- a/src/pages/identity/containers/UserGroup/Detail/index.jsx +++ b/src/pages/identity/containers/UserGroup/Detail/index.jsx @@ -12,16 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -import React from 'react'; import { inject, observer } from 'mobx-react'; -import { Button, Divider } from 'antd'; -import { UpOutlined, DownOutlined } from '@ant-design/icons'; -import globalDomainStore from 'stores/keystone/domain'; import { GroupStore } from 'stores/keystone/user-group'; import Base from 'containers/TabDetail'; import User from '../../User'; import Project from '../../Project'; -import styles from './index.less'; import actionConfigs from '../actions'; export class Detail extends Base { @@ -43,17 +38,6 @@ export class Detail extends Base { init() { this.store = new GroupStore(); - this.domainStore = globalDomainStore; - this.getDomains(); - } - - getDomains() { - this.domainStore.fetchDomain(); - } - - get domainList() { - const { domains } = this.domainStore; - return domains || []; } get detailInfos() { @@ -62,20 +46,14 @@ export class Detail extends Base { title: t('User Group Name'), dataIndex: 'name', }, - // { - // title: t('People Num'), - // dataIndex: 'user_num', - // }, { title: t('Affiliated Domain'), - dataIndex: 'domain_id', - render: (domain_id) => { - const domain = this.domainList.filter((it) => it.id === domain_id); - if (domain[0]) { - return domain[0].name; - } - return domain_id; - }, + dataIndex: 'domain', + render: (value, record) => (value || {}).name || record.domain_id, + }, + { + title: t('User Num'), + dataIndex: 'userCount', }, { title: t('Description'), @@ -99,37 +77,6 @@ export class Detail extends Base { ]; return tabs; } - - goEdit = () => { - const { - params: { id }, - } = this.props.match; - this.routing.push(`${this.listUrl}/edit/${id}`); - }; - - get detailTitle() { - const { - detail: { id }, - } = this.store; - const { collapsed } = this.state; - const icon = collapsed ? : ; - return ( -
- {t('User Group ID')}: - {id} - - -
- ); - } } export default inject('rootStore')(observer(Detail)); diff --git a/src/pages/identity/containers/UserGroup/actions/Create.jsx b/src/pages/identity/containers/UserGroup/actions/Create.jsx index 0b85d60d..c727dd58 100644 --- a/src/pages/identity/containers/UserGroup/actions/Create.jsx +++ b/src/pages/identity/containers/UserGroup/actions/Create.jsx @@ -12,62 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -import React from 'react'; import { inject, observer } from 'mobx-react'; -import globalUserStore from 'stores/keystone/user'; -import { has } from 'lodash'; import { ModalAction } from 'containers/Action'; -import { Select } from 'antd'; -import globalProjectStore from 'stores/keystone/project'; -import globalRoleStore from 'stores/keystone/role'; import globalDomainStore from 'stores/keystone/domain'; import globalGroupStore from 'stores/keystone/user-group'; +import { getDomainFormItem } from 'resources/keystone/domain'; -export class CreateForm extends ModalAction { - constructor(props) { - super(props); - this.state = { - domain: null, - more: false, - newProjectRoles: {}, - }; - } - +export class Create extends ModalAction { init() { - this.userStore = globalUserStore; - this.userGroupStore = globalGroupStore; - this.projectStore = globalProjectStore; + this.store = globalGroupStore; this.domainStore = globalDomainStore; - this.roleStore = globalRoleStore; - this.getUser(); - this.getProject(); - this.getDomains(); - this.getRole(); - } - - getUser() { - this.userStore.fetchList(); - } - - getProject() { - this.projectStore.fetchList(); - } - - getDomains() { this.domainStore.fetchDomain(); } - getRole() { - this.roleStore.fetchList(); - } - static id = 'user-group-create'; static title = t('Create User Group'); - // static path = '/identity/user-group-admin/create'; - - static policy = ['identity:create_group', 'identity:add_user_to_group']; + static policy = 'identity:create_group'; static allowed() { return Promise.resolve(true); @@ -77,128 +39,20 @@ export class CreateForm extends ModalAction { return t('Create User Group'); } - get domainDefault() { - const { domains } = this.domainStore; - const domainDefault = domains.filter((it) => it.id === 'default'); - return domainDefault[0]; - } - get defaultValue() { const data = { - more: false, + domain_id: 'default', }; return data; } - get domainList() { - const { domains } = this.domainStore; - return (domains || []).map((it) => ({ - label: it.name, - value: it.id, - })); - } - - get userList() { - return (this.userStore.list.data || []).map((it) => ({ - ...it, - key: it.id, - })); - } - - get projects() { - return (this.projectStore.list.data || []).map((it) => ({ - ...it, - key: it.id, - })); - } - - groupRolesList = (groupId) => { - return (this.roleStore.list.data || []).map((it) => ({ - label: it.name, - value: it.id, - groupId, - })); - }; - - defaultRoles = () => { - return [this.roleStore.list.data[0].id]; - }; - - groupRoleChange = (value, option) => { - const { newProjectRoles } = this.state; - const { groupId } = option[0]; - newProjectRoles[groupId] = value; - this.setState({ newProjectRoles }); - }; - - onValuesChange = (changedFields) => { - if (has(changedFields, 'more')) { - this.setState({ - more: changedFields.more, - }); - } - }; - - get leftProjectTable() { - return [ - { - dataIndex: 'name', - title: t('Name'), - }, - ]; - } - - get rightProjectTable() { - return [ - { - dataIndex: 'name', - title: t('Name'), - }, - { - title: t('Select Project Role'), - dataIndex: 'id', - render: (id) => { - return ( -