// Copyright 2021 99cloud // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 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 { Select } from 'antd'; import globalProjectStore from 'stores/keystone/project'; import { GroupStore } from 'stores/keystone/user-group'; import globalRoleStore from 'stores/keystone/role'; import { ModalAction } from 'containers/Action'; import { nameDomainColumns, transferFilterOption, } from 'resources/keystone/domain'; import { roleFilterOption } from 'resources/keystone/role'; export class ManageUserGroup extends ModalAction { static id = 'manage-group-group'; static title = t('Manage User Group'); async init() { this.state.groupRoles = this.getInitRoleMap(); this.userGroupStore = new GroupStore(); this.store = globalRoleStore; this.getRoleList(); this.getGroupGroup(); } get name() { return t('Manage user group'); } getInitRoleMap() { const { groups = {} } = this.item; return Object.keys(groups).reduce((pre, cur) => { pre[cur] = groups[cur].map((it) => it.id); return pre; }, {}); } getGroupGroup() { this.userGroupStore.fetchList(); } getRoleList() { this.store.fetchList(); } static get modalSize() { return 'large'; } getModalSize() { return 'large'; } get labelCol() { return { xs: { span: 4 }, sm: { span: 2 }, }; } get wrapperCol() { return { xs: { span: 20 }, sm: { span: 20 }, }; } get groupList() { return (this.userGroupStore.list.data || []).map((it) => ({ ...it, key: it.id, })); } get projectRoleList() { return this.store.list.data || []; } groupRolesList = (groupId) => this.projectRoleList.map((it) => ({ label: it.name, value: it.id, key: it.id, groupId, })); defaultRoles = (groupId) => { const { groups } = this.item; if (!groups[groupId]) { return [this.projectRoleList[0].id]; } const groupProjectRole = groups[groupId].map((it) => { return it.id; }); return groupProjectRole; }; static policy = 'identity:update_project'; static allowed = () => Promise.resolve(true); get leftGroupGroupTable() { return nameDomainColumns; } renderSelect = (groupId) => { return (