Skip to content

Commit

Permalink
fix up places where IsTenancyEnabledTx now returns an error
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Volz authored and dangogh committed Jul 4, 2018
1 parent 6dc69de commit 71972ef
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,13 @@ func readGetDeliveryServices(params map[string]string, tx *sqlx.Tx, user *auth.C
return nil, errs, tc.DataConflictError
}

if tenant.IsTenancyEnabledTx(tx) {
tenancyEnabled, err := tenant.IsTenancyEnabledTx(tx.Tx)
if err != nil {
log.Errorln("checking if tenancy is enabled: " + err.Error())
return nil, []error{tc.DBError}, tc.SystemError
}

if tenancyEnabled {
log.Debugln("Tenancy is enabled")
tenantIDs, err := tenant.GetUserTenantIDListTx(user, tx)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ func (req *TODeliveryServiceRequest) Read(parameters map[string]string) ([]inter
if len(errs) > 0 {
return nil, errs, tc.DataConflictError
}
if tenant.IsTenancyEnabledTx(req.ReqInfo.Tx) {
tenancyEnabled, err := tenant.IsTenancyEnabledTx(req.ReqInfo.Tx.Tx)
if err != nil {
log.Errorln("checking if tenancy is enabled: " + err.Error())
return nil, []error{tc.DBError}, tc.SystemError
}
if tenancyEnabled {
log.Debugln("Tenancy is enabled")
tenantIDs, err := tenant.GetUserTenantIDListTx(req.ReqInfo.User, req.ReqInfo.Tx)
if err != nil {
Expand Down
19 changes: 15 additions & 4 deletions traffic_ops/traffic_ops_golang/origin/origins.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ func (origin *TOOrigin) IsTenantAuthorized(user *auth.CurrentUser) (bool, error)
if err != nil {
return false, err
}

if currentTenantID != nil && tenant.IsTenancyEnabledTx(origin.ReqInfo.Tx) {
tenancyEnabled, err := tenant.IsTenancyEnabledTx(origin.ReqInfo.Tx.Tx)
if err != nil {
return false, err
}
if currentTenantID != nil && tenancyEnabled {
return tenant.IsResourceAuthorizedToUserTx(*currentTenantID, user, origin.ReqInfo.Tx.Tx)
}

Expand Down Expand Up @@ -178,7 +181,11 @@ func (origin *TOOrigin) Read(params map[string]string) ([]interface{}, []error,
}

var err error
if tenant.IsTenancyEnabledTx(origin.ReqInfo.Tx) {
tenancyEnabled, err := tenant.IsTenancyEnabledTx(origin.ReqInfo.Tx.Tx)
if err != nil {
return nil, []error{errors.New("Error checking if tenancy enabled.")}, tc.SystemError
}
if tenancyEnabled {
origins, err = filterAuthorized(origins, origin.ReqInfo.User, origin.ReqInfo.Tx)
if err != nil {
log.Errorln("Checking tenancy: " + err.Error())
Expand Down Expand Up @@ -271,7 +278,11 @@ LEFT JOIN tenant t ON o.tenant = t.id`
}

func checkTenancy(originTenantID, deliveryserviceID *int, tx *sqlx.Tx, user *auth.CurrentUser) (error, tc.ApiErrorType) {
if tenant.IsTenancyEnabledTx(tx) {
tenancyEnabled, err := tenant.IsTenancyEnabledTx(tx.Tx)
if err != nil {
return errors.New("Error checking if tenancy enabled."), tc.SystemError
}
if tenancyEnabled {
if originTenantID == nil {
return tc.NilTenantError, tc.ForbiddenError
}
Expand Down
3 changes: 1 addition & 2 deletions traffic_ops/traffic_ops_golang/test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ package test
*/

import (
"errors"
"reflect"
"sort"
"strings"

"github.com/pkg/errors"
)

// Extract the tag annotations from a struct into a string array
Expand Down

0 comments on commit 71972ef

Please sign in to comment.