Github user nir-sopher commented on a diff in the pull request:

    
https://github.com/apache/incubator-trafficcontrol/pull/644#discussion_r124638570
  
    --- 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())
    --- End diff --
    
    The limit is there to avoid infinite loops in tenant-utils in case of 
cyclic parent pointing. There is no way I;m aware of to create such loops but 
bugs may prove me wrong:)
    As I set a limit in the loops themselves, I wanted to keep the code 
coherent and block the option to create deeper hierarchy.


---
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.
---

Reply via email to