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/04/20 16:05:56 UTC

[3/5] incubator-trafficcontrol git commit: org tenancy. add tenant name to user api

org tenancy. add tenant name to user api


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/dbc0bd8f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/dbc0bd8f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/dbc0bd8f

Branch: refs/heads/master
Commit: dbc0bd8fa64d11feaef11fa3d2aa18e1e874e452
Parents: 0e8978b
Author: Ori Finkelman <or...@qwilt.com>
Authored: Thu Apr 6 11:38:34 2017 +0300
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Thu Apr 20 10:05:19 2017 -0600

----------------------------------------------------------------------
 docs/source/development/traffic_ops_api/v12/user.rst | 14 +++++++++++++-
 traffic_ops/app/lib/API/User.pm                      | 13 ++++++++++---
 traffic_ops/app/t/api/1.2/user.t                     | 14 +++++++++-----
 3 files changed, 32 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/dbc0bd8f/docs/source/development/traffic_ops_api/v12/user.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/user.rst b/docs/source/development/traffic_ops_api/v12/user.rst
index 36e08a7..c84dfc5 100644
--- a/docs/source/development/traffic_ops_api/v12/user.rst
+++ b/docs/source/development/traffic_ops_api/v12/user.rst
@@ -72,6 +72,8 @@ Users
   +----------------------+--------+------------------------------------------------+
   |``stateOrProvince``   | string |                                                |
   +----------------------+--------+------------------------------------------------+
+  | ``tenant``           | string | Owning tenant name                             |
+  +----------------------+--------+------------------------------------------------+
   | ``tenantId``         | int    | Owning tenant ID                               |
   +----------------------+--------+------------------------------------------------+
   |``uid``               | string |                                                |
@@ -102,6 +104,7 @@ Users
 			"role": "6",
 			"rolename": "admin",
 			"stateOrProvince": "",
+			"tenant": "root",
 			"tenantId": 1,
 			"uid": "0",
 			"username": "tsimpson"
@@ -172,6 +175,8 @@ Users
   +----------------------+--------+------------------------------------------------+
   |``stateOrProvince``   | string |                                                |
   +----------------------+--------+------------------------------------------------+
+  | ``tenant``           | string | Owning tenant name                             |
+  +----------------------+--------+------------------------------------------------+
   | ``tenantId``         | int    | Owning tenant ID                               |
   +----------------------+--------+------------------------------------------------+
   |``uid``               | string |                                                |
@@ -202,6 +207,7 @@ Users
 			"role": "6",
 			"rolename": "admin",
 			"stateOrProvince": "",
+			"tenant": "root",
 			"tenantId": 1,
 			"uid": "0",
 			"username": "tsimpson"
@@ -454,7 +460,7 @@ Users
 
   Role(s) Required: None
 
-  **Request Properties**
+  **Response Properties**
 
   +----------------------+---------+------------------------------------------------+
   | Parameter            | Type    | Description                                    |
@@ -493,6 +499,8 @@ Users
   +----------------------+---------+------------------------------------------------+
   |``postalCode``        | string  |                                                |
   +----------------------+---------+------------------------------------------------+
+  | ``tenant``           | string  | Owning tenant name                             |
+  +----------------------+---------+------------------------------------------------+
   | ``tenantId``         | int     | Owning tenant ID                               |
   +----------------------+---------+------------------------------------------------+
 
@@ -517,6 +525,7 @@ Users
                             "addressLine1": "",
                             "gid": "0",
                             "postalCode": "",
+                            "tenant": "root",
                             "tenantId": 1
 
            },
@@ -571,6 +580,8 @@ Users
   +----------------------+---------+------------------------------------------------+
   |``postalCode``        | string  |                                                |
   +----------------------+---------+------------------------------------------------+
+  | ``tenant``           | string  | Owning tenant name                             |
+  +----------------------+---------+------------------------------------------------+
   | ``tenantId``         | int     | Owning tenant ID                               |
   +----------------------+---------+------------------------------------------------+
 
@@ -595,6 +606,7 @@ Users
         "addressLine1": "",
         "gid": "0",
         "postalCode": "",
+        "tenant": "root",
         "tenantId": 1,
 
      }

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/dbc0bd8f/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 34af5e6..88b4d9a 100644
--- a/traffic_ops/app/lib/API/User.pm
+++ b/traffic_ops/app/lib/API/User.pm
@@ -69,7 +69,7 @@ sub index {
 
 	my $dbh;
 	if ( defined $username ) {
-		$dbh = $self->db->resultset("TmUser")->search( { username => $username }, { prefetch => [ { 'role' => undef } ], order_by => 'me.' . $orderby } );
+		$dbh = $self->db->resultset("TmUser")->search( { username => $username }, { prefetch => [ { 'role' => undef }, 'tenant' ], order_by => 'me.' . $orderby } );
 	}
 	else {
 		$dbh = $self->db->resultset("TmUser")->search( undef, { prefetch => [ { 'role' => undef } ], order_by => 'me.' . $orderby } );
@@ -98,6 +98,7 @@ sub index {
 				"stateOrProvince" => $row->state_or_province,
 				"uid"             => $row->uid,
 				"username"        => $row->username,
+				"tenant"          => defined ($row->tenant) ? $row->tenant->name : "N/A",
 				"tenantId"        => $row->tenant_id
 			}
 		);
@@ -109,7 +110,7 @@ sub show {
 	my $self = shift;
 	my $id   = $self->param('id');
 
-	my $rs_data = $self->db->resultset("TmUser")->search( { 'me.id' => $id }, { prefetch => [ 'role' ] } );
+	my $rs_data = $self->db->resultset("TmUser")->search( { 'me.id' => $id }, { prefetch => [ 'role' , 'tenant'] } );
 	my @data = ();
 	while ( my $row = $rs_data->next ) {
 		push(
@@ -134,6 +135,7 @@ sub show {
 				"stateOrProvince" => $row->state_or_province,
 				"uid"             => $row->uid,
 				"username"        => $row->username,
+				"tenant"          => defined ($row->tenant) ? $row->tenant->name : "N/A",
 				"tenantId"        => $row->tenant_id
 			}
 		);
@@ -216,6 +218,7 @@ sub update {
 		$response->{username} 				= $rs->username;
 		$response->{tenantId} 				= $rs->tenant_id;
 
+
 		&log( $self, "Updated User with username '" . $rs->username . "' for id: " . $rs->id, "APICHANGE" );
 
 		return $self->success( $response, "User update was successful." );
@@ -281,11 +284,14 @@ 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";
 		push(
 			@data, {
 				"id"              => "0",
 				"username"        => $current_username,
-				"tenantId"	  => $self->current_user_tenant(),
+				"tenantId"	  => $user_tenant_id,
+				"tenant"          => $user_tenant,
 				"publicSshKey"  => "",
 				"role"            => $role,
 				"uid"             => "0",
@@ -330,6 +336,7 @@ sub current {
 					"phoneNumber"     => $row->phone_number,
 					"postalCode"      => $row->postal_code,
 					"country"         => $row->country,
+					"tenant"          => defined ($row->tenant) ? $row->tenant->name : "N/A",
 					"tenantId"        => $row->tenant_id,
 				}
 			);

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/dbc0bd8f/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 d913043..87250c5 100644
--- a/traffic_ops/app/t/api/1.2/user.t
+++ b/traffic_ops/app/t/api/1.2/user.t
@@ -46,7 +46,7 @@ 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') : "null";
+	my $tenant_name = defined ($tenant_id) ? $schema->resultset('Tenant')->find( { id => $tenant_id } )->get_column('name') : "N/A";
 
 	ok my $portal_user = $schema->resultset('TmUser')->find( { username => $login_user } ), 'Tenant $tenant_name: Does the portal user exist?';
 
@@ -54,7 +54,8 @@ sub run_ut {
 	$t->post_ok( '/api/1.2/user/login', json => { u => $login_user, p => $login_password} )->status_is(200);
 	$t->get_ok('/api/1.2/user/current.json')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
 		->json_is( "/response/username", $login_user )
-		->json_is( "/response/tenantId", $tenant_id);
+		->json_is( "/response/tenantId", $tenant_id)
+		->json_is( "/response/tenant",   $tenant_name);
 
 	# Test required fields
 	$t->post_ok( '/api/1.2/user/current/update',
@@ -65,7 +66,8 @@ sub run_ut {
 	#verify tenancy	
 	$t->get_ok('/api/1.2/user/current.json')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
 		->json_is( "/response/username", $login_user )
-		->json_is( "/response/tenantId", $tenant_id);
+		->json_is( "/response/tenantId", $tenant_id)
+		->json_is( "/response/tenant",   $tenant_name);
 
 	# Test required fields
 	if (defined($tenant_id)){
@@ -77,7 +79,8 @@ sub run_ut {
 		#verify tenancy	
 		$t->get_ok('/api/1.2/user/current.json')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
 			->json_is( "/response/username", $login_user )
-			->json_is( "/response/tenantId", $tenant_id);
+			->json_is( "/response/tenantId", $tenant_id)
+			->json_is( "/response/tenant",   $tenant_name);
 
 		#cannot removed the tenant on current user
 		$t->post_ok( '/api/1.2/user/current/update',
@@ -87,7 +90,8 @@ sub run_ut {
 		#verify tenancy	
 		$t->get_ok('/api/1.2/user/current.json')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
 			->json_is( "/response/username", $login_user )
-			->json_is( "/response/tenantId", $tenant_id);
+			->json_is( "/response/tenantId", $tenant_id)
+			->json_is( "/response/tenant",   $tenant_name);
 	
 	}