feat: support quota info when create subnet

1. Support subnet quota info when create subnet
2. Disable create subnet when left quota is zero
3. Optimize the action disabled check by hasAdminRole in rootStore, not policy
4. Support fetch project subnet quota when project change
5. Optimize project select tip
6. Optimize the project id of current network

Change-Id: Ic7b7b528dcc2e2e3ec23cd8be039a10afa3f197a
This commit is contained in:
Jingwei.Zhang 2022-06-24 10:26:20 +08:00
parent 0ce38d730a
commit 31876de016
3 changed files with 90 additions and 12 deletions

View File

@ -2257,6 +2257,7 @@
"The security group is similar to the firewall function for setting up network access control, or you can go to the console and create a new security group. (Note: The security group you selected will work on all virtual LANS on the instances.)": "The security group is similar to the firewall function for setting up network access control, or you can go to the console and create a new security group. (Note: The security group you selected will work on all virtual LANS on the instances.)",
"The selected VPC/ subnet does not have IPv6 enabled.": "The selected VPC/ subnet does not have IPv6 enabled.",
"The selected network has no subnet": "The selected network has no subnet",
"The selected project is different from the project to which the network belongs. That is, the subnet to be created is not under the same project as the network. Please do not continue unless you are quit sure what you are doing.": "The selected project is different from the project to which the network belongs. That is, the subnet to be created is not under the same project as the network. Please do not continue unless you are quit sure what you are doing.",
"The server {name} is locked. Please unlock first.": "The server {name} is locked. Please unlock first.",
"The session has expired, please log in again.": "The session has expired, please log in again.",
"The shelved offloaded instance only supports immediate deletion": "The shelved offloaded instance only supports immediate deletion",
@ -2510,7 +2511,6 @@
"You are not allowed to { action } {name}.": "You are not allowed to { action } {name}.",
"You are not allowed to {action}, instance: {name}.": "You are not allowed to {action}, instance: {name}.",
"You are not allowed to {action}.": "You are not allowed to {action}.",
"You are trying to edit a network that not belong to current project. Please do not continue unless you are quit sure what you are doing.": "You are trying to edit a network that not belong to current project. Please do not continue unless you are quit sure what you are doing.",
"You can manually specify a physical node to create an instance.": "You can manually specify a physical node to create an instance.",
"You don't have access to get {name}.": "You don't have access to get {name}.",
"Yugoslavia": "Yugoslavia",

View File

@ -2257,6 +2257,7 @@
"The security group is similar to the firewall function for setting up network access control, or you can go to the console and create a new security group. (Note: The security group you selected will work on all virtual LANS on the instances.)": "安全组类似防火墙功能,用于设置网络访问控制,您也可以前往控制台新建安全组。(注:您所选的安全组将作用于云主机的全部虚拟网卡。)",
"The selected VPC/ subnet does not have IPv6 enabled.": "所选的VPC/子网未开通IPv6",
"The selected network has no subnet": "选择的网络没有子网",
"The selected project is different from the project to which the network belongs. That is, the subnet to be created is not under the same project as the network. Please do not continue unless you are quit sure what you are doing.": "您选择的项目与网络所属项目不一致,即您将创建的子网与网络不在同一项目下。除非你非常确认自己在做什么,否则请不要继续。",
"The server {name} is locked. Please unlock first.": "云主机{name}已被锁定,请先解锁。",
"The session has expired, please log in again.": "会话已过期,请重新登录。",
"The shelved offloaded instance only supports immediate deletion": "已归档的云主机仅支持立即删除",
@ -2510,7 +2511,6 @@
"You are not allowed to { action } {name}.": "无法{ action }{ name }。",
"You are not allowed to {action}, instance: {name}.": "无法{ action } 实例名称:{ name }。",
"You are not allowed to {action}.": "无法{ action }。",
"You are trying to edit a network that not belong to current project. Please do not continue unless you are quit sure what you are doing.": "你正在尝试编辑非当前 project 的 network 资源,除非你非常确认自己在做什么,否则请不要继续。",
"You can manually specify a physical node to create an instance.": "您可以手动指定一台物理节点来创建云主机。",
"You don't have access to get {name}.": "您没有权限访问{name}。",
"Yugoslavia": "南斯拉夫",

View File

@ -17,7 +17,6 @@ import { ModalAction } from 'containers/Action';
import { ipValidate } from 'utils/validate';
import globalNetworkStore from 'stores/neutron/network';
import { isEmpty } from 'lodash';
import { checkPolicyRule } from 'resources/skyline/policy';
import globalProjectStore from 'stores/keystone/project';
import globalRootStore from 'stores/root';
import { subnetIpv6Tip } from 'resources/neutron/network';
@ -65,14 +64,62 @@ export class CreateSubnet extends ModalAction {
}
init() {
this.state.projectId = this.currentProjectId;
this.state.quota = {};
this.state.quotaLoading = true;
this.projectStore = globalProjectStore;
this.isSystemAdmin && this.getProjects();
this.getQuota();
}
getProjects() {
this.projectStore.fetchList();
}
static get disableSubmit() {
const {
neutronQuota: { subnet: { left = 0 } = {} },
} = globalProjectStore;
return left === 0;
}
static get showQuota() {
return true;
}
get showQuota() {
return true;
}
async getQuota() {
const { projectId } = this.state;
this.setState({
quotaLoading: true,
});
const result = await this.projectStore.fetchProjectNeutronQuota(projectId);
const { subnet: quota = {} } = result || {};
this.setState({
quota,
quotaLoading: false,
});
}
get quotaInfo() {
const { quota = {}, quotaLoading } = this.state;
if (quotaLoading) {
return [];
}
const { left = 0 } = quota;
const add = left === 0 ? 0 : 1;
const data = {
...quota,
add,
name: 'subnet',
title: t('Subnet'),
};
return [data];
}
checkCidr = (value) => {
const { ip_version = 'ipv4' } = this.state;
@ -108,27 +155,57 @@ export class CreateSubnet extends ModalAction {
static policy = 'create_subnet';
static allowed = (item) => {
static allowed = (item, containerProps) => {
const { project_id } = item || {};
const { detail: { project_id: detailProjectId } = {} } =
containerProps || {};
const networkProjectId = project_id || detailProjectId;
const rootStore = globalRootStore;
if (
!checkPolicyRule('skyline:system_admin') &&
item.project_id !== rootStore.user.project.id
) {
const {
hasAdminRole = false,
user: { project: { id: userProjectId } = {} } = {},
} = rootStore;
if (!hasAdminRole && networkProjectId !== userProjectId) {
return Promise.resolve(false);
}
return Promise.resolve(true);
};
get isSystemAdmin() {
return checkPolicyRule('skyline:system_admin');
return this.props.rootStore.hasAdminRole;
}
validateAllocationPools = (rule, value) => {
return validateAllocationPoolsWithGatewayIp.call(this, rule, value);
};
onProjectChange = (value) => {
this.setState(
{
projectId: value,
},
() => {
this.getQuota();
}
);
};
get networkProjectId() {
const { project_id } = this.item;
if (project_id) {
return project_id;
}
const { detail = {} } = this.containerProps;
return detail.project_id;
}
get formItems() {
const { more, ip_version = 'ipv4', disable_gateway = false } = this.state;
const {
more,
ip_version = 'ipv4',
disable_gateway = false,
projectId,
} = this.state;
const isIpv4 = ip_version === 'ipv4';
const projectOptions = globalProjectStore.list.data.map((project) => ({
label: project.name,
@ -151,11 +228,12 @@ export class CreateSubnet extends ModalAction {
hidden: !this.isSystemAdmin,
showSearch: true,
extra:
this.currentProjectId !== this.item.project_id &&
projectId !== this.networkProjectId &&
t(
'You are trying to edit a network that not belong to current project. Please do not continue unless you are quit sure what you are doing.'
'The selected project is different from the project to which the network belongs. That is, the subnet to be created is not under the same project as the network. Please do not continue unless you are quit sure what you are doing.'
),
options: projectOptions,
onChange: this.onProjectChange,
},
{
name: 'ip_version',