diff --git a/ui/src/config/section/network.js b/ui/src/config/section/network.js index 9685fb05811..b5385d92a12 100644 --- a/ui/src/config/section/network.js +++ b/ui/src/config/section/network.js @@ -98,6 +98,17 @@ export default { docHelp: 'adminguide/networking_and_traffic.html#configure-guest-traffic-in-an-advanced-zone', listView: true, popup: true, + show: () => { + if (!store.getters.zones || store.getters.zones.length === 0) { + return false + } + const AdvancedZones = store.getters.zones.filter(zone => zone.networktype === 'Advanced') + const AdvancedZonesWithoutSG = store.getters.zones.filter(zone => zone.securitygroupsenabled === false) + if ((isAdmin() && AdvancedZones && AdvancedZones.length > 0) || (AdvancedZonesWithoutSG && AdvancedZonesWithoutSG.length > 0)) { + return true + } + return false + }, component: shallowRef(defineAsyncComponent(() => import('@/views/network/CreateNetwork.vue'))) }, { diff --git a/ui/src/views/compute/wizard/NetworkSelection.vue b/ui/src/views/compute/wizard/NetworkSelection.vue index 68c914eb6ba..96a6d28ecf1 100644 --- a/ui/src/views/compute/wizard/NetworkSelection.vue +++ b/ui/src/views/compute/wizard/NetworkSelection.vue @@ -22,7 +22,7 @@ :placeholder="$t('label.search')" v-model:value="filter" @search="handleSearch" /> - + {{ $t('label.create.network') }} import _ from 'lodash' import { api } from '@/api' +import { isAdmin } from '@/role' import store from '@/store' import CreateNetwork from '@/views/network/CreateNetwork' import ResourceIcon from '@/components/view/ResourceIcon' @@ -150,6 +151,7 @@ export default { loading: false, opts: [] }, + showCreateButton: false, showCreateForm: false, oldZoneId: null, options: { @@ -237,6 +239,13 @@ export default { } }, loading () { + api('listZones', { id: this.zoneId }).then(json => { + const zoneResponse = json.listzonesresponse.zone || [] + this.showCreateButton = false + if (zoneResponse && zoneResponse.length > 0 && (!zoneResponse[0].securitygroupsenabled || (isAdmin() && zoneResponse[0].networktype === 'Advanced'))) { + this.showCreateButton = true + } + }) if (!this.loading) { if (this.preFillContent.networkids) { this.selectedRowKeys = this.preFillContent.networkids diff --git a/ui/src/views/network/CreateL2NetworkForm.vue b/ui/src/views/network/CreateL2NetworkForm.vue index 8da95d31209..82a9a0a8943 100644 --- a/ui/src/views/network/CreateL2NetworkForm.vue +++ b/ui/src/views/network/CreateL2NetworkForm.vue @@ -302,7 +302,7 @@ export default { api('listZones', params).then(json => { for (const i in json.listzonesresponse.zone) { const zone = json.listzonesresponse.zone[i] - if (zone.networktype === 'Advanced') { + if (zone.networktype === 'Advanced' && zone.securitygroupsenabled !== true) { this.zones.push(zone) } } diff --git a/ui/src/views/network/CreateNetwork.vue b/ui/src/views/network/CreateNetwork.vue index 168a1083505..82aef814037 100644 --- a/ui/src/views/network/CreateNetwork.vue +++ b/ui/src/views/network/CreateNetwork.vue @@ -26,7 +26,7 @@ @refresh-data="refreshParent" @refresh="handleRefresh"/> - + - + { - this.isAdvancedZoneWithoutSGAvailable = false - this.defaultNetworkTypeTabKey = '2' - - for (const i in this.actionZones) { - const zone = this.actionZones[i] - if (zone.networktype === 'Advanced' && zone.securitygroupsenabled !== true) { - this.isAdvancedZoneWithoutSGAvailable = true - this.defaultNetworkTypeTabKey = '1' - return - } + watch: { + resource: { + deep: true, + handler () { + this.fetchData() } - }) + } + }, + created () { + this.fetchData() }, methods: { + fetchData () { + const promises = [] + promises.push(this.fetchActionZoneData()) + Promise.all(promises).then(() => { + this.isAdvancedZoneWithoutSGAvailable = false + this.defaultNetworkTypeTabKey = '2' + + for (const i in this.actionZones) { + const zone = this.actionZones[i] + if (zone.networktype === 'Advanced' && zone.securitygroupsenabled !== true) { + this.isAdvancedZoneWithoutSGAvailable = true + this.defaultNetworkTypeTabKey = '1' + return + } + } + }) + }, fetchActionZoneData () { this.loading = true const params = {} - if (this.resource && this.resource.zoneid) { + if (this.resource.zoneid && this.$route.name === 'deployVirtualMachine') { params.id = this.resource.zoneid } - this.actionZonesLoading = true + this.actionZoneLoading = true return api('listZones', params).then(json => { this.actionZones = json.listzonesresponse.zone }).finally(() => { diff --git a/ui/src/views/network/CreateSharedNetworkForm.vue b/ui/src/views/network/CreateSharedNetworkForm.vue index 6f4f61a4691..87a3375f3db 100644 --- a/ui/src/views/network/CreateSharedNetworkForm.vue +++ b/ui/src/views/network/CreateSharedNetworkForm.vue @@ -139,13 +139,13 @@ {{ $t('label.all') }} - + {{ $t('label.domain') }} - + {{ $t('label.account') }} - + {{ $t('label.project') }} @@ -648,7 +648,7 @@ export default { api('listZones', params).then(json => { for (const i in json.listzonesresponse.zone) { const zone = json.listzonesresponse.zone[i] - if (zone.networktype === 'Advanced') { + if (zone.networktype === 'Advanced' && (isAdmin() || zone.securitygroupsenabled !== true)) { this.zones.push(zone) } }