Skip to content

Commit 367561e

Browse files
committed
feat: allow editing org icon
1 parent dd99897 commit 367561e

File tree

16 files changed

+104
-14
lines changed

16 files changed

+104
-14
lines changed

coderd/apidoc/docs.go

Lines changed: 9 additions & 0 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: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmem/dbmem.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func New() database.Store {
8888
Name: "first-organization",
8989
DisplayName: "first-organization",
9090
Description: "Builtin default organization.",
91+
Icon: "",
9192
CreatedAt: dbtime.Now(),
9293
UpdatedAt: dbtime.Now(),
9394
})
@@ -6189,6 +6190,7 @@ func (q *FakeQuerier) InsertOrganization(_ context.Context, arg database.InsertO
61896190
Name: arg.Name,
61906191
DisplayName: arg.DisplayName,
61916192
Description: arg.Description,
6193+
Icon: arg.Icon,
61926194
CreatedAt: arg.CreatedAt,
61936195
UpdatedAt: arg.UpdatedAt,
61946196
IsDefault: len(q.organizations) == 0,
@@ -7334,6 +7336,7 @@ func (q *FakeQuerier) UpdateOrganization(_ context.Context, arg database.UpdateO
73347336
org.Name = arg.Name
73357337
org.DisplayName = arg.DisplayName
73367338
org.Description = arg.Description
7339+
org.Icon = arg.Icon
73377340
q.organizations[i] = org
73387341
return org, nil
73397342
}

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 icon;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alter table organizations
2+
add column icon text not null 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: 22 additions & 10 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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ WHERE
4949

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

5757
-- name: UpdateOrganization :one
5858
UPDATE
@@ -61,7 +61,8 @@ SET
6161
updated_at = @updated_at,
6262
name = @name,
6363
display_name = @display_name,
64-
description = @description
64+
description = @description,
65+
icon = @icon
6566
WHERE
6667
id = @id
6768
RETURNING *;

coderd/organizations.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (api *API) postOrganizations(rw http.ResponseWriter, r *http.Request) {
8383
Name: req.Name,
8484
DisplayName: req.DisplayName,
8585
Description: req.Description,
86+
Icon: req.Icon,
8687
CreatedAt: dbtime.Now(),
8788
UpdatedAt: dbtime.Now(),
8889
})
@@ -164,6 +165,7 @@ func (api *API) patchOrganization(rw http.ResponseWriter, r *http.Request) {
164165
Name: organization.Name,
165166
DisplayName: organization.DisplayName,
166167
Description: organization.Description,
168+
Icon: organization.Icon,
167169
}
168170

169171
if req.Name != "" {
@@ -175,6 +177,9 @@ func (api *API) patchOrganization(rw http.ResponseWriter, r *http.Request) {
175177
if req.Description != "" {
176178
updateOrgParams.Description = req.Description
177179
}
180+
if req.Icon != "" {
181+
updateOrgParams.Icon = req.Icon
182+
}
178183

179184
organization, err = tx.UpdateOrganization(ctx, updateOrgParams)
180185
if err != nil {
@@ -248,6 +253,7 @@ func convertOrganization(organization database.Organization) codersdk.Organizati
248253
Name: organization.Name,
249254
DisplayName: organization.DisplayName,
250255
Description: organization.Description,
256+
Icon: organization.Icon,
251257
CreatedAt: organization.CreatedAt,
252258
UpdatedAt: organization.UpdatedAt,
253259
IsDefault: organization.IsDefault,

coderd/organizations_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,13 @@ func TestPostOrganizationsByUser(t *testing.T) {
142142
Name: "new",
143143
DisplayName: "New",
144144
Description: "A new organization to love and cherish forever.",
145+
Icon: "/emojis/1f48f-1f3ff.png",
145146
})
146147
require.NoError(t, err)
147148
require.Equal(t, "new", o.Name)
148149
require.Equal(t, "New", o.DisplayName)
149150
require.Equal(t, "A new organization to love and cherish forever.", o.Description)
151+
require.Equal(t, "/emojis/1f48f-1f3ff.png", o.Icon)
150152
})
151153

152154
t.Run("CreateWithoutExplicitDisplayName", func(t *testing.T) {
@@ -308,6 +310,28 @@ func TestPatchOrganizationsByUser(t *testing.T) {
308310
require.Equal(t, "New", o.DisplayName) // didn't change
309311
require.Equal(t, "wow, this organization description is so updated!", o.Description)
310312
})
313+
314+
t.Run("UpdateIcon", func(t *testing.T) {
315+
t.Parallel()
316+
client := coderdtest.New(t, nil)
317+
_ = coderdtest.CreateFirstUser(t, client)
318+
ctx := testutil.Context(t, testutil.WaitMedium)
319+
320+
o, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
321+
Name: "new",
322+
DisplayName: "New",
323+
})
324+
require.NoError(t, err)
325+
326+
o, err = client.UpdateOrganization(ctx, o.Name, codersdk.UpdateOrganizationRequest{
327+
Icon: "/emojis/1f48f-1f3ff.png",
328+
})
329+
330+
require.NoError(t, err)
331+
require.Equal(t, "new", o.Name) // didn't change
332+
require.Equal(t, "New", o.DisplayName) // didn't change
333+
require.Equal(t, "/emojis/1f48f-1f3ff.png", o.Icon)
334+
})
311335
}
312336

313337
func TestDeleteOrganizationsByUser(t *testing.T) {

codersdk/organizations.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Organization struct {
4747
CreatedAt time.Time `table:"created_at" json:"created_at" validate:"required" format:"date-time"`
4848
UpdatedAt time.Time `table:"updated_at" json:"updated_at" validate:"required" format:"date-time"`
4949
IsDefault bool `table:"default" json:"is_default" validate:"required"`
50+
Icon string `table:"icon" json:"icon"`
5051
}
5152

5253
type OrganizationMember struct {
@@ -62,12 +63,14 @@ type CreateOrganizationRequest struct {
6263
// DisplayName will default to the same value as `Name` if not provided.
6364
DisplayName string `json:"display_name" validate:"omitempty,organization_display_name"`
6465
Description string `json:"description,omitempty"`
66+
Icon string `json:"icon,omitempty"`
6567
}
6668

6769
type UpdateOrganizationRequest struct {
6870
Name string `json:"name,omitempty" validate:"omitempty,organization_name"`
6971
DisplayName string `json:"display_name,omitempty" validate:"omitempty,organization_display_name"`
7072
Description string `json:"description,omitempty"`
73+
Icon string `json:"icon,omitempty"`
7174
}
7275

7376
// CreateTemplateVersionRequest enables callers to create a new Template Version.

0 commit comments

Comments
 (0)