Skip to content

Commit 6e2ffd1

Browse files
committed
feat: allow editing org display name and description
1 parent 83ac386 commit 6e2ffd1

17 files changed

+265
-74
lines changed

coderd/apidoc/docs.go

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 24 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dump.sql

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alter table organizations
2+
drop column display_name;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- This default is just a temporary thing to avoid null errors when first creating the column.
2+
alter table organizations
3+
add column display_name text not null default '';
4+
5+
update organizations
6+
set display_name = name;
7+
8+
-- We can remove the default now that everything has been copied.
9+
alter table organizations
10+
alter column display_name drop default;

coderd/database/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 33 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/organizations.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,19 @@ WHERE
4949

5050
-- name: InsertOrganization :one
5151
INSERT INTO
52-
organizations (id, "name", description, created_at, updated_at, is_default)
52+
organizations (id, "name", display_name, description, created_at, updated_at, is_default)
5353
VALUES
5454
-- If no organizations exist, and this is the first, make it the default.
55-
($1, $2, $3, $4, $5, (SELECT TRUE FROM organizations LIMIT 1) IS NULL) RETURNING *;
55+
(@id, @name, @display_name, @description, @created_at, @updated_at, (SELECT TRUE FROM organizations LIMIT 1) IS NULL) RETURNING *;
5656

5757
-- name: UpdateOrganization :one
5858
UPDATE
5959
organizations
6060
SET
6161
updated_at = @updated_at,
62-
name = @name
62+
name = @name,
63+
display_name = @display_name,
64+
description = @description
6365
WHERE
6466
id = @id
6567
RETURNING *;

coderd/organizations.go

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (api *API) postOrganizations(rw http.ResponseWriter, r *http.Request) {
7777
organization, err = tx.InsertOrganization(ctx, database.InsertOrganizationParams{
7878
ID: uuid.New(),
7979
Name: req.Name,
80+
DisplayName: req.DisplayName,
8081
CreatedAt: dbtime.Now(),
8182
UpdatedAt: dbtime.Now(),
8283
Description: "",
@@ -146,11 +147,38 @@ func (api *API) patchOrganization(rw http.ResponseWriter, r *http.Request) {
146147
return
147148
}
148149

149-
organization, err := api.Database.UpdateOrganization(ctx, database.UpdateOrganizationParams{
150-
ID: organization.ID,
151-
UpdatedAt: dbtime.Now(),
152-
Name: req.Name,
150+
err := database.ReadModifyUpdate(api.Database, func(tx database.Store) error {
151+
var err error
152+
organization, err = tx.GetOrganizationByID(ctx, organization.ID)
153+
if err != nil {
154+
return err
155+
}
156+
157+
updateOrgParams := database.UpdateOrganizationParams{
158+
UpdatedAt: dbtime.Now(),
159+
ID: organization.ID,
160+
Name: organization.Name,
161+
DisplayName: organization.DisplayName,
162+
Description: organization.Description,
163+
}
164+
165+
if req.Name != "" {
166+
updateOrgParams.Name = req.Name
167+
}
168+
if req.DisplayName != "" {
169+
updateOrgParams.DisplayName = req.DisplayName
170+
}
171+
if req.Description != "" {
172+
updateOrgParams.Description = req.Description
173+
}
174+
175+
organization, err = tx.UpdateOrganization(ctx, updateOrgParams)
176+
if err != nil {
177+
return err
178+
}
179+
return nil
153180
})
181+
154182
if httpapi.Is404Error(err) {
155183
httpapi.ResourceNotFound(rw)
156184
return
@@ -212,10 +240,12 @@ func (api *API) deleteOrganization(rw http.ResponseWriter, r *http.Request) {
212240
// convertOrganization consumes the database representation and outputs an API friendly representation.
213241
func convertOrganization(organization database.Organization) codersdk.Organization {
214242
return codersdk.Organization{
215-
ID: organization.ID,
216-
Name: organization.Name,
217-
CreatedAt: organization.CreatedAt,
218-
UpdatedAt: organization.UpdatedAt,
219-
IsDefault: organization.IsDefault,
243+
ID: organization.ID,
244+
Name: organization.Name,
245+
DisplayName: organization.DisplayName,
246+
Description: organization.Description,
247+
CreatedAt: organization.CreatedAt,
248+
UpdatedAt: organization.UpdatedAt,
249+
IsDefault: organization.IsDefault,
220250
}
221251
}

0 commit comments

Comments
 (0)