Github user mitchell852 commented on a diff in the pull request: https://github.com/apache/incubator-trafficcontrol/pull/644#discussion_r124624257 --- Diff: traffic_ops/app/lib/API/Tenant.pm --- @@ -131,21 +130,74 @@ sub update { my $is_active = $params->{active}; - if ( !$params->{active} && $self->isRootTenant($id)) { - return $self->alert("Root user cannot be in-active."); + if ( !$params->{active} && $tenant_utils->is_root_tenant($tenants_data, $id)) { + return $self->alert("Root tenant cannot be in-active."); + } + + #this is a write operation, allowed only by parents of the tenant (which are the owners of the resource of type tenant) + my $current_resource_tenancy = $self->db->resultset('Tenant')->search( { id => $id } )->get_column('parent_id')->single(); + if (!defined($current_resource_tenancy)) { + #no parent - the tenant is its-own owner + $current_resource_tenancy = $id; } + if (!$tenant_utils->is_tenant_resource_accessible($tenants_data, $current_resource_tenancy)) { + return $self->forbidden(); #Current owning tenant is not under user's tenancy + } - if ( !defined($params->{parentId}) && !isRootTenant($id) ) { - return $self->alert("Only the \"root\" tenant can have no parent."); + if (!$tenant_utils->is_tenant_resource_accessible($tenants_data, $params->{parentId})) { + return $self->forbidden(); #Parent tenant to be set is not under user's tenancy } + + + if ($params->{parentId} != $tenant->parent) { + #parent replacement + if (!defined($tenant_utils->get_tenant_by_id($tenants_data, $params->{parentId}))) { + return $self->alert("Parent tenant does not exists."); + } + my $parent_depth = $tenant_utils->get_tenant_heirarchy_depth($tenants_data, $params->{parentId}); + if (!defined($parent_depth)) + { + return $self->alert("Failed to retrieve parent tenant depth."); + } + + my $tenant_height = $tenant_utils->get_tenant_heirarchy_height($tenants_data, $id); + if (!defined($tenant_height)) + { + return $self->alert("Failed to retrieve tenant height."); + } + + if ($parent_depth+$tenant_height+1 > $tenant_utils->max_heirarchy_limit()) + { + return $self->alert("Parent tenant is invalid: heirarchy limit reached."); + } + if ($params->{parentId} == $id){ + return $self->alert("Parent tenant is invalid: same as updated tenant."); + } + + my $is_tenant_achestor_of_parent = $tenant_utils->is_anchestor_of($tenants_data, $id, $params->{parentId}); + if (!defined($is_tenant_achestor_of_parent)) + { + return $self->alert("Failed to check tenant and parent current relations."); --- End diff -- I don't understand this error message
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---