feat: add "Full Name" field to user creation (#13659)

Adds the ability to specify "Full Name" (a.k.a. Name) when
creating users either via CLI or UI.
This commit is contained in:
Cian Johnston
2024-06-26 09:00:42 +01:00
committed by GitHub
parent 87ad560aff
commit 8a3592582b
33 changed files with 435 additions and 25 deletions
+6
View File
@@ -8425,6 +8425,9 @@ const docTemplate = `{
"email": {
"type": "string"
},
"name": {
"type": "string"
},
"password": {
"type": "string"
},
@@ -8787,6 +8790,9 @@ const docTemplate = `{
}
]
},
"name": {
"type": "string"
},
"organization_id": {
"type": "string",
"format": "uuid"
+6
View File
@@ -7493,6 +7493,9 @@
"email": {
"type": "string"
},
"name": {
"type": "string"
},
"password": {
"type": "string"
},
@@ -7824,6 +7827,9 @@
}
]
},
"name": {
"type": "string"
},
"organization_id": {
"type": "string",
"format": "uuid"
+25
View File
@@ -29,6 +29,7 @@ import (
"sync/atomic"
"testing"
"time"
"unicode"
"cloud.google.com/go/compute/metadata"
"github.com/fullsailor/pkcs7"
@@ -658,6 +659,7 @@ var FirstUserParams = codersdk.CreateFirstUserRequest{
Email: "testuser@coder.com",
Username: "testuser",
Password: "SomeSecurePassword!",
Name: "Test User",
}
// CreateFirstUser creates a user with preset credentials and authenticates
@@ -712,6 +714,7 @@ func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationI
req := codersdk.CreateUserRequest{
Email: namesgenerator.GetRandomName(10) + "@coder.com",
Username: RandomUsername(t),
Name: RandomName(t),
Password: "SomeSecurePassword!",
OrganizationID: organizationID,
}
@@ -1390,6 +1393,28 @@ func RandomUsername(t testing.TB) string {
return n
}
func RandomName(t testing.TB) string {
var sb strings.Builder
var err error
ss := strings.Split(namesgenerator.GetRandomName(10), "_")
for si, s := range ss {
for ri, r := range s {
if ri == 0 {
_, err = sb.WriteRune(unicode.ToTitle(r))
require.NoError(t, err)
} else {
_, err = sb.WriteRune(r)
require.NoError(t, err)
}
}
if si < len(ss)-1 {
_, err = sb.WriteRune(' ')
require.NoError(t, err)
}
}
return sb.String()
}
// Used to easily create an HTTP transport!
type roundTripper func(req *http.Request) (*http.Response, error)
+1
View File
@@ -1122,6 +1122,7 @@ func (s *MethodTestSuite) TestUser() {
ID: u.ID,
Email: u.Email,
Username: u.Username,
Name: u.Name,
UpdatedAt: u.UpdatedAt,
}).Asserts(u, policy.ActionUpdatePersonal).Returns(u)
}))
+1
View File
@@ -289,6 +289,7 @@ func User(t testing.TB, db database.Store, orig database.User) database.User {
ID: takeFirst(orig.ID, uuid.New()),
Email: takeFirst(orig.Email, namesgenerator.GetRandomName(1)),
Username: takeFirst(orig.Username, namesgenerator.GetRandomName(1)),
Name: takeFirst(orig.Name, namesgenerator.GetRandomName(1)),
HashedPassword: takeFirstSlice(orig.HashedPassword, []byte(must(cryptorand.String(32)))),
CreatedAt: takeFirst(orig.CreatedAt, dbtime.Now()),
UpdatedAt: takeFirst(orig.UpdatedAt, dbtime.Now()),
+2
View File
@@ -322,6 +322,7 @@ func convertUsers(users []database.User, count int64) []database.GetUsersRow {
ID: u.ID,
Email: u.Email,
Username: u.Username,
Name: u.Name,
HashedPassword: u.HashedPassword,
CreatedAt: u.CreatedAt,
UpdatedAt: u.UpdatedAt,
@@ -6492,6 +6493,7 @@ func (q *FakeQuerier) InsertUser(_ context.Context, arg database.InsertUserParam
CreatedAt: arg.CreatedAt,
UpdatedAt: arg.UpdatedAt,
Username: arg.Username,
Name: arg.Name,
Status: database.UserStatusDormant,
RBACRoles: arg.RBACRoles,
LoginType: arg.LoginType,
+1
View File
@@ -330,6 +330,7 @@ func ConvertUserRows(rows []GetUsersRow) []User {
ID: r.ID,
Email: r.Email,
Username: r.Username,
Name: r.Name,
HashedPassword: r.HashedPassword,
CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt,
+4 -1
View File
@@ -8917,6 +8917,7 @@ INSERT INTO
id,
email,
username,
name,
hashed_password,
created_at,
updated_at,
@@ -8924,13 +8925,14 @@ INSERT INTO
login_type
)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, theme_preference, name
($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, theme_preference, name
`
type InsertUserParams struct {
ID uuid.UUID `db:"id" json:"id"`
Email string `db:"email" json:"email"`
Username string `db:"username" json:"username"`
Name string `db:"name" json:"name"`
HashedPassword []byte `db:"hashed_password" json:"hashed_password"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
@@ -8943,6 +8945,7 @@ func (q *sqlQuerier) InsertUser(ctx context.Context, arg InsertUserParams) (User
arg.ID,
arg.Email,
arg.Username,
arg.Name,
arg.HashedPassword,
arg.CreatedAt,
arg.UpdatedAt,
+2 -1
View File
@@ -62,6 +62,7 @@ INSERT INTO
id,
email,
username,
name,
hashed_password,
created_at,
updated_at,
@@ -69,7 +70,7 @@ INSERT INTO
login_type
)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8) RETURNING *;
($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *;
-- name: UpdateUserProfile :one
UPDATE
+2
View File
@@ -187,6 +187,7 @@ func (api *API) postFirstUser(rw http.ResponseWriter, r *http.Request) {
CreateUserRequest: codersdk.CreateUserRequest{
Email: createUser.Email,
Username: createUser.Username,
Name: createUser.Name,
Password: createUser.Password,
OrganizationID: defaultOrg.ID,
},
@@ -1224,6 +1225,7 @@ func (api *API) CreateUser(ctx context.Context, store database.Store, req Create
ID: uuid.New(),
Email: req.Email,
Username: req.Username,
Name: httpapi.NormalizeRealUsername(req.Name),
CreatedAt: dbtime.Now(),
UpdatedAt: dbtime.Now(),
HashedPassword: []byte{},
+8 -1
View File
@@ -70,8 +70,14 @@ func TestFirstUser(t *testing.T) {
t.Run("Create", func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
client := coderdtest.New(t, nil)
_ = coderdtest.CreateFirstUser(t, client)
u, err := client.User(ctx, codersdk.Me)
require.NoError(t, err)
assert.Equal(t, coderdtest.FirstUserParams.Name, u.Name)
assert.Equal(t, coderdtest.FirstUserParams.Email, u.Email)
assert.Equal(t, coderdtest.FirstUserParams.Username, u.Username)
})
t.Run("Trial", func(t *testing.T) {
@@ -96,6 +102,7 @@ func TestFirstUser(t *testing.T) {
req := codersdk.CreateFirstUserRequest{
Email: "testuser@coder.com",
Username: "testuser",
Name: "Test User",
Password: "SomeSecurePassword!",
Trial: true,
}
@@ -1486,7 +1493,7 @@ func TestUsersFilter(t *testing.T) {
exp = append(exp, made)
}
}
require.ElementsMatch(t, exp, matched.Users, "expected workspaces returned")
require.ElementsMatch(t, exp, matched.Users, "expected users returned")
})
}
}