mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: allow editing org icon (#13547)
This commit is contained in:
Generated
+9
@@ -8376,6 +8376,9 @@ const docTemplate = `{
|
||||
"description": "DisplayName will default to the same value as ` + "`" + `Name` + "`" + ` if not provided.",
|
||||
"type": "string"
|
||||
},
|
||||
"icon": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
@@ -10007,6 +10010,9 @@ const docTemplate = `{
|
||||
"display_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"icon": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "string",
|
||||
"format": "uuid"
|
||||
@@ -11724,6 +11730,9 @@ const docTemplate = `{
|
||||
"display_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"icon": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
|
||||
Generated
+9
@@ -7456,6 +7456,9 @@
|
||||
"description": "DisplayName will default to the same value as `Name` if not provided.",
|
||||
"type": "string"
|
||||
},
|
||||
"icon": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
@@ -8996,6 +8999,9 @@
|
||||
"display_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"icon": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "string",
|
||||
"format": "uuid"
|
||||
@@ -10628,6 +10634,9 @@
|
||||
"display_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"icon": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
|
||||
@@ -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()),
|
||||
})
|
||||
|
||||
@@ -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(),
|
||||
})
|
||||
@@ -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,
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Generated
+2
-1
@@ -595,7 +595,8 @@ CREATE TABLE organizations (
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
updated_at timestamp with time zone NOT NULL,
|
||||
is_default boolean DEFAULT false NOT NULL,
|
||||
display_name text NOT NULL
|
||||
display_name text NOT NULL,
|
||||
icon text DEFAULT ''::text NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE parameter_schemas (
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
alter table organizations
|
||||
drop column icon;
|
||||
@@ -0,0 +1,2 @@
|
||||
alter table organizations
|
||||
add column icon text not null default '';
|
||||
@@ -1933,6 +1933,7 @@ type Organization struct {
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
IsDefault bool `db:"is_default" json:"is_default"`
|
||||
DisplayName string `db:"display_name" json:"display_name"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
}
|
||||
|
||||
type OrganizationMember struct {
|
||||
|
||||
@@ -3949,7 +3949,7 @@ func (q *sqlQuerier) DeleteOrganization(ctx context.Context, id uuid.UUID) error
|
||||
|
||||
const getDefaultOrganization = `-- name: GetDefaultOrganization :one
|
||||
SELECT
|
||||
id, name, description, created_at, updated_at, is_default, display_name
|
||||
id, name, description, created_at, updated_at, is_default, display_name, icon
|
||||
FROM
|
||||
organizations
|
||||
WHERE
|
||||
@@ -3969,13 +3969,14 @@ func (q *sqlQuerier) GetDefaultOrganization(ctx context.Context) (Organization,
|
||||
&i.UpdatedAt,
|
||||
&i.IsDefault,
|
||||
&i.DisplayName,
|
||||
&i.Icon,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getOrganizationByID = `-- name: GetOrganizationByID :one
|
||||
SELECT
|
||||
id, name, description, created_at, updated_at, is_default, display_name
|
||||
id, name, description, created_at, updated_at, is_default, display_name, icon
|
||||
FROM
|
||||
organizations
|
||||
WHERE
|
||||
@@ -3993,13 +3994,14 @@ func (q *sqlQuerier) GetOrganizationByID(ctx context.Context, id uuid.UUID) (Org
|
||||
&i.UpdatedAt,
|
||||
&i.IsDefault,
|
||||
&i.DisplayName,
|
||||
&i.Icon,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getOrganizationByName = `-- name: GetOrganizationByName :one
|
||||
SELECT
|
||||
id, name, description, created_at, updated_at, is_default, display_name
|
||||
id, name, description, created_at, updated_at, is_default, display_name, icon
|
||||
FROM
|
||||
organizations
|
||||
WHERE
|
||||
@@ -4019,13 +4021,14 @@ func (q *sqlQuerier) GetOrganizationByName(ctx context.Context, name string) (Or
|
||||
&i.UpdatedAt,
|
||||
&i.IsDefault,
|
||||
&i.DisplayName,
|
||||
&i.Icon,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getOrganizations = `-- name: GetOrganizations :many
|
||||
SELECT
|
||||
id, name, description, created_at, updated_at, is_default, display_name
|
||||
id, name, description, created_at, updated_at, is_default, display_name, icon
|
||||
FROM
|
||||
organizations
|
||||
`
|
||||
@@ -4047,6 +4050,7 @@ func (q *sqlQuerier) GetOrganizations(ctx context.Context) ([]Organization, erro
|
||||
&i.UpdatedAt,
|
||||
&i.IsDefault,
|
||||
&i.DisplayName,
|
||||
&i.Icon,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -4063,7 +4067,7 @@ func (q *sqlQuerier) GetOrganizations(ctx context.Context) ([]Organization, erro
|
||||
|
||||
const getOrganizationsByUserID = `-- name: GetOrganizationsByUserID :many
|
||||
SELECT
|
||||
id, name, description, created_at, updated_at, is_default, display_name
|
||||
id, name, description, created_at, updated_at, is_default, display_name, icon
|
||||
FROM
|
||||
organizations
|
||||
WHERE
|
||||
@@ -4094,6 +4098,7 @@ func (q *sqlQuerier) GetOrganizationsByUserID(ctx context.Context, userID uuid.U
|
||||
&i.UpdatedAt,
|
||||
&i.IsDefault,
|
||||
&i.DisplayName,
|
||||
&i.Icon,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -4110,10 +4115,10 @@ func (q *sqlQuerier) GetOrganizationsByUserID(ctx context.Context, userID uuid.U
|
||||
|
||||
const insertOrganization = `-- 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.
|
||||
($1, $2, $3, $4, $5, $6, (SELECT TRUE FROM organizations LIMIT 1) IS NULL) RETURNING id, name, description, created_at, updated_at, is_default, display_name
|
||||
($1, $2, $3, $4, $5, $6, $7, (SELECT TRUE FROM organizations LIMIT 1) IS NULL) RETURNING id, name, description, created_at, updated_at, is_default, display_name, icon
|
||||
`
|
||||
|
||||
type InsertOrganizationParams struct {
|
||||
@@ -4121,6 +4126,7 @@ type InsertOrganizationParams struct {
|
||||
Name string `db:"name" json:"name"`
|
||||
DisplayName string `db:"display_name" json:"display_name"`
|
||||
Description string `db:"description" json:"description"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
@@ -4131,6 +4137,7 @@ func (q *sqlQuerier) InsertOrganization(ctx context.Context, arg InsertOrganizat
|
||||
arg.Name,
|
||||
arg.DisplayName,
|
||||
arg.Description,
|
||||
arg.Icon,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
)
|
||||
@@ -4143,6 +4150,7 @@ func (q *sqlQuerier) InsertOrganization(ctx context.Context, arg InsertOrganizat
|
||||
&i.UpdatedAt,
|
||||
&i.IsDefault,
|
||||
&i.DisplayName,
|
||||
&i.Icon,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -4154,10 +4162,11 @@ SET
|
||||
updated_at = $1,
|
||||
name = $2,
|
||||
display_name = $3,
|
||||
description = $4
|
||||
description = $4,
|
||||
icon = $5
|
||||
WHERE
|
||||
id = $5
|
||||
RETURNING id, name, description, created_at, updated_at, is_default, display_name
|
||||
id = $6
|
||||
RETURNING id, name, description, created_at, updated_at, is_default, display_name, icon
|
||||
`
|
||||
|
||||
type UpdateOrganizationParams struct {
|
||||
@@ -4165,6 +4174,7 @@ type UpdateOrganizationParams struct {
|
||||
Name string `db:"name" json:"name"`
|
||||
DisplayName string `db:"display_name" json:"display_name"`
|
||||
Description string `db:"description" json:"description"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
@@ -4174,6 +4184,7 @@ func (q *sqlQuerier) UpdateOrganization(ctx context.Context, arg UpdateOrganizat
|
||||
arg.Name,
|
||||
arg.DisplayName,
|
||||
arg.Description,
|
||||
arg.Icon,
|
||||
arg.ID,
|
||||
)
|
||||
var i Organization
|
||||
@@ -4185,6 +4196,7 @@ func (q *sqlQuerier) UpdateOrganization(ctx context.Context, arg UpdateOrganizat
|
||||
&i.UpdatedAt,
|
||||
&i.IsDefault,
|
||||
&i.DisplayName,
|
||||
&i.Icon,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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 *;
|
||||
|
||||
@@ -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(),
|
||||
})
|
||||
@@ -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 != "" {
|
||||
@@ -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)
|
||||
@@ -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,
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/coder/coder/v2/coderd/coderdtest"
|
||||
"github.com/coder/coder/v2/coderd/util/ptr"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
"github.com/coder/coder/v2/testutil"
|
||||
)
|
||||
@@ -142,11 +143,13 @@ func TestPostOrganizationsByUser(t *testing.T) {
|
||||
Name: "new",
|
||||
DisplayName: "New",
|
||||
Description: "A new organization to love and cherish forever.",
|
||||
Icon: "/emojis/1f48f-1f3ff.png",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "new", o.Name)
|
||||
require.Equal(t, "New", o.DisplayName)
|
||||
require.Equal(t, "A new organization to love and cherish forever.", o.Description)
|
||||
require.Equal(t, "/emojis/1f48f-1f3ff.png", o.Icon)
|
||||
})
|
||||
|
||||
t.Run("CreateWithoutExplicitDisplayName", func(t *testing.T) {
|
||||
@@ -300,7 +303,7 @@ func TestPatchOrganizationsByUser(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
o, err = client.UpdateOrganization(ctx, o.Name, codersdk.UpdateOrganizationRequest{
|
||||
Description: "wow, this organization description is so updated!",
|
||||
Description: ptr.Ref("wow, this organization description is so updated!"),
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
@@ -308,6 +311,28 @@ func TestPatchOrganizationsByUser(t *testing.T) {
|
||||
require.Equal(t, "New", o.DisplayName) // didn't change
|
||||
require.Equal(t, "wow, this organization description is so updated!", o.Description)
|
||||
})
|
||||
|
||||
t.Run("UpdateIcon", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := coderdtest.New(t, nil)
|
||||
_ = coderdtest.CreateFirstUser(t, client)
|
||||
ctx := testutil.Context(t, testutil.WaitMedium)
|
||||
|
||||
o, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
|
||||
Name: "new",
|
||||
DisplayName: "New",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
o, err = client.UpdateOrganization(ctx, o.Name, codersdk.UpdateOrganizationRequest{
|
||||
Icon: ptr.Ref("/emojis/1f48f-1f3ff.png"),
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "new", o.Name) // didn't change
|
||||
require.Equal(t, "New", o.DisplayName) // didn't change
|
||||
require.Equal(t, "/emojis/1f48f-1f3ff.png", o.Icon)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDeleteOrganizationsByUser(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user