Skip to content

Commit 7bb3e0d

Browse files
authored
chore: return organization's display name and icon in templates (coder#13858)
* chore: templates return organization display name and icon * templates api response includes organization display name and icon
1 parent bf392ff commit 7bb3e0d

File tree

18 files changed

+140
-34
lines changed

18 files changed

+140
-34
lines changed

coderd/apidoc/docs.go

Lines changed: 6 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: 6 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ func (q *FakeQuerier) templateWithNameNoLock(tpl database.TemplateTable) databas
558558
withNames.CreatedByUsername = user.Username
559559
withNames.CreatedByAvatarURL = user.AvatarURL
560560
withNames.OrganizationName = org.Name
561+
withNames.OrganizationDisplayName = org.DisplayName
562+
withNames.OrganizationIcon = org.Icon
561563
return withNames
562564
}
563565

coderd/database/dump.sql

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
DROP VIEW template_with_names;
2+
3+
CREATE VIEW
4+
template_with_names
5+
AS
6+
SELECT
7+
templates.*,
8+
coalesce(visible_users.avatar_url, '') AS created_by_avatar_url,
9+
coalesce(visible_users.username, '') AS created_by_username,
10+
coalesce(organizations.name, '') AS organization_name
11+
FROM
12+
templates
13+
LEFT JOIN
14+
visible_users
15+
ON
16+
templates.created_by = visible_users.id
17+
LEFT JOIN
18+
organizations
19+
ON templates.organization_id = organizations.id
20+
;
21+
22+
COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- Update the template_with_names view by recreating it.
2+
DROP VIEW template_with_names;
3+
CREATE VIEW
4+
template_with_names
5+
AS
6+
SELECT
7+
templates.*,
8+
coalesce(visible_users.avatar_url, '') AS created_by_avatar_url,
9+
coalesce(visible_users.username, '') AS created_by_username,
10+
coalesce(organizations.name, '') AS organization_name,
11+
coalesce(organizations.display_name, '') AS organization_display_name,
12+
coalesce(organizations.icon, '') AS organization_icon
13+
FROM
14+
templates
15+
LEFT JOIN
16+
visible_users
17+
ON
18+
templates.created_by = visible_users.id
19+
LEFT JOIN
20+
organizations
21+
ON templates.organization_id = organizations.id
22+
;
23+
24+
COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.';

coderd/database/modelqueries.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate
117117
&i.CreatedByAvatarURL,
118118
&i.CreatedByUsername,
119119
&i.OrganizationName,
120+
&i.OrganizationDisplayName,
121+
&i.OrganizationIcon,
120122
); err != nil {
121123
return nil, err
122124
}

coderd/database/models.go

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

coderd/templates.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,8 @@ func (api *API) convertTemplate(
886886
UpdatedAt: template.UpdatedAt,
887887
OrganizationID: template.OrganizationID,
888888
OrganizationName: template.OrganizationName,
889+
OrganizationDisplayName: template.OrganizationDisplayName,
890+
OrganizationIcon: template.OrganizationIcon,
889891
Name: template.Name,
890892
DisplayName: template.DisplayName,
891893
Provisioner: codersdk.ProvisionerType(template.Provisioner),

coderd/templates_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ func TestTemplatesByOrganization(t *testing.T) {
451451
for _, tmpl := range templates {
452452
require.Equal(t, tmpl.OrganizationID, user.OrganizationID, "organization ID")
453453
require.Equal(t, tmpl.OrganizationName, org.Name, "organization name")
454+
require.Equal(t, tmpl.OrganizationDisplayName, org.DisplayName, "organization display name")
455+
require.Equal(t, tmpl.OrganizationIcon, org.Icon, "organization display name")
454456
}
455457
})
456458
t.Run("MultipleOrganizations", func(t *testing.T) {

codersdk/templates.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ import (
1515
// Template is the JSON representation of a Coder template. This type matches the
1616
// database object for now, but is abstracted for ease of change later on.
1717
type Template struct {
18-
ID uuid.UUID `json:"id" format:"uuid"`
19-
CreatedAt time.Time `json:"created_at" format:"date-time"`
20-
UpdatedAt time.Time `json:"updated_at" format:"date-time"`
21-
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
22-
OrganizationName string `json:"organization_name" format:"url"`
23-
Name string `json:"name"`
24-
DisplayName string `json:"display_name"`
25-
Provisioner ProvisionerType `json:"provisioner" enums:"terraform"`
26-
ActiveVersionID uuid.UUID `json:"active_version_id" format:"uuid"`
18+
ID uuid.UUID `json:"id" format:"uuid"`
19+
CreatedAt time.Time `json:"created_at" format:"date-time"`
20+
UpdatedAt time.Time `json:"updated_at" format:"date-time"`
21+
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
22+
OrganizationName string `json:"organization_name" format:"url"`
23+
OrganizationDisplayName string `json:"organization_display_name"`
24+
OrganizationIcon string `json:"organization_icon"`
25+
Name string `json:"name"`
26+
DisplayName string `json:"display_name"`
27+
Provisioner ProvisionerType `json:"provisioner" enums:"terraform"`
28+
ActiveVersionID uuid.UUID `json:"active_version_id" format:"uuid"`
2729
// ActiveUserCount is set to -1 when loading.
2830
ActiveUserCount int `json:"active_user_count"`
2931
BuildTimeStats TemplateBuildTimeStats `json:"build_time_stats"`

0 commit comments

Comments
 (0)