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:
Ammar Bandukwala
2024-01-30 16:02:21 -06:00
committed by GitHub
parent aeb4112513
commit adbb025e74
44 changed files with 862 additions and 137 deletions

View File

@ -221,6 +221,27 @@ type OIDCAuthMethod struct {
IconURL string `json:"iconUrl"`
}
type UserParameter struct {
Name string `json:"name"`
Value string `json:"value"`
}
// UserAutofillParameters returns all recently used parameters for the given user.
func (c *Client) UserAutofillParameters(ctx context.Context, user string, templateID uuid.UUID) ([]UserParameter, error) {
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/users/%s/autofill-parameters?template_id=%s", user, templateID), nil)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, ReadBodyAsError(res)
}
var params []UserParameter
return params, json.NewDecoder(res.Body).Decode(&params)
}
// HasFirstUser returns whether the first user has been created.
func (c *Client) HasFirstUser(ctx context.Context) (bool, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/users/first", nil)