You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2018/07/23 15:56:58 UTC
[trafficcontrol] 01/02: if user has no tenant,
check if tenancy is on and respond accordingly
This is an automated email from the ASF dual-hosted git repository.
dewrich pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit d6728b08b7d40c432fc142d978ddca63fb59ac81
Author: Dan Kirkwood <da...@apache.org>
AuthorDate: Thu Jul 19 17:15:17 2018 -0600
if user has no tenant, check if tenancy is on and respond accordingly
---
traffic_ops/traffic_ops_golang/tenant/tenant.go | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/traffic_ops/traffic_ops_golang/tenant/tenant.go b/traffic_ops/traffic_ops_golang/tenant/tenant.go
index 24dbf7f..b6d4ec0 100644
--- a/traffic_ops/traffic_ops_golang/tenant/tenant.go
+++ b/traffic_ops/traffic_ops_golang/tenant/tenant.go
@@ -159,6 +159,25 @@ func (ten *TOTenant) Create() (error, tc.ApiErrorType) {
func (ten *TOTenant) Read(parameters map[string]string) ([]interface{}, []error, tc.ApiErrorType) {
var rows *sqlx.Rows
+ tenantID := ten.ReqInfo.User.TenantID
+ if tenantID == auth.TenantIDInvalid {
+ // NOTE: work around issue where user has no tenancy assigned. If tenancy turned off, there
+ // should be no tenancy restrictions. This should be removed once tenant_id NOT NULL constraints
+ // are in place
+ enabled, err := IsTenancyEnabledTx(ten.ReqInfo.Tx.Tx)
+ if err != nil {
+ log.Infof("error checking tenancy: %v", err)
+ return nil, nil, tc.SystemError
+ }
+
+ if enabled {
+ // tenancy enabled, but user doesn't belong to one -- return empty list
+ return nil, nil, tc.NoError
+ }
+ // give it the root tenant -- since tenancy turned off, does not matter what it is
+ tenantID = 1
+ }
+
// Query Parameters to Database Query column mappings
// see the fields mapped in the SQL query
queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
@@ -173,7 +192,7 @@ func (ten *TOTenant) Read(parameters map[string]string) ([]interface{}, []error,
return nil, errs, tc.DataConflictError
}
- query := selectQuery(ten.ReqInfo.User.TenantID) + where + orderBy
+ query := selectQuery(tenantID) + where + orderBy
log.Debugln("Query is ", query)
rows, err := ten.ReqInfo.Tx.NamedQuery(query, queryValues)