Skip to content

refactor: consolidate template and workspace acl validation #19192

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 16 commits into from
Aug 7, 2025

Conversation

aslilac
Copy link
Member

@aslilac aslilac commented Aug 6, 2025

  • Adds ValidateUserIDs query and ValidateGroupIDs queries
    • I know for groups I probably could've used GetGroups, but that has a join in it and would send more data over the wire. Plus it's just nice for these two queries to have parity and there isn't a good equivalent for users already. I hope we can find more places that these will be useful.
    • Also also I looked at the EXPLAIN and this one should be faster (tho not exactly fast, it could certainly be optimized more)
  • Introduces an ACLUpdateValidator interface that lets us create little adapters type for resources that implement an /acl [patch] endpoint like templates and workspaces. It handles validating UUIDs, validating role names, and ensuring that the IDs given actually correspond to IDs in the database.
  • Updates the existing endpoints to use this new interface

@aslilac
Copy link
Member Author

aslilac commented Aug 6, 2025

I think this should finally address all your feedback on the first PR (except for the addition of an "update ACL" verb). sorry for the delay!

@aslilac
Copy link
Member Author

aslilac commented Aug 6, 2025

also do you know how I can get sqlc to use the right name for this argument so the linters will quit yelling at me

jk, I just realized it was only yelling about a file that I can edit, not the fully generated files

@aslilac aslilac requested a review from Emyrk August 6, 2025 22:40
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.

I would like us to test sending in deleted users to the Validate. Idk if we should auto delete or what.

Can also make an issue and follow up 👍

Comment on lines +14 to +26
type UpdateValidator[Role codersdk.WorkspaceRole | codersdk.TemplateRole] interface {
// Users should return a map from user UUIDs (as strings) to the role they
// are being assigned. Additionally, it should return a string that will be
// used as the field name for the ValidationErrors returned from Validate.
Users() (map[string]Role, string)
// Groups should return a map from group UUIDs (as strings) to the role they
// are being assigned. Additionally, it should return a string that will be
// used as the field name for the ValidationErrors returned from Validate.
Groups() (map[string]Role, string)
// ValidateRole should return an error that will be used in the
// ValidationError if the role is invalid for the corresponding resource type.
ValidateRole(role Role) error
}
Copy link
Member

Choose a reason for hiding this comment

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

❤️

@aslilac
Copy link
Member Author

aslilac commented Aug 7, 2025

I tested a deleted user in one of the template tests at least:

deletedUser.ID.String(): codersdk.TemplateRoleDeleted,

I'm working on another pr right now to add the other workspace ACL endpoints and a bunch of tests for all of them

@aslilac aslilac merged commit 26458cd into main Aug 7, 2025
31 checks passed
@aslilac aslilac deleted the lilac/acl-update-validator branch August 7, 2025 16:15
@github-actions github-actions bot locked and limited conversation to collaborators Aug 7, 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.

2 participants