fix: fix the network IP availability showing

By default policy configuration, only administrative users can retrieve IP availability. Otherwise, Not Found (404) will be returned

Closes-Bug: #2003303
Change-Id: I9e3232dc5828208d3ef08b033d953501fe93fed8
This commit is contained in:
xusongfu 2023-02-18 22:15:52 +08:00
parent 0a192be466
commit 520504e26d
7 changed files with 20 additions and 17 deletions

View File

@ -0,0 +1,10 @@
---
fixes:
- |
`Bug #2003303 <https://bugs.launchpad.net/skyline-console/+bug/2003303>`:
Fix the network IP availability showing by role.
By default policy configuration, only administrative users can retrieve IP availability.
Otherwise, Not Found (404) will be returned.

View File

@ -17,7 +17,6 @@ import Base from 'containers/TabDetail';
import { NetworkStore } from 'stores/neutron/network'; import { NetworkStore } from 'stores/neutron/network';
import { networkStatus } from 'resources/neutron/network'; import { networkStatus } from 'resources/neutron/network';
import Port from 'pages/network/containers/Port'; import Port from 'pages/network/containers/Port';
import globalRootStore from 'stores/root';
import Subnet from 'pages/network/containers/Subnet'; import Subnet from 'pages/network/containers/Subnet';
import Detail from './Detail'; import Detail from './Detail';
import actionConfigs from '../actions'; import actionConfigs from '../actions';
@ -50,17 +49,14 @@ export class NetworkDetail extends Base {
.fetchDetailWithAvailabilityAndUsage({ .fetchDetailWithAvailabilityAndUsage({
...newParams, ...newParams,
isAdminPage: this.isAdminPage, isAdminPage: this.isAdminPage,
currentProjectId: globalRootStore.user.project.id, canAddNetworkIPUsageInfo: this.canAddNetworkIPUsageInfo,
}) })
.catch(this.catch); .catch(this.catch);
} }
}; };
get canAddNetworkIPUsageInfo() { get canAddNetworkIPUsageInfo() {
return ( return this.store.hasAdminRole;
this.isAdminPage ||
globalRootStore.user.project.id === this.detailData.project_id
);
} }
get detailInfos() { get detailInfos() {

View File

@ -26,9 +26,7 @@ export class BaseDetail extends Base {
} }
get canAddNetworkIPUsageInfo() { get canAddNetworkIPUsageInfo() {
return ( return this.store.hasAdminRole;
this.isAdminPage || this.currentProjectId === this.detailData.project_id
);
} }
get networkCard() { get networkCard() {

View File

@ -45,6 +45,7 @@ export class SubnetDetail extends Base {
return { return {
...params, ...params,
inDetail: true, inDetail: true,
canAddNetworkIPUsageInfo: this.store.hasAdminRole,
}; };
}; };

View File

@ -49,9 +49,7 @@ export class Subnets extends Base {
}; };
get canAddNetworkIPUsageInfo() { get canAddNetworkIPUsageInfo() {
return ( return this.store.hasAdminRole;
this.isAdminPage || this.currentProjectId === this.props.detail.project_id
);
} }
getColumns = () => { getColumns = () => {

View File

@ -133,7 +133,7 @@ export class NetworkStore extends Base {
async fetchDetailWithAvailabilityAndUsage({ async fetchDetailWithAvailabilityAndUsage({
id, id,
isAdminPage, isAdminPage,
currentProjectId, canAddNetworkIPUsageInfo,
}) { }) {
this.isLoading = true; this.isLoading = true;
const result = await this.client.show(id); const result = await this.client.show(id);
@ -167,8 +167,8 @@ export class NetworkStore extends Base {
projectName: projectDetail.name, projectName: projectDetail.name,
}; };
// Only the administrator or the current network owner can view the number of IP addresses used // Only the administrator can view the number of IP addresses used
if (isAdminPage || currentProjectId === originData.project_id) { if (canAddNetworkIPUsageInfo) {
const used = await this.ipClient.show(id); const used = await this.ipClient.show(id);
this.detail = { this.detail = {
...this.detail, ...this.detail,

View File

@ -89,7 +89,7 @@ export class SubnetStore extends Base {
} }
async detailDidFetch(item, allProjects, filters) { async detailDidFetch(item, allProjects, filters) {
const { inDetail = false } = filters; const { inDetail = false, canAddNetworkIPUsageInfo = false } = filters;
if (!inDetail) { if (!inDetail) {
return item; return item;
} }
@ -97,7 +97,7 @@ export class SubnetStore extends Base {
const networkParams = { const networkParams = {
id: network_id, id: network_id,
isAdminPage: allProjects, isAdminPage: allProjects,
currentProjectId: this.currentProjectId, canAddNetworkIPUsageInfo,
}; };
const { NetworkStore } = require('stores/neutron/network'); const { NetworkStore } = require('stores/neutron/network');
const network = const network =