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');`
groupACL := orig.GroupACL
if groupACL == nil {
groupACL = database.WorkspaceACL{}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Emyrk the new version of workspaces_expanded revealed an issue in a (test) helper function update merged yesterday (by yours truly 🤕).

This hunk fixes the issue so that the tests using the helper don't break when passing in only one from the UserACL/GroupACL pair.

With the old workspace_expanded view the issue (JSON null being saved in DB instead of the default {}) wasn't surfacing, but with the new version of the view, fetching results in this error:

pq: cannot call jsonb_each on a non-object

As I said, this commit fixes the issue for tests, but it begs a bigger question: should we consider adopting 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');

so that JSON nulls never get saved by faulty Go code?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, do we need a db migration and constraint to fix it?

That would be ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If that's OK, I'll submit a separate PR when I have a little more bandwidth.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add sharing info to /workspaces endpoint

4 participants