Skip to content

Commit 4c1e63a

Browse files
authored
feat: add display_name field to groups (#8740)
* feat: add display_name field to groups This is a non-unique human friendly group name for display purposes. This means a display name can be used instead of using an environment var to remap groups with OIDC names to Coder names. Now groups can retain the OIDC name for mapping, and use a display name for display purposes.
1 parent 6ea32e4 commit 4c1e63a

38 files changed

+266
-45
lines changed

coderd/apidoc/docs.go

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbfake/dbfake.go

+3
Original file line numberDiff line numberDiff line change
@@ -3402,6 +3402,7 @@ func (q *FakeQuerier) InsertAllUsersGroup(ctx context.Context, orgID uuid.UUID)
34023402
return q.InsertGroup(ctx, database.InsertGroupParams{
34033403
ID: orgID,
34043404
Name: database.AllUsersGroup,
3405+
DisplayName: "",
34053406
OrganizationID: orgID,
34063407
})
34073408
}
@@ -3521,6 +3522,7 @@ func (q *FakeQuerier) InsertGroup(_ context.Context, arg database.InsertGroupPar
35213522
group := database.Group{
35223523
ID: arg.ID,
35233524
Name: arg.Name,
3525+
DisplayName: arg.DisplayName,
35243526
OrganizationID: arg.OrganizationID,
35253527
AvatarURL: arg.AvatarURL,
35263528
QuotaAllowance: arg.QuotaAllowance,
@@ -4329,6 +4331,7 @@ func (q *FakeQuerier) UpdateGroupByID(_ context.Context, arg database.UpdateGrou
43294331

43304332
for i, group := range q.groups {
43314333
if group.ID == arg.ID {
4334+
group.DisplayName = arg.DisplayName
43324335
group.Name = arg.Name
43334336
group.AvatarURL = arg.AvatarURL
43344337
group.QuotaAllowance = arg.QuotaAllowance

coderd/database/dbgen/dbgen.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,11 @@ func OrganizationMember(t testing.TB, db database.Store, orig database.Organizat
279279
}
280280

281281
func Group(t testing.TB, db database.Store, orig database.Group) database.Group {
282+
name := takeFirst(orig.Name, namesgenerator.GetRandomName(1))
282283
group, err := db.InsertGroup(genCtx, database.InsertGroupParams{
283284
ID: takeFirst(orig.ID, uuid.New()),
284-
Name: takeFirst(orig.Name, namesgenerator.GetRandomName(1)),
285+
Name: name,
286+
DisplayName: takeFirst(orig.DisplayName, name),
285287
OrganizationID: takeFirst(orig.OrganizationID, uuid.New()),
286288
AvatarURL: takeFirst(orig.AvatarURL, "https://logo.example.com"),
287289
QuotaAllowance: takeFirst(orig.QuotaAllowance, 0),

coderd/database/dump.sql

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
BEGIN;
2+
3+
ALTER TABLE groups
4+
DROP COLUMN display_name;
5+
6+
COMMIT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
BEGIN;
2+
3+
ALTER TABLE groups
4+
ADD COLUMN display_name TEXT NOT NULL DEFAULT '';
5+
6+
COMMENT ON COLUMN groups.display_name IS 'Display name is a custom, human-friendly group name that user can set. This is not required to be unique and can be the empty string.';
7+
8+
COMMIT;

coderd/database/models.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

+21-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/groups.sql

+7-5
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ AND
3434
INSERT INTO groups (
3535
id,
3636
name,
37+
display_name,
3738
organization_id,
3839
avatar_url,
3940
quota_allowance
4041
)
4142
VALUES
42-
($1, $2, $3, $4, $5) RETURNING *;
43+
($1, $2, $3, $4, $5, $6) RETURNING *;
4344

4445
-- We use the organization_id as the id
4546
-- for simplicity since all users is
@@ -57,11 +58,12 @@ VALUES
5758
UPDATE
5859
groups
5960
SET
60-
name = $1,
61-
avatar_url = $2,
62-
quota_allowance = $3
61+
name = @name,
62+
display_name = @display_name,
63+
avatar_url = @avatar_url,
64+
quota_allowance = @quota_allowance
6365
WHERE
64-
id = $4
66+
id = @id
6567
RETURNING *;
6668

6769
-- name: DeleteGroupByID :exec

codersdk/groups.go

+3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import (
1212

1313
type CreateGroupRequest struct {
1414
Name string `json:"name"`
15+
DisplayName string `json:"display_name"`
1516
AvatarURL string `json:"avatar_url"`
1617
QuotaAllowance int `json:"quota_allowance"`
1718
}
1819

1920
type Group struct {
2021
ID uuid.UUID `json:"id" format:"uuid"`
2122
Name string `json:"name"`
23+
DisplayName string `json:"display_name"`
2224
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
2325
Members []User `json:"members"`
2426
AvatarURL string `json:"avatar_url"`
@@ -98,6 +100,7 @@ type PatchGroupRequest struct {
98100
AddUsers []string `json:"add_users"`
99101
RemoveUsers []string `json:"remove_users"`
100102
Name string `json:"name"`
103+
DisplayName *string `json:"display_name"`
101104
AvatarURL *string `json:"avatar_url"`
102105
QuotaAllowance *int `json:"quota_allowance"`
103106
}

0 commit comments

Comments
 (0)