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.
import store from '@/store'
import { isAdmin } from '@/role'
export default {
name: 'network',
@ -29,8 +30,20 @@ export default {
icon: 'apartment',
permission: ['listNetworks'],
resourceType: 'Network',
columns: ['name', 'state', 'type', 'vpcname', 'cidr', 'ip6cidr', 'broadcasturi', 'domain', 'account', 'zonename'],
details: ['name', 'id', 'description', 'type', 'traffictype', 'vpcid', 'vlan', 'broadcasturi', 'cidr', 'ip6cidr', 'netmask', 'gateway', 'aclname', 'ispersistent', 'restartrequired', 'reservediprange', 'redundantrouter', 'networkdomain', 'zonename', 'account', 'domain'],
columns: () => {
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'],
searchFilters: ['keyword', 'zoneid', 'domainid', 'account', 'tags'],
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>
import { api } from '@/api'
import { isAdmin } from '@/role'
import { mixinDevice } from '@/utils/mixin.js'
import DetailsTab from '@/components/view/DetailsTab'
import FirewallRules from '@/views/network/FirewallRules'
@ -230,7 +231,7 @@ export default {
dataIndex: 'zonename'
}
]
if (!this.isAdmin()) {
if (!isAdmin()) {
this.vmColumns = this.vmColumns.filter(x => x.dataIndex !== 'instancename')
}
this.handleFetchData()
@ -279,12 +280,6 @@ export default {
}).join('&')
)
},
isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
},
isAdminOrDomainAdmin () {
return ['Admin', 'DomainAdmin'].includes(this.$store.getters.userInfo.roletype)
},
isValidValueForKey (obj, key) {
return key in obj && obj[key] != null
},

View File

@ -68,7 +68,7 @@
</a-select-option>
</a-select>
</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"/>
<a-select
v-decorator="['domainid', {}]"
@ -193,6 +193,7 @@
<script>
import { api } from '@/api'
import { isAdmin, isAdminOrDomainAdmin } from '@/role'
import ResourceIcon from '@/components/view/ResourceIcon'
import TooltipLabel from '@/components/widgets/TooltipLabel'
@ -231,7 +232,7 @@ export default {
vpcs: [],
vpcLoading: false,
selectedVpc: {},
accountVisible: this.isAdminOrDomainAdmin()
accountVisible: isAdminOrDomainAdmin()
}
},
watch: {
@ -257,11 +258,8 @@ export default {
this.fetchDomainData()
this.fetchZoneData()
},
isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
},
isAdminOrDomainAdmin () {
return ['Admin', 'DomainAdmin'].includes(this.$store.getters.userInfo.roletype)
return isAdminOrDomainAdmin()
},
isObjectEmpty (obj) {
return !(obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object)
@ -320,7 +318,7 @@ export default {
handleDomainChange (domain) {
this.selectedDomain = domain
this.accountVisible = domain.id !== '-1'
if (this.isAdminOrDomainAdmin()) {
if (isAdminOrDomainAdmin()) {
this.updateVPCCheckAndFetchNetworkOfferingData()
}
},
@ -349,10 +347,10 @@ export default {
supportedServices: 'SourceNat',
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
}
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
}
if (forVpc !== null) {

View File

@ -68,7 +68,7 @@
</a-select-option>
</a-select>
</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"/>
<a-select
v-decorator="['domainid', {}]"
@ -180,6 +180,7 @@
<script>
import { api } from '@/api'
import { isAdmin, isAdminOrDomainAdmin } from '@/role'
import ResourceIcon from '@/components/view/ResourceIcon'
import TooltipLabel from '@/components/widgets/TooltipLabel'
@ -215,7 +216,7 @@ export default {
networkOfferings: [],
networkOfferingLoading: false,
selectedNetworkOffering: {},
accountVisible: this.isAdminOrDomainAdmin(),
accountVisible: isAdminOrDomainAdmin(),
isolatePvlanType: 'none'
}
},
@ -242,11 +243,8 @@ export default {
this.fetchDomainData()
this.fetchZoneData()
},
isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
},
isAdminOrDomainAdmin () {
return ['Admin', 'DomainAdmin'].includes(this.$store.getters.userInfo.roletype)
return isAdminOrDomainAdmin()
},
isObjectEmpty (obj) {
return !(obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object)
@ -309,7 +307,7 @@ export default {
handleDomainChange (domain) {
this.selectedDomain = domain
this.accountVisible = domain.id !== '-1'
if (this.isAdminOrDomainAdmin()) {
if (isAdminOrDomainAdmin()) {
this.updateVPCCheckAndFetchNetworkOfferingData()
}
},
@ -337,10 +335,10 @@ export default {
guestiptype: 'L2',
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
}
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
}
if (forVpc !== null) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -142,6 +142,7 @@
<script>
import { api } from '@/api'
import { isAdmin } from '@/role'
import CheckBoxSelectPair from '@/components/CheckBoxSelectPair'
import ResourceIcon from '@/components/view/ResourceIcon'
import TooltipLabel from '@/components/widgets/TooltipLabel'
@ -190,7 +191,7 @@ export default {
this.fetchSupportedServiceData()
},
isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
return isAdmin()
},
isSupportedServiceObject (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"
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-form-item>
@ -103,6 +103,7 @@
<script>
import { api } from '@/api'
import { isAdmin } from '@/role'
import ResourceIcon from '@/components/view/ResourceIcon'
export default {
@ -169,7 +170,7 @@ export default {
this.fetchZoneData()
},
isAdmin () {
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
return isAdmin()
},
fetchOfferingData () {
this.loading = true
@ -228,7 +229,7 @@ export default {
}
}
} else {
if (this.isAdmin()) {
if (isAdmin()) {
this.offeringIsPublic = true
}
}