Skip to content

chore: return organization's display name and icon in templates #13858

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 9 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
chore: templates return organization display name and icon
  • Loading branch information
Emyrk committed Jul 10, 2024
commit ef49cd72085fb9147d08183e9b9f6c610650d290
5 changes: 4 additions & 1 deletion coderd/database/dump.sql

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

22 changes: 22 additions & 0 deletions coderd/database/migrations/000223_template_display_name.down.sql
Original file line number Diff line number Diff line change
@@ -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.';
25 changes: 25 additions & 0 deletions coderd/database/migrations/000223_template_display_name.up.sql
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that the created_by user is not visible by the caller of this? I'm thinking the case where someone is removed from an org after creating a template.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, but we decided awhile back that if you can read the template, you should also see who created it. So granting read permission on the template gives some implicit permission to reading the user's name + organization information.

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.';
3 changes: 3 additions & 0 deletions coderd/database/modelqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions coderd/database/models.go

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

20 changes: 16 additions & 4 deletions coderd/database/queries.sql.go

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