Org tenancy: use undef when tenant does not exist instead of "N/A"
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/e39428f1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/e39428f1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/e39428f1 Branch: refs/heads/master Commit: e39428f1dc816babf06cda9cd6316be00f2e7cd1 Parents: dbc0bd8 Author: Ori Finkelman <o...@qwilt.com> Authored: Tue Apr 18 15:13:11 2017 +0300 Committer: Jeremy Mitchell <mitchell...@gmail.com> Committed: Thu Apr 20 10:05:19 2017 -0600 ---------------------------------------------------------------------- traffic_ops/app/lib/API/User.pm | 14 +++++++------- traffic_ops/app/t/api/1.2/user.t | 9 +++++---- 2 files changed, 12 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/e39428f1/traffic_ops/app/lib/API/User.pm ---------------------------------------------------------------------- diff --git a/traffic_ops/app/lib/API/User.pm b/traffic_ops/app/lib/API/User.pm index 88b4d9a..3831392 100644 --- a/traffic_ops/app/lib/API/User.pm +++ b/traffic_ops/app/lib/API/User.pm @@ -69,10 +69,10 @@ sub index { my $dbh; if ( defined $username ) { - $dbh = $self->db->resultset("TmUser")->search( { username => $username }, { prefetch => [ { 'role' => undef }, 'tenant' ], order_by => 'me.' . $orderby } ); + $dbh = $self->db->resultset("TmUser")->search( { username => $username }, { prefetch => [ 'role', 'tenant' ], order_by => 'me.' . $orderby } ); } else { - $dbh = $self->db->resultset("TmUser")->search( undef, { prefetch => [ { 'role' => undef } ], order_by => 'me.' . $orderby } ); + $dbh = $self->db->resultset("TmUser")->search( undef, { prefetch => [ 'role', 'tenant' ], order_by => 'me.' . $orderby } ); } while ( my $row = $dbh->next ) { @@ -98,7 +98,7 @@ sub index { "stateOrProvince" => $row->state_or_province, "uid" => $row->uid, "username" => $row->username, - "tenant" => defined ($row->tenant) ? $row->tenant->name : "N/A", + "tenant" => defined ($row->tenant) ? $row->tenant->name : undef, "tenantId" => $row->tenant_id } ); @@ -135,7 +135,7 @@ sub show { "stateOrProvince" => $row->state_or_province, "uid" => $row->uid, "username" => $row->username, - "tenant" => defined ($row->tenant) ? $row->tenant->name : "N/A", + "tenant" => defined ($row->tenant) ? $row->tenant->name : undef, "tenantId" => $row->tenant_id } ); @@ -285,7 +285,7 @@ sub current { if ( &is_ldap($self) ) { my $role = $self->db->resultset('Role')->search( { name => "read-only" } )->get_column('id')->single; my $user_tenant_id = $self->current_user_tenant(); - my $user_tenant = defined($user_tenant_id) ? $self->db->resultset('Tenant')->search( { id => $user_tenant_id } )->get_column('name')->single : "N/A"; + my $user_tenant = defined($user_tenant_id) ? $self->db->resultset('Tenant')->search( { id => $user_tenant_id } )->get_column('name')->single : undef; push( @data, { "id" => "0", @@ -314,7 +314,7 @@ sub current { return $self->success( @data ); } else { - my $dbh = $self->db->resultset('TmUser')->search( { username => $current_username } ); + my $dbh = $self->db->resultset('TmUser')->search( { username => $current_username } , { prefetch => [ 'role' , 'tenant'] } ); while ( my $row = $dbh->next ) { push( @data, { @@ -336,7 +336,7 @@ sub current { "phoneNumber" => $row->phone_number, "postalCode" => $row->postal_code, "country" => $row->country, - "tenant" => defined ($row->tenant) ? $row->tenant->name : "N/A", + "tenant" => defined ($row->tenant) ? $row->tenant->name : undef, "tenantId" => $row->tenant_id, } ); http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/e39428f1/traffic_ops/app/t/api/1.2/user.t ---------------------------------------------------------------------- diff --git a/traffic_ops/app/t/api/1.2/user.t b/traffic_ops/app/t/api/1.2/user.t index 87250c5..d1488a9 100644 --- a/traffic_ops/app/t/api/1.2/user.t +++ b/traffic_ops/app/t/api/1.2/user.t @@ -46,7 +46,8 @@ sub run_ut { Test::TestHelper->load_core_data($schema); my $tenant_id = $schema->resultset('TmUser')->find( { username => $login_user } )->get_column('tenant_id'); - my $tenant_name = defined ($tenant_id) ? $schema->resultset('Tenant')->find( { id => $tenant_id } )->get_column('name') : "N/A"; + my $tenant_name = defined ($tenant_id) ? $schema->resultset('Tenant')->find( { id => $tenant_id } )->get_column('name') : undef; + my $tenant = defined ($tenant_name) ? $tenant_name : "null"; ok my $portal_user = $schema->resultset('TmUser')->find( { username => $login_user } ), 'Tenant $tenant_name: Does the portal user exist?'; @@ -98,15 +99,15 @@ sub run_ut { # Ensure unique emails ok $t->post_ok( '/api/1.2/user/current/update', json => { user => { username => $login_user, email => 'testport...@kabletown.com', tenantId => $tenant_id } } ) ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )->json_is( "/alerts/0/level", "success" ), - "Tenant $tenant_name: Verify that the emails are unique"; + "Tenant $tenant: Verify that the emails are unique"; ok $t->post_ok( '/api/1.2/user/current/update', json => { user => { username => $login_user, email => '@kabletown.com', tenantId => $tenant_id } } ) ->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } )->json_is( "/alerts/0/level", "error" ), - "Tenant $tenant_name: Verify that the emails are properly formatted"; + "Tenant $tenant: Verify that the emails are properly formatted"; ok $t->post_ok( '/api/1.2/user/current/update', json => { user => { username => $login_user, email => '@kabletown.com', tenantId => $tenant_id } } ) ->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } )->json_is( "/alerts/0/level", "error" ), - "Tenant $tenant_name: Verify that the usernames are unique"; + "Tenant $tenant: Verify that the usernames are unique"; $t->post_ok( '/api/1.2/user/current/update', json => { user => { email => 'testport...@kabletown.com', tenantId => $tenant_id } } )->status_is(400) ->or( sub { diag $t->tx->res->content->asset->{content}; } )->json_is( "/alerts/0/text", "username is required" );