Skip to content

Commit 8bc69e9

Browse files
DaanHooglandDaan Hoogland
andauthored
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>
1 parent a47e53f commit 8bc69e9

13 files changed

Lines changed: 83 additions & 52 deletions

ui/src/config/section/network.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717

1818
import store from '@/store'
19+
import { isAdmin } from '@/role'
1920

2021
export default {
2122
name: 'network',
@@ -29,8 +30,20 @@ export default {
2930
icon: 'apartment',
3031
permission: ['listNetworks'],
3132
resourceType: 'Network',
32-
columns: ['name', 'state', 'type', 'vpcname', 'cidr', 'ip6cidr', 'broadcasturi', 'domain', 'account', 'zonename'],
33-
details: ['name', 'id', 'description', 'type', 'traffictype', 'vpcid', 'vlan', 'broadcasturi', 'cidr', 'ip6cidr', 'netmask', 'gateway', 'aclname', 'ispersistent', 'restartrequired', 'reservediprange', 'redundantrouter', 'networkdomain', 'zonename', 'account', 'domain'],
33+
columns: () => {
34+
var fields = ['name', 'state', 'type', 'vpcname', 'cidr', 'ip6cidr', 'broadcasturi', 'domain', 'account', 'zonename']
35+
if (!isAdmin()) {
36+
fields = fields.filter(function (e) { return e !== 'broadcasturi' })
37+
}
38+
return fields
39+
},
40+
details: () => {
41+
var fields = ['name', 'id', 'description', 'type', 'traffictype', 'vpcid', 'vlan', 'broadcasturi', 'cidr', 'ip6cidr', 'netmask', 'gateway', 'aclname', 'ispersistent', 'restartrequired', 'reservediprange', 'redundantrouter', 'networkdomain', 'zonename', 'account', 'domain']
42+
if (!isAdmin()) {
43+
fields = fields.filter(function (e) { return e !== 'broadcasturi' })
44+
}
45+
return fields
46+
},
3447
filters: ['all', 'isolated', 'shared', 'l2'],
3548
searchFilters: ['keyword', 'zoneid', 'domainid', 'account', 'tags'],
3649
related: [{

ui/src/role/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
import store from '@/store'
19+
20+
export function isAdmin () {
21+
return ['Admin'].includes(store.getters.userInfo.roletype)
22+
}
23+
24+
export function isAdminOrDomainAdmin () {
25+
return ['Admin', 'DomainAdmin'].includes(this.$store.getters.userInfo.roletype)
26+
}

ui/src/views/compute/KubernetesServiceTab.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150

151151
<script>
152152
import { api } from '@/api'
153+
import { isAdmin } from '@/role'
153154
import { mixinDevice } from '@/utils/mixin.js'
154155
import DetailsTab from '@/components/view/DetailsTab'
155156
import FirewallRules from '@/views/network/FirewallRules'
@@ -230,7 +231,7 @@ export default {
230231
dataIndex: 'zonename'
231232
}
232233
]
233-
if (!this.isAdmin()) {
234+
if (!isAdmin()) {
234235
this.vmColumns = this.vmColumns.filter(x => x.dataIndex !== 'instancename')
235236
}
236237
this.handleFetchData()
@@ -279,12 +280,6 @@ export default {
279280
}).join('&')
280281
)
281282
},
282-
isAdmin () {
283-
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
284-
},
285-
isAdminOrDomainAdmin () {
286-
return ['Admin', 'DomainAdmin'].includes(this.$store.getters.userInfo.roletype)
287-
},
288283
isValidValueForKey (obj, key) {
289284
return key in obj && obj[key] != null
290285
},

ui/src/views/network/CreateIsolatedNetworkForm.vue

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
</a-select-option>
6969
</a-select>
7070
</a-form-item>
71-
<a-form-item v-if="this.isAdminOrDomainAdmin()">
71+
<a-form-item v-if="isAdminOrDomainAdmin()">
7272
<tooltip-label slot="label" :title="$t('label.domainid')" :tooltip="apiParams.domainid.description"/>
7373
<a-select
7474
v-decorator="['domainid', {}]"
@@ -193,6 +193,7 @@
193193

194194
<script>
195195
import { api } from '@/api'
196+
import { isAdmin, isAdminOrDomainAdmin } from '@/role'
196197
import ResourceIcon from '@/components/view/ResourceIcon'
197198
import TooltipLabel from '@/components/widgets/TooltipLabel'
198199
@@ -231,7 +232,7 @@ export default {
231232
vpcs: [],
232233
vpcLoading: false,
233234
selectedVpc: {},
234-
accountVisible: this.isAdminOrDomainAdmin()
235+
accountVisible: isAdminOrDomainAdmin()
235236
}
236237
},
237238
watch: {
@@ -257,11 +258,8 @@ export default {
257258
this.fetchDomainData()
258259
this.fetchZoneData()
259260
},
260-
isAdmin () {
261-
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
262-
},
263261
isAdminOrDomainAdmin () {
264-
return ['Admin', 'DomainAdmin'].includes(this.$store.getters.userInfo.roletype)
262+
return isAdminOrDomainAdmin()
265263
},
266264
isObjectEmpty (obj) {
267265
return !(obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object)
@@ -320,7 +318,7 @@ export default {
320318
handleDomainChange (domain) {
321319
this.selectedDomain = domain
322320
this.accountVisible = domain.id !== '-1'
323-
if (this.isAdminOrDomainAdmin()) {
321+
if (isAdminOrDomainAdmin()) {
324322
this.updateVPCCheckAndFetchNetworkOfferingData()
325323
}
326324
},
@@ -349,10 +347,10 @@ export default {
349347
supportedServices: 'SourceNat',
350348
state: 'Enabled'
351349
}
352-
if (this.isAdminOrDomainAdmin() && this.selectedDomain.id !== '-1') { // domain is visible only for admins
350+
if (isAdminOrDomainAdmin() && this.selectedDomain.id !== '-1') { // domain is visible only for admins
353351
params.domainid = this.selectedDomain.id
354352
}
355-
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
353+
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
356354
params.specifyvlan = false
357355
}
358356
if (forVpc !== null) {

ui/src/views/network/CreateL2NetworkForm.vue

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
</a-select-option>
6969
</a-select>
7070
</a-form-item>
71-
<a-form-item v-if="this.isAdminOrDomainAdmin()">
71+
<a-form-item v-if="isAdminOrDomainAdmin()">
7272
<tooltip-label slot="label" :title="$t('label.domainid')" :tooltip="apiParams.domainid.description"/>
7373
<a-select
7474
v-decorator="['domainid', {}]"
@@ -180,6 +180,7 @@
180180

181181
<script>
182182
import { api } from '@/api'
183+
import { isAdmin, isAdminOrDomainAdmin } from '@/role'
183184
import ResourceIcon from '@/components/view/ResourceIcon'
184185
import TooltipLabel from '@/components/widgets/TooltipLabel'
185186
@@ -215,7 +216,7 @@ export default {
215216
networkOfferings: [],
216217
networkOfferingLoading: false,
217218
selectedNetworkOffering: {},
218-
accountVisible: this.isAdminOrDomainAdmin(),
219+
accountVisible: isAdminOrDomainAdmin(),
219220
isolatePvlanType: 'none'
220221
}
221222
},
@@ -242,11 +243,8 @@ export default {
242243
this.fetchDomainData()
243244
this.fetchZoneData()
244245
},
245-
isAdmin () {
246-
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
247-
},
248246
isAdminOrDomainAdmin () {
249-
return ['Admin', 'DomainAdmin'].includes(this.$store.getters.userInfo.roletype)
247+
return isAdminOrDomainAdmin()
250248
},
251249
isObjectEmpty (obj) {
252250
return !(obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object)
@@ -309,7 +307,7 @@ export default {
309307
handleDomainChange (domain) {
310308
this.selectedDomain = domain
311309
this.accountVisible = domain.id !== '-1'
312-
if (this.isAdminOrDomainAdmin()) {
310+
if (isAdminOrDomainAdmin()) {
313311
this.updateVPCCheckAndFetchNetworkOfferingData()
314312
}
315313
},
@@ -337,10 +335,10 @@ export default {
337335
guestiptype: 'L2',
338336
state: 'Enabled'
339337
}
340-
if (this.isAdminOrDomainAdmin() && this.selectedDomain.id !== '-1') { // domain is visible only for admins
338+
if (isAdminOrDomainAdmin() && this.selectedDomain.id !== '-1') { // domain is visible only for admins
341339
params.domainid = this.selectedDomain.id
342340
}
343-
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
341+
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
344342
params.specifyvlan = false
345343
}
346344
if (forVpc !== null) {

ui/src/views/network/CreateNetwork.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
@refresh-data="refreshParent"
3535
@refresh="handleRefresh"/>
3636
</a-tab-pane>
37-
<a-tab-pane :tab="$t('label.shared')" key="3" v-if="this.isAdmin()">
37+
<a-tab-pane :tab="$t('label.shared')" key="3" v-if="isAdmin()">
3838
<CreateSharedNetworkForm
3939
:loading="loading"
4040
:resource="resource"
@@ -48,6 +48,7 @@
4848

4949
<script>
5050
import { api } from '@/api'
51+
import { isAdmin } from '@/role'
5152
import CreateIsolatedNetworkForm from '@/views/network/CreateIsolatedNetworkForm'
5253
import CreateL2NetworkForm from '@/views/network/CreateL2NetworkForm'
5354
import CreateSharedNetworkForm from '@/views/network/CreateSharedNetworkForm'
@@ -89,9 +90,6 @@ export default {
8990
})
9091
},
9192
methods: {
92-
isAdmin () {
93-
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
94-
},
9593
fetchActionZoneData () {
9694
this.loading = true
9795
const params = {}
@@ -107,6 +105,9 @@ export default {
107105
this.loading = false
108106
})
109107
},
108+
isAdmin () {
109+
return isAdmin()
110+
},
110111
handleRefresh () {
111112
},
112113
refreshParent () {

ui/src/views/network/CreateSharedNetworkForm.vue

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,6 @@ export default {
423423
this.fetchNetworkOfferingData()
424424
}
425425
},
426-
isAdmin () {
427-
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
428-
},
429-
isAdminOrDomainAdmin () {
430-
return ['Admin', 'DomainAdmin'].includes(this.$store.getters.userInfo.roletype)
431-
},
432426
isObjectEmpty (obj) {
433427
return !(obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object)
434428
},

ui/src/views/network/UpdateNetwork.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106

107107
<script>
108108
import { api } from '@/api'
109+
import { isAdmin } from '@/role'
109110
import TooltipLabel from '@/components/widgets/TooltipLabel'
110111
111112
export default {
@@ -156,12 +157,12 @@ export default {
156157
}
157158
},
158159
methods: {
159-
isAdmin () {
160-
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
161-
},
162160
fetchData () {
163161
this.fetchNetworkOfferingData()
164162
},
163+
isAdmin () {
164+
return isAdmin()
165+
},
165166
arrayHasItems (array) {
166167
return array !== null && array !== undefined && Array.isArray(array) && array.length > 0
167168
},

ui/src/views/offering/AddComputeOffering.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@
516516

517517
<script>
518518
import { api } from '@/api'
519+
import { isAdmin } from '@/role'
519520
import ResourceIcon from '@/components/view/ResourceIcon'
520521
import TooltipLabel from '@/components/widgets/TooltipLabel'
521522
@@ -609,19 +610,19 @@ export default {
609610
this.isSystem = true
610611
}
611612
this.fetchData()
612-
this.isPublic = this.isAdmin()
613+
this.isPublic = isAdmin()
613614
},
614615
methods: {
615616
fetchData () {
616617
this.fetchDomainData()
617618
this.fetchZoneData()
618-
if (this.isAdmin()) {
619+
if (isAdmin()) {
619620
this.fetchStorageTagData()
620621
this.fetchDeploymentPlannerData()
621622
}
622623
},
623624
isAdmin () {
624-
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
625+
return isAdmin()
625626
},
626627
arrayHasItems (array) {
627628
return array !== null && array !== undefined && Array.isArray(array) && array.length > 0
@@ -713,7 +714,7 @@ export default {
713714
this.selectedDeployementPlanner = planner
714715
this.plannerModeVisible = false
715716
if (this.selectedDeployementPlanner === 'ImplicitDedicationPlanner') {
716-
this.plannerModeVisible = this.isAdmin()
717+
this.plannerModeVisible = isAdmin()
717718
}
718719
},
719720
handlePlannerModeChange (val) {

ui/src/views/offering/AddDiskOffering.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@
351351

352352
<script>
353353
import { api } from '@/api'
354+
import { isAdmin } from '@/role'
354355
import ResourceIcon from '@/components/view/ResourceIcon'
355356
import TooltipLabel from '@/components/widgets/TooltipLabel'
356357
@@ -397,18 +398,18 @@ export default {
397398
}
398399
]
399400
this.fetchData()
400-
this.isPublic = this.isAdmin()
401+
this.isPublic = isAdmin()
401402
},
402403
methods: {
403404
fetchData () {
404405
this.fetchDomainData()
405406
this.fetchZoneData()
406-
if (this.isAdmin()) {
407+
if (isAdmin()) {
407408
this.fetchStorageTagData()
408409
}
409410
},
410411
isAdmin () {
411-
return ['Admin'].includes(this.$store.getters.userInfo.roletype)
412+
return isAdmin()
412413
},
413414
arrayHasItems (array) {
414415
return array !== null && array !== undefined && Array.isArray(array) && array.length > 0

0 commit comments

Comments
 (0)