Tenant util - remove readable/writeable separation
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/0fffefea Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/0fffefea Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/0fffefea Branch: refs/heads/master Commit: 0fffefea371d4520f972ff7b9fc5e4bd3007a659 Parents: 4d2951c Author: nir-sopher <[email protected]> Authored: Tue Jun 6 07:42:37 2017 +0300 Committer: Jeremy Mitchell <[email protected]> Committed: Tue Jul 18 12:12:32 2017 -0600 ---------------------------------------------------------------------- traffic_ops/app/lib/API/Tenant.pm | 12 +++---- traffic_ops/app/lib/UI/TenantUtils.pm | 15 ++------ traffic_ops/app/t/api/1.2/tenant.t | 57 ++++++++++-------------------- 3 files changed, 27 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0fffefea/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 390b1e5..1c226b3 100644 --- a/traffic_ops/app/lib/API/Tenant.pm +++ b/traffic_ops/app/lib/API/Tenant.pm @@ -42,7 +42,7 @@ sub index { my @data = (); my @tenants_list = $tenant_utils->get_hierarchic_tenants_list($tenants_data, undef); foreach my $row (@tenants_list) { - if ($tenant_utils->is_tenant_readable($tenants_data, $row->id)) { + if ($tenant_utils->is_tenant_resource_accessible($tenants_data, $row->id)) { push( @data, { "id" => $row->id, @@ -68,7 +68,7 @@ sub show { my @data = (); my $rs_data = $self->db->resultset("Tenant")->search( { 'me.id' => $id }); while ( my $row = $rs_data->next ) { - if ($tenant_utils->is_tenant_readable($tenants_data, $row->id)) { + if ($tenant_utils->is_tenant_resource_accessible($tenants_data, $row->id)) { push( @data, { "id" => $row->id, @@ -142,11 +142,11 @@ sub update { $current_resource_tenancy = $id; } - if (!$tenant_utils->is_tenant_writeable($tenants_data, $current_resource_tenancy)) { + if (!$tenant_utils->is_tenant_resource_accessible($tenants_data, $current_resource_tenancy)) { return $self->forbidden(); #Current owning tenant is not under user's tenancy } - if (!$tenant_utils->is_tenant_writeable($tenants_data, $params->{parentId})) { + if (!$tenant_utils->is_tenant_resource_accessible($tenants_data, $params->{parentId})) { return $self->forbidden(); #Parent tenant to be set is not under user's tenancy } @@ -248,7 +248,7 @@ sub create { my $tenant_utils = UI::TenantUtils->new($self); my $tenants_data = $tenant_utils->create_tenants_data_from_db(undef); - if (!$tenant_utils->is_tenant_writeable($tenants_data, $params->{parentId})) { + if (!$tenant_utils->is_tenant_resource_accessible($tenants_data, $params->{parentId})) { return $self->forbidden(); #Parent tenant to be set is not under user's tenancy } @@ -333,7 +333,7 @@ sub delete { my $tenant_utils = UI::TenantUtils->new($self); my $tenants_data = $tenant_utils->create_tenants_data_from_db(undef); - if (!$tenant_utils->is_tenant_writeable($tenants_data, $parent_tenant)) { + if (!$tenant_utils->is_tenant_resource_accessible($tenants_data, $parent_tenant)) { return $self->forbidden(); #Parent tenant is not under user's tenancy } http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0fffefea/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 d21505f..852380f 100644 --- a/traffic_ops/app/lib/UI/TenantUtils.pm +++ b/traffic_ops/app/lib/UI/TenantUtils.pm @@ -190,22 +190,12 @@ sub is_root_tenant { return !( defined( $tenants_data->{tenants_dict}{$tenant_id}{parent} ) ); } -sub is_tenant_readable { +sub is_tenant_resource_accessible { my $self = shift; my $tenants_data = shift; my $resource_tenancy = shift; - return $self->_is_resource_accessable( $tenants_data, $resource_tenancy, - "r" ); -} - -sub is_tenant_writeable { - my $self = shift; - my $tenants_data = shift; - my $resource_tenancy = shift; - - return $self->_is_resource_accessable( $tenants_data, $resource_tenancy, - "w" ); + return $self->_is_resource_accessable( $tenants_data, $resource_tenancy); } sub get_tenant_heirarchy_depth { @@ -349,7 +339,6 @@ sub _is_resource_accessable { my $self = shift; my $tenants_data = shift; my $resource_tenant = shift; - my $operation = shift; my $user_tenant = $self->current_user_tenant(); if ( defined($user_tenant) ) { http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0fffefea/traffic_ops/app/t/api/1.2/tenant.t ---------------------------------------------------------------------- diff --git a/traffic_ops/app/t/api/1.2/tenant.t b/traffic_ops/app/t/api/1.2/tenant.t index 6d96f2d..38bf1e2 100644 --- a/traffic_ops/app/t/api/1.2/tenant.t +++ b/traffic_ops/app/t/api/1.2/tenant.t @@ -200,70 +200,51 @@ ok $tenant_utils_of_root->get_tenant_heirarchy_height($tenants_data, $tenantE_id ############################ #testing tenancy checks #root tenant - touch entire hierarchy as well as null -ok $tenant_utils_of_root->is_tenant_readable($tenants_data, $root_tenant_id) == 1; -ok $tenant_utils_of_root->is_tenant_writeable($tenants_data, $root_tenant_id) == 1; -ok $tenant_utils_of_root->is_tenant_readable($tenants_data, undef) == 1; -ok $tenant_utils_of_root->is_tenant_writeable($tenants_data, undef) == 1; -ok $tenant_utils_of_root->is_tenant_readable($tenants_data, $tenantA_id) == 1; -ok $tenant_utils_of_root->is_tenant_writeable($tenants_data, $tenantA_id) == 1; -ok $tenant_utils_of_root->is_tenant_readable($tenants_data, $tenantE_id) == 1; -ok $tenant_utils_of_root->is_tenant_writeable($tenants_data, $tenantE_id) == 1; +ok $tenant_utils_of_root->is_tenant_resource_accessible($tenants_data, $root_tenant_id) == 1; +ok $tenant_utils_of_root->is_tenant_resource_accessible($tenants_data, undef) == 1; +ok $tenant_utils_of_root->is_tenant_resource_accessible($tenants_data, $tenantA_id) == 1; +ok $tenant_utils_of_root->is_tenant_resource_accessible($tenants_data, $tenantE_id) == 1; my $tenant_utils_of_a = UI::TenantUtils->new(undef, $tenantA_id, $schema); my $tenants_data_of_a = $tenant_utils_of_a->create_tenants_data_from_db(); #parent - no access -ok $tenant_utils_of_a->is_tenant_readable($tenants_data_of_a, $root_tenant_id) == 0; -ok $tenant_utils_of_a->is_tenant_writeable($tenants_data_of_a, $root_tenant_id) == 0; +ok $tenant_utils_of_a->is_tenant_resource_accessible($tenants_data_of_a, $root_tenant_id) == 0; #undef - all have access -ok $tenant_utils_of_a->is_tenant_readable($tenants_data_of_a, undef) == 1; -ok $tenant_utils_of_a->is_tenant_writeable($tenants_data_of_a, undef) == 1; +ok $tenant_utils_of_a->is_tenant_resource_accessible($tenants_data_of_a, undef) == 1; #itself - full access -ok $tenant_utils_of_a->is_tenant_readable($tenants_data_of_a, $tenantA_id) == 1; -ok $tenant_utils_of_a->is_tenant_writeable($tenants_data_of_a, $tenantA_id) == 1; +ok $tenant_utils_of_a->is_tenant_resource_accessible($tenants_data_of_a, $tenantA_id) == 1; # child - full access -ok $tenant_utils_of_a->is_tenant_readable($tenants_data_of_a, $tenantE_id) == 1; -ok $tenant_utils_of_a->is_tenant_writeable($tenants_data_of_a, $tenantE_id) == 1; +ok $tenant_utils_of_a->is_tenant_resource_accessible($tenants_data_of_a, $tenantE_id) == 1; # Brother - no access -ok $tenant_utils_of_a->is_tenant_readable($tenants_data_of_a, $tenantB_id) == 0; -ok $tenant_utils_of_a->is_tenant_writeable($tenants_data_of_a, $tenantB_id) == 0; +ok $tenant_utils_of_a->is_tenant_resource_accessible($tenants_data_of_a, $tenantB_id) == 0; #leaf test my $tenant_utils_of_d = UI::TenantUtils->new(undef, $tenantD_id, $schema); my $tenants_data_of_d = $tenant_utils_of_d->create_tenants_data_from_db(); #anchestor - no access -ok $tenant_utils_of_d->is_tenant_readable($tenants_data_of_d, $root_tenant_id) == 0; -ok $tenant_utils_of_d->is_tenant_writeable($tenants_data_of_d, $root_tenant_id) == 0; +ok $tenant_utils_of_d->is_tenant_resource_accessible($tenants_data_of_d, $root_tenant_id) == 0; #undef - all have access -ok $tenant_utils_of_d->is_tenant_readable($tenants_data_of_d, undef) == 1; -ok $tenant_utils_of_d->is_tenant_writeable($tenants_data_of_d, undef) == 1; +ok $tenant_utils_of_d->is_tenant_resource_accessible($tenants_data_of_d, undef) == 1; # parent - no access -ok $tenant_utils_of_d->is_tenant_readable($tenants_data_of_d, $tenantA_id) == 0; -ok $tenant_utils_of_d->is_tenant_writeable($tenants_data_of_d, $tenantA_id) == 0; +ok $tenant_utils_of_d->is_tenant_resource_accessible($tenants_data_of_d, $tenantA_id) == 0; # itself - full access -ok $tenant_utils_of_d->is_tenant_readable($tenants_data_of_d, $tenantD_id) == 1; -ok $tenant_utils_of_d->is_tenant_writeable($tenants_data_of_d, $tenantD_id) == 1; +ok $tenant_utils_of_d->is_tenant_resource_accessible($tenants_data_of_d, $tenantD_id) == 1; # uncle - no access -ok $tenant_utils_of_d->is_tenant_readable($tenants_data_of_d, $tenantB_id) == 0; -ok $tenant_utils_of_d->is_tenant_writeable($tenants_data_of_d, $tenantB_id) == 0; +ok $tenant_utils_of_d->is_tenant_resource_accessible($tenants_data_of_d, $tenantB_id) == 0; #inactive - nothing can do my $tenant_utils_of_e = UI::TenantUtils->new(undef, $tenantE_id, $schema); my $tenants_data_of_e = $tenant_utils_of_e->create_tenants_data_from_db(); #anchestor - no access -ok $tenant_utils_of_e->is_tenant_readable($tenants_data_of_e, $root_tenant_id) == 0; -ok $tenant_utils_of_e->is_tenant_writeable($tenants_data_of_e, $root_tenant_id) == 0; +ok $tenant_utils_of_e->is_tenant_resource_accessible($tenants_data_of_e, $root_tenant_id) == 0; #undef - all have access -ok $tenant_utils_of_e->is_tenant_readable($tenants_data_of_e, undef) == 0; -ok $tenant_utils_of_e->is_tenant_writeable($tenants_data_of_e, undef) == 0; +ok $tenant_utils_of_e->is_tenant_resource_accessible($tenants_data_of_e, undef) == 0; # parent - no access -ok $tenant_utils_of_e->is_tenant_readable($tenants_data_of_e, $tenantA_id) == 0; -ok $tenant_utils_of_e->is_tenant_writeable($tenants_data_of_e, $tenantA_id) == 0; +ok $tenant_utils_of_e->is_tenant_resource_accessible($tenants_data_of_e, $tenantA_id) == 0; # itself - full access -ok $tenant_utils_of_e->is_tenant_readable($tenants_data_of_e, $tenantE_id) == 0; -ok $tenant_utils_of_e->is_tenant_writeable($tenants_data_of_e, $tenantE_id) == 0; +ok $tenant_utils_of_e->is_tenant_resource_accessible($tenants_data_of_e, $tenantE_id) == 0; # uncle - no access -ok $tenant_utils_of_e->is_tenant_readable($tenants_data_of_e, $tenantB_id) == 0; -ok $tenant_utils_of_e->is_tenant_writeable($tenants_data_of_e, $tenantB_id) == 0; +ok $tenant_utils_of_e->is_tenant_resource_accessible($tenants_data_of_e, $tenantB_id) == 0; #################
