You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2017/07/10 20:50:00 UTC
[08/14] incubator-trafficcontrol git commit: A tenant cannot be
deleted if a ds is assigned to it
A tenant cannot be deleted if a ds is assigned to it
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/7d4ea45e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/7d4ea45e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/7d4ea45e
Branch: refs/heads/master
Commit: 7d4ea45e53dd67926d80f43640dc8c2343cac091
Parents: dc000f8
Author: nir-sopher <ni...@gmail.com>
Authored: Wed Mar 22 23:00:54 2017 +0200
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Mon Jul 10 14:41:42 2017 -0600
----------------------------------------------------------------------
traffic_ops/app/lib/API/Tenant.pm | 5 +++++
traffic_ops/app/t/api/1.2/tenant.t | 8 ++++++++
2 files changed, 13 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7d4ea45e/traffic_ops/app/lib/API/Tenant.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Tenant.pm b/traffic_ops/app/lib/API/Tenant.pm
index c09df37..784cb67 100644
--- a/traffic_ops/app/lib/API/Tenant.pm
+++ b/traffic_ops/app/lib/API/Tenant.pm
@@ -255,6 +255,11 @@ sub delete {
return $self->alert("Tenant '$name' has children tenant(s): e.g '$existing_child'. Please update these tenants and retry.");
}
+ #The order of the below tests is intentional - allowing UT to cover all cases - TODO(nirs) remove this comment when a full "tenancy" UT is added, including permissions and such (no use in putting effort into it yet)
+ my $existing_ds = $self->db->resultset('Deliveryservice')->search( { tenant_id => $id })->get_column('xml_id')->first();
+ if ($existing_ds) {
+ return $self->alert("Tenant '$name' is assign with delivery-services(s): e.g. '$existing_ds'. Please update/delete these delivery-services and retry.");
+
my $existing_user = $self->db->resultset('TmUser')->search( { tenant_id => $id }, {order_by => 'me.username' })->get_column('username')->first();
if ($existing_user) {
return $self->alert("Tenant '$name' is assign with user(s): e.g. '$existing_user'. Please update these users and retry.");
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7d4ea45e/traffic_ops/app/t/api/1.2/tenant.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/tenant.t b/traffic_ops/app/t/api/1.2/tenant.t
index a66a8a3..ece6d3e 100644
--- a/traffic_ops/app/t/api/1.2/tenant.t
+++ b/traffic_ops/app/t/api/1.2/tenant.t
@@ -152,6 +152,14 @@ ok $t->delete_ok('/api/1.2/tenants/' . $tenantE_id)->status_is(200)->or( sub { d
ok $t->delete_ok('/api/1.2/tenants/' . $tenantD_id)->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } );
ok $t->delete_ok('/api/1.2/tenants/' . $tenantA_id)->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } );
+#TODO(nirs): move to a "tenancy" UT when written
+#cannot delete a tenant that have a delivery-service
+ok $t->delete_ok('/api/1.2/tenants/' . 10**9)->status_is(400)
+ ->json_is( "/alerts/0/text" => "Tenant 'root' is assign with delivery-services(s): e.g. 'test-ds1-root'. Please update/delete these delivery-services and retry." )
+ ->or( sub { diag $t->tx->res->content->asset->{content}; } );
+
+ok $t->delete_ok('/api/1.2/deliveryservices/' . 2100)->status_is(200)
+
#cannot delete a tenant that have a user
ok $t->delete_ok('/api/1.2/tenants/' . 10**9)->status_is(400)
->json_is( "/alerts/0/text" => "Tenant 'root' is assign with user(s): e.g. 'admin-root'. Please update these users and retry." )