conditional broadcastUri (#5745)

* conditional broadcastUri

* add filter to keep order and apply to details as well

* use global isAdmin method

Co-authored-by: Daan Hoogland <dahn@onecht.net>
This commit is contained in:
dahn 2021-12-08 05:57:58 +01:00 committed by GitHub
parent a47e53fcee
commit 8bc69e919c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 83 additions and 52 deletions

View File

@ -16,6 +16,7 @@
// under the License. // under the License.
import store from '@/store' import store from '@/store'
import { isAdmin } from '@/role'
export default { export default {
name: 'network', name: 'network',
@ -29,8 +30,20 @@ export default {
icon: 'apartment', icon: 'apartment',
permission: ['listNetworks'], permission: ['listNetworks'],
resourceType: 'Network', resourceType: 'Network',
columns: ['name', 'state', 'type', 'vpcname', 'cidr', 'ip6cidr', 'broadcasturi', 'domain', 'account', 'zonename'], columns: () => {
details: ['name', 'id', 'description', 'type', 'traffictype', 'vpcid', 'vlan', 'broadcasturi', 'cidr', 'ip6cidr', 'netmask', 'gateway', 'aclname', 'ispersistent', 'restartrequired', 'reservediprange', 'redundantrouter', 'networkdomain', 'zonename', 'account', 'domain'], var fields = ['name', 'state', 'type', 'vpcname', 'cidr', 'ip6cidr', 'broadcasturi', 'domain', 'account', 'zonename']
if (!isAdmin()) {
fields = fields.filter(function (e) { return e !== 'broadcasturi' })
}
return fields
},
details: () => {
var fields = ['name', 'id', 'description', 'type', 'traffictype', 'vpcid', 'vlan', 'broadcasturi', 'cidr', 'ip6cidr', 'netmask', 'gateway', 'aclname', 'ispersistent', 'restartrequired', 'reservediprange', 'redundantrouter', 'networkdomain', 'zonename', 'account', 'domain']
if (!isAdmin()) {
fields = fields.filter(function (e) { return e !== 'broadcasturi' })
}
return fields
},
filters: ['all', 'isolated', 'shared', 'l2'], filters: ['all', 'isolated', 'shared', 'l2'],
searchFilters: ['keyword', 'zoneid', 'domainid', 'account', 'tags'], searchFilters: ['keyword', 'zoneid', 'domainid', 'account', 'tags'],
related: [{ related: [{

26
ui/src/role/index.js Normal file
View File

@ -0,0 +1,26 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 store from '@/store'
export function isAdmin () {
return ['Admin'].includes(store.getters.userInfo.roletype)
}
export function isAdminOrDomainAdmin () {
return ['Admin', 'DomainAdmin'].includes(this.$store.getters.userInfo.roletype)
}

View File

@ -150,6 +150,7 @@
<script> <script>
import { api } from '@/api' import { api } from '@/api'
import { isAdmin } from '@/role'
import { mixinDevice } from '@/utils/mixin.js' import { mixinDevice } from '@/utils/mixin.js'
import DetailsTab from '@/components/view/DetailsTab' import DetailsTab from '@/components/view/DetailsTab'
import FirewallRules from '@/views/network/FirewallRules' import FirewallRules from '@/views/network/FirewallRules'
@ -230,7 +231,7 @@ export default {
dataIndex: 'zonename' dataIndex: 'zonename'
} }
] ]
if (!this.isAdmin()) { if (!isAdmin()) {
this.vmColumns = this.vmColumns.filter(x => x.dataIndex !== 'instancename') this.vmColumns = this.vmColumns.filter(x => x.dataIndex !== 'instancename')
} }
this.handleFetchData() this.handleFetchData()
@ -279,12 +280,6 @@ export default {
}).join('&') }).join('&')
) )
}, },
isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
},
isAdminOrDomainAdmin () {
return ['Admin', 'DomainAdmin'].includes(this.$store.getters.userInfo.roletype)
},
isValidValueForKey (obj, key) { isValidValueForKey (obj, key) {
return key in obj && obj[key] != null return key in obj && obj[key] != null
}, },

View File

@ -68,7 +68,7 @@
</a-select-option> </a-select-option>
</a-select> </a-select>
</a-form-item> </a-form-item>
<a-form-item v-if="this.isAdminOrDomainAdmin()"> <a-form-item v-if="isAdminOrDomainAdmin()">
<tooltip-label slot="label" :title="$t('label.domainid')" :tooltip="apiParams.domainid.description"/> <tooltip-label slot="label" :title="$t('label.domainid')" :tooltip="apiParams.domainid.description"/>
<a-select <a-select
v-decorator="['domainid', {}]" v-decorator="['domainid', {}]"
@ -193,6 +193,7 @@
<script> <script>
import { api } from '@/api' import { api } from '@/api'
import { isAdmin, isAdminOrDomainAdmin } from '@/role'
import ResourceIcon from '@/components/view/ResourceIcon' import ResourceIcon from '@/components/view/ResourceIcon'
import TooltipLabel from '@/components/widgets/TooltipLabel' import TooltipLabel from '@/components/widgets/TooltipLabel'
@ -231,7 +232,7 @@ export default {
vpcs: [], vpcs: [],
vpcLoading: false, vpcLoading: false,
selectedVpc: {}, selectedVpc: {},
accountVisible: this.isAdminOrDomainAdmin() accountVisible: isAdminOrDomainAdmin()
} }
}, },
watch: { watch: {
@ -257,11 +258,8 @@ export default {
this.fetchDomainData() this.fetchDomainData()
this.fetchZoneData() this.fetchZoneData()
}, },
isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
},
isAdminOrDomainAdmin () { isAdminOrDomainAdmin () {
return ['Admin', 'DomainAdmin'].includes(this.$store.getters.userInfo.roletype) return isAdminOrDomainAdmin()
}, },
isObjectEmpty (obj) { isObjectEmpty (obj) {
return !(obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object) return !(obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object)
@ -320,7 +318,7 @@ export default {
handleDomainChange (domain) { handleDomainChange (domain) {
this.selectedDomain = domain this.selectedDomain = domain
this.accountVisible = domain.id !== '-1' this.accountVisible = domain.id !== '-1'
if (this.isAdminOrDomainAdmin()) { if (isAdminOrDomainAdmin()) {
this.updateVPCCheckAndFetchNetworkOfferingData() this.updateVPCCheckAndFetchNetworkOfferingData()
} }
}, },
@ -349,10 +347,10 @@ export default {
supportedServices: 'SourceNat', supportedServices: 'SourceNat',
state: 'Enabled' state: 'Enabled'
} }
if (this.isAdminOrDomainAdmin() && this.selectedDomain.id !== '-1') { // domain is visible only for admins if (isAdminOrDomainAdmin() && this.selectedDomain.id !== '-1') { // domain is visible only for admins
params.domainid = this.selectedDomain.id params.domainid = this.selectedDomain.id
} }
if (!this.isAdmin()) { // normal user is not aware of the VLANs in the system, so normal user is not allowed to create network with network offerings whose specifyvlan = true if (!isAdmin()) { // normal user is not aware of the VLANs in the system, so normal user is not allowed to create network with network offerings whose specifyvlan = true
params.specifyvlan = false params.specifyvlan = false
} }
if (forVpc !== null) { if (forVpc !== null) {

View File

@ -68,7 +68,7 @@
</a-select-option> </a-select-option>
</a-select> </a-select>
</a-form-item> </a-form-item>
<a-form-item v-if="this.isAdminOrDomainAdmin()"> <a-form-item v-if="isAdminOrDomainAdmin()">
<tooltip-label slot="label" :title="$t('label.domainid')" :tooltip="apiParams.domainid.description"/> <tooltip-label slot="label" :title="$t('label.domainid')" :tooltip="apiParams.domainid.description"/>
<a-select <a-select
v-decorator="['domainid', {}]" v-decorator="['domainid', {}]"
@ -180,6 +180,7 @@
<script> <script>
import { api } from '@/api' import { api } from '@/api'
import { isAdmin, isAdminOrDomainAdmin } from '@/role'
import ResourceIcon from '@/components/view/ResourceIcon' import ResourceIcon from '@/components/view/ResourceIcon'
import TooltipLabel from '@/components/widgets/TooltipLabel' import TooltipLabel from '@/components/widgets/TooltipLabel'
@ -215,7 +216,7 @@ export default {
networkOfferings: [], networkOfferings: [],
networkOfferingLoading: false, networkOfferingLoading: false,
selectedNetworkOffering: {}, selectedNetworkOffering: {},
accountVisible: this.isAdminOrDomainAdmin(), accountVisible: isAdminOrDomainAdmin(),
isolatePvlanType: 'none' isolatePvlanType: 'none'
} }
}, },
@ -242,11 +243,8 @@ export default {
this.fetchDomainData() this.fetchDomainData()
this.fetchZoneData() this.fetchZoneData()
}, },
isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
},
isAdminOrDomainAdmin () { isAdminOrDomainAdmin () {
return ['Admin', 'DomainAdmin'].includes(this.$store.getters.userInfo.roletype) return isAdminOrDomainAdmin()
}, },
isObjectEmpty (obj) { isObjectEmpty (obj) {
return !(obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object) return !(obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object)
@ -309,7 +307,7 @@ export default {
handleDomainChange (domain) { handleDomainChange (domain) {
this.selectedDomain = domain this.selectedDomain = domain
this.accountVisible = domain.id !== '-1' this.accountVisible = domain.id !== '-1'
if (this.isAdminOrDomainAdmin()) { if (isAdminOrDomainAdmin()) {
this.updateVPCCheckAndFetchNetworkOfferingData() this.updateVPCCheckAndFetchNetworkOfferingData()
} }
}, },
@ -337,10 +335,10 @@ export default {
guestiptype: 'L2', guestiptype: 'L2',
state: 'Enabled' state: 'Enabled'
} }
if (this.isAdminOrDomainAdmin() && this.selectedDomain.id !== '-1') { // domain is visible only for admins if (isAdminOrDomainAdmin() && this.selectedDomain.id !== '-1') { // domain is visible only for admins
params.domainid = this.selectedDomain.id params.domainid = this.selectedDomain.id
} }
if (!this.isAdmin()) { // normal user is not aware of the VLANs in the system, so normal user is not allowed to create network with network offerings whose specifyvlan = true if (!isAdmin()) { // normal user is not aware of the VLANs in the system, so normal user is not allowed to create network with network offerings whose specifyvlan = true
params.specifyvlan = false params.specifyvlan = false
} }
if (forVpc !== null) { if (forVpc !== null) {

View File

@ -34,7 +34,7 @@
@refresh-data="refreshParent" @refresh-data="refreshParent"
@refresh="handleRefresh"/> @refresh="handleRefresh"/>
</a-tab-pane> </a-tab-pane>
<a-tab-pane :tab="$t('label.shared')" key="3" v-if="this.isAdmin()"> <a-tab-pane :tab="$t('label.shared')" key="3" v-if="isAdmin()">
<CreateSharedNetworkForm <CreateSharedNetworkForm
:loading="loading" :loading="loading"
:resource="resource" :resource="resource"
@ -48,6 +48,7 @@
<script> <script>
import { api } from '@/api' import { api } from '@/api'
import { isAdmin } from '@/role'
import CreateIsolatedNetworkForm from '@/views/network/CreateIsolatedNetworkForm' import CreateIsolatedNetworkForm from '@/views/network/CreateIsolatedNetworkForm'
import CreateL2NetworkForm from '@/views/network/CreateL2NetworkForm' import CreateL2NetworkForm from '@/views/network/CreateL2NetworkForm'
import CreateSharedNetworkForm from '@/views/network/CreateSharedNetworkForm' import CreateSharedNetworkForm from '@/views/network/CreateSharedNetworkForm'
@ -89,9 +90,6 @@ export default {
}) })
}, },
methods: { methods: {
isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
},
fetchActionZoneData () { fetchActionZoneData () {
this.loading = true this.loading = true
const params = {} const params = {}
@ -107,6 +105,9 @@ export default {
this.loading = false this.loading = false
}) })
}, },
isAdmin () {
return isAdmin()
},
handleRefresh () { handleRefresh () {
}, },
refreshParent () { refreshParent () {

View File

@ -423,12 +423,6 @@ export default {
this.fetchNetworkOfferingData() this.fetchNetworkOfferingData()
} }
}, },
isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
},
isAdminOrDomainAdmin () {
return ['Admin', 'DomainAdmin'].includes(this.$store.getters.userInfo.roletype)
},
isObjectEmpty (obj) { isObjectEmpty (obj) {
return !(obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object) return !(obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object)
}, },

View File

@ -106,6 +106,7 @@
<script> <script>
import { api } from '@/api' import { api } from '@/api'
import { isAdmin } from '@/role'
import TooltipLabel from '@/components/widgets/TooltipLabel' import TooltipLabel from '@/components/widgets/TooltipLabel'
export default { export default {
@ -156,12 +157,12 @@ export default {
} }
}, },
methods: { methods: {
isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
},
fetchData () { fetchData () {
this.fetchNetworkOfferingData() this.fetchNetworkOfferingData()
}, },
isAdmin () {
return isAdmin()
},
arrayHasItems (array) { arrayHasItems (array) {
return array !== null && array !== undefined && Array.isArray(array) && array.length > 0 return array !== null && array !== undefined && Array.isArray(array) && array.length > 0
}, },

View File

@ -516,6 +516,7 @@
<script> <script>
import { api } from '@/api' import { api } from '@/api'
import { isAdmin } from '@/role'
import ResourceIcon from '@/components/view/ResourceIcon' import ResourceIcon from '@/components/view/ResourceIcon'
import TooltipLabel from '@/components/widgets/TooltipLabel' import TooltipLabel from '@/components/widgets/TooltipLabel'
@ -609,19 +610,19 @@ export default {
this.isSystem = true this.isSystem = true
} }
this.fetchData() this.fetchData()
this.isPublic = this.isAdmin() this.isPublic = isAdmin()
}, },
methods: { methods: {
fetchData () { fetchData () {
this.fetchDomainData() this.fetchDomainData()
this.fetchZoneData() this.fetchZoneData()
if (this.isAdmin()) { if (isAdmin()) {
this.fetchStorageTagData() this.fetchStorageTagData()
this.fetchDeploymentPlannerData() this.fetchDeploymentPlannerData()
} }
}, },
isAdmin () { isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype) return isAdmin()
}, },
arrayHasItems (array) { arrayHasItems (array) {
return array !== null && array !== undefined && Array.isArray(array) && array.length > 0 return array !== null && array !== undefined && Array.isArray(array) && array.length > 0
@ -713,7 +714,7 @@ export default {
this.selectedDeployementPlanner = planner this.selectedDeployementPlanner = planner
this.plannerModeVisible = false this.plannerModeVisible = false
if (this.selectedDeployementPlanner === 'ImplicitDedicationPlanner') { if (this.selectedDeployementPlanner === 'ImplicitDedicationPlanner') {
this.plannerModeVisible = this.isAdmin() this.plannerModeVisible = isAdmin()
} }
}, },
handlePlannerModeChange (val) { handlePlannerModeChange (val) {

View File

@ -351,6 +351,7 @@
<script> <script>
import { api } from '@/api' import { api } from '@/api'
import { isAdmin } from '@/role'
import ResourceIcon from '@/components/view/ResourceIcon' import ResourceIcon from '@/components/view/ResourceIcon'
import TooltipLabel from '@/components/widgets/TooltipLabel' import TooltipLabel from '@/components/widgets/TooltipLabel'
@ -397,18 +398,18 @@ export default {
} }
] ]
this.fetchData() this.fetchData()
this.isPublic = this.isAdmin() this.isPublic = isAdmin()
}, },
methods: { methods: {
fetchData () { fetchData () {
this.fetchDomainData() this.fetchDomainData()
this.fetchZoneData() this.fetchZoneData()
if (this.isAdmin()) { if (isAdmin()) {
this.fetchStorageTagData() this.fetchStorageTagData()
} }
}, },
isAdmin () { isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype) return isAdmin()
}, },
arrayHasItems (array) { arrayHasItems (array) {
return array !== null && array !== undefined && Array.isArray(array) && array.length > 0 return array !== null && array !== undefined && Array.isArray(array) && array.length > 0

View File

@ -433,6 +433,7 @@
<script> <script>
import { api } from '@/api' import { api } from '@/api'
import { isAdmin } from '@/role'
import CheckBoxSelectPair from '@/components/CheckBoxSelectPair' import CheckBoxSelectPair from '@/components/CheckBoxSelectPair'
import ResourceIcon from '@/components/view/ResourceIcon' import ResourceIcon from '@/components/view/ResourceIcon'
import TooltipLabel from '@/components/widgets/TooltipLabel' import TooltipLabel from '@/components/widgets/TooltipLabel'
@ -498,7 +499,7 @@ export default {
this.fetchServiceOfferingData() this.fetchServiceOfferingData()
}, },
isAdmin () { isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype) return isAdmin()
}, },
isSupportedServiceObject (obj) { isSupportedServiceObject (obj) {
return (obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object && 'provider' in obj) return (obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object && 'provider' in obj)

View File

@ -142,6 +142,7 @@
<script> <script>
import { api } from '@/api' import { api } from '@/api'
import { isAdmin } from '@/role'
import CheckBoxSelectPair from '@/components/CheckBoxSelectPair' import CheckBoxSelectPair from '@/components/CheckBoxSelectPair'
import ResourceIcon from '@/components/view/ResourceIcon' import ResourceIcon from '@/components/view/ResourceIcon'
import TooltipLabel from '@/components/widgets/TooltipLabel' import TooltipLabel from '@/components/widgets/TooltipLabel'
@ -190,7 +191,7 @@ export default {
this.fetchSupportedServiceData() this.fetchSupportedServiceData()
}, },
isAdmin () { isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype) return isAdmin()
}, },
isSupportedServiceObject (obj) { isSupportedServiceObject (obj) {
return (obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object && 'provider' in obj) return (obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object && 'provider' in obj)

View File

@ -23,7 +23,7 @@
@submit="handleSubmit" @submit="handleSubmit"
layout="vertical"> layout="vertical">
<a-form-item :label="$t('label.ispublic')" v-show="this.isAdmin()"> <a-form-item :label="$t('label.ispublic')" v-show="isAdmin()">
<a-switch v-decorator="['ispublic', { initialValue: this.offeringIsPublic }]" :checked="this.offeringIsPublic" @change="val => { this.offeringIsPublic = val }" /> <a-switch v-decorator="['ispublic', { initialValue: this.offeringIsPublic }]" :checked="this.offeringIsPublic" @change="val => { this.offeringIsPublic = val }" />
</a-form-item> </a-form-item>
@ -103,6 +103,7 @@
<script> <script>
import { api } from '@/api' import { api } from '@/api'
import { isAdmin } from '@/role'
import ResourceIcon from '@/components/view/ResourceIcon' import ResourceIcon from '@/components/view/ResourceIcon'
export default { export default {
@ -169,7 +170,7 @@ export default {
this.fetchZoneData() this.fetchZoneData()
}, },
isAdmin () { isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype) return isAdmin()
}, },
fetchOfferingData () { fetchOfferingData () {
this.loading = true this.loading = true
@ -228,7 +229,7 @@ export default {
} }
} }
} else { } else {
if (this.isAdmin()) { if (isAdmin()) {
this.offeringIsPublic = true this.offeringIsPublic = true
} }
} }