From 8bc69e919c965efcb0efcd5239c2c39c4782f6df Mon Sep 17 00:00:00 2001 From: dahn Date: Wed, 8 Dec 2021 05:57:58 +0100 Subject: [PATCH] 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 --- ui/src/config/section/network.js | 17 ++++++++++-- ui/src/role/index.js | 26 +++++++++++++++++++ ui/src/views/compute/KubernetesServiceTab.vue | 9 ++----- .../network/CreateIsolatedNetworkForm.vue | 16 +++++------- ui/src/views/network/CreateL2NetworkForm.vue | 16 +++++------- ui/src/views/network/CreateNetwork.vue | 9 ++++--- .../views/network/CreateSharedNetworkForm.vue | 6 ----- ui/src/views/network/UpdateNetwork.vue | 7 ++--- ui/src/views/offering/AddComputeOffering.vue | 9 ++++--- ui/src/views/offering/AddDiskOffering.vue | 7 ++--- ui/src/views/offering/AddNetworkOffering.vue | 3 ++- ui/src/views/offering/AddVpcOffering.vue | 3 ++- .../views/offering/UpdateOfferingAccess.vue | 7 ++--- 13 files changed, 83 insertions(+), 52 deletions(-) create mode 100644 ui/src/role/index.js diff --git a/ui/src/config/section/network.js b/ui/src/config/section/network.js index a91e6b5e145..95c24159bb0 100644 --- a/ui/src/config/section/network.js +++ b/ui/src/config/section/network.js @@ -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: [{ diff --git a/ui/src/role/index.js b/ui/src/role/index.js new file mode 100644 index 00000000000..2052e3e0577 --- /dev/null +++ b/ui/src/role/index.js @@ -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) +} diff --git a/ui/src/views/compute/KubernetesServiceTab.vue b/ui/src/views/compute/KubernetesServiceTab.vue index 3a738f7a76f..97f1c5456ec 100644 --- a/ui/src/views/compute/KubernetesServiceTab.vue +++ b/ui/src/views/compute/KubernetesServiceTab.vue @@ -150,6 +150,7 @@