Skip to content

Commit 0fd416d

Browse files
UI: Enable shared network with scope option in advanced zone with SG (#7067)
1 parent 6f6cec5 commit 0fd416d

File tree

5 files changed

+56
-25
lines changed

5 files changed

+56
-25
lines changed

ui/src/config/section/network.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ export default {
9898
docHelp: 'adminguide/networking_and_traffic.html#configure-guest-traffic-in-an-advanced-zone',
9999
listView: true,
100100
popup: true,
101+
show: () => {
102+
if (!store.getters.zones || store.getters.zones.length === 0) {
103+
return false
104+
}
105+
const AdvancedZones = store.getters.zones.filter(zone => zone.networktype === 'Advanced')
106+
const AdvancedZonesWithoutSG = store.getters.zones.filter(zone => zone.securitygroupsenabled === false)
107+
if ((isAdmin() && AdvancedZones && AdvancedZones.length > 0) || (AdvancedZonesWithoutSG && AdvancedZonesWithoutSG.length > 0)) {
108+
return true
109+
}
110+
return false
111+
},
101112
component: shallowRef(defineAsyncComponent(() => import('@/views/network/CreateNetwork.vue')))
102113
},
103114
{

ui/src/views/compute/wizard/NetworkSelection.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
:placeholder="$t('label.search')"
2323
v-model:value="filter"
2424
@search="handleSearch" />
25-
<a-button type="primary" @click="onCreateNetworkClick" style="float: right; margin-right: 5px; z-index: 8">
25+
<a-button type="primary" @click="onCreateNetworkClick" style="float: right; margin-right: 5px; z-index: 8" v-if="showCreateButton">
2626
{{ $t('label.create.network') }}
2727
</a-button>
2828
<a-table
@@ -100,6 +100,7 @@
100100
<script>
101101
import _ from 'lodash'
102102
import { api } from '@/api'
103+
import { isAdmin } from '@/role'
103104
import store from '@/store'
104105
import CreateNetwork from '@/views/network/CreateNetwork'
105106
import ResourceIcon from '@/components/view/ResourceIcon'
@@ -150,6 +151,7 @@ export default {
150151
loading: false,
151152
opts: []
152153
},
154+
showCreateButton: false,
153155
showCreateForm: false,
154156
oldZoneId: null,
155157
options: {
@@ -237,6 +239,13 @@ export default {
237239
}
238240
},
239241
loading () {
242+
api('listZones', { id: this.zoneId }).then(json => {
243+
const zoneResponse = json.listzonesresponse.zone || []
244+
this.showCreateButton = false
245+
if (zoneResponse && zoneResponse.length > 0 && (!zoneResponse[0].securitygroupsenabled || (isAdmin() && zoneResponse[0].networktype === 'Advanced'))) {
246+
this.showCreateButton = true
247+
}
248+
})
240249
if (!this.loading) {
241250
if (this.preFillContent.networkids) {
242251
this.selectedRowKeys = this.preFillContent.networkids

ui/src/views/network/CreateL2NetworkForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export default {
302302
api('listZones', params).then(json => {
303303
for (const i in json.listzonesresponse.zone) {
304304
const zone = json.listzonesresponse.zone[i]
305-
if (zone.networktype === 'Advanced') {
305+
if (zone.networktype === 'Advanced' && zone.securitygroupsenabled !== true) {
306306
this.zones.push(zone)
307307
}
308308
}

ui/src/views/network/CreateNetwork.vue

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
@refresh-data="refreshParent"
2727
@refresh="handleRefresh"/>
2828
</a-tab-pane>
29-
<a-tab-pane :tab="$t('label.l2')" key="2">
29+
<a-tab-pane :tab="$t('label.l2')" key="3" v-if="isAdvancedZoneWithoutSGAvailable">
3030
<CreateL2NetworkForm
3131
:loading="loading"
3232
:resource="resource"
3333
@close-action="closeAction"
3434
@refresh-data="refreshParent"
3535
@refresh="handleRefresh"/>
3636
</a-tab-pane>
37-
<a-tab-pane :tab="$t('label.shared')" key="3">
37+
<a-tab-pane :tab="$t('label.shared')" key="2">
3838
<CreateSharedNetworkForm
3939
:loading="loading"
4040
:resource="resource"
@@ -74,31 +74,42 @@ export default {
7474
actionZoneLoading: false
7575
}
7676
},
77-
created () {
78-
const promises = []
79-
promises.push(this.fetchActionZoneData())
80-
Promise.all(promises).then(() => {
81-
this.isAdvancedZoneWithoutSGAvailable = false
82-
this.defaultNetworkTypeTabKey = '2'
83-
84-
for (const i in this.actionZones) {
85-
const zone = this.actionZones[i]
86-
if (zone.networktype === 'Advanced' && zone.securitygroupsenabled !== true) {
87-
this.isAdvancedZoneWithoutSGAvailable = true
88-
this.defaultNetworkTypeTabKey = '1'
89-
return
90-
}
77+
watch: {
78+
resource: {
79+
deep: true,
80+
handler () {
81+
this.fetchData()
9182
}
92-
})
83+
}
84+
},
85+
created () {
86+
this.fetchData()
9387
},
9488
methods: {
89+
fetchData () {
90+
const promises = []
91+
promises.push(this.fetchActionZoneData())
92+
Promise.all(promises).then(() => {
93+
this.isAdvancedZoneWithoutSGAvailable = false
94+
this.defaultNetworkTypeTabKey = '2'
95+
96+
for (const i in this.actionZones) {
97+
const zone = this.actionZones[i]
98+
if (zone.networktype === 'Advanced' && zone.securitygroupsenabled !== true) {
99+
this.isAdvancedZoneWithoutSGAvailable = true
100+
this.defaultNetworkTypeTabKey = '1'
101+
return
102+
}
103+
}
104+
})
105+
},
95106
fetchActionZoneData () {
96107
this.loading = true
97108
const params = {}
98-
if (this.resource && this.resource.zoneid) {
109+
if (this.resource.zoneid && this.$route.name === 'deployVirtualMachine') {
99110
params.id = this.resource.zoneid
100111
}
101-
this.actionZonesLoading = true
112+
this.actionZoneLoading = true
102113
return api('listZones', params).then(json => {
103114
this.actionZones = json.listzonesresponse.zone
104115
}).finally(() => {

ui/src/views/network/CreateSharedNetworkForm.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@
139139
<a-radio-button value="all" v-if="isAdmin()">
140140
{{ $t('label.all') }}
141141
</a-radio-button>
142-
<a-radio-button value="domain" v-if="!parseBooleanValueForKey(selectedZone, 'securitygroupsenabled') && isAdminOrDomainAdmin()">
142+
<a-radio-button value="domain" v-if="!parseBooleanValueForKey(selectedZone, 'securitygroupsenabled') && isAdminOrDomainAdmin() || 'Advanced' === selectedZone.networktype && isAdmin()">
143143
{{ $t('label.domain') }}
144144
</a-radio-button>
145-
<a-radio-button value="account" v-if="!parseBooleanValueForKey(selectedZone, 'securitygroupsenabled')">
145+
<a-radio-button value="account" v-if="!parseBooleanValueForKey(selectedZone, 'securitygroupsenabled') || 'Advanced' === selectedZone.networktype && isAdmin()">
146146
{{ $t('label.account') }}
147147
</a-radio-button>
148-
<a-radio-button value="project" v-if="!parseBooleanValueForKey(selectedZone, 'securitygroupsenabled')">
148+
<a-radio-button value="project" v-if="!parseBooleanValueForKey(selectedZone, 'securitygroupsenabled') || 'Advanced' === selectedZone.networktype && isAdmin()">
149149
{{ $t('label.project') }}
150150
</a-radio-button>
151151
</a-radio-group>
@@ -648,7 +648,7 @@ export default {
648648
api('listZones', params).then(json => {
649649
for (const i in json.listzonesresponse.zone) {
650650
const zone = json.listzonesresponse.zone[i]
651-
if (zone.networktype === 'Advanced') {
651+
if (zone.networktype === 'Advanced' && (isAdmin() || zone.securitygroupsenabled !== true)) {
652652
this.zones.push(zone)
653653
}
654654
}

0 commit comments

Comments
 (0)