Skip to content

feat: add workspace sharing page #19107

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 24 commits into from
Jul 31, 2025
Merged

feat: add workspace sharing page #19107

merged 24 commits into from
Jul 31, 2025

Conversation

aslilac
Copy link
Member

@aslilac aslilac commented Jul 31, 2025

...with a "Share with Kirby" button!

That was in the RFC right?

@aslilac aslilac requested a review from Emyrk as a code owner July 31, 2025 00:19
return w.WorkspaceTable(), nil
}

return fetchAndExec(q.log, q.auth, policy.ActionCreate, fetch, q.db.UpdateWorkspaceACLByID)(ctx, arg)
Copy link
Member

Choose a reason for hiding this comment

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

We can add a new verb to account for this, and not overload create.

Comment on lines +2507 to +2512
// This could get slow if we get a ton of group perm updates.
_, err = db.GetGroupByID(ctx, id)
if err != nil {
validErrs = append(validErrs, codersdk.ValidationError{Field: field, Detail: fmt.Sprintf("Failed to find resource with ID %q: %v", idStr, err.Error())})
continue
}
Copy link
Member

Choose a reason for hiding this comment

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

Can use GetGroups to batch the request of all ids at once.

	db.GetGroups(ctx, database.GetGroupsParams{
		GroupIds:       []uuid.UUID{...},
	})

Comment on lines +2075 to +2081
validErrs := validateWorkspaceACLPerms(ctx, api.Database, req.UserRoles, "user_roles")
validErrs = append(validErrs, validateWorkspaceACLPerms(
ctx,
api.Database,
req.GroupRoles,
"group_roles",
)...)
Copy link
Member

Choose a reason for hiding this comment

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

Might want user_roles and group_roles to be a constant if we are using them as args 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

we could even use reflect to actually read the struct tags

Comment on lines +2481 to +2519
func validateWorkspaceACLPerms(ctx context.Context, db database.Store, perms map[string]codersdk.WorkspaceRole, field string) []codersdk.ValidationError {
// nolint:gocritic // Validate requires full read access to users and groups
ctx = dbauthz.AsSystemRestricted(ctx)
var validErrs []codersdk.ValidationError
for idStr, role := range perms {
if err := validateWorkspaceRole(role); err != nil {
validErrs = append(validErrs, codersdk.ValidationError{Field: field, Detail: err.Error()})
continue
}

id, err := uuid.Parse(idStr)
if err != nil {
validErrs = append(validErrs, codersdk.ValidationError{Field: field, Detail: idStr + "is not a valid UUID."})
continue
}

switch field {
case "user_roles":
// TODO(lilac): put this back after Kirby button shenanigans are over
// This could get slow if we get a ton of user perm updates.
// _, err = db.GetUserByID(ctx, id)
// if err != nil {
// validErrs = append(validErrs, codersdk.ValidationError{Field: field, Detail: fmt.Sprintf("Failed to find resource with ID %q: %v", idStr, err.Error())})
// continue
// }
case "group_roles":
// This could get slow if we get a ton of group perm updates.
_, err = db.GetGroupByID(ctx, id)
if err != nil {
validErrs = append(validErrs, codersdk.ValidationError{Field: field, Detail: fmt.Sprintf("Failed to find resource with ID %q: %v", idStr, err.Error())})
continue
}
default:
validErrs = append(validErrs, codersdk.ValidationError{Field: field, Detail: "invalid field"})
}
}

return validErrs
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's merge this with the template ACL one. Pass in the func like validateWorkspaceRole and validateTemplateRole.

@stirby
Copy link
Collaborator

stirby commented Jul 31, 2025

Adding my stamp of responsibility here. This is purely for a demo and some if not all of these changes will be reverted soon.

This PR will not be released.

@Emyrk
Copy link
Member

Emyrk commented Jul 31, 2025

This PR is going to be reverted after a demo on dev.coder.com. It is being demonstrated in a product demo to introduce Workspace Sharing among another set of demos on the same deployment.

The feature is gated on an experiment flag, so has no effect in any existing deployment. None of this code is reachable without the unsafe experiment specifically opted into.

@aslilac aslilac enabled auto-merge (squash) July 31, 2025 15:04
@aslilac aslilac merged commit 1cffd11 into main Jul 31, 2025
34 of 36 checks passed
@aslilac aslilac deleted the lilac/kirby-button branch July 31, 2025 15:05
@github-actions github-actions bot locked and limited conversation to collaborators Jul 31, 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.

3 participants