MCPcopy Index your code
hub / github.com/coder/coder / userAutofillParameters

Method userAutofillParameters

coderd/users.go:788–826  ·  view source on GitHub ↗

Returns recent build parameters for the signed-in user. @Summary Get autofill build parameters for user @ID get-autofill-build-parameters-for-user @Security CoderSessionToken @Produce json @Tags Users @Param user path string true "User ID, username, or me" @Param template_id query string true "Temp

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

786// @Success 200 {array} codersdk.UserParameter
787// @Router /api/v2/users/{user}/autofill-parameters [get]
788func (api *API) userAutofillParameters(rw http.ResponseWriter, r *http.Request) {
789 user := httpmw.UserParam(r)
790
791 p := httpapi.NewQueryParamParser().RequiredNotEmpty("template_id")
792 templateID := p.UUID(r.URL.Query(), uuid.UUID{}, "template_id")
793 p.ErrorExcessParams(r.URL.Query())
794 if len(p.Errors) > 0 {
795 httpapi.Write(r.Context(), rw, http.StatusBadRequest, codersdk.Response{
796 Message: "Invalid query parameters.",
797 Validations: p.Errors,
798 })
799 return
800 }
801
802 params, err := api.Database.GetUserWorkspaceBuildParameters(
803 r.Context(),
804 database.GetUserWorkspaceBuildParametersParams{
805 OwnerID: user.ID,
806 TemplateID: templateID,
807 },
808 )
809 if err != nil && !errors.Is(err, sql.ErrNoRows) {
810 httpapi.Write(r.Context(), rw, http.StatusInternalServerError, codersdk.Response{
811 Message: "Internal error fetching user's parameters.",
812 Detail: err.Error(),
813 })
814 return
815 }
816
817 sdkParams := []codersdk.UserParameter{}
818 for _, param := range params {
819 sdkParams = append(sdkParams, codersdk.UserParameter{
820 Name: param.Name,
821 Value: param.Value,
822 })
823 }
824
825 httpapi.Write(r.Context(), rw, http.StatusOK, sdkParams)
826}
827
828// Returns the user's login type. This only works if the api key for authorization
829// and the requested user match. Eg: 'me'

Callers

nothing calls this directly

Calls 10

UserParamFunction · 0.92
NewQueryParamParserFunction · 0.92
WriteFunction · 0.92
RequiredNotEmptyMethod · 0.80
UUIDMethod · 0.80
ErrorExcessParamsMethod · 0.80
ContextMethod · 0.65
IsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected