mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
feat: add user-level parameter autofill (#11731)
This PR solves #10478 by auto-filling previously used template values in create and update workspace flows. I decided against explicit user values in settings for these reasons: * Autofill is far easier to implement * Users benefit from autofill _by default_ — we don't need to teach them new concepts * If we decide that autofill creates more harm than good, we can remove it without breaking compatibility
This commit is contained in:
@ -3797,6 +3797,65 @@ func (q *FakeQuerier) GetUserLinksByUserID(_ context.Context, userID uuid.UUID)
|
||||
return uls, nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) GetUserWorkspaceBuildParameters(_ context.Context, params database.GetUserWorkspaceBuildParametersParams) ([]database.GetUserWorkspaceBuildParametersRow, error) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
userWorkspaceIDs := make(map[uuid.UUID]struct{})
|
||||
for _, ws := range q.workspaces {
|
||||
if ws.OwnerID != params.OwnerID {
|
||||
continue
|
||||
}
|
||||
if ws.TemplateID != params.TemplateID {
|
||||
continue
|
||||
}
|
||||
userWorkspaceIDs[ws.ID] = struct{}{}
|
||||
}
|
||||
|
||||
userWorkspaceBuilds := make(map[uuid.UUID]struct{})
|
||||
for _, wb := range q.workspaceBuilds {
|
||||
if _, ok := userWorkspaceIDs[wb.WorkspaceID]; !ok {
|
||||
continue
|
||||
}
|
||||
userWorkspaceBuilds[wb.ID] = struct{}{}
|
||||
}
|
||||
|
||||
templateVersions := make(map[uuid.UUID]struct{})
|
||||
for _, tv := range q.templateVersions {
|
||||
if tv.TemplateID.UUID != params.TemplateID {
|
||||
continue
|
||||
}
|
||||
templateVersions[tv.ID] = struct{}{}
|
||||
}
|
||||
|
||||
tvps := make(map[string]struct{})
|
||||
for _, tvp := range q.templateVersionParameters {
|
||||
if _, ok := templateVersions[tvp.TemplateVersionID]; !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := tvps[tvp.Name]; !ok && !tvp.Ephemeral {
|
||||
tvps[tvp.Name] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
userWorkspaceBuildParameters := make(map[string]database.GetUserWorkspaceBuildParametersRow)
|
||||
for _, wbp := range q.workspaceBuildParameters {
|
||||
if _, ok := userWorkspaceBuilds[wbp.WorkspaceBuildID]; !ok {
|
||||
continue
|
||||
}
|
||||
if _, ok := tvps[wbp.Name]; !ok {
|
||||
continue
|
||||
}
|
||||
userWorkspaceBuildParameters[wbp.Name] = database.GetUserWorkspaceBuildParametersRow{
|
||||
Name: wbp.Name,
|
||||
Value: wbp.Value,
|
||||
}
|
||||
}
|
||||
|
||||
return maps.Values(userWorkspaceBuildParameters), nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) GetUsers(_ context.Context, params database.GetUsersParams) ([]database.GetUsersRow, error) {
|
||||
if err := validateDatabaseType(params); err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user