Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing registration changelog to include username #7511

Merged
merged 5 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 14 additions & 11 deletions traffic_ops/traffic_ops_golang/login/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ RETURNING (
SELECT tenant.name
FROM tenant
WHERE tenant.id=tm_user.tenant_id
) AS tenant
) AS tenant,
username
`

const renewRegistrationQuery = `
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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)
}

Expand All @@ -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
}