Org tenancy - users - minor fixes following a review:
* Cannot remove "current user" tenancy
* Comments


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

Branch: refs/heads/master
Commit: d9b7693ba3c7836665c39b4bf18f93e517be8da6
Parents: 97764b1
Author: nir-sopher <nirsop...@gmail.com>
Authored: Sat Apr 1 22:10:21 2017 +0300
Committer: Jeremy Mitchell <mitchell...@gmail.com>
Committed: Sun Apr 2 16:08:51 2017 -0600

----------------------------------------------------------------------
 traffic_ops/app/lib/API/Tenant.pm |  2 --
 traffic_ops/app/lib/API/User.pm   |  7 ++-----
 traffic_ops/app/t/api/1.2/user.t  | 13 ++-----------
 3 files changed, 4 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d9b7693b/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 d9167e7..4b74e25 100644
--- a/traffic_ops/app/lib/API/Tenant.pm
+++ b/traffic_ops/app/lib/API/Tenant.pm
@@ -224,8 +224,6 @@ sub delete {
                return $self->alert("Tenant '$name' has children tenant(s): e.g 
'$existing_child'. Please update these tenants and retry.");
        }
 
-       #The order of the below tests is intentional - allowing UT to cover all 
cases - TODO(nirs) remove this comment when a full "tenancy" UT is added, 
including permissions and such (no use in putting effort into it yet)
-
        my $existing_user = $self->db->resultset('TmUser')->search( { tenant_id 
=> $id })->get_column('username')->first();
        if ($existing_user) {
                return $self->alert("Tenant '$name' is assign with user(s): 
e.g. '$existing_user'. Please update these users and retry.");

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d9b7693b/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 51b68e8..34af5e6 100644
--- a/traffic_ops/app/lib/API/User.pm
+++ b/traffic_ops/app/lib/API/User.pm
@@ -161,7 +161,7 @@ sub update {
                return $self->not_found();
        }
 
-       #setting tenant_id to undef if tenant is not set. TODO(nirs): remove 
when tenancy is no longer optional in the API
+       #setting tenant_id to undef if tenant is not set. 
        my $tenant_id = exists($params->{tenantId}) ? $params->{tenantId} :  
undef; 
        
        my $values = {
@@ -385,8 +385,7 @@ sub update_current {
                if ( defined( $user->{"username"} ) ) {
                        $db_user->{"username"} = $user->{"username"};
                }
-               if ( exists( $user->{"tenantId"} ) ) {
-                       #if value is not set, it will be kept as is. Keeping 
consistency. Using "exists" and not "defined" to allow data clearing
+               if ( defined( $user->{"tenantId"} ) ) {
                        $db_user->{"tenant_id"} = $user->{"tenantId"};
                }
                if ( defined( $user->{"public_ssh_key"} ) ) {
@@ -490,8 +489,6 @@ sub is_valid {
                                }
                        },
                        
-                       #TODO(nirs) MAYBE when tenancy is not optional, add a 
tenant not null check
-
                ]
        };
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d9b7693b/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 bda22c1..d913043 100644
--- a/traffic_ops/app/t/api/1.2/user.t
+++ b/traffic_ops/app/t/api/1.2/user.t
@@ -79,7 +79,7 @@ sub run_ut {
                        ->json_is( "/response/username", $login_user )
                        ->json_is( "/response/tenantId", $tenant_id);
 
-               #removed the tenant
+               #cannot removed the tenant on current user
                $t->post_ok( '/api/1.2/user/current/update',
                        json => { user => { username => $login_user, email => 
'testport...@kabletown.com', address_line1 => 'newaddress', tenantId => undef} 
} )
                        ->status_is(200)->or( sub { diag 
$t->tx->res->content->asset->{content}; } )
@@ -87,17 +87,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", undef);
-       
-               #putting the tenant back the update with no "tenant" removed 
the tenant
-               $t->post_ok( '/api/1.2/user/current/update',
-                       json => { user => { username => $login_user, email => 
'testport...@kabletown.com', address_line1 => 'newaddress', tenantId => 
$tenant_id} } )
-                       ->status_is(200)->or( sub { diag 
$t->tx->res->content->asset->{content}; } )
-                       ->json_is( "/alerts/0/text", "UserProfile was 
successfully updated." );
-               #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);
+       
        }
        
        # Ensure unique emails

Reply via email to