tenancy utils - get_tenants_list and get_tenant
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/f5ca6007 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/f5ca6007 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/f5ca6007 Branch: refs/heads/master Commit: f5ca6007f7e5c7e1ca001f37ebb9b74f5be6e199 Parents: 2dcc139 Author: nir-sopher <[email protected]> Authored: Fri Jun 2 16:19:58 2017 +0300 Committer: Jeremy Mitchell <[email protected]> Committed: Tue Jul 18 12:12:31 2017 -0600 ---------------------------------------------------------------------- traffic_ops/app/lib/API/Tenant.pm | 17 ++--------------- traffic_ops/app/lib/UI/TenantUtils.pm | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/f5ca6007/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 ab335e2..4812439 100644 --- a/traffic_ops/app/lib/API/Tenant.pm +++ b/traffic_ops/app/lib/API/Tenant.pm @@ -36,12 +36,6 @@ sub index { my $self = shift; my $orderby = $self->param('orderby') || "name"; - my %idnames; - my $rs_data = $self->db->resultset("Tenant")->search(); - while ( my $row = $rs_data->next ) { - $idnames{ $row->id } = $row->name; - } - my @data = (); my $tenantUtils = UI::TenantUtils->new($self); my @tenants_list = $tenantUtils->get_hierarchic_tenants_list(undef, $orderby); @@ -53,7 +47,7 @@ sub index { "name" => $row->name, "active" => \$row->active, "parentId" => $row->parent_id, - "parentName" => ( defined $row->parent_id ) ? $idnames{ $row->parent_id } : undef, + "parentName" => ( defined $row->parent_id ) ? $tenantUtils->get_tenant($row->parent_id)->name : undef, } ); } @@ -67,13 +61,6 @@ sub show { my $id = $self->param('id'); my @data = (); - my %idnames; - - my $rs_idnames = $self->db->resultset("Tenant")->search( undef, { columns => [qw/id name/] } ); - while ( my $row = $rs_idnames->next ) { - $idnames{ $row->id } = $row->name; - } - my $tenantUtils = UI::TenantUtils->new($self); my $rs_data = $self->db->resultset("Tenant")->search( { 'me.id' => $id }); while ( my $row = $rs_data->next ) { @@ -84,7 +71,7 @@ sub show { "name" => $row->name, "active" => \$row->active, "parentId" => $row->parent_id, - "parentName" => ( defined $row->parent_id ) ? $idnames{ $row->parent_id } : undef, + "parentName" => ( defined $row->parent_id ) ? $tenantUtils->get_tenant($row->parent_id)->name : undef, } ); } http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/f5ca6007/traffic_ops/app/lib/UI/TenantUtils.pm ---------------------------------------------------------------------- diff --git a/traffic_ops/app/lib/UI/TenantUtils.pm b/traffic_ops/app/lib/UI/TenantUtils.pm index 118ba79..d2b1ea5 100644 --- a/traffic_ops/app/lib/UI/TenantUtils.pm +++ b/traffic_ops/app/lib/UI/TenantUtils.pm @@ -44,6 +44,29 @@ sub current_user_tenant { return $self->{user_tenant_id}; } +sub get_tenant { + my $self = shift; + my $tenant_id = shift; + + $self->_init_tenants_if_needed(undef); + + return $self->{tenants_dict}->{$tenant_id}{row}; +} + +sub get_tenants_list { + my $self = shift; + my $order_by = shift; + + $self->_init_tenants_if_needed($order_by); + + my @result = (); + foreach my $tenant_id (@{ $self->{ordered_by} }) { + push @result, $self->{tenants_dict}->{$tenant_id}{row}; + } + + return @result; +} + sub get_hierarchic_tenants_list { my $self = shift; my $tree_root = shift;
