You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ro...@apache.org on 2019/02/19 16:00:15 UTC

[trafficcontrol] branch master updated: Revert "Use JSONIntStr for user endpoint"

This is an automated email from the ASF dual-hosted git repository.

rob pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 01ef925  Revert "Use JSONIntStr for user endpoint"
01ef925 is described below

commit 01ef925a4d0526f19f0ab6a60b687e384ca69f71
Author: moltzaum <ma...@moltzau.net>
AuthorDate: Fri Feb 8 13:24:43 2019 -0700

    Revert "Use JSONIntStr for user endpoint"
    
    This reverts commit ccec233e2c7951e28b42bf370e5fc6b5c498df95.
    
    In the conversion from perl to go, perl will accept strings or ints as
    integers because it is a weakly typed language. The use of JSONIntStr
    allowed the same to happen in golang (in this case for a single
    endpoint).
    
    The use of JSONIntStr would keep the functionaility from perl, however I
    am reverting the change because keeping this behavior implies that we
    want to maintain it in the future for all other endpoints.
    
    When the original commit was made, there was not yet a consensus to keep the bug as is.
    Here is a part of the discussion (the rest was in slack):
    https://lists.apache.org/thread.html/f0624d4386f1de1f18b322436df6fa0402bf34314abd4b108edc5fde@%3Cdev.trafficcontrol.apache.org%3E
---
 lib/go-tc/users.go                          | 38 ++++++++++++++---------------
 traffic_ops/client/user.go                  |  8 ++----
 traffic_ops/traffic_ops_golang/user/user.go |  6 ++---
 3 files changed, 23 insertions(+), 29 deletions(-)

diff --git a/lib/go-tc/users.go b/lib/go-tc/users.go
index d072a5c..25c3fc8 100644
--- a/lib/go-tc/users.go
+++ b/lib/go-tc/users.go
@@ -1,7 +1,5 @@
 package tc
 
-import util "github.com/apache/trafficcontrol/lib/go-util"
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -56,24 +54,24 @@ type UserV13 struct {
 // commonUserFields is unexported, but its contents are still visible when it is embedded
 // LastUpdated is a new field for some structs
 type commonUserFields struct {
-	AddressLine1    *string          `json:"addressLine1" db:"address_line1"`
-	AddressLine2    *string          `json:"addressLine2" db:"address_line2"`
-	City            *string          `json:"city" db:"city"`
-	Company         *string          `json:"company" db:"company"`
-	Country         *string          `json:"country" db:"country"`
-	Email           *string          `json:"email" db:"email"`
-	FullName        *string          `json:"fullName" db:"full_name"`
-	GID             *int             `json:"gid"`
-	ID              *int             `json:"id" db:"id"`
-	NewUser         *bool            `json:"newUser" db:"new_user"`
-	PhoneNumber     *string          `json:"phoneNumber" db:"phone_number"`
-	PostalCode      *string          `json:"postalCode" db:"postal_code"`
-	PublicSSHKey    *string          `json:"publicSshKey" db:"public_ssh_key"`
-	Role            *util.JSONIntStr `json:"role" db:"role"`
-	StateOrProvince *string          `json:"stateOrProvince" db:"state_or_province"`
-	Tenant          *string          `json:"tenant"`
-	TenantID        *util.JSONIntStr `json:"tenantId" db:"tenant_id"`
-	UID             *int             `json:"uid"`
+	AddressLine1    *string `json:"addressLine1" db:"address_line1"`
+	AddressLine2    *string `json:"addressLine2" db:"address_line2"`
+	City            *string `json:"city" db:"city"`
+	Company         *string `json:"company" db:"company"`
+	Country         *string `json:"country" db:"country"`
+	Email           *string `json:"email" db:"email"`
+	FullName        *string `json:"fullName" db:"full_name"`
+	GID             *int    `json:"gid"`
+	ID              *int    `json:"id" db:"id"`
+	NewUser         *bool   `json:"newUser" db:"new_user"`
+	PhoneNumber     *string `json:"phoneNumber" db:"phone_number"`
+	PostalCode      *string `json:"postalCode" db:"postal_code"`
+	PublicSSHKey    *string `json:"publicSshKey" db:"public_ssh_key"`
+	Role            *int    `json:"role" db:"role"`
+	StateOrProvince *string `json:"stateOrProvince" db:"state_or_province"`
+	Tenant          *string `json:"tenant"`
+	TenantID        *int    `json:"tenantId" db:"tenant_id"`
+	UID             *int    `json:"uid"`
 	//Username        *string    `json:"username" db:"username"`  //not including major change due to naming incompatibility
 	LastUpdated *TimeNoMod `json:"lastUpdated" db:"last_updated"`
 }
diff --git a/traffic_ops/client/user.go b/traffic_ops/client/user.go
index c2ebaed..93f4de3 100644
--- a/traffic_ops/client/user.go
+++ b/traffic_ops/client/user.go
@@ -24,7 +24,6 @@ import (
 	"strconv"
 
 	"github.com/apache/trafficcontrol/lib/go-tc"
-	util "github.com/apache/trafficcontrol/lib/go-util"
 )
 
 // Users gets an array of Users.
@@ -79,7 +78,6 @@ func (to *Session) GetUserCurrent() (*tc.UserCurrent, ReqInf, error) {
 
 // CreateUser creates a user
 func (to *Session) CreateUser(user *tc.User) (*tc.CreateUserResponse, ReqInf, error) {
-
 	if user.TenantID == nil && user.Tenant != nil {
 		tenant, _, err := to.TenantByName(*user.Tenant)
 		if err != nil {
@@ -91,8 +89,7 @@ func (to *Session) CreateUser(user *tc.User) (*tc.CreateUserResponse, ReqInf, er
 		if err != nil {
 			return nil, ReqInf{}, err
 		}
-		tmp := util.JSONIntStr(tenant.ID)
-		user.TenantID = &tmp
+		user.TenantID = &tenant.ID
 	}
 
 	if user.RoleName != nil && *user.RoleName != "" {
@@ -106,8 +103,7 @@ func (to *Session) CreateUser(user *tc.User) (*tc.CreateUserResponse, ReqInf, er
 		if err != nil {
 			return nil, ReqInf{}, err
 		}
-		tmp := util.JSONIntStr(*roles[0].ID)
-		user.Role = &tmp
+		user.Role = roles[0].ID
 	}
 
 	var remoteAddr net.Addr
diff --git a/traffic_ops/traffic_ops_golang/user/user.go b/traffic_ops/traffic_ops_golang/user/user.go
index bb62cfc..44c5845 100644
--- a/traffic_ops/traffic_ops_golang/user/user.go
+++ b/traffic_ops/traffic_ops_golang/user/user.go
@@ -221,7 +221,7 @@ func (this *TOUser) Read() ([]interface{}, error, error, int) {
 }
 
 func (user *TOUser) privCheck() (error, error, int) {
-	requestedPrivLevel, _, err := dbhelpers.GetPrivLevelFromRoleID(user.ReqInfo.Tx.Tx, int(*user.Role))
+	requestedPrivLevel, _, err := dbhelpers.GetPrivLevelFromRoleID(user.ReqInfo.Tx.Tx, *user.Role)
 	if err != nil {
 		return nil, err, http.StatusInternalServerError
 	}
@@ -236,7 +236,7 @@ func (user *TOUser) privCheck() (error, error, int) {
 func (user *TOUser) Update() (error, error, int) {
 
 	// make sure current user cannot update their own role to a new value
-	if user.ReqInfo.User.ID == *user.ID && user.ReqInfo.User.Role != int(*user.Role) {
+	if user.ReqInfo.User.ID == *user.ID && user.ReqInfo.User.Role != *user.Role {
 		return fmt.Errorf("users cannot update their own role"), nil, http.StatusBadRequest
 	}
 
@@ -323,7 +323,7 @@ func (u *TOUser) IsTenantAuthorized(user *auth.CurrentUser) (bool, error) {
 	if u.TenantID != nil { // new tenant id (only on create or udpate)
 
 		//log.Debugf("%d with tenancy %d trying to access %d", user.ID, user.TenantID, *u.TenantID)
-		authorized, err := tenant.IsResourceAuthorizedToUserTx(int(*u.TenantID), user, tx)
+		authorized, err := tenant.IsResourceAuthorizedToUserTx(*u.TenantID, user, tx)
 		if err != nil {
 			return false, err
 		}