Tenant-utils - current_user_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/731ceb14
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/731ceb14
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/731ceb14

Branch: refs/heads/master
Commit: 731ceb1401312dfef3bd96314250dc51fc723b10
Parents: ea12516
Author: nir-sopher <[email protected]>
Authored: Thu Jun 1 16:37:09 2017 +0300
Committer: Jeremy Mitchell <[email protected]>
Committed: Tue Jul 18 12:12:31 2017 -0600

----------------------------------------------------------------------
 traffic_ops/app/lib/API/User.pm       |  3 ++-
 traffic_ops/app/lib/UI/TenantUtils.pm | 10 ++++++++++
 traffic_ops/app/lib/UI/User.pm        |  4 +++-
 traffic_ops/app/lib/UI/Utils.pm       |  3 ++-
 4 files changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/731ceb14/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 c83d9ef..91b56fd 100644
--- a/traffic_ops/app/lib/API/User.pm
+++ b/traffic_ops/app/lib/API/User.pm
@@ -18,6 +18,7 @@ package API::User;
 
 # JvD Note: you always want to put Utils as the first use. Sh*t don't work if 
it's after the Mojo lines.
 use UI::Utils;
+use UI::TenantUtils;
 
 use Mojo::Base 'Mojolicious::Controller';
 use Utils::Helper;
@@ -404,7 +405,7 @@ sub current {
        my $self = shift;
        my @data;
        my $current_username = $self->current_user()->{username};
-
+       my $tenantUtils = UI::TenantUtils->new($self);
        if ( &is_ldap($self) ) {
                my $role = $self->db->resultset('Role')->search( { name => 
"read-only" } )->get_column('id')->single;
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/731ceb14/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 d40b3ba..44a7f17 100644
--- a/traffic_ops/app/lib/UI/TenantUtils.pm
+++ b/traffic_ops/app/lib/UI/TenantUtils.pm
@@ -32,6 +32,16 @@ sub new {
        return bless $self, $class;
 }
 
+
+sub current_user_tenant {
+       my $self = shift;
+       if ($self->{user_tenant_id} == -1) 
+       {
+               $self->{user_tenant_id} = 
$self->{context}->db->resultset('TmUser')->search( { username => 
$self->{context}->current_user()->{username} } 
)->get_column('tenant_id')->single();
+       }
+       return $self->{user_tenant_id};
+}
+
 sub get_hierarchic_tenants_list {
        my $self = shift;
        my $tree_root = shift;  

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/731ceb14/traffic_ops/app/lib/UI/User.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/UI/User.pm b/traffic_ops/app/lib/UI/User.pm
index f44dab4..2f7c1fe 100644
--- a/traffic_ops/app/lib/UI/User.pm
+++ b/traffic_ops/app/lib/UI/User.pm
@@ -18,6 +18,7 @@ package UI::User;
 
 # JvD Note: you always want to put Utils as the first use. Sh*t don't work if 
it's after the Mojo lines.
 use UI::Utils;
+use UI::TenantUtils;
 
 use Mojo::Base 'Mojolicious::Controller';
 use Utils::Helper;
@@ -285,11 +286,12 @@ sub is_send_register_valid {
 sub create_user {
        my $self   = shift;
        my $new_id = -1;
+       my $tenantUtils = UI::TenantUtils->new($self);
        my $dbh    = $self->db->resultset('TmUser')->create(
                {
                        full_name            => 
$self->param('tm_user.full_name'),
                        username             => 
$self->param('tm_user.username'),
-                       tenant_id            => current_user_tenant($self), 
#Tenancy is not dealt by the UI for now. getting the tenancy from the user      
            
+                       tenant_id            => 
$tenantUtils->current_user_tenant(), #Tenancy is not dealt by the UI for now. 
getting the tenancy from the user                 
                        public_ssh_key       => 
$self->param('tm_user.public_ssh_key'),
                        phone_number         => 
$self->param('tm_user.phone_number'),
                        email                => $self->param('tm_user.email'),

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/731ceb14/traffic_ops/app/lib/UI/Utils.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/UI/Utils.pm b/traffic_ops/app/lib/UI/Utils.pm
index 4ac2385..2b22726 100644
--- a/traffic_ops/app/lib/UI/Utils.pm
+++ b/traffic_ops/app/lib/UI/Utils.pm
@@ -42,7 +42,7 @@ use constant ADMIN      => 30;
 our %EXPORT_TAGS = (
        'all' => [
                qw(trim_whitespace is_admin is_oper is_ldap is_privileged log 
is_ipaddress is_ip6address is_netmask in_same_net is_hostname admin_status_id 
type_id type_ids
-                       profile_id profile_ids tm_version tm_url 
name_version_string is_regexp stash_role navbarpage rascal_hosts_by_cdn 
is_steering defined_or_default current_user_tenant)
+                       profile_id profile_ids tm_version tm_url 
name_version_string is_regexp stash_role navbarpage rascal_hosts_by_cdn 
is_steering defined_or_default)
        ]
 );
 our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } );
@@ -412,4 +412,5 @@ sub current_user_tenant {
     my $self = shift;
     return $self->db->resultset('TmUser')->search( { username => 
$self->current_user()->{username} } )->get_column('tenant_id')->single();
 }    
+
 1;

Reply via email to