From ef49cd72085fb9147d08183e9b9f6c610650d290 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Tue, 9 Jul 2024 16:11:17 -0500 Subject: [PATCH 1/9] chore: templates return organization display name and icon --- coderd/database/dump.sql | 5 +++- .../000223_template_display_name.down.sql | 22 ++++++++++++++++ .../000223_template_display_name.up.sql | 25 +++++++++++++++++++ coderd/database/modelqueries.go | 3 +++ coderd/database/models.go | 3 +++ coderd/database/queries.sql.go | 20 ++++++++++++--- 6 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 coderd/database/migrations/000223_template_display_name.down.sql create mode 100644 coderd/database/migrations/000223_template_display_name.up.sql diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql index 3f2da45155da1..222b554fe8ed3 100644 --- a/coderd/database/dump.sql +++ b/coderd/database/dump.sql @@ -1087,7 +1087,10 @@ CREATE VIEW template_with_names AS templates.max_port_sharing_level, COALESCE(visible_users.avatar_url, ''::text) AS created_by_avatar_url, COALESCE(visible_users.username, ''::text) AS created_by_username, - COALESCE(organizations.name, ''::text) AS organization_name + COALESCE(organizations.name, ''::text) AS organization_name, + COALESCE(organizations.display_name, ''::text) AS organization_display_name, + COALESCE(organizations.description, ''::text) AS organization_description, + COALESCE(organizations.icon, ''::text) AS organization_icon FROM ((templates LEFT JOIN visible_users ON ((templates.created_by = visible_users.id))) LEFT JOIN organizations ON ((templates.organization_id = organizations.id))); diff --git a/coderd/database/migrations/000223_template_display_name.down.sql b/coderd/database/migrations/000223_template_display_name.down.sql new file mode 100644 index 0000000000000..2b0dc7d8adf29 --- /dev/null +++ b/coderd/database/migrations/000223_template_display_name.down.sql @@ -0,0 +1,22 @@ +DROP VIEW template_with_names; + +CREATE VIEW + template_with_names +AS +SELECT + templates.*, + coalesce(visible_users.avatar_url, '') AS created_by_avatar_url, + coalesce(visible_users.username, '') AS created_by_username, + coalesce(organizations.name, '') AS organization_name +FROM + templates + LEFT JOIN + visible_users + ON + templates.created_by = visible_users.id + LEFT JOIN + organizations + ON templates.organization_id = organizations.id +; + +COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.'; diff --git a/coderd/database/migrations/000223_template_display_name.up.sql b/coderd/database/migrations/000223_template_display_name.up.sql new file mode 100644 index 0000000000000..c4ca6cf42d973 --- /dev/null +++ b/coderd/database/migrations/000223_template_display_name.up.sql @@ -0,0 +1,25 @@ +-- Update the template_with_names view by recreating it. +DROP VIEW template_with_names; +CREATE VIEW + template_with_names +AS +SELECT + templates.*, + coalesce(visible_users.avatar_url, '') AS created_by_avatar_url, + coalesce(visible_users.username, '') AS created_by_username, + coalesce(organizations.name, '') AS organization_name, + coalesce(organizations.display_name, '') AS organization_display_name, + coalesce(organizations.description, '') AS organization_description, + coalesce(organizations.icon, '') AS organization_icon +FROM + templates + LEFT JOIN + visible_users + ON + templates.created_by = visible_users.id + LEFT JOIN + organizations + ON templates.organization_id = organizations.id +; + +COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.'; diff --git a/coderd/database/modelqueries.go b/coderd/database/modelqueries.go index 3323ed834b31d..7f4452d3c1599 100644 --- a/coderd/database/modelqueries.go +++ b/coderd/database/modelqueries.go @@ -117,6 +117,9 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate &i.CreatedByAvatarURL, &i.CreatedByUsername, &i.OrganizationName, + &i.OrganizationDisplayName, + &i.OrganizationDescription, + &i.OrganizationIcon, ); err != nil { return nil, err } diff --git a/coderd/database/models.go b/coderd/database/models.go index 4ff84ddc8891f..71acb39abbe96 100644 --- a/coderd/database/models.go +++ b/coderd/database/models.go @@ -2279,6 +2279,9 @@ type Template struct { CreatedByAvatarURL string `db:"created_by_avatar_url" json:"created_by_avatar_url"` CreatedByUsername string `db:"created_by_username" json:"created_by_username"` OrganizationName string `db:"organization_name" json:"organization_name"` + OrganizationDisplayName string `db:"organization_display_name" json:"organization_display_name"` + OrganizationDescription string `db:"organization_description" json:"organization_description"` + OrganizationIcon string `db:"organization_icon" json:"organization_icon"` } type TemplateTable struct { diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index 83be6184706ce..ffdce74d620f8 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -7247,7 +7247,7 @@ func (q *sqlQuerier) GetTemplateAverageBuildTime(ctx context.Context, arg GetTem const getTemplateByID = `-- name: GetTemplateByID :one SELECT - id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name + id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name, organization_display_name, organization_description, organization_icon FROM template_with_names WHERE @@ -7291,13 +7291,16 @@ func (q *sqlQuerier) GetTemplateByID(ctx context.Context, id uuid.UUID) (Templat &i.CreatedByAvatarURL, &i.CreatedByUsername, &i.OrganizationName, + &i.OrganizationDisplayName, + &i.OrganizationDescription, + &i.OrganizationIcon, ) return i, err } const getTemplateByOrganizationAndName = `-- name: GetTemplateByOrganizationAndName :one SELECT - id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name + id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name, organization_display_name, organization_description, organization_icon FROM template_with_names AS templates WHERE @@ -7349,12 +7352,15 @@ func (q *sqlQuerier) GetTemplateByOrganizationAndName(ctx context.Context, arg G &i.CreatedByAvatarURL, &i.CreatedByUsername, &i.OrganizationName, + &i.OrganizationDisplayName, + &i.OrganizationDescription, + &i.OrganizationIcon, ) return i, err } const getTemplates = `-- name: GetTemplates :many -SELECT id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name FROM template_with_names AS templates +SELECT id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name, organization_display_name, organization_description, organization_icon FROM template_with_names AS templates ORDER BY (name, id) ASC ` @@ -7399,6 +7405,9 @@ func (q *sqlQuerier) GetTemplates(ctx context.Context) ([]Template, error) { &i.CreatedByAvatarURL, &i.CreatedByUsername, &i.OrganizationName, + &i.OrganizationDisplayName, + &i.OrganizationDescription, + &i.OrganizationIcon, ); err != nil { return nil, err } @@ -7415,7 +7424,7 @@ func (q *sqlQuerier) GetTemplates(ctx context.Context) ([]Template, error) { const getTemplatesWithFilter = `-- name: GetTemplatesWithFilter :many SELECT - id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name + id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name, organization_display_name, organization_description, organization_icon FROM template_with_names AS templates WHERE @@ -7510,6 +7519,9 @@ func (q *sqlQuerier) GetTemplatesWithFilter(ctx context.Context, arg GetTemplate &i.CreatedByAvatarURL, &i.CreatedByUsername, &i.OrganizationName, + &i.OrganizationDisplayName, + &i.OrganizationDescription, + &i.OrganizationIcon, ); err != nil { return nil, err } From ed2b48f9cd3814cd6bcd045c19874ccc6245771d Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Tue, 9 Jul 2024 16:17:49 -0500 Subject: [PATCH 2/9] templates api response includes organization display name and icon --- coderd/database/dump.sql | 1 - .../000223_template_display_name.up.sql | 1 - coderd/database/modelqueries.go | 1 - coderd/database/models.go | 1 - coderd/database/queries.sql.go | 12 ++++------- coderd/templates.go | 2 ++ codersdk/templates.go | 20 ++++++++++--------- 7 files changed, 17 insertions(+), 21 deletions(-) diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql index 222b554fe8ed3..55102d827d50c 100644 --- a/coderd/database/dump.sql +++ b/coderd/database/dump.sql @@ -1089,7 +1089,6 @@ CREATE VIEW template_with_names AS COALESCE(visible_users.username, ''::text) AS created_by_username, COALESCE(organizations.name, ''::text) AS organization_name, COALESCE(organizations.display_name, ''::text) AS organization_display_name, - COALESCE(organizations.description, ''::text) AS organization_description, COALESCE(organizations.icon, ''::text) AS organization_icon FROM ((templates LEFT JOIN visible_users ON ((templates.created_by = visible_users.id))) diff --git a/coderd/database/migrations/000223_template_display_name.up.sql b/coderd/database/migrations/000223_template_display_name.up.sql index c4ca6cf42d973..2b3c1ddef1de9 100644 --- a/coderd/database/migrations/000223_template_display_name.up.sql +++ b/coderd/database/migrations/000223_template_display_name.up.sql @@ -9,7 +9,6 @@ SELECT coalesce(visible_users.username, '') AS created_by_username, coalesce(organizations.name, '') AS organization_name, coalesce(organizations.display_name, '') AS organization_display_name, - coalesce(organizations.description, '') AS organization_description, coalesce(organizations.icon, '') AS organization_icon FROM templates diff --git a/coderd/database/modelqueries.go b/coderd/database/modelqueries.go index 7f4452d3c1599..7ee4f4f676eea 100644 --- a/coderd/database/modelqueries.go +++ b/coderd/database/modelqueries.go @@ -118,7 +118,6 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate &i.CreatedByUsername, &i.OrganizationName, &i.OrganizationDisplayName, - &i.OrganizationDescription, &i.OrganizationIcon, ); err != nil { return nil, err diff --git a/coderd/database/models.go b/coderd/database/models.go index 71acb39abbe96..c92d51b4366d3 100644 --- a/coderd/database/models.go +++ b/coderd/database/models.go @@ -2280,7 +2280,6 @@ type Template struct { CreatedByUsername string `db:"created_by_username" json:"created_by_username"` OrganizationName string `db:"organization_name" json:"organization_name"` OrganizationDisplayName string `db:"organization_display_name" json:"organization_display_name"` - OrganizationDescription string `db:"organization_description" json:"organization_description"` OrganizationIcon string `db:"organization_icon" json:"organization_icon"` } diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index ffdce74d620f8..5e85fd10d9838 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -7247,7 +7247,7 @@ func (q *sqlQuerier) GetTemplateAverageBuildTime(ctx context.Context, arg GetTem const getTemplateByID = `-- name: GetTemplateByID :one SELECT - id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name, organization_display_name, organization_description, organization_icon + id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name, organization_display_name, organization_icon FROM template_with_names WHERE @@ -7292,7 +7292,6 @@ func (q *sqlQuerier) GetTemplateByID(ctx context.Context, id uuid.UUID) (Templat &i.CreatedByUsername, &i.OrganizationName, &i.OrganizationDisplayName, - &i.OrganizationDescription, &i.OrganizationIcon, ) return i, err @@ -7300,7 +7299,7 @@ func (q *sqlQuerier) GetTemplateByID(ctx context.Context, id uuid.UUID) (Templat const getTemplateByOrganizationAndName = `-- name: GetTemplateByOrganizationAndName :one SELECT - id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name, organization_display_name, organization_description, organization_icon + id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name, organization_display_name, organization_icon FROM template_with_names AS templates WHERE @@ -7353,14 +7352,13 @@ func (q *sqlQuerier) GetTemplateByOrganizationAndName(ctx context.Context, arg G &i.CreatedByUsername, &i.OrganizationName, &i.OrganizationDisplayName, - &i.OrganizationDescription, &i.OrganizationIcon, ) return i, err } const getTemplates = `-- name: GetTemplates :many -SELECT id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name, organization_display_name, organization_description, organization_icon FROM template_with_names AS templates +SELECT id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name, organization_display_name, organization_icon FROM template_with_names AS templates ORDER BY (name, id) ASC ` @@ -7406,7 +7404,6 @@ func (q *sqlQuerier) GetTemplates(ctx context.Context) ([]Template, error) { &i.CreatedByUsername, &i.OrganizationName, &i.OrganizationDisplayName, - &i.OrganizationDescription, &i.OrganizationIcon, ); err != nil { return nil, err @@ -7424,7 +7421,7 @@ func (q *sqlQuerier) GetTemplates(ctx context.Context) ([]Template, error) { const getTemplatesWithFilter = `-- name: GetTemplatesWithFilter :many SELECT - id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name, organization_display_name, organization_description, organization_icon + id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, default_ttl, created_by, icon, user_acl, group_acl, display_name, allow_user_cancel_workspace_jobs, allow_user_autostart, allow_user_autostop, failure_ttl, time_til_dormant, time_til_dormant_autodelete, autostop_requirement_days_of_week, autostop_requirement_weeks, autostart_block_days_of_week, require_active_version, deprecated, activity_bump, max_port_sharing_level, created_by_avatar_url, created_by_username, organization_name, organization_display_name, organization_icon FROM template_with_names AS templates WHERE @@ -7520,7 +7517,6 @@ func (q *sqlQuerier) GetTemplatesWithFilter(ctx context.Context, arg GetTemplate &i.CreatedByUsername, &i.OrganizationName, &i.OrganizationDisplayName, - &i.OrganizationDescription, &i.OrganizationIcon, ); err != nil { return nil, err diff --git a/coderd/templates.go b/coderd/templates.go index 00401c209b0a2..78f821a382a8d 100644 --- a/coderd/templates.go +++ b/coderd/templates.go @@ -886,6 +886,8 @@ func (api *API) convertTemplate( UpdatedAt: template.UpdatedAt, OrganizationID: template.OrganizationID, OrganizationName: template.OrganizationName, + OrganizationDisplayName: template.OrganizationDisplayName, + OrganizationIcon: template.OrganizationIcon, Name: template.Name, DisplayName: template.DisplayName, Provisioner: codersdk.ProvisionerType(template.Provisioner), diff --git a/codersdk/templates.go b/codersdk/templates.go index 0a9e26da105be..cad6ef2ca49dc 100644 --- a/codersdk/templates.go +++ b/codersdk/templates.go @@ -15,15 +15,17 @@ import ( // Template is the JSON representation of a Coder template. This type matches the // database object for now, but is abstracted for ease of change later on. type Template struct { - ID uuid.UUID `json:"id" format:"uuid"` - CreatedAt time.Time `json:"created_at" format:"date-time"` - UpdatedAt time.Time `json:"updated_at" format:"date-time"` - OrganizationID uuid.UUID `json:"organization_id" format:"uuid"` - OrganizationName string `json:"organization_name" format:"url"` - Name string `json:"name"` - DisplayName string `json:"display_name"` - Provisioner ProvisionerType `json:"provisioner" enums:"terraform"` - ActiveVersionID uuid.UUID `json:"active_version_id" format:"uuid"` + ID uuid.UUID `json:"id" format:"uuid"` + CreatedAt time.Time `json:"created_at" format:"date-time"` + UpdatedAt time.Time `json:"updated_at" format:"date-time"` + OrganizationID uuid.UUID `json:"organization_id" format:"uuid"` + OrganizationName string `json:"organization_name" format:"url"` + OrganizationDisplayName string `json:"organization_display_name"` + OrganizationIcon string `json:"organization_icon"` + Name string `json:"name"` + DisplayName string `json:"display_name"` + Provisioner ProvisionerType `json:"provisioner" enums:"terraform"` + ActiveVersionID uuid.UUID `json:"active_version_id" format:"uuid"` // ActiveUserCount is set to -1 when loading. ActiveUserCount int `json:"active_user_count"` BuildTimeStats TemplateBuildTimeStats `json:"build_time_stats"` From f7d3e17f52e75828b12317579191d6a7064b9a10 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Tue, 9 Jul 2024 16:20:27 -0500 Subject: [PATCH 3/9] unit test --- coderd/database/dbmem/dbmem.go | 2 ++ coderd/templates_test.go | 2 ++ site/src/api/typesGenerated.ts | 2 ++ 3 files changed, 6 insertions(+) diff --git a/coderd/database/dbmem/dbmem.go b/coderd/database/dbmem/dbmem.go index 420d6bc466420..5842ad8a2f921 100644 --- a/coderd/database/dbmem/dbmem.go +++ b/coderd/database/dbmem/dbmem.go @@ -558,6 +558,8 @@ func (q *FakeQuerier) templateWithNameNoLock(tpl database.TemplateTable) databas withNames.CreatedByUsername = user.Username withNames.CreatedByAvatarURL = user.AvatarURL withNames.OrganizationName = org.Name + withNames.OrganizationDisplayName = org.DisplayName + withNames.OrganizationIcon = org.Icon return withNames } diff --git a/coderd/templates_test.go b/coderd/templates_test.go index 612591120ec1a..b82d043bba84c 100644 --- a/coderd/templates_test.go +++ b/coderd/templates_test.go @@ -451,6 +451,8 @@ func TestTemplatesByOrganization(t *testing.T) { for _, tmpl := range templates { require.Equal(t, tmpl.OrganizationID, user.OrganizationID, "organization ID") require.Equal(t, tmpl.OrganizationName, org.Name, "organization name") + require.Equal(t, tmpl.OrganizationDisplayName, org.DisplayName, "organization display name") + require.Equal(t, tmpl.OrganizationIcon, org.Icon, "organization display name") } }) t.Run("MultipleOrganizations", func(t *testing.T) { diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index 6a3ce9adaae82..70318955fd18f 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -1127,6 +1127,8 @@ export interface Template { readonly updated_at: string; readonly organization_id: string; readonly organization_name: string; + readonly organization_display_name: string; + readonly organization_icon: string; readonly name: string; readonly display_name: string; readonly provisioner: ProvisionerType; From f3c2361eff0c9aee24f82ac8700dafce8e47d8e0 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Tue, 9 Jul 2024 16:21:31 -0500 Subject: [PATCH 4/9] fixup typescript mocks --- site/src/testHelpers/entities.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/site/src/testHelpers/entities.ts b/site/src/testHelpers/entities.ts index 8c5ec8c79a2ce..0d63a8e7c5720 100644 --- a/site/src/testHelpers/entities.ts +++ b/site/src/testHelpers/entities.ts @@ -481,6 +481,8 @@ export const MockTemplate: TypesGen.Template = { updated_at: "2022-05-18T17:39:01.382927298Z", organization_id: MockOrganization.id, organization_name: "default", + organization_display_name: "Default", + organization_icon: "/emojis/1f5fa.png", name: "test-template", display_name: "Test Template", provisioner: MockProvisioner.provisioners[0], From 378a0429352eb01bbbecf8362de427f2f82ba505 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Tue, 9 Jul 2024 16:27:01 -0500 Subject: [PATCH 5/9] update audit table --- enterprise/audit/table.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/enterprise/audit/table.go b/enterprise/audit/table.go index f2ec06701904d..3a0a1eb209ed9 100644 --- a/enterprise/audit/table.go +++ b/enterprise/audit/table.go @@ -83,6 +83,8 @@ var auditableResourcesTypes = map[any]map[string]Action{ "updated_at": ActionIgnore, // Changes, but is implicit and not helpful in a diff. "organization_id": ActionIgnore, /// Never changes. "organization_name": ActionIgnore, // Ignore these changes + "organization_display_name": ActionIgnore, // Ignore these changes + "organization_icon": ActionIgnore, // Ignore these changes "deleted": ActionIgnore, // Changes, but is implicit when a delete event is fired. "name": ActionTrack, "display_name": ActionTrack, From eb9391129a5eda62bc409a7f4d70648160049e4a Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Tue, 9 Jul 2024 16:47:06 -0500 Subject: [PATCH 6/9] make gen --- coderd/apidoc/docs.go | 6 ++++++ docs/api/schemas.md | 4 ++++ docs/api/templates.md | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/coderd/apidoc/docs.go b/coderd/apidoc/docs.go index 6554372157207..0382ab967dcd4 100644 --- a/coderd/apidoc/docs.go +++ b/coderd/apidoc/docs.go @@ -11428,6 +11428,12 @@ const docTemplate = `{ "name": { "type": "string" }, + "organization_display_name": { + "type": "string" + }, + "organization_icon": { + "type": "string" + }, "organization_id": { "type": "string", "format": "uuid" diff --git a/docs/api/schemas.md b/docs/api/schemas.md index fd0d4c87437d4..1f1fff531593f 100644 --- a/docs/api/schemas.md +++ b/docs/api/schemas.md @@ -4480,6 +4480,8 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "max_port_share_level": "owner", "name": "string", + "organization_display_name": "string", + "organization_icon": "string", "organization_id": "7c60d51f-b44e-4682-87d6-449835ea4de6", "organization_name": "string", "provisioner": "terraform", @@ -4516,6 +4518,8 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o | `id` | string | false | | | | `max_port_share_level` | [codersdk.WorkspaceAgentPortShareLevel](#codersdkworkspaceagentportsharelevel) | false | | | | `name` | string | false | | | +| `organization_display_name` | string | false | | | +| `organization_icon` | string | false | | | | `organization_id` | string | false | | | | `organization_name` | string | false | | | | `provisioner` | string | false | | | diff --git a/docs/api/templates.md b/docs/api/templates.md index 2f713d027482c..f42c4306d01a8 100644 --- a/docs/api/templates.md +++ b/docs/api/templates.md @@ -62,6 +62,8 @@ curl -X GET http://coder-server:8080/api/v2/organizations/{organization}/templat "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "max_port_share_level": "owner", "name": "string", + "organization_display_name": "string", + "organization_icon": "string", "organization_id": "7c60d51f-b44e-4682-87d6-449835ea4de6", "organization_name": "string", "provisioner": "terraform", @@ -115,6 +117,8 @@ Status Code **200** | `» id` | string(uuid) | false | | | | `» max_port_share_level` | [codersdk.WorkspaceAgentPortShareLevel](schemas.md#codersdkworkspaceagentportsharelevel) | false | | | | `» name` | string | false | | | +| `» organization_display_name` | string | false | | | +| `» organization_icon` | string | false | | | | `» organization_id` | string(uuid) | false | | | | `» organization_name` | string(url) | false | | | | `» provisioner` | string | false | | | @@ -226,6 +230,8 @@ curl -X POST http://coder-server:8080/api/v2/organizations/{organization}/templa "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "max_port_share_level": "owner", "name": "string", + "organization_display_name": "string", + "organization_icon": "string", "organization_id": "7c60d51f-b44e-4682-87d6-449835ea4de6", "organization_name": "string", "provisioner": "terraform", @@ -366,6 +372,8 @@ curl -X GET http://coder-server:8080/api/v2/organizations/{organization}/templat "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "max_port_share_level": "owner", "name": "string", + "organization_display_name": "string", + "organization_icon": "string", "organization_id": "7c60d51f-b44e-4682-87d6-449835ea4de6", "organization_name": "string", "provisioner": "terraform", @@ -677,6 +685,8 @@ curl -X GET http://coder-server:8080/api/v2/templates \ "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "max_port_share_level": "owner", "name": "string", + "organization_display_name": "string", + "organization_icon": "string", "organization_id": "7c60d51f-b44e-4682-87d6-449835ea4de6", "organization_name": "string", "provisioner": "terraform", @@ -730,6 +740,8 @@ Status Code **200** | `» id` | string(uuid) | false | | | | `» max_port_share_level` | [codersdk.WorkspaceAgentPortShareLevel](schemas.md#codersdkworkspaceagentportsharelevel) | false | | | | `» name` | string | false | | | +| `» organization_display_name` | string | false | | | +| `» organization_icon` | string | false | | | | `» organization_id` | string(uuid) | false | | | | `» organization_name` | string(url) | false | | | | `» provisioner` | string | false | | | @@ -810,6 +822,8 @@ curl -X GET http://coder-server:8080/api/v2/templates/{template} \ "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "max_port_share_level": "owner", "name": "string", + "organization_display_name": "string", + "organization_icon": "string", "organization_id": "7c60d51f-b44e-4682-87d6-449835ea4de6", "organization_name": "string", "provisioner": "terraform", @@ -933,6 +947,8 @@ curl -X PATCH http://coder-server:8080/api/v2/templates/{template} \ "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "max_port_share_level": "owner", "name": "string", + "organization_display_name": "string", + "organization_icon": "string", "organization_id": "7c60d51f-b44e-4682-87d6-449835ea4de6", "organization_name": "string", "provisioner": "terraform", From 8cae3e332604d3175d99878f0780947403f9a2b2 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Tue, 9 Jul 2024 16:51:09 -0500 Subject: [PATCH 7/9] forgot swagger doc --- coderd/apidoc/swagger.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/coderd/apidoc/swagger.json b/coderd/apidoc/swagger.json index 03b0ba7716e2b..0c44ef0f255ed 100644 --- a/coderd/apidoc/swagger.json +++ b/coderd/apidoc/swagger.json @@ -10340,6 +10340,12 @@ "name": { "type": "string" }, + "organization_display_name": { + "type": "string" + }, + "organization_icon": { + "type": "string" + }, "organization_id": { "type": "string", "format": "uuid" From b3bd5a27afbd55253e7d09ac2b2b334ef9539d3f Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Wed, 10 Jul 2024 09:43:16 -0500 Subject: [PATCH 8/9] bump migration --- ...isplay_name.down.sql => 000224_template_display_name.down.sql} | 0 ...te_display_name.up.sql => 000224_template_display_name.up.sql} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename coderd/database/migrations/{000223_template_display_name.down.sql => 000224_template_display_name.down.sql} (100%) rename coderd/database/migrations/{000223_template_display_name.up.sql => 000224_template_display_name.up.sql} (100%) diff --git a/coderd/database/migrations/000223_template_display_name.down.sql b/coderd/database/migrations/000224_template_display_name.down.sql similarity index 100% rename from coderd/database/migrations/000223_template_display_name.down.sql rename to coderd/database/migrations/000224_template_display_name.down.sql diff --git a/coderd/database/migrations/000223_template_display_name.up.sql b/coderd/database/migrations/000224_template_display_name.up.sql similarity index 100% rename from coderd/database/migrations/000223_template_display_name.up.sql rename to coderd/database/migrations/000224_template_display_name.up.sql From 31bd3fd9a152d32c4a47e5c5e04ef2d575f28b20 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Wed, 10 Jul 2024 09:48:59 -0500 Subject: [PATCH 9/9] make gen --- docs/admin/audit-logs.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/admin/audit-logs.md b/docs/admin/audit-logs.md index f239589f9700a..40eb173cad869 100644 --- a/docs/admin/audit-logs.md +++ b/docs/admin/audit-logs.md @@ -8,26 +8,26 @@ We track the following resources: -| Resource | | -| -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| APIKey
login, logout, register, create, delete |
FieldTracked
created_attrue
expires_attrue
hashed_secretfalse
idfalse
ip_addressfalse
last_usedtrue
lifetime_secondsfalse
login_typefalse
scopefalse
token_namefalse
updated_atfalse
user_idtrue
| -| AuditOAuthConvertState
|
FieldTracked
created_attrue
expires_attrue
from_login_typetrue
to_login_typetrue
user_idtrue
| -| Group
create, write, delete |
FieldTracked
avatar_urltrue
display_nametrue
idtrue
memberstrue
nametrue
organization_idfalse
quota_allowancetrue
sourcefalse
| -| AuditableOrganizationMember
|
FieldTracked
created_attrue
organization_idtrue
rolestrue
updated_attrue
user_idtrue
usernametrue
| -| CustomRole
|
FieldTracked
created_atfalse
display_nametrue
idfalse
nametrue
org_permissionstrue
organization_idtrue
site_permissionstrue
updated_atfalse
user_permissionstrue
| -| GitSSHKey
create |
FieldTracked
created_atfalse
private_keytrue
public_keytrue
updated_atfalse
user_idtrue
| -| HealthSettings
|
FieldTracked
dismissed_healthcheckstrue
idfalse
| -| License
create, delete |
FieldTracked
exptrue
idfalse
jwtfalse
uploaded_attrue
uuidtrue
| -| NotificationsSettings
|
FieldTracked
idfalse
notifier_pausedtrue
| -| OAuth2ProviderApp
|
FieldTracked
callback_urltrue
created_atfalse
icontrue
idfalse
nametrue
updated_atfalse
| -| OAuth2ProviderAppSecret
|
FieldTracked
app_idfalse
created_atfalse
display_secretfalse
hashed_secretfalse
idfalse
last_used_atfalse
secret_prefixfalse
| -| Organization
|
FieldTracked
created_atfalse
descriptiontrue
display_nametrue
icontrue
idfalse
is_defaulttrue
nametrue
updated_attrue
| -| Template
write, delete |
FieldTracked
active_version_idtrue
activity_bumptrue
allow_user_autostarttrue
allow_user_autostoptrue
allow_user_cancel_workspace_jobstrue
autostart_block_days_of_weektrue
autostop_requirement_days_of_weektrue
autostop_requirement_weekstrue
created_atfalse
created_bytrue
created_by_avatar_urlfalse
created_by_usernamefalse
default_ttltrue
deletedfalse
deprecatedtrue
descriptiontrue
display_nametrue
failure_ttltrue
group_acltrue
icontrue
idtrue
max_port_sharing_leveltrue
nametrue
organization_idfalse
organization_namefalse
provisionertrue
require_active_versiontrue
time_til_dormanttrue
time_til_dormant_autodeletetrue
updated_atfalse
user_acltrue
| -| TemplateVersion
create, write |
FieldTracked
archivedtrue
created_atfalse
created_bytrue
created_by_avatar_urlfalse
created_by_usernamefalse
external_auth_providersfalse
idtrue
job_idfalse
messagefalse
nametrue
organization_idfalse
readmetrue
template_idtrue
updated_atfalse
| -| User
create, write, delete |
FieldTracked
avatar_urlfalse
created_atfalse
deletedtrue
emailtrue
hashed_passwordtrue
idtrue
last_seen_atfalse
login_typetrue
nametrue
quiet_hours_scheduletrue
rbac_rolestrue
statustrue
theme_preferencefalse
updated_atfalse
usernametrue
| -| Workspace
create, write, delete |
FieldTracked
automatic_updatestrue
autostart_scheduletrue
created_atfalse
deletedfalse
deleting_attrue
dormant_attrue
favoritetrue
idtrue
last_used_atfalse
nametrue
organization_idfalse
owner_idtrue
template_idtrue
ttltrue
updated_atfalse
| -| WorkspaceBuild
start, stop |
FieldTracked
build_numberfalse
created_atfalse
daily_costfalse
deadlinefalse
idfalse
initiator_by_avatar_urlfalse
initiator_by_usernamefalse
initiator_idfalse
job_idfalse
max_deadlinefalse
provisioner_statefalse
reasonfalse
template_version_idtrue
transitionfalse
updated_atfalse
workspace_idfalse
| -| WorkspaceProxy
|
FieldTracked
created_attrue
deletedfalse
derp_enabledtrue
derp_onlytrue
display_nametrue
icontrue
idtrue
nametrue
region_idtrue
token_hashed_secrettrue
updated_atfalse
urltrue
versiontrue
wildcard_hostnametrue
| +| Resource | | +| -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| APIKey
login, logout, register, create, delete |
FieldTracked
created_attrue
expires_attrue
hashed_secretfalse
idfalse
ip_addressfalse
last_usedtrue
lifetime_secondsfalse
login_typefalse
scopefalse
token_namefalse
updated_atfalse
user_idtrue
| +| AuditOAuthConvertState
|
FieldTracked
created_attrue
expires_attrue
from_login_typetrue
to_login_typetrue
user_idtrue
| +| Group
create, write, delete |
FieldTracked
avatar_urltrue
display_nametrue
idtrue
memberstrue
nametrue
organization_idfalse
quota_allowancetrue
sourcefalse
| +| AuditableOrganizationMember
|
FieldTracked
created_attrue
organization_idtrue
rolestrue
updated_attrue
user_idtrue
usernametrue
| +| CustomRole
|
FieldTracked
created_atfalse
display_nametrue
idfalse
nametrue
org_permissionstrue
organization_idtrue
site_permissionstrue
updated_atfalse
user_permissionstrue
| +| GitSSHKey
create |
FieldTracked
created_atfalse
private_keytrue
public_keytrue
updated_atfalse
user_idtrue
| +| HealthSettings
|
FieldTracked
dismissed_healthcheckstrue
idfalse
| +| License
create, delete |
FieldTracked
exptrue
idfalse
jwtfalse
uploaded_attrue
uuidtrue
| +| NotificationsSettings
|
FieldTracked
idfalse
notifier_pausedtrue
| +| OAuth2ProviderApp
|
FieldTracked
callback_urltrue
created_atfalse
icontrue
idfalse
nametrue
updated_atfalse
| +| OAuth2ProviderAppSecret
|
FieldTracked
app_idfalse
created_atfalse
display_secretfalse
hashed_secretfalse
idfalse
last_used_atfalse
secret_prefixfalse
| +| Organization
|
FieldTracked
created_atfalse
descriptiontrue
display_nametrue
icontrue
idfalse
is_defaulttrue
nametrue
updated_attrue
| +| Template
write, delete |
FieldTracked
active_version_idtrue
activity_bumptrue
allow_user_autostarttrue
allow_user_autostoptrue
allow_user_cancel_workspace_jobstrue
autostart_block_days_of_weektrue
autostop_requirement_days_of_weektrue
autostop_requirement_weekstrue
created_atfalse
created_bytrue
created_by_avatar_urlfalse
created_by_usernamefalse
default_ttltrue
deletedfalse
deprecatedtrue
descriptiontrue
display_nametrue
failure_ttltrue
group_acltrue
icontrue
idtrue
max_port_sharing_leveltrue
nametrue
organization_display_namefalse
organization_iconfalse
organization_idfalse
organization_namefalse
provisionertrue
require_active_versiontrue
time_til_dormanttrue
time_til_dormant_autodeletetrue
updated_atfalse
user_acltrue
| +| TemplateVersion
create, write |
FieldTracked
archivedtrue
created_atfalse
created_bytrue
created_by_avatar_urlfalse
created_by_usernamefalse
external_auth_providersfalse
idtrue
job_idfalse
messagefalse
nametrue
organization_idfalse
readmetrue
template_idtrue
updated_atfalse
| +| User
create, write, delete |
FieldTracked
avatar_urlfalse
created_atfalse
deletedtrue
emailtrue
hashed_passwordtrue
idtrue
last_seen_atfalse
login_typetrue
nametrue
quiet_hours_scheduletrue
rbac_rolestrue
statustrue
theme_preferencefalse
updated_atfalse
usernametrue
| +| Workspace
create, write, delete |
FieldTracked
automatic_updatestrue
autostart_scheduletrue
created_atfalse
deletedfalse
deleting_attrue
dormant_attrue
favoritetrue
idtrue
last_used_atfalse
nametrue
organization_idfalse
owner_idtrue
template_idtrue
ttltrue
updated_atfalse
| +| WorkspaceBuild
start, stop |
FieldTracked
build_numberfalse
created_atfalse
daily_costfalse
deadlinefalse
idfalse
initiator_by_avatar_urlfalse
initiator_by_usernamefalse
initiator_idfalse
job_idfalse
max_deadlinefalse
provisioner_statefalse
reasonfalse
template_version_idtrue
transitionfalse
updated_atfalse
workspace_idfalse
| +| WorkspaceProxy
|
FieldTracked
created_attrue
deletedfalse
derp_enabledtrue
derp_onlytrue
display_nametrue
icontrue
idtrue
nametrue
region_idtrue
token_hashed_secrettrue
updated_atfalse
urltrue
versiontrue
wildcard_hostnametrue
|