Skip to content

feat: add display_name field to groups #8740

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

Merged
merged 20 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
display name defaults to empty string
  • Loading branch information
Emyrk committed Jul 26, 2023
commit 532aaa105038007f5e3b881e38c981ba3ccb6b1c
2 changes: 1 addition & 1 deletion coderd/database/dbfake/dbfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -3381,7 +3381,7 @@ func (q *FakeQuerier) InsertAllUsersGroup(ctx context.Context, orgID uuid.UUID)
return q.InsertGroup(ctx, database.InsertGroupParams{
ID: orgID,
Name: database.AllUsersGroup,
DisplayName: database.AllUsersGroup,
DisplayName: "",
OrganizationID: orgID,
})
}
Expand Down
3 changes: 0 additions & 3 deletions coderd/database/migrations/000142_group_display_name.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ ALTER TABLE groups

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.';

-- Use the name as the display name for all existing groups
UPDATE groups SET display_name = name;

COMMIT;
3 changes: 1 addition & 2 deletions coderd/database/queries/groups.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ VALUES
INSERT INTO groups (
id,
name,
display_name,
organization_id
)
VALUES
(sqlc.arg(organization_id), 'Everyone', 'Everyone', sqlc.arg(organization_id)) RETURNING *;
(sqlc.arg(organization_id), 'Everyone', sqlc.arg(organization_id)) RETURNING *;

-- name: UpdateGroupByID :one
UPDATE
Expand Down
2 changes: 2 additions & 0 deletions enterprise/cli/grouplist.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type groupTableRow struct {

// For table output:
Name string `json:"-" table:"name,default_sort"`
DisplayName string `json:"-" table:"display_name"`
OrganizationID uuid.UUID `json:"-" table:"organization_id"`
Members []string `json:"-" table:"members"`
AvatarURL string `json:"-" table:"avatar_url"`
Expand All @@ -81,6 +82,7 @@ func groupsToRows(groups ...codersdk.Group) []groupTableRow {
}
rows = append(rows, groupTableRow{
Name: group.Name,
DisplayName: group.DisplayName,
OrganizationID: group.OrganizationID,
AvatarURL: group.AvatarURL,
Members: members,
Expand Down
16 changes: 10 additions & 6 deletions enterprise/coderd/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
req.Name = ""
}

// Do not update the display name if it is the same.
if req.DisplayName == group.DisplayName {
req.DisplayName = ""
}

users := make([]string, 0, len(req.AddUsers)+len(req.RemoveUsers))
users = append(users, req.AddUsers...)
users = append(users, req.RemoveUsers...)
Expand Down Expand Up @@ -205,6 +200,10 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
if req.DisplayName != "" {
updateGroupParams.DisplayName = req.DisplayName
}
// If the names are identical, then remove the display name.
if req.DisplayName == req.Name {
updateGroupParams.DisplayName = ""
}

group, err = tx.UpdateGroupByID(ctx, updateGroupParams)
if err != nil {
Expand Down Expand Up @@ -410,10 +409,15 @@ func convertGroup(g database.Group, users []database.User) codersdk.Group {
for _, user := range users {
orgs[user.ID] = []uuid.UUID{g.OrganizationID}
}
// Always default to the group name if the display name is empty
displayName := g.DisplayName
if displayName == "" {
displayName = g.Name
}
return codersdk.Group{
ID: g.ID,
Name: g.Name,
DisplayName: g.DisplayName,
DisplayName: displayName,
OrganizationID: g.OrganizationID,
AvatarURL: g.AvatarURL,
QuotaAllowance: int(g.QuotaAllowance),
Expand Down
16 changes: 15 additions & 1 deletion site/src/pages/GroupsPage/SettingsGroupPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ const UpdateGroupForm: FC<{
const form = useFormik<FormData>({
initialValues: {
name: group.name,
display_name: group.display_name,
// If these are equal, keep the display name blank. A blank display name means
// default to using the name.
display_name: group.display_name === group.name ? "" : group.display_name,
avatar_url: group.avatar_url,
quota_allowance: group.quota_allowance,
},
Expand All @@ -57,6 +59,18 @@ const UpdateGroupForm: FC<{
fullWidth
label="Name"
/>
{/* We might want to always show this at some point, but for now only show if
the display name differs from the original name. */}
{group.name !== group.display_name && (
<TextField
{...getFieldHelpers("display_name")}
onChange={onChangeTrimmed(form)}
autoComplete="display_name"
autoFocus
fullWidth
label="Display Name"
/>
)}

<LazyIconField
{...getFieldHelpers("avatar_url")}
Expand Down