You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by rs...@apache.org on 2023/05/12 22:26:21 UTC

[trafficcontrol] branch master updated: Changing registration changelog to include username (#7511)

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

rshah 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 b0d00b1901 Changing registration changelog to include username (#7511)
b0d00b1901 is described below

commit b0d00b1901e9b49b9aee726302094d70996a49c7
Author: Srijeet Chatterjee <30...@users.noreply.github.com>
AuthorDate: Fri May 12 16:26:15 2023 -0600

    Changing registration changelog to include username (#7511)
    
    * Changing registration changelog to include username
    
    * fix changelog
    
    * fix bug where username is empty
    
    * Address code review
---
 CHANGELOG.md                                     |  1 +
 traffic_ops/traffic_ops_golang/login/register.go | 25 +++++++++++++-----------
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index beb1ac775c..74d705c02d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -53,6 +53,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - [#7469](https://github.com/apache/trafficcontrol/pull/7469) *Traffic Ops* Changed logic to not report empty or missing cookies into TO error.log.
 
 ### Fixed
+- [#7511](https://github.com/apache/trafficcontrol/pull/7511) *Traffic Ops* Fixed the changelog registration message to include the username instead of duplicate email entry.
 - [#7505](https://github.com/apache/trafficcontrol/pull/7505) *Traffic Portal* Fix an issue where a Delivery Service with Geo Limit Countries Set was unable to be updated.
 - [#7441](https://github.com/apache/trafficcontrol/pull/7441) *Traffic Ops* Fixed the invalidation jobs endpoint to respect CDN locks.
 - [#7413](https://github.com/apache/trafficcontrol/issues/7413) *Traffic Ops* Fixes service_category apis to respond with RFC3339 date/time Format
diff --git a/traffic_ops/traffic_ops_golang/login/register.go b/traffic_ops/traffic_ops_golang/login/register.go
index 8f664a3bed..6a0fc0164b 100644
--- a/traffic_ops/traffic_ops_golang/login/register.go
+++ b/traffic_ops/traffic_ops_golang/login/register.go
@@ -69,7 +69,8 @@ RETURNING (
 	SELECT tenant.name
 	FROM tenant
 	WHERE tenant.id=tm_user.tenant_id
-) AS tenant
+) AS tenant,
+username
 `
 
 const renewRegistrationQuery = `
@@ -246,6 +247,7 @@ func RegisterUser(w http.ResponseWriter, r *http.Request) {
 
 	var role string
 	var tenant string
+	var username string
 	user, exists, err := dbhelpers.GetUserByEmail(email.Address.Address, inf.Tx.Tx)
 	if err != nil {
 		errCode = http.StatusInternalServerError
@@ -260,10 +262,9 @@ func RegisterUser(w http.ResponseWriter, r *http.Request) {
 			api.HandleErr(w, r, tx, errCode, userErr, nil)
 			return
 		}
-
 		role, tenant, err = renewRegistration(tx, req, t, user)
 	} else {
-		role, tenant, err = newRegistration(tx, req, t)
+		role, tenant, username, err = newRegistration(tx, req, t)
 	}
 
 	if err != nil {
@@ -272,10 +273,13 @@ func RegisterUser(w http.ResponseWriter, r *http.Request) {
 		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
 		return
 	}
+	if user.Username != nil {
+		username = *user.Username
+	}
 
 	msg, err := createRegistrationMsg(email, t, tx, inf.Config.ConfigPortal)
 	if err != nil {
-		sysErr = fmt.Errorf("Failed to create email message: %v", err)
+		sysErr = fmt.Errorf("failed to create email message: %v", err)
 		errCode = http.StatusInternalServerError
 		api.HandleErr(w, r, tx, errCode, nil, sysErr)
 		return
@@ -287,13 +291,12 @@ func RegisterUser(w http.ResponseWriter, r *http.Request) {
 		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
 		return
 	}
-
 	var alert = "Sent user registration to %s with the following permissions [ role: %s | tenant: %s ]"
 	alert = fmt.Sprintf(alert, email, role, tenant)
 	api.WriteRespAlert(w, r, tc.SuccessLevel, alert)
 
 	var changeLog = "USER: %s, EMAIL: %s, ACTION: registration sent with role %s and tenant %s"
-	changeLog = fmt.Sprintf(changeLog, email, email, role, tenant)
+	changeLog = fmt.Sprintf(changeLog, username, email, role, tenant)
 	api.CreateChangeLogRawTx(api.ApiChange, changeLog, inf.User, tx)
 }
 
@@ -309,14 +312,14 @@ func renewRegistration(tx *sql.Tx, req tc.UserRegistrationRequest, t string, u t
 	return role, tenant, nil
 }
 
-func newRegistration(tx *sql.Tx, req tc.UserRegistrationRequest, t string) (string, string, error) {
+func newRegistration(tx *sql.Tx, req tc.UserRegistrationRequest, t string) (string, string, string, error) {
 	var role string
 	var tenant string
-
+	var username string
 	var row = tx.QueryRow(registerUserQuery, req.Email.Address.Address, req.Role, req.TenantID, t)
-	if err := row.Scan(&role, &tenant); err != nil {
-		return "", "", err
+	if err := row.Scan(&role, &tenant, &username); err != nil {
+		return "", "", "", err
 	}
 
-	return role, tenant, nil
+	return role, tenant, username, nil
 }