From e049609f88b67325df57cf96cb08398d8bba5a90 Mon Sep 17 00:00:00 2001 From: Artem Tiumentcev Date: Mon, 14 Aug 2017 10:10:49 +0300 Subject: [PATCH] Hide button "delete subnet" on the network topology for shared networks Co-Authored-By: Ameed Ashour Co-Authored-By: Artem Tiumentcev Change-Id: Ia1bd3b231a039adef9be92a873e65bfd476088a5 Closes-Bug: #1703021 --- .../network_topology/client_side/_balloon_container.html | 2 ++ .../network_topology/client_side/_balloon_net.html | 2 ++ .../dashboards/project/network_topology/tests.py | 1 + .../dashboards/project/network_topology/views.py | 8 ++++++++ openstack_dashboard/static/js/horizon.networktopology.js | 3 +++ 5 files changed, 16 insertions(+) diff --git a/openstack_dashboard/dashboards/project/network_topology/templates/network_topology/client_side/_balloon_container.html b/openstack_dashboard/dashboards/project/network_topology/templates/network_topology/client_side/_balloon_container.html index 4ba7d42975..68e1571112 100644 --- a/openstack_dashboard/dashboards/project/network_topology/templates/network_topology/client_side/_balloon_container.html +++ b/openstack_dashboard/dashboards/project/network_topology/templates/network_topology/client_side/_balloon_container.html @@ -22,6 +22,7 @@ [[/console]] [[#type]] + [[#allow_delete_subnet]]
+ [[/allow_delete_subnet]] [[/type]] diff --git a/openstack_dashboard/dashboards/project/network_topology/templates/network_topology/client_side/_balloon_net.html b/openstack_dashboard/dashboards/project/network_topology/templates/network_topology/client_side/_balloon_net.html index 19e4b78fc6..e7bf15ee2b 100644 --- a/openstack_dashboard/dashboards/project/network_topology/templates/network_topology/client_side/_balloon_net.html +++ b/openstack_dashboard/dashboards/project/network_topology/templates/network_topology/client_side/_balloon_net.html @@ -26,11 +26,13 @@ [[cidr]] + [[#allow_delete_subnet]] + [[/allow_delete_subnet]] [[/subnet]] diff --git a/openstack_dashboard/dashboards/project/network_topology/tests.py b/openstack_dashboard/dashboards/project/network_topology/tests.py index 2aa5bc0337..3de8b81bf7 100644 --- a/openstack_dashboard/dashboards/project/network_topology/tests.py +++ b/openstack_dashboard/dashboards/project/network_topology/tests.py @@ -148,6 +148,7 @@ class NetworkTopologyTests(test.TestCase): 'name': net.name, 'router:external': net.router__external, 'status': net.status.title(), + 'allow_delete_subnet': True, 'original_status': net.status, 'subnets': [{ 'cidr': subnet.cidr, diff --git a/openstack_dashboard/dashboards/project/network_topology/views.py b/openstack_dashboard/dashboards/project/network_topology/views.py index 87dc4696b0..355218f5bc 100644 --- a/openstack_dashboard/dashboards/project/network_topology/views.py +++ b/openstack_dashboard/dashboards/project/network_topology/views.py @@ -75,6 +75,7 @@ from openstack_dashboard.dashboards.project.routers.tables import \ STATUS_DISPLAY_CHOICES as routers_status_choices from openstack_dashboard.dashboards.project.routers import\ views as r_views +from openstack_dashboard import policy # List of known server statuses that wont connect to the console console_invalid_status = { @@ -270,12 +271,19 @@ class JSONView(View): neutron_networks = [] networks = [] for network in neutron_networks: + allow_delete_subnet = policy.check( + (("network", "delete_subnet"),), + request, + target={'network:tenant_id': getattr(network, + 'tenant_id', None)} + ) obj = {'name': network.name_or_id, 'id': network.id, 'subnets': [{'id': subnet.id, 'cidr': subnet.cidr} for subnet in network.subnets], 'status': self.trans.network[network.status], + 'allow_delete_subnet': allow_delete_subnet, 'original_status': network.status, 'router:external': network['router:external']} self.add_resource_url('horizon:project:networks:subnets:detail', diff --git a/openstack_dashboard/static/js/horizon.networktopology.js b/openstack_dashboard/static/js/horizon.networktopology.js index 08d3cf42eb..97df127d3c 100644 --- a/openstack_dashboard/static/js/horizon.networktopology.js +++ b/openstack_dashboard/static/js/horizon.networktopology.js @@ -1066,6 +1066,9 @@ horizon.network_topology = { htmlData.subnet = subnets; if (d instanceof Network) { htmlData.delete_label = gettext('Delete Network'); + if (d.allow_delete_subnet){ + htmlData.allow_delete_subnet = d.allow_delete_subnet; + } } htmlData.add_subnet_url = 'network/' + d.id + '/subnet/create'; htmlData.add_subnet_label = gettext('Create Subnet');