Admin can now change the user name of a user account. Closes issue #2.

This commit is contained in:
2026-04-21 15:40:50 -05:00
parent ea807cc55f
commit 17de55c5c2
5 changed files with 34 additions and 0 deletions
+1
View File
@@ -93,6 +93,7 @@ const (
AuditAdminChangeUserAccount = 111
AuditAdminSetAccountSecurity = 112
AuditAdminLockUnlockAccount = 113
AuditAdminSetUserName = 114
AuditCommunityCreate = 201
AuditCommunitySetMembership = 202
AuditCommunityContactInfo = 203
+2
View File
@@ -44,6 +44,8 @@ auditReference:
text: "Admin Set Account Security"
- code: 113
text: "Admin Lock/Unlock Account"
- code: 114
text: "Admin Set User Name"
- code: 201
text: "Create New Community"
- code: 202
+12
View File
@@ -381,6 +381,18 @@ func (u *User) Prefs(ctx context.Context) (*UserPrefs, error) {
return u.prefs, nil
}
func (u *User) SetUsername(ctx context.Context, username string, setter *User, ipaddr string) error {
u.Mutex.Lock()
_, err := amdb.ExecContext(ctx, "UPDATE users SET username = ? WHERE uid = ?", username, u.Uid)
u.Mutex.Unlock()
if err == nil {
u.Username = username
AmStoreAudit(AmNewAudit(AuditAdminSetUserName, setter.Uid, ipaddr, fmt.Sprintf("uid=%d", u.Uid),
fmt.Sprintf("newname=%s", username)))
}
return err
}
/* SetProfileData sets the "profile" variables for this user.
* Parameters:
* ctx - Standard Go context value.