Skip to content

feat: allow editing org icon #13547

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 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions clock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package clock

import (
"context"
"errors"
"fmt"
"slices"
"sync"
"testing"
"time"

"golang.org/x/xerrors"
)

// Mock is the testing implementation of Clock. It tracks a time that monotonically increases
Expand Down Expand Up @@ -571,7 +572,7 @@ func (t *Trap) Close() {
close(t.done)
}

var ErrTrapClosed = errors.New("trap closed")
var ErrTrapClosed = xerrors.New("trap closed")

func (t *Trap) Wait(ctx context.Context) (*Call, error) {
select {
Expand Down
9 changes: 9 additions & 0 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions coderd/database/dbgen/dbgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ func Organization(t testing.TB, db database.Store, orig database.Organization) d
Name: takeFirst(orig.Name, namesgenerator.GetRandomName(1)),
DisplayName: takeFirst(orig.Name, namesgenerator.GetRandomName(1)),
Description: takeFirst(orig.Description, namesgenerator.GetRandomName(1)),
Icon: takeFirst(orig.Icon, ""),
CreatedAt: takeFirst(orig.CreatedAt, dbtime.Now()),
UpdatedAt: takeFirst(orig.UpdatedAt, dbtime.Now()),
})
Expand Down
3 changes: 3 additions & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func New() database.Store {
Name: "first-organization",
DisplayName: "first-organization",
Description: "Builtin default organization.",
Icon: "",
CreatedAt: dbtime.Now(),
UpdatedAt: dbtime.Now(),
})
Expand Down Expand Up @@ -6189,6 +6190,7 @@ func (q *FakeQuerier) InsertOrganization(_ context.Context, arg database.InsertO
Name: arg.Name,
DisplayName: arg.DisplayName,
Description: arg.Description,
Icon: arg.Icon,
CreatedAt: arg.CreatedAt,
UpdatedAt: arg.UpdatedAt,
IsDefault: len(q.organizations) == 0,
Expand Down Expand Up @@ -7334,6 +7336,7 @@ func (q *FakeQuerier) UpdateOrganization(_ context.Context, arg database.UpdateO
org.Name = arg.Name
org.DisplayName = arg.DisplayName
org.Description = arg.Description
org.Icon = arg.Icon
q.organizations[i] = org
return org, nil
}
Expand Down
3 changes: 2 additions & 1 deletion coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions coderd/database/migrations/000219_organization_icon.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table organizations
drop column icon;
2 changes: 2 additions & 0 deletions coderd/database/migrations/000219_organization_icon.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table organizations
add column icon text not null default '';
1 change: 1 addition & 0 deletions coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 22 additions & 10 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions coderd/database/queries/organizations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ WHERE

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

-- name: UpdateOrganization :one
UPDATE
Expand All @@ -61,7 +61,8 @@ SET
updated_at = @updated_at,
name = @name,
display_name = @display_name,
description = @description
description = @description,
icon = @icon
WHERE
id = @id
RETURNING *;
Expand Down
10 changes: 8 additions & 2 deletions coderd/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (api *API) postOrganizations(rw http.ResponseWriter, r *http.Request) {
Name: req.Name,
DisplayName: req.DisplayName,
Description: req.Description,
Icon: req.Icon,
CreatedAt: dbtime.Now(),
UpdatedAt: dbtime.Now(),
})
Expand Down Expand Up @@ -164,6 +165,7 @@ func (api *API) patchOrganization(rw http.ResponseWriter, r *http.Request) {
Name: organization.Name,
DisplayName: organization.DisplayName,
Description: organization.Description,
Icon: organization.Icon,
}

if req.Name != "" {
Expand All @@ -172,8 +174,11 @@ func (api *API) patchOrganization(rw http.ResponseWriter, r *http.Request) {
if req.DisplayName != "" {
updateOrgParams.DisplayName = req.DisplayName
}
if req.Description != "" {
updateOrgParams.Description = req.Description
if req.Description != nil {
updateOrgParams.Description = *req.Description
}
if req.Icon != nil {
updateOrgParams.Icon = *req.Icon
}

organization, err = tx.UpdateOrganization(ctx, updateOrgParams)
Expand Down Expand Up @@ -248,6 +253,7 @@ func convertOrganization(organization database.Organization) codersdk.Organizati
Name: organization.Name,
DisplayName: organization.DisplayName,
Description: organization.Description,
Icon: organization.Icon,
CreatedAt: organization.CreatedAt,
UpdatedAt: organization.UpdatedAt,
IsDefault: organization.IsDefault,
Expand Down
Loading
Loading