Skip to content

Commit 73a619c

Browse files
committed
refactor: use separate columns in the workspaces_expanded view for the acl actors display info
1 parent 5762ebc commit 73a619c

File tree

10 files changed

+142
-75
lines changed

10 files changed

+142
-75
lines changed

coderd/database/dump.sql

Lines changed: 9 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000403_workspaces_expanded_acl_actor_info.up.sql

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
DROP VIEW workspaces_expanded;
22

3-
-- Enrich group_acl and user_acl with the actors' display information.
3+
-- Expand more by including group_acl_display_info and
4+
-- user_acl_display_info columns with the actors' name and avatar.
45
CREATE VIEW workspaces_expanded AS
56
SELECT workspaces.id,
67
workspaces.created_at,
@@ -18,42 +19,43 @@ CREATE VIEW workspaces_expanded AS
1819
workspaces.automatic_updates,
1920
workspaces.favorite,
2021
workspaces.next_start_at,
21-
-- Enrich group_acl with group info
22+
workspaces.group_acl,
23+
workspaces.user_acl,
24+
visible_users.avatar_url AS owner_avatar_url,
25+
visible_users.username AS owner_username,
26+
visible_users.name AS owner_name,
27+
organizations.name AS organization_name,
28+
organizations.display_name AS organization_display_name,
29+
organizations.icon AS organization_icon,
30+
organizations.description AS organization_description,
31+
templates.name AS template_name,
32+
templates.display_name AS template_display_name,
33+
templates.icon AS template_icon,
34+
templates.description AS template_description,
35+
tasks.id AS task_id,
36+
-- Workspace ACL actors' display info
2237
COALESCE((
2338
SELECT jsonb_object_agg(
2439
acl.key,
25-
acl.value || jsonb_build_object(
40+
jsonb_build_object(
2641
'name', g.name,
2742
'avatar_url', COALESCE(g.avatar_url, '')
2843
)
2944
)
3045
FROM jsonb_each(workspaces.group_acl) AS acl
3146
LEFT JOIN groups g ON g.id = acl.key::uuid
32-
), '{}'::jsonb) AS group_acl,
33-
-- Enrich user_acl with user info
47+
), '{}'::jsonb) AS group_acl_display_info,
3448
COALESCE((
3549
SELECT jsonb_object_agg(
3650
acl.key,
37-
acl.value || jsonb_build_object(
51+
jsonb_build_object(
3852
'name', COALESCE(vu.name, ''),
3953
'avatar_url', COALESCE(vu.avatar_url, '')
4054
)
4155
)
4256
FROM jsonb_each(workspaces.user_acl) AS acl
4357
LEFT JOIN visible_users vu ON vu.id = acl.key::uuid
44-
), '{}'::jsonb) AS user_acl,
45-
visible_users.avatar_url AS owner_avatar_url,
46-
visible_users.username AS owner_username,
47-
visible_users.name AS owner_name,
48-
organizations.name AS organization_name,
49-
organizations.display_name AS organization_display_name,
50-
organizations.icon AS organization_icon,
51-
organizations.description AS organization_description,
52-
templates.name AS template_name,
53-
templates.display_name AS template_display_name,
54-
templates.icon AS template_icon,
55-
templates.description AS template_description,
56-
tasks.id AS task_id
58+
), '{}'::jsonb) AS user_acl_display_info
5759
FROM ((((workspaces
5860
JOIN visible_users ON ((workspaces.owner_id = visible_users.id)))
5961
JOIN organizations ON ((workspaces.organization_id = organizations.id)))

coderd/database/modelmethods.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,27 @@ func ConvertWorkspaceRows(rows []GetWorkspacesRow) ([]Workspace, error) {
692692
TaskID: r.TaskID,
693693
}
694694

695-
if err := workspaces[i].UserACL.Scan(r.UserACL); err != nil {
695+
var err error
696+
697+
err = workspaces[i].UserACL.Scan(r.UserACL)
698+
if err != nil {
696699
return nil, xerrors.Errorf("scan user ACL %q: %w", r.UserACL, err)
697700
}
698-
if err := workspaces[i].GroupACL.Scan(r.GroupACL); err != nil {
701+
err = workspaces[i].GroupACL.Scan(r.GroupACL)
702+
if err != nil {
699703
return nil, xerrors.Errorf("scan group ACL %q: %w", r.GroupACL, err)
700704
}
705+
706+
err = workspaces[i].UserACLDisplayInfo.Scan(r.UserACLDisplayInfo)
707+
if err != nil {
708+
return nil, xerrors.Errorf("scan user ACL display info %q: %w",
709+
r.UserACLDisplayInfo, err)
710+
}
711+
err = workspaces[i].GroupACLDisplayInfo.Scan(r.GroupACLDisplayInfo)
712+
if err != nil {
713+
return nil, xerrors.Errorf("scan group ACL display info %q: %w",
714+
r.GroupACLDisplayInfo, err)
715+
}
701716
}
702717

703718
return workspaces, nil

coderd/database/modelqueries.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
323323
&i.TemplateIcon,
324324
&i.TemplateDescription,
325325
&i.TaskID,
326+
&i.GroupACLDisplayInfo,
327+
&i.UserACLDisplayInfo,
326328
&i.TemplateVersionID,
327329
&i.TemplateVersionName,
328330
&i.LatestBuildCompletedAt,

coderd/database/models.go

Lines changed: 32 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)