Skip to content

Conversation

@geokat
Copy link
Contributor

@geokat geokat commented Dec 2, 2025

Similar to #19375, this one uses system permissions for fetching actual user and group data.
An implementation that doesn't do that is also buried in the commits, so it should be easy to switch to if needed.

closes: coder/internal#858

@geokat geokat force-pushed the geokat/internal-858-sharing-info-in-workspaces-response branch from f0eda46 to 9e33549 Compare December 2, 2025 01:52
@geokat geokat marked this pull request as ready for review December 2, 2025 03:45
@geokat geokat requested review from Emyrk, aslilac and jaaydenh December 2, 2025 03:46
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

Do you think we could do this all in the postgres view?

We have the view

CREATE VIEW workspaces_expanded AS

I know the ACLs are jsonb. If we add this to the view though, that would save us work downstream.

There are api endpoints in this PR that return workspaces without the shared info. I'd rather us be consistent what fields are returned when fetching a workspace.

@geokat geokat force-pushed the geokat/internal-858-sharing-info-in-workspaces-response branch from 9e33549 to 77ea00b Compare December 4, 2025 18:00
@geokat geokat requested a review from Emyrk December 4, 2025 18:34
Copy link
Member

@aslilac aslilac left a comment

Choose a reason for hiding this comment

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

the go code all looks largely fine but I'd love to have a second pair of eyes on the sql view because it's quite involved.

@geokat geokat force-pushed the geokat/internal-858-sharing-info-in-workspaces-response branch from a73d47f to 3777de0 Compare December 10, 2025 20:32
…r/group acl in workspace test table

Because such nulls break tests fetching the new workspace_expanded
view, with the following error:

`cannot call jsonb_each on a non-object`

(null is a non-object, that's why we use `{}`as default).

This begs the question if we want to adopt check constraints for JSONB
columns across our schema, e.g.:

`ALTER TABLE workspaces
   ADD CONSTRAINT group_acl_is_object CHECK (jsonb_typeof(group_acl) = 'object');`
Copy link
Member

@aslilac aslilac left a comment

Choose a reason for hiding this comment

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

sorry, noticed something on a second look that I think we should address

return json.Marshal(t)
}

type WorkspaceACLEntry struct {
Copy link
Member

Choose a reason for hiding this comment

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

this type is used by the UpdateWorkspaceACLByID query. I don't think we want to add these extra fields here, because they're not valid to set when calling that query.

in the RFC this used a type called SharedWorkspaceActor https://www.notion.so/coderhq/Shared-Workspaces-214d579be592803697cdef7a662d35b5?source=copy_link#224d579be59280688617ed6001e46377

Role WorkspaceRole `json:"role" enums:"admin,use"`
}

type SharedWorkspaceActor struct {
Copy link
Member

Choose a reason for hiding this comment

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

ah, yeah, we do define that here still. can we avoid polluting the db type and either convert to this earlier or use a different type as the intermediate?

Copy link
Contributor Author

@geokat geokat Dec 12, 2025

Choose a reason for hiding this comment

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

Good point, thanks! Pushed an update that reads the ACL actors' display info as separate columns on the workspaces_expanded view.

The query behind this version of the view is slightly (up to 20%) faster, likely because it doesn't need to parse saved ACL JSON (just extracts the keys).

old version
new version

The downside is more data on the wire and extra boilerplate.

@geokat geokat requested a review from aslilac December 12, 2025 06:10
@geokat geokat force-pushed the geokat/internal-858-sharing-info-in-workspaces-response branch 2 times, most recently from 629e5b4 to 73a619c Compare December 12, 2025 15:16
@geokat geokat force-pushed the geokat/internal-858-sharing-info-in-workspaces-response branch from 73a619c to a50b597 Compare December 12, 2025 16:37
Copy link
Member

@aslilac aslilac left a comment

Choose a reason for hiding this comment

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

thanks!

@geokat geokat requested a review from Emyrk December 12, 2025 18:30
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

The split into 2 columns is fine. Not ideal, but if it's more efficient, than that is a win.

Comment on lines +36 to +58
-- Workspace ACL actors' display info
COALESCE((
SELECT jsonb_object_agg(
acl.key,
jsonb_build_object(
'name', COALESCE(g.name, ''),
'avatar_url', COALESCE(g.avatar_url, '')
)
)
FROM jsonb_each(workspaces.group_acl) AS acl
LEFT JOIN groups g ON g.id = acl.key::uuid
), '{}'::jsonb) AS group_acl_display_info,
COALESCE((
SELECT jsonb_object_agg(
acl.key,
jsonb_build_object(
'name', COALESCE(vu.name, ''),
'avatar_url', COALESCE(vu.avatar_url, '')
)
)
FROM jsonb_each(workspaces.user_acl) AS acl
LEFT JOIN visible_users vu ON vu.id = acl.key::uuid
), '{}'::jsonb) AS user_acl_display_info
Copy link
Member

Choose a reason for hiding this comment

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

Interesting this saved some time. Although I'm sus with the planner now 😄

Comment on lines +119 to +122
type WorkspaceACLDisplayInfo map[string]struct {
Name string `json:"name"`
AvatarURL string `json:"avatar_url"`
}
Copy link
Member

Choose a reason for hiding this comment

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

It is unfortunate we cannot type the key as a uuid.UUID. The rbac stuff does not enforce that type though, so string is safer.

Can we just add a comment to that effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@geokat geokat merged commit 103967e into main Dec 15, 2025
35 checks passed
@geokat geokat deleted the geokat/internal-858-sharing-info-in-workspaces-response branch December 15, 2025 16:42
@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add sharing info to /workspaces endpoint

4 participants